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 |
| 54 | // - JSRegExp |
| 55 | // - JSFunction |
| 56 | // - GlobalObject |
| 57 | // - JSGlobalObject |
| 58 | // - JSBuiltinsObject |
| 59 | // - JSGlobalProxy |
| 60 | // - JSValue |
| 61 | // - JSMessageObject |
| 62 | // - JSProxy |
| 63 | // - JSFunctionProxy |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 64 | // - ByteArray |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 65 | // - ExternalArray |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 66 | // - ExternalPixelArray |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 67 | // - ExternalByteArray |
| 68 | // - ExternalUnsignedByteArray |
| 69 | // - ExternalShortArray |
| 70 | // - ExternalUnsignedShortArray |
| 71 | // - ExternalIntArray |
| 72 | // - ExternalUnsignedIntArray |
| 73 | // - ExternalFloatArray |
| 74 | // - FixedArray |
| 75 | // - DescriptorArray |
| 76 | // - HashTable |
| 77 | // - Dictionary |
| 78 | // - SymbolTable |
| 79 | // - CompilationCacheTable |
| 80 | // - CodeCacheHashTable |
| 81 | // - MapCache |
| 82 | // - Context |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 83 | // - JSFunctionResultCache |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 84 | // - SerializedScopeInfo |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 85 | // - String |
| 86 | // - SeqString |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 87 | // - SeqAsciiString |
| 88 | // - SeqTwoByteString |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 89 | // - ConsString |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 90 | // - ExternalString |
| 91 | // - ExternalAsciiString |
| 92 | // - ExternalTwoByteString |
| 93 | // - HeapNumber |
| 94 | // - Code |
| 95 | // - Map |
| 96 | // - Oddball |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 97 | // - Foreign |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 98 | // - SharedFunctionInfo |
| 99 | // - Struct |
| 100 | // - AccessorInfo |
| 101 | // - AccessCheckInfo |
| 102 | // - InterceptorInfo |
| 103 | // - CallHandlerInfo |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 104 | // - TemplateInfo |
| 105 | // - FunctionTemplateInfo |
| 106 | // - ObjectTemplateInfo |
| 107 | // - Script |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 108 | // - SignatureInfo |
| 109 | // - TypeSwitchInfo |
| 110 | // - DebugInfo |
| 111 | // - BreakPointInfo |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 112 | // - CodeCache |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 113 | // |
| 114 | // Formats of Object*: |
| 115 | // Smi: [31 bit signed int] 0 |
| 116 | // HeapObject: [32 bit direct pointer] (4 byte aligned) | 01 |
| 117 | // Failure: [30 bit signed int] 11 |
| 118 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 119 | // Ecma-262 3rd 8.6.1 |
| 120 | enum PropertyAttributes { |
| 121 | NONE = v8::None, |
| 122 | READ_ONLY = v8::ReadOnly, |
| 123 | DONT_ENUM = v8::DontEnum, |
| 124 | DONT_DELETE = v8::DontDelete, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 125 | 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] | 126 | // ABSENT can never be stored in or returned from a descriptor's attributes |
| 127 | // bitfield. It is only used as a return value meaning the attributes of |
| 128 | // a non-existent property. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 129 | }; |
| 130 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 131 | namespace v8 { |
| 132 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 133 | |
| 134 | |
| 135 | // PropertyDetails captures type and attributes for a property. |
| 136 | // They are used both in property dictionaries and instance descriptors. |
| 137 | class PropertyDetails BASE_EMBEDDED { |
| 138 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 139 | PropertyDetails(PropertyAttributes attributes, |
| 140 | PropertyType type, |
| 141 | int index = 0) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 142 | ASSERT(type != EXTERNAL_ARRAY_TRANSITION); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 143 | ASSERT(TypeField::is_valid(type)); |
| 144 | ASSERT(AttributesField::is_valid(attributes)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 145 | ASSERT(StorageField::is_valid(index)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 146 | |
| 147 | value_ = TypeField::encode(type) |
| 148 | | AttributesField::encode(attributes) |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 149 | | StorageField::encode(index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 150 | |
| 151 | ASSERT(type == this->type()); |
| 152 | ASSERT(attributes == this->attributes()); |
| 153 | ASSERT(index == this->index()); |
| 154 | } |
| 155 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 156 | PropertyDetails(PropertyAttributes attributes, |
| 157 | PropertyType type, |
| 158 | ExternalArrayType array_type) { |
| 159 | ASSERT(type == EXTERNAL_ARRAY_TRANSITION); |
| 160 | ASSERT(TypeField::is_valid(type)); |
| 161 | ASSERT(AttributesField::is_valid(attributes)); |
| 162 | ASSERT(StorageField::is_valid(static_cast<int>(array_type))); |
| 163 | |
| 164 | value_ = TypeField::encode(type) |
| 165 | | AttributesField::encode(attributes) |
| 166 | | StorageField::encode(static_cast<int>(array_type)); |
| 167 | |
| 168 | ASSERT(type == this->type()); |
| 169 | ASSERT(attributes == this->attributes()); |
| 170 | ASSERT(array_type == this->array_type()); |
| 171 | } |
| 172 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 173 | // Conversion for storing details as Object*. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 174 | explicit inline PropertyDetails(Smi* smi); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 175 | inline Smi* AsSmi(); |
| 176 | |
| 177 | PropertyType type() { return TypeField::decode(value_); } |
| 178 | |
| 179 | bool IsTransition() { |
| 180 | PropertyType t = type(); |
| 181 | ASSERT(t != INTERCEPTOR); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 182 | return t == MAP_TRANSITION || t == CONSTANT_TRANSITION || |
| 183 | t == EXTERNAL_ARRAY_TRANSITION; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 184 | } |
| 185 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 186 | bool IsProperty() { |
| 187 | return type() < FIRST_PHANTOM_PROPERTY_TYPE; |
| 188 | } |
| 189 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 190 | PropertyAttributes attributes() { return AttributesField::decode(value_); } |
| 191 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 192 | int index() { return StorageField::decode(value_); } |
| 193 | |
| 194 | ExternalArrayType array_type() { |
| 195 | ASSERT(type() == EXTERNAL_ARRAY_TRANSITION); |
| 196 | return static_cast<ExternalArrayType>(StorageField::decode(value_)); |
| 197 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 198 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 199 | inline PropertyDetails AsDeleted(); |
| 200 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 201 | static bool IsValidIndex(int index) { |
| 202 | return StorageField::is_valid(index); |
| 203 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 204 | |
| 205 | bool IsReadOnly() { return (attributes() & READ_ONLY) != 0; } |
| 206 | bool IsDontDelete() { return (attributes() & DONT_DELETE) != 0; } |
| 207 | bool IsDontEnum() { return (attributes() & DONT_ENUM) != 0; } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 208 | bool IsDeleted() { return DeletedField::decode(value_) != 0;} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 209 | |
| 210 | // Bit fields in value_ (type, shift, size). Must be public so the |
| 211 | // constants can be embedded in generated code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 212 | class TypeField: public BitField<PropertyType, 0, 4> {}; |
| 213 | class AttributesField: public BitField<PropertyAttributes, 4, 3> {}; |
| 214 | class DeletedField: public BitField<uint32_t, 7, 1> {}; |
| 215 | class StorageField: public BitField<uint32_t, 8, 32-8> {}; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 216 | |
| 217 | static const int kInitialIndex = 1; |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 218 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 219 | private: |
| 220 | uint32_t value_; |
| 221 | }; |
| 222 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 223 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 224 | // Setter that skips the write barrier if mode is SKIP_WRITE_BARRIER. |
| 225 | enum WriteBarrierMode { SKIP_WRITE_BARRIER, UPDATE_WRITE_BARRIER }; |
| 226 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 227 | |
| 228 | // PropertyNormalizationMode is used to specify whether to keep |
| 229 | // inobject properties when normalizing properties of a JSObject. |
| 230 | enum PropertyNormalizationMode { |
| 231 | CLEAR_INOBJECT_PROPERTIES, |
| 232 | KEEP_INOBJECT_PROPERTIES |
| 233 | }; |
| 234 | |
| 235 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 236 | // NormalizedMapSharingMode is used to specify whether a map may be shared |
| 237 | // by different objects with normalized properties. |
| 238 | enum NormalizedMapSharingMode { |
| 239 | UNIQUE_NORMALIZED_MAP, |
| 240 | SHARED_NORMALIZED_MAP |
| 241 | }; |
| 242 | |
| 243 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 244 | // Instance size sentinel for objects of variable size. |
| 245 | static const int kVariableSizeSentinel = 0; |
| 246 | |
| 247 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 248 | // All Maps have a field instance_type containing a InstanceType. |
| 249 | // It describes the type of the instances. |
| 250 | // |
| 251 | // As an example, a JavaScript object is a heap object and its map |
| 252 | // instance_type is JS_OBJECT_TYPE. |
| 253 | // |
| 254 | // The names of the string instance types are intended to systematically |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 255 | // mirror their encoding in the instance_type field of the map. The default |
| 256 | // encoding is considered TWO_BYTE. It is not mentioned in the name. ASCII |
| 257 | // encoding is mentioned explicitly in the name. Likewise, the default |
| 258 | // representation is considered sequential. It is not mentioned in the |
| 259 | // name. The other representations (eg, CONS, EXTERNAL) are explicitly |
| 260 | // mentioned. Finally, the string is either a SYMBOL_TYPE (if it is a |
| 261 | // symbol) or a STRING_TYPE (if it is not a symbol). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 262 | // |
| 263 | // NOTE: The following things are some that depend on the string types having |
| 264 | // instance_types that are less than those of all other types: |
| 265 | // HeapObject::Size, HeapObject::IterateBody, the typeof operator, and |
| 266 | // Object::IsString. |
| 267 | // |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 268 | // NOTE: Everything following JS_VALUE_TYPE is considered a |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 269 | // JSObject for GC purposes. The first four entries here have typeof |
| 270 | // 'object', whereas JS_FUNCTION_TYPE has typeof 'function'. |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 271 | #define INSTANCE_TYPE_LIST_ALL(V) \ |
| 272 | V(SYMBOL_TYPE) \ |
| 273 | V(ASCII_SYMBOL_TYPE) \ |
| 274 | V(CONS_SYMBOL_TYPE) \ |
| 275 | V(CONS_ASCII_SYMBOL_TYPE) \ |
| 276 | V(EXTERNAL_SYMBOL_TYPE) \ |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 277 | V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 278 | V(EXTERNAL_ASCII_SYMBOL_TYPE) \ |
| 279 | V(STRING_TYPE) \ |
| 280 | V(ASCII_STRING_TYPE) \ |
| 281 | V(CONS_STRING_TYPE) \ |
| 282 | V(CONS_ASCII_STRING_TYPE) \ |
| 283 | V(EXTERNAL_STRING_TYPE) \ |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 284 | V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 285 | V(EXTERNAL_ASCII_STRING_TYPE) \ |
| 286 | V(PRIVATE_EXTERNAL_ASCII_STRING_TYPE) \ |
| 287 | \ |
| 288 | V(MAP_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 289 | V(CODE_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 290 | V(ODDBALL_TYPE) \ |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 291 | V(JS_GLOBAL_PROPERTY_CELL_TYPE) \ |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 292 | \ |
| 293 | V(HEAP_NUMBER_TYPE) \ |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 294 | V(FOREIGN_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 295 | V(BYTE_ARRAY_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 296 | /* Note: the order of these external array */ \ |
| 297 | /* types is relied upon in */ \ |
| 298 | /* Object::IsExternalArray(). */ \ |
| 299 | V(EXTERNAL_BYTE_ARRAY_TYPE) \ |
| 300 | V(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE) \ |
| 301 | V(EXTERNAL_SHORT_ARRAY_TYPE) \ |
| 302 | V(EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE) \ |
| 303 | V(EXTERNAL_INT_ARRAY_TYPE) \ |
| 304 | V(EXTERNAL_UNSIGNED_INT_ARRAY_TYPE) \ |
| 305 | V(EXTERNAL_FLOAT_ARRAY_TYPE) \ |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 306 | V(EXTERNAL_PIXEL_ARRAY_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 307 | V(FILLER_TYPE) \ |
| 308 | \ |
| 309 | V(ACCESSOR_INFO_TYPE) \ |
| 310 | V(ACCESS_CHECK_INFO_TYPE) \ |
| 311 | V(INTERCEPTOR_INFO_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 312 | V(CALL_HANDLER_INFO_TYPE) \ |
| 313 | V(FUNCTION_TEMPLATE_INFO_TYPE) \ |
| 314 | V(OBJECT_TEMPLATE_INFO_TYPE) \ |
| 315 | V(SIGNATURE_INFO_TYPE) \ |
| 316 | V(TYPE_SWITCH_INFO_TYPE) \ |
| 317 | V(SCRIPT_TYPE) \ |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 318 | V(CODE_CACHE_TYPE) \ |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 319 | V(POLYMORPHIC_CODE_CACHE_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 320 | \ |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 321 | V(FIXED_ARRAY_TYPE) \ |
| 322 | V(SHARED_FUNCTION_INFO_TYPE) \ |
| 323 | \ |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 324 | V(JS_MESSAGE_OBJECT_TYPE) \ |
| 325 | \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 326 | V(JS_VALUE_TYPE) \ |
| 327 | V(JS_OBJECT_TYPE) \ |
| 328 | V(JS_CONTEXT_EXTENSION_OBJECT_TYPE) \ |
| 329 | V(JS_GLOBAL_OBJECT_TYPE) \ |
| 330 | V(JS_BUILTINS_OBJECT_TYPE) \ |
| 331 | V(JS_GLOBAL_PROXY_TYPE) \ |
| 332 | V(JS_ARRAY_TYPE) \ |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 333 | V(JS_PROXY_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 334 | V(JS_REGEXP_TYPE) \ |
| 335 | \ |
| 336 | V(JS_FUNCTION_TYPE) \ |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 337 | V(JS_FUNCTION_PROXY_TYPE) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 338 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 339 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 340 | #define INSTANCE_TYPE_LIST_DEBUGGER(V) \ |
| 341 | V(DEBUG_INFO_TYPE) \ |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 342 | V(BREAK_POINT_INFO_TYPE) |
| 343 | #else |
| 344 | #define INSTANCE_TYPE_LIST_DEBUGGER(V) |
| 345 | #endif |
| 346 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 347 | #define INSTANCE_TYPE_LIST(V) \ |
| 348 | INSTANCE_TYPE_LIST_ALL(V) \ |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 349 | INSTANCE_TYPE_LIST_DEBUGGER(V) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 350 | |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 351 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 352 | // Since string types are not consecutive, this macro is used to |
| 353 | // iterate over them. |
| 354 | #define STRING_TYPE_LIST(V) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 355 | V(SYMBOL_TYPE, \ |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 356 | kVariableSizeSentinel, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 357 | symbol, \ |
| 358 | Symbol) \ |
| 359 | V(ASCII_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 | ascii_symbol, \ |
| 362 | AsciiSymbol) \ |
| 363 | V(CONS_SYMBOL_TYPE, \ |
| 364 | ConsString::kSize, \ |
| 365 | cons_symbol, \ |
| 366 | ConsSymbol) \ |
| 367 | V(CONS_ASCII_SYMBOL_TYPE, \ |
| 368 | ConsString::kSize, \ |
| 369 | cons_ascii_symbol, \ |
| 370 | ConsAsciiSymbol) \ |
| 371 | V(EXTERNAL_SYMBOL_TYPE, \ |
| 372 | ExternalTwoByteString::kSize, \ |
| 373 | external_symbol, \ |
| 374 | ExternalSymbol) \ |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 375 | V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \ |
| 376 | ExternalTwoByteString::kSize, \ |
| 377 | external_symbol_with_ascii_data, \ |
| 378 | ExternalSymbolWithAsciiData) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 379 | V(EXTERNAL_ASCII_SYMBOL_TYPE, \ |
| 380 | ExternalAsciiString::kSize, \ |
| 381 | external_ascii_symbol, \ |
| 382 | ExternalAsciiSymbol) \ |
| 383 | V(STRING_TYPE, \ |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 384 | kVariableSizeSentinel, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 385 | string, \ |
| 386 | String) \ |
| 387 | V(ASCII_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 | ascii_string, \ |
| 390 | AsciiString) \ |
| 391 | V(CONS_STRING_TYPE, \ |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 392 | ConsString::kSize, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 393 | cons_string, \ |
| 394 | ConsString) \ |
| 395 | V(CONS_ASCII_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_ascii_string, \ |
| 398 | ConsAsciiString) \ |
| 399 | V(EXTERNAL_STRING_TYPE, \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 400 | ExternalTwoByteString::kSize, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 401 | external_string, \ |
| 402 | ExternalString) \ |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 403 | V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \ |
| 404 | ExternalTwoByteString::kSize, \ |
| 405 | external_string_with_ascii_data, \ |
| 406 | ExternalStringWithAsciiData) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 407 | V(EXTERNAL_ASCII_STRING_TYPE, \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 408 | ExternalAsciiString::kSize, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 409 | external_ascii_string, \ |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 410 | ExternalAsciiString) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 411 | |
| 412 | // A struct is a simple object a set of object-valued fields. Including an |
| 413 | // object type in this causes the compiler to generate most of the boilerplate |
| 414 | // code for the class including allocation and garbage collection routines, |
| 415 | // casts and predicates. All you need to define is the class, methods and |
| 416 | // object verification routines. Easy, no? |
| 417 | // |
| 418 | // Note that for subtle reasons related to the ordering or numerical values of |
| 419 | // type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST |
| 420 | // manually. |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 421 | #define STRUCT_LIST_ALL(V) \ |
| 422 | V(ACCESSOR_INFO, AccessorInfo, accessor_info) \ |
| 423 | V(ACCESS_CHECK_INFO, AccessCheckInfo, access_check_info) \ |
| 424 | V(INTERCEPTOR_INFO, InterceptorInfo, interceptor_info) \ |
| 425 | V(CALL_HANDLER_INFO, CallHandlerInfo, call_handler_info) \ |
| 426 | V(FUNCTION_TEMPLATE_INFO, FunctionTemplateInfo, function_template_info) \ |
| 427 | V(OBJECT_TEMPLATE_INFO, ObjectTemplateInfo, object_template_info) \ |
| 428 | V(SIGNATURE_INFO, SignatureInfo, signature_info) \ |
| 429 | V(TYPE_SWITCH_INFO, TypeSwitchInfo, type_switch_info) \ |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 430 | V(SCRIPT, Script, script) \ |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 431 | V(CODE_CACHE, CodeCache, code_cache) \ |
| 432 | V(POLYMORPHIC_CODE_CACHE, PolymorphicCodeCache, polymorphic_code_cache) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 433 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 434 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 435 | #define STRUCT_LIST_DEBUGGER(V) \ |
| 436 | V(DEBUG_INFO, DebugInfo, debug_info) \ |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 437 | V(BREAK_POINT_INFO, BreakPointInfo, break_point_info) |
| 438 | #else |
| 439 | #define STRUCT_LIST_DEBUGGER(V) |
| 440 | #endif |
| 441 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 442 | #define STRUCT_LIST(V) \ |
| 443 | STRUCT_LIST_ALL(V) \ |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 444 | STRUCT_LIST_DEBUGGER(V) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 445 | |
| 446 | // We use the full 8 bits of the instance_type field to encode heap object |
| 447 | // instance types. The high-order bit (bit 7) is set if the object is not a |
| 448 | // string, and cleared if it is a string. |
| 449 | const uint32_t kIsNotStringMask = 0x80; |
| 450 | const uint32_t kStringTag = 0x0; |
| 451 | const uint32_t kNotStringTag = 0x80; |
| 452 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 453 | // Bit 6 indicates that the object is a symbol (if set) or not (if cleared). |
| 454 | // There are not enough types that the non-string types (with bit 7 set) can |
| 455 | // have bit 6 set too. |
| 456 | const uint32_t kIsSymbolMask = 0x40; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 457 | const uint32_t kNotSymbolTag = 0x0; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 458 | const uint32_t kSymbolTag = 0x40; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 459 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 460 | // If bit 7 is clear then bit 2 indicates whether the string consists of |
| 461 | // two-byte characters or one-byte characters. |
| 462 | const uint32_t kStringEncodingMask = 0x4; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 463 | const uint32_t kTwoByteStringTag = 0x0; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 464 | const uint32_t kAsciiStringTag = 0x4; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 465 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 466 | // 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] | 467 | // of the string. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 468 | const uint32_t kStringRepresentationMask = 0x03; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 469 | enum StringRepresentationTag { |
| 470 | kSeqStringTag = 0x0, |
| 471 | kConsStringTag = 0x1, |
sgjesse@chromium.org | 82dbbab | 2010-06-02 08:57:44 +0000 | [diff] [blame] | 472 | kExternalStringTag = 0x2 |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 473 | }; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 474 | const uint32_t kIsConsStringMask = 0x1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 475 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 476 | // If bit 7 is clear, then bit 3 indicates whether this two-byte |
| 477 | // string actually contains ascii data. |
| 478 | const uint32_t kAsciiDataHintMask = 0x08; |
| 479 | const uint32_t kAsciiDataHintTag = 0x08; |
| 480 | |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 481 | |
| 482 | // A ConsString with an empty string as the right side is a candidate |
| 483 | // for being shortcut by the garbage collector unless it is a |
| 484 | // symbol. It's not common to have non-flat symbols, so we do not |
| 485 | // shortcut them thereby avoiding turning symbols into strings. See |
| 486 | // heap.cc and mark-compact.cc. |
| 487 | const uint32_t kShortcutTypeMask = |
| 488 | kIsNotStringMask | |
| 489 | kIsSymbolMask | |
| 490 | kStringRepresentationMask; |
| 491 | const uint32_t kShortcutTypeTag = kConsStringTag; |
| 492 | |
| 493 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 494 | enum InstanceType { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 495 | // String types. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 496 | SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kSeqStringTag, |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 497 | ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kSeqStringTag, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 498 | CONS_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kConsStringTag, |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 499 | CONS_ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kConsStringTag, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 500 | EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kExternalStringTag, |
| 501 | EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE = |
| 502 | kTwoByteStringTag | kSymbolTag | kExternalStringTag | kAsciiDataHintTag, |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 503 | EXTERNAL_ASCII_SYMBOL_TYPE = |
| 504 | kAsciiStringTag | kSymbolTag | kExternalStringTag, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 505 | STRING_TYPE = kTwoByteStringTag | kSeqStringTag, |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 506 | ASCII_STRING_TYPE = kAsciiStringTag | kSeqStringTag, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 507 | CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag, |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 508 | CONS_ASCII_STRING_TYPE = kAsciiStringTag | kConsStringTag, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 509 | EXTERNAL_STRING_TYPE = kTwoByteStringTag | kExternalStringTag, |
| 510 | EXTERNAL_STRING_WITH_ASCII_DATA_TYPE = |
| 511 | kTwoByteStringTag | kExternalStringTag | kAsciiDataHintTag, |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 512 | // LAST_STRING_TYPE |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 513 | EXTERNAL_ASCII_STRING_TYPE = kAsciiStringTag | kExternalStringTag, |
| 514 | PRIVATE_EXTERNAL_ASCII_STRING_TYPE = EXTERNAL_ASCII_STRING_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 515 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 516 | // Objects allocated in their own spaces (never in new space). |
| 517 | MAP_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 518 | CODE_TYPE, |
| 519 | ODDBALL_TYPE, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 520 | JS_GLOBAL_PROPERTY_CELL_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 521 | |
| 522 | // "Data", objects that cannot contain non-map-word pointers to heap |
| 523 | // objects. |
| 524 | HEAP_NUMBER_TYPE, |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 525 | FOREIGN_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 526 | BYTE_ARRAY_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 527 | EXTERNAL_BYTE_ARRAY_TYPE, // FIRST_EXTERNAL_ARRAY_TYPE |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 528 | EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE, |
| 529 | EXTERNAL_SHORT_ARRAY_TYPE, |
| 530 | EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE, |
| 531 | EXTERNAL_INT_ARRAY_TYPE, |
| 532 | EXTERNAL_UNSIGNED_INT_ARRAY_TYPE, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 533 | EXTERNAL_FLOAT_ARRAY_TYPE, |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 534 | EXTERNAL_DOUBLE_ARRAY_TYPE, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 535 | EXTERNAL_PIXEL_ARRAY_TYPE, // LAST_EXTERNAL_ARRAY_TYPE |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame^] | 536 | FIXED_DOUBLE_ARRAY_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 537 | FILLER_TYPE, // LAST_DATA_TYPE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 538 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 539 | // Structs. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 540 | ACCESSOR_INFO_TYPE, |
| 541 | ACCESS_CHECK_INFO_TYPE, |
| 542 | INTERCEPTOR_INFO_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 543 | CALL_HANDLER_INFO_TYPE, |
| 544 | FUNCTION_TEMPLATE_INFO_TYPE, |
| 545 | OBJECT_TEMPLATE_INFO_TYPE, |
| 546 | SIGNATURE_INFO_TYPE, |
| 547 | TYPE_SWITCH_INFO_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 548 | SCRIPT_TYPE, |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 549 | CODE_CACHE_TYPE, |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 550 | POLYMORPHIC_CODE_CACHE_TYPE, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 551 | // The following two instance types are only used when ENABLE_DEBUGGER_SUPPORT |
| 552 | // is defined. However as include/v8.h contain some of the instance type |
| 553 | // constants always having them avoids them getting different numbers |
| 554 | // depending on whether ENABLE_DEBUGGER_SUPPORT is defined or not. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 555 | DEBUG_INFO_TYPE, |
| 556 | BREAK_POINT_INFO_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 557 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 558 | FIXED_ARRAY_TYPE, |
| 559 | SHARED_FUNCTION_INFO_TYPE, |
| 560 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 561 | JS_MESSAGE_OBJECT_TYPE, |
| 562 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 563 | 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] | 564 | JS_OBJECT_TYPE, |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 565 | JS_CONTEXT_EXTENSION_OBJECT_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 566 | JS_GLOBAL_OBJECT_TYPE, |
| 567 | JS_BUILTINS_OBJECT_TYPE, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 568 | JS_GLOBAL_PROXY_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 569 | JS_ARRAY_TYPE, |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 570 | JS_PROXY_TYPE, |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 571 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 572 | JS_REGEXP_TYPE, // LAST_NONCALLABLE_SPEC_OBJECT_TYPE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 573 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 574 | JS_FUNCTION_TYPE, // FIRST_CALLABLE_SPEC_OBJECT_TYPE |
| 575 | JS_FUNCTION_PROXY_TYPE, // LAST_CALLABLE_SPEC_OBJECT_TYPE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 576 | |
| 577 | // Pseudo-types |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 578 | FIRST_TYPE = 0x0, |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 579 | LAST_TYPE = JS_FUNCTION_PROXY_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 580 | INVALID_TYPE = FIRST_TYPE - 1, |
| 581 | FIRST_NONSTRING_TYPE = MAP_TYPE, |
| 582 | // Boundaries for testing for an external array. |
| 583 | FIRST_EXTERNAL_ARRAY_TYPE = EXTERNAL_BYTE_ARRAY_TYPE, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 584 | LAST_EXTERNAL_ARRAY_TYPE = EXTERNAL_PIXEL_ARRAY_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 585 | // Boundary for promotion to old data space/old pointer space. |
| 586 | LAST_DATA_TYPE = FILLER_TYPE, |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 587 | // Boundary for objects represented as JSReceiver (i.e. JSObject or JSProxy). |
| 588 | // Note that there is no range for JSObject or JSProxy, since their subtypes |
| 589 | // are not continuous in this enum! The enum ranges instead reflect the |
| 590 | // external class names, where proxies are treated as either ordinary objects, |
| 591 | // or functions. |
| 592 | FIRST_JS_RECEIVER_TYPE = JS_VALUE_TYPE, |
| 593 | LAST_JS_RECEIVER_TYPE = LAST_TYPE, |
| 594 | // Boundaries for testing the types for which typeof is "object". |
| 595 | FIRST_NONCALLABLE_SPEC_OBJECT_TYPE = JS_VALUE_TYPE, |
| 596 | LAST_NONCALLABLE_SPEC_OBJECT_TYPE = JS_REGEXP_TYPE, |
| 597 | // Boundaries for testing the types for which typeof is "function". |
| 598 | FIRST_CALLABLE_SPEC_OBJECT_TYPE = JS_FUNCTION_TYPE, |
| 599 | LAST_CALLABLE_SPEC_OBJECT_TYPE = JS_FUNCTION_PROXY_TYPE, |
| 600 | // Boundaries for testing whether the type is a JavaScript object. |
| 601 | FIRST_SPEC_OBJECT_TYPE = FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, |
| 602 | LAST_SPEC_OBJECT_TYPE = LAST_CALLABLE_SPEC_OBJECT_TYPE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 603 | }; |
| 604 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 605 | static const int kExternalArrayTypeCount = LAST_EXTERNAL_ARRAY_TYPE - |
| 606 | FIRST_EXTERNAL_ARRAY_TYPE + 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 607 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 608 | STATIC_CHECK(JS_OBJECT_TYPE == Internals::kJSObjectType); |
| 609 | STATIC_CHECK(FIRST_NONSTRING_TYPE == Internals::kFirstNonstringType); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 610 | STATIC_CHECK(FOREIGN_TYPE == Internals::kForeignType); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 611 | |
| 612 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 613 | enum CompareResult { |
| 614 | LESS = -1, |
| 615 | EQUAL = 0, |
| 616 | GREATER = 1, |
| 617 | |
| 618 | NOT_EQUAL = GREATER |
| 619 | }; |
| 620 | |
| 621 | |
| 622 | #define DECL_BOOLEAN_ACCESSORS(name) \ |
| 623 | inline bool name(); \ |
| 624 | inline void set_##name(bool value); \ |
| 625 | |
| 626 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 627 | #define DECL_ACCESSORS(name, type) \ |
| 628 | inline type* name(); \ |
| 629 | inline void set_##name(type* value, \ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 630 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 631 | |
| 632 | |
| 633 | class StringStream; |
| 634 | class ObjectVisitor; |
| 635 | |
| 636 | struct ValueInfo : public Malloced { |
| 637 | ValueInfo() : type(FIRST_TYPE), ptr(NULL), str(NULL), number(0) { } |
| 638 | InstanceType type; |
| 639 | Object* ptr; |
| 640 | const char* str; |
| 641 | double number; |
| 642 | }; |
| 643 | |
| 644 | |
| 645 | // A template-ized version of the IsXXX functions. |
| 646 | template <class C> static inline bool Is(Object* obj); |
| 647 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 648 | class Failure; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 649 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 650 | class MaybeObject BASE_EMBEDDED { |
| 651 | public: |
| 652 | inline bool IsFailure(); |
| 653 | inline bool IsRetryAfterGC(); |
| 654 | inline bool IsOutOfMemory(); |
| 655 | inline bool IsException(); |
| 656 | INLINE(bool IsTheHole()); |
| 657 | inline bool ToObject(Object** obj) { |
| 658 | if (IsFailure()) return false; |
| 659 | *obj = reinterpret_cast<Object*>(this); |
| 660 | return true; |
| 661 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 662 | inline Failure* ToFailureUnchecked() { |
| 663 | ASSERT(IsFailure()); |
| 664 | return reinterpret_cast<Failure*>(this); |
| 665 | } |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 666 | inline Object* ToObjectUnchecked() { |
| 667 | ASSERT(!IsFailure()); |
| 668 | return reinterpret_cast<Object*>(this); |
| 669 | } |
| 670 | inline Object* ToObjectChecked() { |
| 671 | CHECK(!IsFailure()); |
| 672 | return reinterpret_cast<Object*>(this); |
| 673 | } |
| 674 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 675 | template<typename T> |
| 676 | inline bool To(T** obj) { |
| 677 | if (IsFailure()) return false; |
| 678 | *obj = T::cast(reinterpret_cast<Object*>(this)); |
| 679 | return true; |
| 680 | } |
| 681 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 682 | #ifdef OBJECT_PRINT |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 683 | // Prints this object with details. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 684 | inline void Print() { |
| 685 | Print(stdout); |
| 686 | }; |
| 687 | inline void PrintLn() { |
| 688 | PrintLn(stdout); |
| 689 | } |
| 690 | void Print(FILE* out); |
| 691 | void PrintLn(FILE* out); |
| 692 | #endif |
| 693 | #ifdef DEBUG |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 694 | // Verifies the object. |
| 695 | void Verify(); |
| 696 | #endif |
| 697 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 698 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 699 | |
| 700 | #define OBJECT_TYPE_LIST(V) \ |
| 701 | V(Smi) \ |
| 702 | V(HeapObject) \ |
| 703 | V(Number) \ |
| 704 | |
| 705 | #define HEAP_OBJECT_TYPE_LIST(V) \ |
| 706 | V(HeapNumber) \ |
| 707 | V(String) \ |
| 708 | V(Symbol) \ |
| 709 | V(SeqString) \ |
| 710 | V(ExternalString) \ |
| 711 | V(ConsString) \ |
| 712 | V(ExternalTwoByteString) \ |
| 713 | V(ExternalAsciiString) \ |
| 714 | V(SeqTwoByteString) \ |
| 715 | V(SeqAsciiString) \ |
| 716 | \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 717 | V(ExternalArray) \ |
| 718 | V(ExternalByteArray) \ |
| 719 | V(ExternalUnsignedByteArray) \ |
| 720 | V(ExternalShortArray) \ |
| 721 | V(ExternalUnsignedShortArray) \ |
| 722 | V(ExternalIntArray) \ |
| 723 | V(ExternalUnsignedIntArray) \ |
| 724 | V(ExternalFloatArray) \ |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 725 | V(ExternalDoubleArray) \ |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 726 | V(ExternalPixelArray) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 727 | V(ByteArray) \ |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 728 | V(JSReceiver) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 729 | V(JSObject) \ |
| 730 | V(JSContextExtensionObject) \ |
| 731 | V(Map) \ |
| 732 | V(DescriptorArray) \ |
| 733 | V(DeoptimizationInputData) \ |
| 734 | V(DeoptimizationOutputData) \ |
| 735 | V(FixedArray) \ |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame^] | 736 | V(FixedDoubleArray) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 737 | V(Context) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 738 | V(GlobalContext) \ |
| 739 | V(JSFunction) \ |
| 740 | V(Code) \ |
| 741 | V(Oddball) \ |
| 742 | V(SharedFunctionInfo) \ |
| 743 | V(JSValue) \ |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 744 | V(JSMessageObject) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 745 | V(StringWrapper) \ |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 746 | V(Foreign) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 747 | V(Boolean) \ |
| 748 | V(JSArray) \ |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 749 | V(JSProxy) \ |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 750 | V(JSFunctionProxy) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 751 | V(JSRegExp) \ |
| 752 | V(HashTable) \ |
| 753 | V(Dictionary) \ |
| 754 | V(SymbolTable) \ |
| 755 | V(JSFunctionResultCache) \ |
| 756 | V(NormalizedMapCache) \ |
| 757 | V(CompilationCacheTable) \ |
| 758 | V(CodeCacheHashTable) \ |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 759 | V(PolymorphicCodeCacheHashTable) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 760 | V(MapCache) \ |
| 761 | V(Primitive) \ |
| 762 | V(GlobalObject) \ |
| 763 | V(JSGlobalObject) \ |
| 764 | V(JSBuiltinsObject) \ |
| 765 | V(JSGlobalProxy) \ |
| 766 | V(UndetectableObject) \ |
| 767 | V(AccessCheckNeeded) \ |
| 768 | V(JSGlobalPropertyCell) \ |
| 769 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 770 | // Object is the abstract superclass for all classes in the |
| 771 | // object hierarchy. |
| 772 | // Object does not use any virtual functions to avoid the |
| 773 | // allocation of the C++ vtable. |
| 774 | // Since Smi and Failure are subclasses of Object no |
| 775 | // data members can be present in Object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 776 | class Object : public MaybeObject { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 777 | public: |
| 778 | // Type testing. |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 779 | #define IS_TYPE_FUNCTION_DECL(type_) inline bool Is##type_(); |
| 780 | OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
| 781 | HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
| 782 | #undef IS_TYPE_FUNCTION_DECL |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 783 | |
| 784 | // Returns true if this object is an instance of the specified |
| 785 | // function template. |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 786 | inline bool IsInstanceOf(FunctionTemplateInfo* type); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 787 | |
| 788 | inline bool IsStruct(); |
| 789 | #define DECLARE_STRUCT_PREDICATE(NAME, Name, name) inline bool Is##Name(); |
| 790 | STRUCT_LIST(DECLARE_STRUCT_PREDICATE) |
| 791 | #undef DECLARE_STRUCT_PREDICATE |
| 792 | |
| 793 | // Oddball testing. |
| 794 | INLINE(bool IsUndefined()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 795 | INLINE(bool IsNull()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 796 | INLINE(bool IsTheHole()); // Shadows MaybeObject's implementation. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 797 | INLINE(bool IsTrue()); |
| 798 | INLINE(bool IsFalse()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 799 | inline bool IsArgumentsMarker(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 800 | |
| 801 | // Extract the number. |
| 802 | inline double Number(); |
| 803 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame^] | 804 | // Returns true if the object is of the correct type to be used as a |
| 805 | // implementation of a JSObject's elements. |
| 806 | inline bool HasValidElements(); |
| 807 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 808 | inline bool HasSpecificClassOf(String* name); |
| 809 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 810 | MUST_USE_RESULT MaybeObject* ToObject(); // ECMA-262 9.9. |
| 811 | Object* ToBoolean(); // ECMA-262 9.2. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 812 | |
| 813 | // Convert to a JSObject if needed. |
| 814 | // global_context is used when creating wrapper object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 815 | MUST_USE_RESULT MaybeObject* ToObject(Context* global_context); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 816 | |
| 817 | // Converts this to a Smi if possible. |
| 818 | // Failure is returned otherwise. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 819 | MUST_USE_RESULT inline MaybeObject* ToSmi(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 820 | |
| 821 | void Lookup(String* name, LookupResult* result); |
| 822 | |
| 823 | // Property access. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 824 | MUST_USE_RESULT inline MaybeObject* GetProperty(String* key); |
| 825 | MUST_USE_RESULT inline MaybeObject* GetProperty( |
| 826 | String* key, |
| 827 | PropertyAttributes* attributes); |
| 828 | MUST_USE_RESULT MaybeObject* GetPropertyWithReceiver( |
| 829 | Object* receiver, |
| 830 | String* key, |
| 831 | PropertyAttributes* attributes); |
| 832 | MUST_USE_RESULT MaybeObject* GetProperty(Object* receiver, |
| 833 | LookupResult* result, |
| 834 | String* key, |
| 835 | PropertyAttributes* attributes); |
| 836 | MUST_USE_RESULT MaybeObject* GetPropertyWithCallback(Object* receiver, |
| 837 | Object* structure, |
| 838 | String* name, |
| 839 | Object* holder); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 840 | MUST_USE_RESULT MaybeObject* GetPropertyWithHandler(Object* receiver, |
| 841 | String* name, |
| 842 | Object* handler); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 843 | MUST_USE_RESULT MaybeObject* GetPropertyWithDefinedGetter(Object* receiver, |
| 844 | JSFunction* getter); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 845 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 846 | inline MaybeObject* GetElement(uint32_t index); |
| 847 | // For use when we know that no exception can be thrown. |
| 848 | inline Object* GetElementNoExceptionThrown(uint32_t index); |
| 849 | MaybeObject* GetElementWithReceiver(Object* receiver, uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 850 | |
| 851 | // Return the object's prototype (might be Heap::null_value()). |
| 852 | Object* GetPrototype(); |
| 853 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 854 | // Tries to convert an object to an array index. Returns true and sets |
| 855 | // the output parameter if it succeeds. |
| 856 | inline bool ToArrayIndex(uint32_t* index); |
| 857 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 858 | // Returns true if this is a JSValue containing a string and the index is |
| 859 | // < the length of the string. Used to implement [] on strings. |
| 860 | inline bool IsStringObjectWithCharacterAt(uint32_t index); |
| 861 | |
| 862 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 863 | // Verify a pointer is a valid object pointer. |
| 864 | static void VerifyPointer(Object* p); |
| 865 | #endif |
| 866 | |
| 867 | // Prints this object without details. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 868 | inline void ShortPrint() { |
| 869 | ShortPrint(stdout); |
| 870 | } |
| 871 | void ShortPrint(FILE* out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 872 | |
| 873 | // Prints this object without details to a message accumulator. |
| 874 | void ShortPrint(StringStream* accumulator); |
| 875 | |
| 876 | // Casting: This cast is only needed to satisfy macros in objects-inl.h. |
| 877 | static Object* cast(Object* value) { return value; } |
| 878 | |
| 879 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 880 | 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] | 881 | |
| 882 | private: |
| 883 | DISALLOW_IMPLICIT_CONSTRUCTORS(Object); |
| 884 | }; |
| 885 | |
| 886 | |
| 887 | // Smi represents integer Numbers that can be stored in 31 bits. |
| 888 | // 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] | 889 | // 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] | 890 | // For long smis it has the following format: |
| 891 | // [32 bit signed int] [31 bits zero padding] 0 |
| 892 | // Smi stands for small integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 893 | class Smi: public Object { |
| 894 | public: |
| 895 | // Returns the integer value. |
| 896 | inline int value(); |
| 897 | |
| 898 | // Convert a value to a Smi object. |
| 899 | static inline Smi* FromInt(int value); |
| 900 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 901 | static inline Smi* FromIntptr(intptr_t value); |
| 902 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 903 | // Returns whether value can be represented in a Smi. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 904 | static inline bool IsValid(intptr_t value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 905 | |
| 906 | // Casting. |
| 907 | static inline Smi* cast(Object* object); |
| 908 | |
| 909 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 910 | inline void SmiPrint() { |
| 911 | SmiPrint(stdout); |
| 912 | } |
| 913 | void SmiPrint(FILE* out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 914 | void SmiPrint(StringStream* accumulator); |
| 915 | #ifdef DEBUG |
| 916 | void SmiVerify(); |
| 917 | #endif |
| 918 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 919 | static const int kMinValue = (-1 << (kSmiValueSize - 1)); |
| 920 | static const int kMaxValue = -(kMinValue + 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 921 | |
| 922 | private: |
| 923 | DISALLOW_IMPLICIT_CONSTRUCTORS(Smi); |
| 924 | }; |
| 925 | |
| 926 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 927 | // Failure is used for reporting out of memory situations and |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 928 | // propagating exceptions through the runtime system. Failure objects |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 929 | // are transient and cannot occur as part of the object graph. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 930 | // |
| 931 | // Failures are a single word, encoded as follows: |
| 932 | // +-------------------------+---+--+--+ |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 933 | // |.........unused..........|sss|tt|11| |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 934 | // +-------------------------+---+--+--+ |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 935 | // 7 6 4 32 10 |
| 936 | // |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 937 | // |
| 938 | // The low two bits, 0-1, are the failure tag, 11. The next two bits, |
| 939 | // 2-3, are a failure type tag 'tt' with possible values: |
| 940 | // 00 RETRY_AFTER_GC |
| 941 | // 01 EXCEPTION |
| 942 | // 10 INTERNAL_ERROR |
| 943 | // 11 OUT_OF_MEMORY_EXCEPTION |
| 944 | // |
| 945 | // The next three bits, 4-6, are an allocation space tag 'sss'. The |
| 946 | // allocation space tag is 000 for all failure types except |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 947 | // RETRY_AFTER_GC. For RETRY_AFTER_GC, the possible values are the |
| 948 | // allocation spaces (the encoding is found in globals.h). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 949 | |
| 950 | // Failure type tag info. |
| 951 | const int kFailureTypeTagSize = 2; |
| 952 | const int kFailureTypeTagMask = (1 << kFailureTypeTagSize) - 1; |
| 953 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 954 | class Failure: public MaybeObject { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 955 | public: |
| 956 | // RuntimeStubs assumes EXCEPTION = 1 in the compiler-generated code. |
| 957 | enum Type { |
| 958 | RETRY_AFTER_GC = 0, |
| 959 | EXCEPTION = 1, // Returning this marker tells the real exception |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 960 | // is in Isolate::pending_exception. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 961 | INTERNAL_ERROR = 2, |
| 962 | OUT_OF_MEMORY_EXCEPTION = 3 |
| 963 | }; |
| 964 | |
| 965 | inline Type type() const; |
| 966 | |
| 967 | // Returns the space that needs to be collected for RetryAfterGC failures. |
| 968 | inline AllocationSpace allocation_space() const; |
| 969 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 970 | inline bool IsInternalError() const; |
| 971 | inline bool IsOutOfMemoryException() const; |
| 972 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 973 | static inline Failure* RetryAfterGC(AllocationSpace space); |
| 974 | static inline Failure* RetryAfterGC(); // NEW_SPACE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 975 | static inline Failure* Exception(); |
| 976 | static inline Failure* InternalError(); |
| 977 | static inline Failure* OutOfMemoryException(); |
| 978 | // Casting. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 979 | static inline Failure* cast(MaybeObject* object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 980 | |
| 981 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 982 | inline void FailurePrint() { |
| 983 | FailurePrint(stdout); |
| 984 | } |
| 985 | void FailurePrint(FILE* out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 986 | void FailurePrint(StringStream* accumulator); |
| 987 | #ifdef DEBUG |
| 988 | void FailureVerify(); |
| 989 | #endif |
| 990 | |
| 991 | private: |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 992 | inline intptr_t value() const; |
| 993 | static inline Failure* Construct(Type type, intptr_t value = 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 994 | |
| 995 | DISALLOW_IMPLICIT_CONSTRUCTORS(Failure); |
| 996 | }; |
| 997 | |
| 998 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 999 | // Heap objects typically have a map pointer in their first word. However, |
| 1000 | // during GC other data (eg, mark bits, forwarding addresses) is sometimes |
| 1001 | // encoded in the first word. The class MapWord is an abstraction of the |
| 1002 | // value in a heap object's first word. |
| 1003 | class MapWord BASE_EMBEDDED { |
| 1004 | public: |
| 1005 | // Normal state: the map word contains a map pointer. |
| 1006 | |
| 1007 | // Create a map word from a map pointer. |
| 1008 | static inline MapWord FromMap(Map* map); |
| 1009 | |
| 1010 | // View this map word as a map pointer. |
| 1011 | inline Map* ToMap(); |
| 1012 | |
| 1013 | |
| 1014 | // Scavenge collection: the map word of live objects in the from space |
| 1015 | // contains a forwarding address (a heap object pointer in the to space). |
| 1016 | |
| 1017 | // True if this map word is a forwarding address for a scavenge |
| 1018 | // collection. Only valid during a scavenge collection (specifically, |
| 1019 | // when all map words are heap object pointers, ie. not during a full GC). |
| 1020 | inline bool IsForwardingAddress(); |
| 1021 | |
| 1022 | // Create a map word from a forwarding address. |
| 1023 | static inline MapWord FromForwardingAddress(HeapObject* object); |
| 1024 | |
| 1025 | // View this map word as a forwarding address. |
| 1026 | inline HeapObject* ToForwardingAddress(); |
| 1027 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1028 | // Marking phase of full collection: the map word of live objects is |
| 1029 | // marked, and may be marked as overflowed (eg, the object is live, its |
| 1030 | // children have not been visited, and it does not fit in the marking |
| 1031 | // stack). |
| 1032 | |
| 1033 | // True if this map word's mark bit is set. |
| 1034 | inline bool IsMarked(); |
| 1035 | |
| 1036 | // Return this map word but with its mark bit set. |
| 1037 | inline void SetMark(); |
| 1038 | |
| 1039 | // Return this map word but with its mark bit cleared. |
| 1040 | inline void ClearMark(); |
| 1041 | |
| 1042 | // True if this map word's overflow bit is set. |
| 1043 | inline bool IsOverflowed(); |
| 1044 | |
| 1045 | // Return this map word but with its overflow bit set. |
| 1046 | inline void SetOverflow(); |
| 1047 | |
| 1048 | // Return this map word but with its overflow bit cleared. |
| 1049 | inline void ClearOverflow(); |
| 1050 | |
| 1051 | |
| 1052 | // Compacting phase of a full compacting collection: the map word of live |
| 1053 | // objects contains an encoding of the original map address along with the |
| 1054 | // forwarding address (represented as an offset from the first live object |
| 1055 | // in the same page as the (old) object address). |
| 1056 | |
| 1057 | // Create a map word from a map address and a forwarding address offset. |
| 1058 | static inline MapWord EncodeAddress(Address map_address, int offset); |
| 1059 | |
| 1060 | // Return the map address encoded in this map word. |
| 1061 | inline Address DecodeMapAddress(MapSpace* map_space); |
| 1062 | |
| 1063 | // Return the forwarding offset encoded in this map word. |
| 1064 | inline int DecodeOffset(); |
| 1065 | |
| 1066 | |
| 1067 | // During serialization: the map word is used to hold an encoded |
| 1068 | // address, and possibly a mark bit (set and cleared with SetMark |
| 1069 | // and ClearMark). |
| 1070 | |
| 1071 | // Create a map word from an encoded address. |
| 1072 | static inline MapWord FromEncodedAddress(Address address); |
| 1073 | |
| 1074 | inline Address ToEncodedAddress(); |
| 1075 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1076 | // Bits used by the marking phase of the garbage collector. |
| 1077 | // |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1078 | // 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] | 1079 | // bits are tagged as '01' (kHeapObjectTag). We reuse the last two bits to |
| 1080 | // mark an object as live and/or overflowed: |
| 1081 | // last bit = 0, marked as alive |
| 1082 | // second bit = 1, overflowed |
| 1083 | // An object is only marked as overflowed when it is marked as live while |
| 1084 | // the marking stack is overflowed. |
| 1085 | static const int kMarkingBit = 0; // marking bit |
| 1086 | static const int kMarkingMask = (1 << kMarkingBit); // marking mask |
| 1087 | static const int kOverflowBit = 1; // overflow bit |
| 1088 | static const int kOverflowMask = (1 << kOverflowBit); // overflow mask |
| 1089 | |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 1090 | // Forwarding pointers and map pointer encoding. On 32 bit all the bits are |
| 1091 | // used. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1092 | // +-----------------+------------------+-----------------+ |
| 1093 | // |forwarding offset|page offset of map|page index of map| |
| 1094 | // +-----------------+------------------+-----------------+ |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 1095 | // ^ ^ ^ |
| 1096 | // | | | |
| 1097 | // | | kMapPageIndexBits |
| 1098 | // | kMapPageOffsetBits |
| 1099 | // kForwardingOffsetBits |
| 1100 | static const int kMapPageOffsetBits = kPageSizeBits - kMapAlignmentBits; |
| 1101 | static const int kForwardingOffsetBits = kPageSizeBits - kObjectAlignmentBits; |
| 1102 | #ifdef V8_HOST_ARCH_64_BIT |
| 1103 | static const int kMapPageIndexBits = 16; |
| 1104 | #else |
| 1105 | // Use all the 32-bits to encode on a 32-bit platform. |
| 1106 | static const int kMapPageIndexBits = |
| 1107 | 32 - (kMapPageOffsetBits + kForwardingOffsetBits); |
| 1108 | #endif |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1109 | |
| 1110 | static const int kMapPageIndexShift = 0; |
| 1111 | static const int kMapPageOffsetShift = |
| 1112 | kMapPageIndexShift + kMapPageIndexBits; |
| 1113 | static const int kForwardingOffsetShift = |
| 1114 | kMapPageOffsetShift + kMapPageOffsetBits; |
| 1115 | |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 1116 | // Bit masks covering the different parts the encoding. |
| 1117 | static const uintptr_t kMapPageIndexMask = |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1118 | (1 << kMapPageOffsetShift) - 1; |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 1119 | static const uintptr_t kMapPageOffsetMask = |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1120 | ((1 << kForwardingOffsetShift) - 1) & ~kMapPageIndexMask; |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 1121 | static const uintptr_t kForwardingOffsetMask = |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1122 | ~(kMapPageIndexMask | kMapPageOffsetMask); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1123 | |
| 1124 | private: |
| 1125 | // HeapObject calls the private constructor and directly reads the value. |
| 1126 | friend class HeapObject; |
| 1127 | |
| 1128 | explicit MapWord(uintptr_t value) : value_(value) {} |
| 1129 | |
| 1130 | uintptr_t value_; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1131 | }; |
| 1132 | |
| 1133 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1134 | // HeapObject is the superclass for all classes describing heap allocated |
| 1135 | // objects. |
| 1136 | class HeapObject: public Object { |
| 1137 | public: |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1138 | // [map]: Contains a map which contains the object's reflective |
| 1139 | // information. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1140 | inline Map* map(); |
| 1141 | inline void set_map(Map* value); |
| 1142 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1143 | // During garbage collection, the map word of a heap object does not |
| 1144 | // necessarily contain a map pointer. |
| 1145 | inline MapWord map_word(); |
| 1146 | inline void set_map_word(MapWord map_word); |
| 1147 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1148 | // The Heap the object was allocated in. Used also to access Isolate. |
| 1149 | // This method can not be used during GC, it ASSERTs this. |
| 1150 | inline Heap* GetHeap(); |
| 1151 | // Convenience method to get current isolate. This method can be |
| 1152 | // accessed only when its result is the same as |
| 1153 | // Isolate::Current(), it ASSERTs this. See also comment for GetHeap. |
| 1154 | inline Isolate* GetIsolate(); |
| 1155 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1156 | // Converts an address to a HeapObject pointer. |
| 1157 | static inline HeapObject* FromAddress(Address address); |
| 1158 | |
| 1159 | // Returns the address of this HeapObject. |
| 1160 | inline Address address(); |
| 1161 | |
| 1162 | // Iterates over pointers contained in the object (including the Map) |
| 1163 | void Iterate(ObjectVisitor* v); |
| 1164 | |
| 1165 | // Iterates over all pointers contained in the object except the |
| 1166 | // first map pointer. The object type is given in the first |
| 1167 | // parameter. This function does not access the map pointer in the |
| 1168 | // object, and so is safe to call while the map pointer is modified. |
| 1169 | void IterateBody(InstanceType type, int object_size, ObjectVisitor* v); |
| 1170 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1171 | // Returns the heap object's size in bytes |
| 1172 | inline int Size(); |
| 1173 | |
| 1174 | // Given a heap object's map pointer, returns the heap size in bytes |
| 1175 | // Useful when the map pointer field is used for other purposes. |
| 1176 | // GC internal. |
| 1177 | inline int SizeFromMap(Map* map); |
| 1178 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1179 | // Support for the marking heap objects during the marking phase of GC. |
| 1180 | // True if the object is marked live. |
| 1181 | inline bool IsMarked(); |
| 1182 | |
| 1183 | // Mutate this object's map pointer to indicate that the object is live. |
| 1184 | inline void SetMark(); |
| 1185 | |
| 1186 | // Mutate this object's map pointer to remove the indication that the |
| 1187 | // object is live (ie, partially restore the map pointer). |
| 1188 | inline void ClearMark(); |
| 1189 | |
| 1190 | // True if this object is marked as overflowed. Overflowed objects have |
| 1191 | // been reached and marked during marking of the heap, but their children |
| 1192 | // have not necessarily been marked and they have not been pushed on the |
| 1193 | // marking stack. |
| 1194 | inline bool IsOverflowed(); |
| 1195 | |
| 1196 | // Mutate this object's map pointer to indicate that the object is |
| 1197 | // overflowed. |
| 1198 | inline void SetOverflow(); |
| 1199 | |
| 1200 | // Mutate this object's map pointer to remove the indication that the |
| 1201 | // object is overflowed (ie, partially restore the map pointer). |
| 1202 | inline void ClearOverflow(); |
| 1203 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 1204 | // Returns the field at offset in obj, as a read/write Object* reference. |
| 1205 | // 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] | 1206 | // Does not invoke write barrier, so should only be assigned to |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 1207 | // during marking GC. |
| 1208 | static inline Object** RawField(HeapObject* obj, int offset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1209 | |
| 1210 | // Casting. |
| 1211 | static inline HeapObject* cast(Object* obj); |
| 1212 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1213 | // Return the write barrier mode for this. Callers of this function |
| 1214 | // must be able to present a reference to an AssertNoAllocation |
| 1215 | // object as a sign that they are not going to use this function |
| 1216 | // from code that allocates and thus invalidates the returned write |
| 1217 | // barrier mode. |
| 1218 | inline WriteBarrierMode GetWriteBarrierMode(const AssertNoAllocation&); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1219 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1220 | // Dispatched behavior. |
| 1221 | void HeapObjectShortPrint(StringStream* accumulator); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1222 | #ifdef OBJECT_PRINT |
| 1223 | inline void HeapObjectPrint() { |
| 1224 | HeapObjectPrint(stdout); |
| 1225 | } |
| 1226 | void HeapObjectPrint(FILE* out); |
| 1227 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1228 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1229 | void HeapObjectVerify(); |
| 1230 | inline void VerifyObjectField(int offset); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1231 | inline void VerifySmiField(int offset); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1232 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1233 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1234 | #ifdef OBJECT_PRINT |
| 1235 | void PrintHeader(FILE* out, const char* id); |
| 1236 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1237 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1238 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1239 | // Verify a pointer is a valid HeapObject pointer that points to object |
| 1240 | // areas in the heap. |
| 1241 | static void VerifyHeapPointer(Object* p); |
| 1242 | #endif |
| 1243 | |
| 1244 | // Layout description. |
| 1245 | // First field in a heap object is map. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1246 | static const int kMapOffset = Object::kHeaderSize; |
| 1247 | static const int kHeaderSize = kMapOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1248 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1249 | STATIC_CHECK(kMapOffset == Internals::kHeapObjectMapOffset); |
| 1250 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1251 | protected: |
| 1252 | // helpers for calling an ObjectVisitor to iterate over pointers in the |
| 1253 | // half-open range [start, end) specified as integer offsets |
| 1254 | inline void IteratePointers(ObjectVisitor* v, int start, int end); |
| 1255 | // as above, for the single element at "offset" |
| 1256 | inline void IteratePointer(ObjectVisitor* v, int offset); |
| 1257 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1258 | private: |
| 1259 | DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject); |
| 1260 | }; |
| 1261 | |
| 1262 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1263 | #define SLOT_ADDR(obj, offset) \ |
| 1264 | reinterpret_cast<Object**>((obj)->address() + offset) |
| 1265 | |
| 1266 | // This class describes a body of an object of a fixed size |
| 1267 | // in which all pointer fields are located in the [start_offset, end_offset) |
| 1268 | // interval. |
| 1269 | template<int start_offset, int end_offset, int size> |
| 1270 | class FixedBodyDescriptor { |
| 1271 | public: |
| 1272 | static const int kStartOffset = start_offset; |
| 1273 | static const int kEndOffset = end_offset; |
| 1274 | static const int kSize = size; |
| 1275 | |
| 1276 | static inline void IterateBody(HeapObject* obj, ObjectVisitor* v); |
| 1277 | |
| 1278 | template<typename StaticVisitor> |
| 1279 | static inline void IterateBody(HeapObject* obj) { |
| 1280 | StaticVisitor::VisitPointers(SLOT_ADDR(obj, start_offset), |
| 1281 | SLOT_ADDR(obj, end_offset)); |
| 1282 | } |
| 1283 | }; |
| 1284 | |
| 1285 | |
| 1286 | // This class describes a body of an object of a variable size |
| 1287 | // in which all pointer fields are located in the [start_offset, object_size) |
| 1288 | // interval. |
| 1289 | template<int start_offset> |
| 1290 | class FlexibleBodyDescriptor { |
| 1291 | public: |
| 1292 | static const int kStartOffset = start_offset; |
| 1293 | |
| 1294 | static inline void IterateBody(HeapObject* obj, |
| 1295 | int object_size, |
| 1296 | ObjectVisitor* v); |
| 1297 | |
| 1298 | template<typename StaticVisitor> |
| 1299 | static inline void IterateBody(HeapObject* obj, int object_size) { |
| 1300 | StaticVisitor::VisitPointers(SLOT_ADDR(obj, start_offset), |
| 1301 | SLOT_ADDR(obj, object_size)); |
| 1302 | } |
| 1303 | }; |
| 1304 | |
| 1305 | #undef SLOT_ADDR |
| 1306 | |
| 1307 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1308 | // The HeapNumber class describes heap allocated numbers that cannot be |
| 1309 | // represented in a Smi (small integer) |
| 1310 | class HeapNumber: public HeapObject { |
| 1311 | public: |
| 1312 | // [value]: number value. |
| 1313 | inline double value(); |
| 1314 | inline void set_value(double value); |
| 1315 | |
| 1316 | // Casting. |
| 1317 | static inline HeapNumber* cast(Object* obj); |
| 1318 | |
| 1319 | // Dispatched behavior. |
| 1320 | Object* HeapNumberToBoolean(); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1321 | inline void HeapNumberPrint() { |
| 1322 | HeapNumberPrint(stdout); |
| 1323 | } |
| 1324 | void HeapNumberPrint(FILE* out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1325 | void HeapNumberPrint(StringStream* accumulator); |
| 1326 | #ifdef DEBUG |
| 1327 | void HeapNumberVerify(); |
| 1328 | #endif |
| 1329 | |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 1330 | inline int get_exponent(); |
| 1331 | inline int get_sign(); |
| 1332 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1333 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1334 | static const int kValueOffset = HeapObject::kHeaderSize; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1335 | // IEEE doubles are two 32 bit words. The first is just mantissa, the second |
| 1336 | // is a mixture of sign, exponent and mantissa. Our current platforms are all |
| 1337 | // little endian apart from non-EABI arm which is little endian with big |
| 1338 | // endian floating point word ordering! |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1339 | static const int kMantissaOffset = kValueOffset; |
| 1340 | static const int kExponentOffset = kValueOffset + 4; |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1341 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1342 | static const int kSize = kValueOffset + kDoubleSize; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1343 | static const uint32_t kSignMask = 0x80000000u; |
| 1344 | static const uint32_t kExponentMask = 0x7ff00000u; |
| 1345 | static const uint32_t kMantissaMask = 0xfffffu; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1346 | static const int kMantissaBits = 52; |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1347 | static const int kExponentBits = 11; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1348 | static const int kExponentBias = 1023; |
| 1349 | static const int kExponentShift = 20; |
| 1350 | static const int kMantissaBitsInTopWord = 20; |
| 1351 | static const int kNonMantissaBitsInTopWord = 12; |
| 1352 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1353 | private: |
| 1354 | DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumber); |
| 1355 | }; |
| 1356 | |
| 1357 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1358 | // JSReceiver includes types on which properties can be defined, i.e., |
| 1359 | // JSObject and JSProxy. |
| 1360 | class JSReceiver: public HeapObject { |
| 1361 | public: |
| 1362 | // Casting. |
| 1363 | static inline JSReceiver* cast(Object* obj); |
| 1364 | |
| 1365 | // Can cause GC. |
| 1366 | MUST_USE_RESULT MaybeObject* SetProperty(String* key, |
| 1367 | Object* value, |
| 1368 | PropertyAttributes attributes, |
| 1369 | StrictModeFlag strict_mode); |
| 1370 | MUST_USE_RESULT MaybeObject* SetProperty(LookupResult* result, |
| 1371 | String* key, |
| 1372 | Object* value, |
| 1373 | PropertyAttributes attributes, |
| 1374 | StrictModeFlag strict_mode); |
| 1375 | |
| 1376 | // Returns the class name ([[Class]] property in the specification). |
| 1377 | String* class_name(); |
| 1378 | |
| 1379 | // Returns the constructor name (the name (possibly, inferred name) of the |
| 1380 | // function that was used to instantiate the object). |
| 1381 | String* constructor_name(); |
| 1382 | |
| 1383 | inline PropertyAttributes GetPropertyAttribute(String* name); |
| 1384 | PropertyAttributes GetPropertyAttributeWithReceiver(JSReceiver* receiver, |
| 1385 | String* name); |
| 1386 | PropertyAttributes GetLocalPropertyAttribute(String* name); |
| 1387 | |
| 1388 | // Can cause a GC. |
| 1389 | bool HasProperty(String* name) { |
| 1390 | return GetPropertyAttribute(name) != ABSENT; |
| 1391 | } |
| 1392 | |
| 1393 | // Can cause a GC. |
| 1394 | bool HasLocalProperty(String* name) { |
| 1395 | return GetLocalPropertyAttribute(name) != ABSENT; |
| 1396 | } |
| 1397 | |
| 1398 | // Return the object's prototype (might be Heap::null_value()). |
| 1399 | inline Object* GetPrototype(); |
| 1400 | |
| 1401 | // Set the object's prototype (only JSReceiver and null are allowed). |
| 1402 | MUST_USE_RESULT MaybeObject* SetPrototype(Object* value, |
| 1403 | bool skip_hidden_prototypes); |
| 1404 | |
| 1405 | // Lookup a property. If found, the result is valid and has |
| 1406 | // detailed information. |
| 1407 | void LocalLookup(String* name, LookupResult* result); |
| 1408 | void Lookup(String* name, LookupResult* result); |
| 1409 | |
| 1410 | private: |
| 1411 | PropertyAttributes GetPropertyAttribute(JSReceiver* receiver, |
| 1412 | LookupResult* result, |
| 1413 | String* name, |
| 1414 | bool continue_search); |
| 1415 | |
| 1416 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSReceiver); |
| 1417 | }; |
| 1418 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1419 | // The JSObject describes real heap allocated JavaScript objects with |
| 1420 | // properties. |
| 1421 | // Note that the map of JSObject changes during execution to enable inline |
| 1422 | // caching. |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1423 | class JSObject: public JSReceiver { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1424 | public: |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1425 | enum DeleteMode { |
| 1426 | NORMAL_DELETION, |
| 1427 | STRICT_DELETION, |
| 1428 | FORCE_DELETION |
| 1429 | }; |
| 1430 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1431 | enum ElementsKind { |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1432 | // The "fast" kind for tagged values. Must be first to make it possible |
| 1433 | // to efficiently check maps if they have fast elements. |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1434 | FAST_ELEMENTS, |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame^] | 1435 | |
| 1436 | // The "fast" kind for unwrapped, non-tagged double values. |
| 1437 | FAST_DOUBLE_ELEMENTS, |
| 1438 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1439 | // The "slow" kind. |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1440 | DICTIONARY_ELEMENTS, |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1441 | // The "fast" kind for external arrays |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1442 | EXTERNAL_BYTE_ELEMENTS, |
| 1443 | EXTERNAL_UNSIGNED_BYTE_ELEMENTS, |
| 1444 | EXTERNAL_SHORT_ELEMENTS, |
| 1445 | EXTERNAL_UNSIGNED_SHORT_ELEMENTS, |
| 1446 | EXTERNAL_INT_ELEMENTS, |
| 1447 | EXTERNAL_UNSIGNED_INT_ELEMENTS, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1448 | EXTERNAL_FLOAT_ELEMENTS, |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 1449 | EXTERNAL_DOUBLE_ELEMENTS, |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1450 | EXTERNAL_PIXEL_ELEMENTS, |
| 1451 | |
| 1452 | // Derived constants from ElementsKind |
| 1453 | FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_BYTE_ELEMENTS, |
| 1454 | LAST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS, |
| 1455 | FIRST_ELEMENTS_KIND = FAST_ELEMENTS, |
| 1456 | LAST_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1457 | }; |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1458 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1459 | static const int kElementsKindCount = |
| 1460 | LAST_ELEMENTS_KIND - FIRST_ELEMENTS_KIND + 1; |
| 1461 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1462 | // [properties]: Backing storage for properties. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1463 | // 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] | 1464 | // slow case. |
| 1465 | DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1466 | inline void initialize_properties(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1467 | inline bool HasFastProperties(); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 1468 | inline StringDictionary* property_dictionary(); // Gets slow properties. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1469 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1470 | // [elements]: The elements (properties with names that are integers). |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1471 | // |
| 1472 | // Elements can be in two general modes: fast and slow. Each mode |
| 1473 | // corrensponds to a set of object representations of elements that |
| 1474 | // have something in common. |
| 1475 | // |
| 1476 | // In the fast mode elements is a FixedArray and so each element can |
| 1477 | // be quickly accessed. This fact is used in the generated code. The |
| 1478 | // elements array can have one of the two maps in this mode: |
| 1479 | // fixed_array_map or fixed_cow_array_map (for copy-on-write |
| 1480 | // arrays). In the latter case the elements array may be shared by a |
| 1481 | // few objects and so before writing to any element the array must |
| 1482 | // be copied. Use EnsureWritableFastElements in this case. |
| 1483 | // |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1484 | // In the slow mode elements is either a NumberDictionary or an ExternalArray. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1485 | DECL_ACCESSORS(elements, HeapObject) |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1486 | inline void initialize_elements(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1487 | MUST_USE_RESULT inline MaybeObject* ResetElements(); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1488 | inline ElementsKind GetElementsKind(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1489 | inline bool HasFastElements(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame^] | 1490 | inline bool HasFastDoubleElements(); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1491 | inline bool HasDictionaryElements(); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1492 | inline bool HasExternalPixelElements(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1493 | inline bool HasExternalArrayElements(); |
| 1494 | inline bool HasExternalByteElements(); |
| 1495 | inline bool HasExternalUnsignedByteElements(); |
| 1496 | inline bool HasExternalShortElements(); |
| 1497 | inline bool HasExternalUnsignedShortElements(); |
| 1498 | inline bool HasExternalIntElements(); |
| 1499 | inline bool HasExternalUnsignedIntElements(); |
| 1500 | inline bool HasExternalFloatElements(); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 1501 | inline bool HasExternalDoubleElements(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1502 | inline bool AllowsSetElementsLength(); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 1503 | inline NumberDictionary* element_dictionary(); // Gets slow elements. |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1504 | // Requires: this->HasFastElements(). |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1505 | MUST_USE_RESULT inline MaybeObject* EnsureWritableFastElements(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1506 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 1507 | // Collects elements starting at index 0. |
| 1508 | // Undefined values are placed after non-undefined values. |
| 1509 | // Returns the number of non-undefined values. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1510 | MUST_USE_RESULT MaybeObject* PrepareElementsForSort(uint32_t limit); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 1511 | // As PrepareElementsForSort, but only on objects where elements is |
| 1512 | // a dictionary, and it will stay a dictionary. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1513 | MUST_USE_RESULT MaybeObject* PrepareSlowElementsForSort(uint32_t limit); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 1514 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1515 | MUST_USE_RESULT MaybeObject* SetPropertyForResult(LookupResult* result, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1516 | String* key, |
| 1517 | Object* value, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1518 | PropertyAttributes attributes, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1519 | StrictModeFlag strict_mode); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1520 | MUST_USE_RESULT MaybeObject* SetPropertyWithFailedAccessCheck( |
| 1521 | LookupResult* result, |
| 1522 | String* name, |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1523 | Object* value, |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 1524 | bool check_prototype, |
| 1525 | StrictModeFlag strict_mode); |
| 1526 | MUST_USE_RESULT MaybeObject* SetPropertyWithCallback( |
| 1527 | Object* structure, |
| 1528 | String* name, |
| 1529 | Object* value, |
| 1530 | JSObject* holder, |
| 1531 | StrictModeFlag strict_mode); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1532 | MUST_USE_RESULT MaybeObject* SetPropertyWithDefinedSetter(JSFunction* setter, |
| 1533 | Object* value); |
| 1534 | MUST_USE_RESULT MaybeObject* SetPropertyWithInterceptor( |
| 1535 | String* name, |
| 1536 | Object* value, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1537 | PropertyAttributes attributes, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1538 | StrictModeFlag strict_mode); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1539 | MUST_USE_RESULT MaybeObject* SetPropertyPostInterceptor( |
| 1540 | String* name, |
| 1541 | Object* value, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1542 | PropertyAttributes attributes, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1543 | StrictModeFlag strict_mode); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1544 | MUST_USE_RESULT MaybeObject* SetLocalPropertyIgnoreAttributes( |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1545 | String* key, |
| 1546 | Object* value, |
| 1547 | PropertyAttributes attributes); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1548 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1549 | // Retrieve a value in a normalized object given a lookup result. |
| 1550 | // Handles the special representation of JS global objects. |
| 1551 | Object* GetNormalizedProperty(LookupResult* result); |
| 1552 | |
| 1553 | // Sets the property value in a normalized object given a lookup result. |
| 1554 | // Handles the special representation of JS global objects. |
| 1555 | Object* SetNormalizedProperty(LookupResult* result, Object* value); |
| 1556 | |
| 1557 | // Sets the property value in a normalized object given (key, value, details). |
| 1558 | // Handles the special representation of JS global objects. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1559 | MUST_USE_RESULT MaybeObject* SetNormalizedProperty(String* name, |
| 1560 | Object* value, |
| 1561 | PropertyDetails details); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1562 | |
| 1563 | // Deletes the named property in a normalized object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1564 | MUST_USE_RESULT MaybeObject* DeleteNormalizedProperty(String* name, |
| 1565 | DeleteMode mode); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1566 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1567 | // Retrieve interceptors. |
| 1568 | InterceptorInfo* GetNamedInterceptor(); |
| 1569 | InterceptorInfo* GetIndexedInterceptor(); |
| 1570 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1571 | // Used from JSReceiver. |
| 1572 | PropertyAttributes GetPropertyAttributePostInterceptor(JSObject* receiver, |
| 1573 | String* name, |
| 1574 | bool continue_search); |
| 1575 | PropertyAttributes GetPropertyAttributeWithInterceptor(JSObject* receiver, |
| 1576 | String* name, |
| 1577 | bool continue_search); |
| 1578 | PropertyAttributes GetPropertyAttributeWithFailedAccessCheck( |
| 1579 | Object* receiver, |
| 1580 | LookupResult* result, |
| 1581 | String* name, |
| 1582 | bool continue_search); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1583 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1584 | MUST_USE_RESULT MaybeObject* DefineAccessor(String* name, |
| 1585 | bool is_getter, |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1586 | Object* fun, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1587 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1588 | Object* LookupAccessor(String* name, bool is_getter); |
| 1589 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1590 | MUST_USE_RESULT MaybeObject* DefineAccessor(AccessorInfo* info); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1591 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1592 | // Used from Object::GetProperty(). |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1593 | MaybeObject* GetPropertyWithFailedAccessCheck( |
| 1594 | Object* receiver, |
| 1595 | LookupResult* result, |
| 1596 | String* name, |
| 1597 | PropertyAttributes* attributes); |
| 1598 | MaybeObject* GetPropertyWithInterceptor( |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1599 | JSReceiver* receiver, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1600 | String* name, |
| 1601 | PropertyAttributes* attributes); |
| 1602 | MaybeObject* GetPropertyPostInterceptor( |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1603 | JSReceiver* receiver, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1604 | String* name, |
| 1605 | PropertyAttributes* attributes); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1606 | MaybeObject* GetLocalPropertyPostInterceptor(JSReceiver* receiver, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1607 | String* name, |
| 1608 | PropertyAttributes* attributes); |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 1609 | |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 1610 | // Returns true if this is an instance of an api function and has |
| 1611 | // been modified since it was created. May give false positives. |
| 1612 | bool IsDirty(); |
| 1613 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1614 | // If the receiver is a JSGlobalProxy this method will return its prototype, |
| 1615 | // otherwise the result is the receiver itself. |
| 1616 | inline Object* BypassGlobalProxy(); |
| 1617 | |
| 1618 | // Accessors for hidden properties object. |
| 1619 | // |
| 1620 | // Hidden properties are not local properties of the object itself. |
| 1621 | // Instead they are stored on an auxiliary JSObject stored as a local |
| 1622 | // property with a special name Heap::hidden_symbol(). But if the |
| 1623 | // receiver is a JSGlobalProxy then the auxiliary object is a property |
| 1624 | // of its prototype. |
| 1625 | // |
| 1626 | // Has/Get/SetHiddenPropertiesObject methods don't allow the holder to be |
| 1627 | // a JSGlobalProxy. Use BypassGlobalProxy method above to get to the real |
| 1628 | // holder. |
| 1629 | // |
| 1630 | // These accessors do not touch interceptors or accessors. |
| 1631 | inline bool HasHiddenPropertiesObject(); |
| 1632 | inline Object* GetHiddenPropertiesObject(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1633 | MUST_USE_RESULT inline MaybeObject* SetHiddenPropertiesObject( |
| 1634 | Object* hidden_obj); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1635 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1636 | MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode); |
| 1637 | MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1638 | |
| 1639 | // Tests for the fast common case for property enumeration. |
| 1640 | bool IsSimpleEnum(); |
| 1641 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1642 | // Do we want to keep the elements in fast case when increasing the |
| 1643 | // capacity? |
| 1644 | bool ShouldConvertToSlowElements(int new_capacity); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1645 | // Returns true if the backing storage for the slow-case elements of |
| 1646 | // this object takes up nearly as much space as a fast-case backing |
| 1647 | // storage would. In that case the JSObject should have fast |
| 1648 | // elements. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1649 | bool ShouldConvertToFastElements(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame^] | 1650 | // Returns true if the elements of JSObject contains only values that can be |
| 1651 | // represented in a FixedDoubleArray. |
| 1652 | bool ShouldConvertToFastDoubleElements(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1653 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1654 | // Tells whether the index'th element is present. |
| 1655 | inline bool HasElement(uint32_t index); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1656 | bool HasElementWithReceiver(JSReceiver* receiver, uint32_t index); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1657 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1658 | // Computes the new capacity when expanding the elements of a JSObject. |
| 1659 | static int NewElementsCapacity(int old_capacity) { |
| 1660 | // (old_capacity + 50%) + 16 |
| 1661 | return old_capacity + (old_capacity >> 1) + 16; |
| 1662 | } |
| 1663 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1664 | // Tells whether the index'th element is present and how it is stored. |
| 1665 | enum LocalElementType { |
| 1666 | // There is no element with given index. |
| 1667 | UNDEFINED_ELEMENT, |
| 1668 | |
| 1669 | // Element with given index is handled by interceptor. |
| 1670 | INTERCEPTED_ELEMENT, |
| 1671 | |
| 1672 | // Element with given index is character in string. |
| 1673 | STRING_CHARACTER_ELEMENT, |
| 1674 | |
| 1675 | // Element with given index is stored in fast backing store. |
| 1676 | FAST_ELEMENT, |
| 1677 | |
| 1678 | // Element with given index is stored in slow backing store. |
| 1679 | DICTIONARY_ELEMENT |
| 1680 | }; |
| 1681 | |
| 1682 | LocalElementType HasLocalElement(uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1683 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1684 | bool HasElementWithInterceptor(JSReceiver* receiver, uint32_t index); |
| 1685 | bool HasElementPostInterceptor(JSReceiver* receiver, uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1686 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1687 | MUST_USE_RESULT MaybeObject* SetFastElement(uint32_t index, |
| 1688 | Object* value, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1689 | StrictModeFlag strict_mode, |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1690 | bool check_prototype = true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1691 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame^] | 1692 | MUST_USE_RESULT MaybeObject* SetFastDoubleElement( |
| 1693 | uint32_t index, |
| 1694 | Object* value, |
| 1695 | StrictModeFlag strict_mode, |
| 1696 | bool check_prototype = true); |
| 1697 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1698 | // Set the index'th array element. |
| 1699 | // A Failure object is returned if GC is needed. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1700 | MUST_USE_RESULT MaybeObject* SetElement(uint32_t index, |
| 1701 | Object* value, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1702 | StrictModeFlag strict_mode, |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1703 | bool check_prototype = true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1704 | |
| 1705 | // Returns the index'th element. |
| 1706 | // The undefined object if index is out of bounds. |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1707 | MaybeObject* GetElementWithReceiver(Object* receiver, uint32_t index); |
| 1708 | MaybeObject* GetElementWithInterceptor(Object* receiver, uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1709 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1710 | // Get external element value at index if there is one and undefined |
| 1711 | // otherwise. Can return a failure if allocation of a heap number |
| 1712 | // failed. |
| 1713 | MaybeObject* GetExternalElement(uint32_t index); |
| 1714 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1715 | MUST_USE_RESULT MaybeObject* SetFastElementsCapacityAndLength(int capacity, |
| 1716 | int length); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame^] | 1717 | MUST_USE_RESULT MaybeObject* SetFastDoubleElementsCapacityAndLength( |
| 1718 | int capacity, |
| 1719 | int length); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1720 | MUST_USE_RESULT MaybeObject* SetSlowElements(Object* length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1721 | |
| 1722 | // Lookup interceptors are used for handling properties controlled by host |
| 1723 | // objects. |
| 1724 | inline bool HasNamedInterceptor(); |
| 1725 | inline bool HasIndexedInterceptor(); |
| 1726 | |
| 1727 | // Support functions for v8 api (needed for correct interceptor behavior). |
| 1728 | bool HasRealNamedProperty(String* key); |
| 1729 | bool HasRealElementProperty(uint32_t index); |
| 1730 | bool HasRealNamedCallbackProperty(String* key); |
| 1731 | |
| 1732 | // Initializes the array to a certain length |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1733 | MUST_USE_RESULT MaybeObject* SetElementsLength(Object* length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1734 | |
| 1735 | // Get the header size for a JSObject. Used to compute the index of |
| 1736 | // internal fields as well as the number of internal fields. |
| 1737 | inline int GetHeaderSize(); |
| 1738 | |
| 1739 | inline int GetInternalFieldCount(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1740 | inline int GetInternalFieldOffset(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1741 | inline Object* GetInternalField(int index); |
| 1742 | inline void SetInternalField(int index, Object* value); |
| 1743 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1744 | // Lookup a property. If found, the result is valid and has |
| 1745 | // detailed information. |
| 1746 | void LocalLookup(String* name, LookupResult* result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1747 | |
| 1748 | // The following lookup functions skip interceptors. |
| 1749 | void LocalLookupRealNamedProperty(String* name, LookupResult* result); |
| 1750 | void LookupRealNamedProperty(String* name, LookupResult* result); |
| 1751 | void LookupRealNamedPropertyInPrototypes(String* name, LookupResult* result); |
| 1752 | void LookupCallbackSetterInPrototypes(String* name, LookupResult* result); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1753 | MUST_USE_RESULT MaybeObject* SetElementWithCallbackSetterInPrototypes( |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 1754 | uint32_t index, Object* value, bool* found, StrictModeFlag strict_mode); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 1755 | void LookupCallback(String* name, LookupResult* result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1756 | |
| 1757 | // Returns the number of properties on this object filtering out properties |
| 1758 | // with the specified attributes (ignoring interceptors). |
| 1759 | int NumberOfLocalProperties(PropertyAttributes filter); |
| 1760 | // Returns the number of enumerable properties (ignoring interceptors). |
| 1761 | int NumberOfEnumProperties(); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 1762 | // Fill in details for properties into storage starting at the specified |
| 1763 | // index. |
| 1764 | void GetLocalPropertyNames(FixedArray* storage, int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1765 | |
| 1766 | // Returns the number of properties on this object filtering out properties |
| 1767 | // with the specified attributes (ignoring interceptors). |
| 1768 | int NumberOfLocalElements(PropertyAttributes filter); |
| 1769 | // Returns the number of enumerable elements (ignoring interceptors). |
| 1770 | int NumberOfEnumElements(); |
| 1771 | // Returns the number of elements on this object filtering out elements |
| 1772 | // with the specified attributes (ignoring interceptors). |
| 1773 | int GetLocalElementKeys(FixedArray* storage, PropertyAttributes filter); |
| 1774 | // Count and fill in the enumerable elements into storage. |
| 1775 | // (storage->length() == NumberOfEnumElements()). |
| 1776 | // If storage is NULL, will count the elements without adding |
| 1777 | // them to any storage. |
| 1778 | // Returns the number of enumerable elements. |
| 1779 | int GetEnumElementKeys(FixedArray* storage); |
| 1780 | |
| 1781 | // Add a property to a fast-case object using a map transition to |
| 1782 | // new_map. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1783 | MUST_USE_RESULT MaybeObject* AddFastPropertyUsingMap(Map* new_map, |
| 1784 | String* name, |
| 1785 | Object* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1786 | |
| 1787 | // 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] | 1788 | // This leaves a CONSTANT_TRANSITION in the old map, and |
| 1789 | // if it is called on a second object with this map, a |
| 1790 | // normal property is added instead, with a map transition. |
| 1791 | // This avoids the creation of many maps with the same constant |
| 1792 | // function, all orphaned. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1793 | MUST_USE_RESULT MaybeObject* AddConstantFunctionProperty( |
| 1794 | String* name, |
| 1795 | JSFunction* function, |
| 1796 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1797 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1798 | MUST_USE_RESULT MaybeObject* ReplaceSlowProperty( |
| 1799 | String* name, |
| 1800 | Object* value, |
| 1801 | PropertyAttributes attributes); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1802 | |
| 1803 | // Converts a descriptor of any other type to a real field, |
| 1804 | // backed by the properties array. Descriptors of visible |
| 1805 | // types, such as CONSTANT_FUNCTION, keep their enumeration order. |
| 1806 | // Converts the descriptor on the original object's map to a |
| 1807 | // 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] | 1808 | MUST_USE_RESULT MaybeObject* ConvertDescriptorToFieldAndMapTransition( |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1809 | String* name, |
| 1810 | Object* new_value, |
| 1811 | PropertyAttributes attributes); |
| 1812 | |
| 1813 | // Converts a descriptor of any other type to a real field, |
| 1814 | // backed by the properties array. Descriptors of visible |
| 1815 | // types, such as CONSTANT_FUNCTION, keep their enumeration order. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1816 | MUST_USE_RESULT MaybeObject* ConvertDescriptorToField( |
| 1817 | String* name, |
| 1818 | Object* new_value, |
| 1819 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1820 | |
| 1821 | // Add a property to a fast-case object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1822 | MUST_USE_RESULT MaybeObject* AddFastProperty(String* name, |
| 1823 | Object* value, |
| 1824 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1825 | |
| 1826 | // Add a property to a slow-case object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1827 | MUST_USE_RESULT MaybeObject* AddSlowProperty(String* name, |
| 1828 | Object* value, |
| 1829 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1830 | |
| 1831 | // Add a property to an object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1832 | MUST_USE_RESULT MaybeObject* AddProperty(String* name, |
| 1833 | Object* value, |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1834 | PropertyAttributes attributes, |
| 1835 | StrictModeFlag strict_mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1836 | |
| 1837 | // Convert the object to use the canonical dictionary |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1838 | // representation. If the object is expected to have additional properties |
| 1839 | // added this number can be indicated to have the backing store allocated to |
| 1840 | // an initial capacity for holding these properties. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1841 | MUST_USE_RESULT MaybeObject* NormalizeProperties( |
| 1842 | PropertyNormalizationMode mode, |
| 1843 | int expected_additional_properties); |
| 1844 | MUST_USE_RESULT MaybeObject* NormalizeElements(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1845 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1846 | MUST_USE_RESULT MaybeObject* UpdateMapCodeCache(String* name, Code* code); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1847 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1848 | // Transform slow named properties to fast variants. |
| 1849 | // Returns failure if allocation failed. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1850 | MUST_USE_RESULT MaybeObject* TransformToFastProperties( |
| 1851 | int unused_property_fields); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1852 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1853 | // Access fast-case object properties at index. |
| 1854 | inline Object* FastPropertyAt(int index); |
| 1855 | inline Object* FastPropertyAtPut(int index, Object* value); |
| 1856 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1857 | // Access to in object properties. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1858 | inline int GetInObjectPropertyOffset(int index); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1859 | inline Object* InObjectPropertyAt(int index); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1860 | inline Object* InObjectPropertyAtPut(int index, |
| 1861 | Object* value, |
| 1862 | WriteBarrierMode mode |
| 1863 | = UPDATE_WRITE_BARRIER); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1864 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1865 | // initializes the body after properties slot, properties slot is |
| 1866 | // initialized by set_properties |
| 1867 | // Note: this call does not update write barrier, it is caller's |
| 1868 | // reponsibility to ensure that *v* can be collected without WB here. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1869 | inline void InitializeBody(int object_size, Object* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1870 | |
| 1871 | // Check whether this object references another object |
| 1872 | bool ReferencesObject(Object* obj); |
| 1873 | |
| 1874 | // Casting. |
| 1875 | static inline JSObject* cast(Object* obj); |
| 1876 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1877 | // Disalow further properties to be added to the object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1878 | MUST_USE_RESULT MaybeObject* PreventExtensions(); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1879 | |
| 1880 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1881 | // Dispatched behavior. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1882 | void JSObjectShortPrint(StringStream* accumulator); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1883 | #ifdef OBJECT_PRINT |
| 1884 | inline void JSObjectPrint() { |
| 1885 | JSObjectPrint(stdout); |
| 1886 | } |
| 1887 | void JSObjectPrint(FILE* out); |
| 1888 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1889 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1890 | void JSObjectVerify(); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1891 | #endif |
| 1892 | #ifdef OBJECT_PRINT |
| 1893 | inline void PrintProperties() { |
| 1894 | PrintProperties(stdout); |
| 1895 | } |
| 1896 | void PrintProperties(FILE* out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1897 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1898 | inline void PrintElements() { |
| 1899 | PrintElements(stdout); |
| 1900 | } |
| 1901 | void PrintElements(FILE* out); |
| 1902 | #endif |
| 1903 | |
| 1904 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1905 | // Structure for collecting spill information about JSObjects. |
| 1906 | class SpillInformation { |
| 1907 | public: |
| 1908 | void Clear(); |
| 1909 | void Print(); |
| 1910 | int number_of_objects_; |
| 1911 | int number_of_objects_with_fast_properties_; |
| 1912 | int number_of_objects_with_fast_elements_; |
| 1913 | int number_of_fast_used_fields_; |
| 1914 | int number_of_fast_unused_fields_; |
| 1915 | int number_of_slow_used_properties_; |
| 1916 | int number_of_slow_unused_properties_; |
| 1917 | int number_of_fast_used_elements_; |
| 1918 | int number_of_fast_unused_elements_; |
| 1919 | int number_of_slow_used_elements_; |
| 1920 | int number_of_slow_unused_elements_; |
| 1921 | }; |
| 1922 | |
| 1923 | void IncrementSpillStatistics(SpillInformation* info); |
| 1924 | #endif |
| 1925 | Object* SlowReverseLookup(Object* value); |
| 1926 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1927 | // Maximal number of fast properties for the JSObject. Used to |
| 1928 | // restrict the number of map transitions to avoid an explosion in |
| 1929 | // the number of maps for objects used as dictionaries. |
| 1930 | inline int MaxFastProperties(); |
| 1931 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 1932 | // Maximal number of elements (numbered 0 .. kMaxElementCount - 1). |
| 1933 | // Also maximal value of JSArray's length property. |
| 1934 | static const uint32_t kMaxElementCount = 0xffffffffu; |
| 1935 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1936 | static const uint32_t kMaxGap = 1024; |
| 1937 | static const int kMaxFastElementsLength = 5000; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1938 | static const int kInitialMaxFastElementArray = 100000; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1939 | static const int kMaxFastProperties = 12; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1940 | static const int kMaxInstanceSize = 255 * kPointerSize; |
| 1941 | // When extending the backing storage for property values, we increase |
| 1942 | // its size by more than the 1 entry necessary, so sequentially adding fields |
| 1943 | // to the same object requires fewer allocations and copies. |
| 1944 | static const int kFieldsAdded = 3; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1945 | |
| 1946 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1947 | static const int kPropertiesOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1948 | static const int kElementsOffset = kPropertiesOffset + kPointerSize; |
| 1949 | static const int kHeaderSize = kElementsOffset + kPointerSize; |
| 1950 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1951 | STATIC_CHECK(kHeaderSize == Internals::kJSObjectHeaderSize); |
| 1952 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1953 | class BodyDescriptor : public FlexibleBodyDescriptor<kPropertiesOffset> { |
| 1954 | public: |
| 1955 | static inline int SizeOf(Map* map, HeapObject* object); |
| 1956 | }; |
| 1957 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1958 | private: |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1959 | MUST_USE_RESULT MaybeObject* GetElementWithCallback(Object* receiver, |
| 1960 | Object* structure, |
| 1961 | uint32_t index, |
| 1962 | Object* holder); |
| 1963 | MaybeObject* SetElementWithCallback(Object* structure, |
| 1964 | uint32_t index, |
| 1965 | Object* value, |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 1966 | JSObject* holder, |
| 1967 | StrictModeFlag strict_mode); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1968 | MUST_USE_RESULT MaybeObject* SetElementWithInterceptor( |
| 1969 | uint32_t index, |
| 1970 | Object* value, |
| 1971 | StrictModeFlag strict_mode, |
| 1972 | bool check_prototype); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1973 | MUST_USE_RESULT MaybeObject* SetElementWithoutInterceptor( |
| 1974 | uint32_t index, |
| 1975 | Object* value, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1976 | StrictModeFlag strict_mode, |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1977 | bool check_prototype); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1978 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1979 | MaybeObject* GetElementPostInterceptor(Object* receiver, uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1980 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1981 | MUST_USE_RESULT MaybeObject* DeletePropertyPostInterceptor(String* name, |
| 1982 | DeleteMode mode); |
| 1983 | MUST_USE_RESULT MaybeObject* DeletePropertyWithInterceptor(String* name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1984 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1985 | MUST_USE_RESULT MaybeObject* DeleteElementPostInterceptor(uint32_t index, |
| 1986 | DeleteMode mode); |
| 1987 | MUST_USE_RESULT MaybeObject* DeleteElementWithInterceptor(uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1988 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1989 | // Returns true if most of the elements backing storage is used. |
| 1990 | bool HasDenseElements(); |
| 1991 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1992 | bool CanSetCallback(String* name); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1993 | MUST_USE_RESULT MaybeObject* SetElementCallback( |
| 1994 | uint32_t index, |
| 1995 | Object* structure, |
| 1996 | PropertyAttributes attributes); |
| 1997 | MUST_USE_RESULT MaybeObject* SetPropertyCallback( |
| 1998 | String* name, |
| 1999 | Object* structure, |
| 2000 | PropertyAttributes attributes); |
| 2001 | MUST_USE_RESULT MaybeObject* DefineGetterSetter( |
| 2002 | String* name, |
| 2003 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2004 | |
| 2005 | void LookupInDescriptor(String* name, LookupResult* result); |
| 2006 | |
| 2007 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject); |
| 2008 | }; |
| 2009 | |
| 2010 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame^] | 2011 | // Common superclass for FixedArrays that allow implementations to share |
| 2012 | // common accessors and some code paths. |
| 2013 | class FixedArrayBase: public HeapObject { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2014 | public: |
| 2015 | // [length]: length of the array. |
| 2016 | inline int length(); |
| 2017 | inline void set_length(int value); |
| 2018 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame^] | 2019 | inline static FixedArrayBase* cast(Object* object); |
| 2020 | |
| 2021 | // Layout description. |
| 2022 | // Length is smi tagged when it is stored. |
| 2023 | static const int kLengthOffset = HeapObject::kHeaderSize; |
| 2024 | static const int kHeaderSize = kLengthOffset + kPointerSize; |
| 2025 | }; |
| 2026 | |
| 2027 | |
| 2028 | // FixedArray describes fixed-sized arrays with element type Object*. |
| 2029 | class FixedArray: public FixedArrayBase { |
| 2030 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2031 | // Setter and getter for elements. |
| 2032 | inline Object* get(int index); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2033 | // Setter that uses write barrier. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2034 | inline void set(int index, Object* value); |
| 2035 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2036 | // Setter that doesn't need write barrier). |
| 2037 | inline void set(int index, Smi* value); |
| 2038 | // Setter with explicit barrier mode. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2039 | inline void set(int index, Object* value, WriteBarrierMode mode); |
| 2040 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2041 | // Setters for frequently used oddballs located in old space. |
| 2042 | inline void set_undefined(int index); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2043 | // TODO(isolates): duplicate. |
| 2044 | inline void set_undefined(Heap* heap, int index); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2045 | inline void set_null(int index); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2046 | // TODO(isolates): duplicate. |
| 2047 | inline void set_null(Heap* heap, int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2048 | inline void set_the_hole(int index); |
| 2049 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 2050 | // Setters with less debug checks for the GC to use. |
| 2051 | inline void set_unchecked(int index, Smi* value); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2052 | inline void set_null_unchecked(Heap* heap, int index); |
| 2053 | inline void set_unchecked(Heap* heap, int index, Object* value, |
| 2054 | WriteBarrierMode mode); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 2055 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2056 | // Gives access to raw memory which stores the array's data. |
| 2057 | inline Object** data_start(); |
| 2058 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2059 | // Copy operations. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2060 | MUST_USE_RESULT inline MaybeObject* Copy(); |
| 2061 | MUST_USE_RESULT MaybeObject* CopySize(int new_length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2062 | |
| 2063 | // Add the elements of a JSArray to this FixedArray. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2064 | MUST_USE_RESULT MaybeObject* AddKeysFromJSArray(JSArray* array); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2065 | |
| 2066 | // Compute the union of this and other. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2067 | MUST_USE_RESULT MaybeObject* UnionOfKeys(FixedArray* other); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2068 | |
| 2069 | // Copy a sub array from the receiver to dest. |
| 2070 | void CopyTo(int pos, FixedArray* dest, int dest_pos, int len); |
| 2071 | |
| 2072 | // Garbage collection support. |
| 2073 | static int SizeFor(int length) { return kHeaderSize + length * kPointerSize; } |
| 2074 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2075 | // Code Generation support. |
| 2076 | static int OffsetOfElementAt(int index) { return SizeFor(index); } |
| 2077 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2078 | // Casting. |
| 2079 | static inline FixedArray* cast(Object* obj); |
| 2080 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2081 | // Maximal allowed size, in bytes, of a single FixedArray. |
| 2082 | // Prevents overflowing size computations, as well as extreme memory |
| 2083 | // consumption. |
| 2084 | static const int kMaxSize = 512 * MB; |
| 2085 | // Maximally allowed length of a FixedArray. |
| 2086 | static const int kMaxLength = (kMaxSize - kHeaderSize) / kPointerSize; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2087 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2088 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2089 | #ifdef OBJECT_PRINT |
| 2090 | inline void FixedArrayPrint() { |
| 2091 | FixedArrayPrint(stdout); |
| 2092 | } |
| 2093 | void FixedArrayPrint(FILE* out); |
| 2094 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2095 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2096 | void FixedArrayVerify(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2097 | // Checks if two FixedArrays have identical contents. |
| 2098 | bool IsEqualTo(FixedArray* other); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2099 | #endif |
| 2100 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2101 | // Swap two elements in a pair of arrays. If this array and the |
| 2102 | // numbers array are the same object, the elements are only swapped |
| 2103 | // once. |
| 2104 | void SwapPairs(FixedArray* numbers, int i, int j); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2105 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2106 | // Sort prefix of this array and the numbers array as pairs wrt. the |
| 2107 | // numbers. If the numbers array and the this array are the same |
| 2108 | // object, the prefix of this array is sorted. |
| 2109 | void SortPairs(FixedArray* numbers, uint32_t len); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2110 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2111 | class BodyDescriptor : public FlexibleBodyDescriptor<kHeaderSize> { |
| 2112 | public: |
| 2113 | static inline int SizeOf(Map* map, HeapObject* object) { |
| 2114 | return SizeFor(reinterpret_cast<FixedArray*>(object)->length()); |
| 2115 | } |
| 2116 | }; |
| 2117 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2118 | protected: |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2119 | // Set operation on FixedArray without using write barriers. Can |
| 2120 | // only be used for storing old space objects or smis. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2121 | static inline void fast_set(FixedArray* array, int index, Object* value); |
| 2122 | |
| 2123 | private: |
| 2124 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedArray); |
| 2125 | }; |
| 2126 | |
| 2127 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame^] | 2128 | // FixedDoubleArray describes fixed-sized arrays with element type double. |
| 2129 | class FixedDoubleArray: public FixedArrayBase { |
| 2130 | public: |
| 2131 | inline void Initialize(FixedArray* from); |
| 2132 | inline void Initialize(FixedDoubleArray* from); |
| 2133 | inline void Initialize(NumberDictionary* from); |
| 2134 | |
| 2135 | // Setter and getter for elements. |
| 2136 | inline double get(int index); |
| 2137 | inline void set(int index, double value); |
| 2138 | inline void set_the_hole(int index); |
| 2139 | |
| 2140 | // Checking for the hole. |
| 2141 | inline bool is_the_hole(int index); |
| 2142 | |
| 2143 | // Garbage collection support. |
| 2144 | inline static int SizeFor(int length) { |
| 2145 | return kHeaderSize + length * kDoubleSize; |
| 2146 | } |
| 2147 | |
| 2148 | // The following can't be declared inline as const static |
| 2149 | // because they're 64-bit. |
| 2150 | static uint64_t kCanonicalNonHoleNanLower32; |
| 2151 | static uint64_t kCanonicalNonHoleNanInt64; |
| 2152 | static uint64_t kHoleNanInt64; |
| 2153 | |
| 2154 | inline static bool is_the_hole_nan(double value) { |
| 2155 | return BitCast<uint64_t, double>(value) == kHoleNanInt64; |
| 2156 | } |
| 2157 | |
| 2158 | inline static double hole_nan_as_double() { |
| 2159 | return BitCast<double, uint64_t>(kHoleNanInt64); |
| 2160 | } |
| 2161 | |
| 2162 | inline static double canonical_not_the_hole_nan_as_double() { |
| 2163 | return BitCast<double, uint64_t>(kCanonicalNonHoleNanInt64); |
| 2164 | } |
| 2165 | |
| 2166 | // Casting. |
| 2167 | static inline FixedDoubleArray* cast(Object* obj); |
| 2168 | |
| 2169 | // Maximal allowed size, in bytes, of a single FixedDoubleArray. |
| 2170 | // Prevents overflowing size computations, as well as extreme memory |
| 2171 | // consumption. |
| 2172 | static const int kMaxSize = 512 * MB; |
| 2173 | // Maximally allowed length of a FixedArray. |
| 2174 | static const int kMaxLength = (kMaxSize - kHeaderSize) / kDoubleSize; |
| 2175 | |
| 2176 | // Dispatched behavior. |
| 2177 | #ifdef OBJECT_PRINT |
| 2178 | inline void FixedDoubleArrayPrint() { |
| 2179 | FixedDoubleArrayPrint(stdout); |
| 2180 | } |
| 2181 | void FixedDoubleArrayPrint(FILE* out); |
| 2182 | #endif |
| 2183 | |
| 2184 | #ifdef DEBUG |
| 2185 | void FixedDoubleArrayVerify(); |
| 2186 | #endif |
| 2187 | |
| 2188 | private: |
| 2189 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedDoubleArray); |
| 2190 | }; |
| 2191 | |
| 2192 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2193 | // DescriptorArrays are fixed arrays used to hold instance descriptors. |
| 2194 | // The format of the these objects is: |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2195 | // TODO(1399): It should be possible to make room for bit_field3 in the map |
| 2196 | // without overloading the instance descriptors field in the map |
| 2197 | // (and storing it in the DescriptorArray when the map has one). |
| 2198 | // [0]: storage for bit_field3 for Map owning this object (Smi) |
| 2199 | // [1]: point to a fixed array with (value, detail) pairs. |
| 2200 | // [2]: next enumeration index (Smi), or pointer to small fixed array: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2201 | // [0]: next enumeration index (Smi) |
| 2202 | // [1]: pointer to fixed array with enum cache |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2203 | // [3]: first key |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2204 | // [length() - 1]: last key |
| 2205 | // |
| 2206 | class DescriptorArray: public FixedArray { |
| 2207 | public: |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2208 | // Returns true for both shared empty_descriptor_array and for smis, which the |
| 2209 | // map uses to encode additional bit fields when the descriptor array is not |
| 2210 | // yet used. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2211 | inline bool IsEmpty(); |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 2212 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2213 | // Returns the number of descriptors in the array. |
| 2214 | int number_of_descriptors() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2215 | ASSERT(length() > kFirstIndex || IsEmpty()); |
| 2216 | int len = length(); |
| 2217 | return len <= kFirstIndex ? 0 : len - kFirstIndex; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2218 | } |
| 2219 | |
| 2220 | int NextEnumerationIndex() { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2221 | if (IsEmpty()) return PropertyDetails::kInitialIndex; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2222 | Object* obj = get(kEnumerationIndexIndex); |
| 2223 | if (obj->IsSmi()) { |
| 2224 | return Smi::cast(obj)->value(); |
| 2225 | } else { |
| 2226 | Object* index = FixedArray::cast(obj)->get(kEnumCacheBridgeEnumIndex); |
| 2227 | return Smi::cast(index)->value(); |
| 2228 | } |
| 2229 | } |
| 2230 | |
| 2231 | // Set next enumeration index and flush any enum cache. |
| 2232 | void SetNextEnumerationIndex(int value) { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2233 | if (!IsEmpty()) { |
| 2234 | fast_set(this, kEnumerationIndexIndex, Smi::FromInt(value)); |
| 2235 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2236 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2237 | bool HasEnumCache() { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2238 | return !IsEmpty() && !get(kEnumerationIndexIndex)->IsSmi(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2239 | } |
| 2240 | |
| 2241 | Object* GetEnumCache() { |
| 2242 | ASSERT(HasEnumCache()); |
| 2243 | FixedArray* bridge = FixedArray::cast(get(kEnumerationIndexIndex)); |
| 2244 | return bridge->get(kEnumCacheBridgeCacheIndex); |
| 2245 | } |
| 2246 | |
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 | inline int bit_field3_storage(); |
| 2251 | inline void set_bit_field3_storage(int value); |
| 2252 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2253 | // Initialize or change the enum cache, |
| 2254 | // using the supplied storage for the small "bridge". |
| 2255 | void SetEnumCache(FixedArray* bridge_storage, FixedArray* new_cache); |
| 2256 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2257 | // Accessors for fetching instance descriptor at descriptor number. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2258 | inline String* GetKey(int descriptor_number); |
| 2259 | inline Object* GetValue(int descriptor_number); |
| 2260 | inline Smi* GetDetails(int descriptor_number); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2261 | inline PropertyType GetType(int descriptor_number); |
| 2262 | inline int GetFieldIndex(int descriptor_number); |
| 2263 | inline JSFunction* GetConstantFunction(int descriptor_number); |
| 2264 | inline Object* GetCallbacksObject(int descriptor_number); |
| 2265 | inline AccessorDescriptor* GetCallbacks(int descriptor_number); |
| 2266 | inline bool IsProperty(int descriptor_number); |
| 2267 | inline bool IsTransition(int descriptor_number); |
| 2268 | inline bool IsNullDescriptor(int descriptor_number); |
| 2269 | inline bool IsDontEnum(int descriptor_number); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2270 | |
| 2271 | // Accessor for complete descriptor. |
| 2272 | inline void Get(int descriptor_number, Descriptor* desc); |
| 2273 | inline void Set(int descriptor_number, Descriptor* desc); |
| 2274 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2275 | // Transfer complete descriptor from another descriptor array to |
| 2276 | // this one. |
| 2277 | inline void CopyFrom(int index, DescriptorArray* src, int src_index); |
| 2278 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2279 | // 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] | 2280 | // remove map transitions. If the descriptor is already present, it is |
| 2281 | // replaced. If a replaced descriptor is a real property (not a transition |
| 2282 | // or null), its enumeration index is kept as is. |
| 2283 | // If adding a real property, map transitions must be removed. If adding |
| 2284 | // 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] | 2285 | MUST_USE_RESULT MaybeObject* CopyInsert(Descriptor* descriptor, |
| 2286 | TransitionFlag transition_flag); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2287 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2288 | // Remove all transitions. Return a copy of the array with all transitions |
| 2289 | // 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] | 2290 | MUST_USE_RESULT MaybeObject* RemoveTransitions(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2291 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2292 | // Sort the instance descriptors by the hash codes of their keys. |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 2293 | // Does not check for duplicates. |
| 2294 | void SortUnchecked(); |
| 2295 | |
| 2296 | // Sort the instance descriptors by the hash codes of their keys. |
| 2297 | // Checks the result for duplicates. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2298 | void Sort(); |
| 2299 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2300 | // Search the instance descriptors for given name. |
| 2301 | inline int Search(String* name); |
| 2302 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2303 | // As the above, but uses DescriptorLookupCache and updates it when |
| 2304 | // necessary. |
| 2305 | inline int SearchWithCache(String* name); |
| 2306 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2307 | // Tells whether the name is present int the array. |
| 2308 | bool Contains(String* name) { return kNotFound != Search(name); } |
| 2309 | |
| 2310 | // Perform a binary search in the instance descriptors represented |
| 2311 | // by this fixed array. low and high are descriptor indices. If there |
| 2312 | // are three instance descriptors in this array it should be called |
| 2313 | // with low=0 and high=2. |
| 2314 | int BinarySearch(String* name, int low, int high); |
| 2315 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2316 | // Perform a linear search in the instance descriptors represented |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2317 | // 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] | 2318 | // valid. Does not require the descriptors to be sorted. |
| 2319 | int LinearSearch(String* name, int len); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2320 | |
| 2321 | // Allocates a DescriptorArray, but returns the singleton |
| 2322 | // empty descriptor array object if number_of_descriptors is 0. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2323 | MUST_USE_RESULT static MaybeObject* Allocate(int number_of_descriptors); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2324 | |
| 2325 | // Casting. |
| 2326 | static inline DescriptorArray* cast(Object* obj); |
| 2327 | |
| 2328 | // Constant for denoting key was not found. |
| 2329 | static const int kNotFound = -1; |
| 2330 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2331 | static const int kBitField3StorageIndex = 0; |
| 2332 | static const int kContentArrayIndex = 1; |
| 2333 | static const int kEnumerationIndexIndex = 2; |
| 2334 | static const int kFirstIndex = 3; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2335 | |
| 2336 | // The length of the "bridge" to the enum cache. |
| 2337 | static const int kEnumCacheBridgeLength = 2; |
| 2338 | static const int kEnumCacheBridgeEnumIndex = 0; |
| 2339 | static const int kEnumCacheBridgeCacheIndex = 1; |
| 2340 | |
| 2341 | // Layout description. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2342 | static const int kBitField3StorageOffset = FixedArray::kHeaderSize; |
| 2343 | static const int kContentArrayOffset = kBitField3StorageOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2344 | static const int kEnumerationIndexOffset = kContentArrayOffset + kPointerSize; |
| 2345 | static const int kFirstOffset = kEnumerationIndexOffset + kPointerSize; |
| 2346 | |
| 2347 | // Layout description for the bridge array. |
| 2348 | static const int kEnumCacheBridgeEnumOffset = FixedArray::kHeaderSize; |
| 2349 | static const int kEnumCacheBridgeCacheOffset = |
| 2350 | kEnumCacheBridgeEnumOffset + kPointerSize; |
| 2351 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2352 | #ifdef OBJECT_PRINT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2353 | // Print all the descriptors. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2354 | inline void PrintDescriptors() { |
| 2355 | PrintDescriptors(stdout); |
| 2356 | } |
| 2357 | void PrintDescriptors(FILE* out); |
| 2358 | #endif |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 2359 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2360 | #ifdef DEBUG |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 2361 | // Is the descriptor array sorted and without duplicates? |
| 2362 | bool IsSortedNoDuplicates(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2363 | |
| 2364 | // Are two DescriptorArrays equal? |
| 2365 | bool IsEqualTo(DescriptorArray* other); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2366 | #endif |
| 2367 | |
| 2368 | // The maximum number of descriptors we want in a descriptor array (should |
| 2369 | // fit in a page). |
| 2370 | static const int kMaxNumberOfDescriptors = 1024 + 512; |
| 2371 | |
| 2372 | private: |
| 2373 | // Conversion from descriptor number to array indices. |
| 2374 | static int ToKeyIndex(int descriptor_number) { |
| 2375 | return descriptor_number+kFirstIndex; |
| 2376 | } |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 2377 | |
| 2378 | static int ToDetailsIndex(int descriptor_number) { |
| 2379 | return (descriptor_number << 1) + 1; |
| 2380 | } |
| 2381 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2382 | static int ToValueIndex(int descriptor_number) { |
| 2383 | return descriptor_number << 1; |
| 2384 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2385 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2386 | bool is_null_descriptor(int descriptor_number) { |
| 2387 | return PropertyDetails(GetDetails(descriptor_number)).type() == |
| 2388 | NULL_DESCRIPTOR; |
| 2389 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2390 | // Swap operation on FixedArray without using write barriers. |
| 2391 | static inline void fast_swap(FixedArray* array, int first, int second); |
| 2392 | |
| 2393 | // Swap descriptor first and second. |
| 2394 | inline void Swap(int first, int second); |
| 2395 | |
| 2396 | FixedArray* GetContentArray() { |
| 2397 | return FixedArray::cast(get(kContentArrayIndex)); |
| 2398 | } |
| 2399 | DISALLOW_IMPLICIT_CONSTRUCTORS(DescriptorArray); |
| 2400 | }; |
| 2401 | |
| 2402 | |
| 2403 | // HashTable is a subclass of FixedArray that implements a hash table |
| 2404 | // that uses open addressing and quadratic probing. |
| 2405 | // |
| 2406 | // In order for the quadratic probing to work, elements that have not |
| 2407 | // yet been used and elements that have been deleted are |
| 2408 | // distinguished. Probing continues when deleted elements are |
| 2409 | // encountered and stops when unused elements are encountered. |
| 2410 | // |
| 2411 | // - Elements with key == undefined have not been used yet. |
| 2412 | // - Elements with key == null have been deleted. |
| 2413 | // |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2414 | // The hash table class is parameterized with a Shape and a Key. |
| 2415 | // Shape must be a class with the following interface: |
| 2416 | // class ExampleShape { |
| 2417 | // public: |
| 2418 | // // Tells whether key matches other. |
| 2419 | // static bool IsMatch(Key key, Object* other); |
| 2420 | // // Returns the hash value for key. |
| 2421 | // static uint32_t Hash(Key key); |
| 2422 | // // Returns the hash value for object. |
| 2423 | // static uint32_t HashForObject(Key key, Object* object); |
| 2424 | // // Convert key to an object. |
| 2425 | // static inline Object* AsObject(Key key); |
| 2426 | // // The prefix size indicates number of elements in the beginning |
| 2427 | // // of the backing storage. |
| 2428 | // static const int kPrefixSize = ..; |
| 2429 | // // The Element size indicates number of elements per entry. |
| 2430 | // static const int kEntrySize = ..; |
| 2431 | // }; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2432 | // The prefix size indicates an amount of memory in the |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2433 | // beginning of the backing storage that can be used for non-element |
| 2434 | // information by subclasses. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2435 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2436 | template<typename Shape, typename Key> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2437 | class HashTable: public FixedArray { |
| 2438 | public: |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2439 | // Returns the number of elements in the hash table. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2440 | int NumberOfElements() { |
| 2441 | return Smi::cast(get(kNumberOfElementsIndex))->value(); |
| 2442 | } |
| 2443 | |
kasperl@chromium.org | edf0cd1 | 2010-01-05 13:29:12 +0000 | [diff] [blame] | 2444 | // Returns the number of deleted elements in the hash table. |
| 2445 | int NumberOfDeletedElements() { |
| 2446 | return Smi::cast(get(kNumberOfDeletedElementsIndex))->value(); |
| 2447 | } |
| 2448 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2449 | // Returns the capacity of the hash table. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2450 | int Capacity() { |
| 2451 | return Smi::cast(get(kCapacityIndex))->value(); |
| 2452 | } |
| 2453 | |
| 2454 | // 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] | 2455 | // hash table. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2456 | void ElementAdded() { SetNumberOfElements(NumberOfElements() + 1); } |
| 2457 | |
| 2458 | // 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] | 2459 | // a hash table. |
kasperl@chromium.org | edf0cd1 | 2010-01-05 13:29:12 +0000 | [diff] [blame] | 2460 | void ElementRemoved() { |
| 2461 | SetNumberOfElements(NumberOfElements() - 1); |
| 2462 | SetNumberOfDeletedElements(NumberOfDeletedElements() + 1); |
| 2463 | } |
| 2464 | void ElementsRemoved(int n) { |
| 2465 | SetNumberOfElements(NumberOfElements() - n); |
| 2466 | SetNumberOfDeletedElements(NumberOfDeletedElements() + n); |
| 2467 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2468 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2469 | // Returns a new HashTable object. Might return Failure. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2470 | MUST_USE_RESULT static MaybeObject* Allocate( |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2471 | int at_least_space_for, |
| 2472 | PretenureFlag pretenure = NOT_TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2473 | |
| 2474 | // Returns the key at entry. |
| 2475 | Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } |
| 2476 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2477 | // 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] | 2478 | // as keys and can be used to indicate missing or deleted elements. |
| 2479 | bool IsKey(Object* k) { |
| 2480 | return !k->IsNull() && !k->IsUndefined(); |
| 2481 | } |
| 2482 | |
| 2483 | // Garbage collection support. |
| 2484 | void IteratePrefix(ObjectVisitor* visitor); |
| 2485 | void IterateElements(ObjectVisitor* visitor); |
| 2486 | |
| 2487 | // Casting. |
| 2488 | static inline HashTable* cast(Object* obj); |
| 2489 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2490 | // Compute the probe offset (quadratic probing). |
| 2491 | INLINE(static uint32_t GetProbeOffset(uint32_t n)) { |
| 2492 | return (n + n * n) >> 1; |
| 2493 | } |
| 2494 | |
| 2495 | static const int kNumberOfElementsIndex = 0; |
kasperl@chromium.org | edf0cd1 | 2010-01-05 13:29:12 +0000 | [diff] [blame] | 2496 | static const int kNumberOfDeletedElementsIndex = 1; |
| 2497 | static const int kCapacityIndex = 2; |
| 2498 | static const int kPrefixStartIndex = 3; |
| 2499 | static const int kElementsStartIndex = |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2500 | kPrefixStartIndex + Shape::kPrefixSize; |
kasperl@chromium.org | edf0cd1 | 2010-01-05 13:29:12 +0000 | [diff] [blame] | 2501 | static const int kEntrySize = Shape::kEntrySize; |
| 2502 | static const int kElementsStartOffset = |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2503 | kHeaderSize + kElementsStartIndex * kPointerSize; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2504 | static const int kCapacityOffset = |
| 2505 | kHeaderSize + kCapacityIndex * kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2506 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2507 | // Constant used for denoting a absent entry. |
| 2508 | static const int kNotFound = -1; |
| 2509 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2510 | // Maximal capacity of HashTable. Based on maximal length of underlying |
| 2511 | // FixedArray. Staying below kMaxCapacity also ensures that EntryToIndex |
| 2512 | // cannot overflow. |
| 2513 | static const int kMaxCapacity = |
| 2514 | (FixedArray::kMaxLength - kElementsStartOffset) / kEntrySize; |
| 2515 | |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2516 | // Find entry for key otherwise return kNotFound. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2517 | inline int FindEntry(Key key); |
| 2518 | int FindEntry(Isolate* isolate, Key key); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2519 | |
| 2520 | protected: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2521 | // Find the entry at which to insert element with the given key that |
| 2522 | // has the given hash value. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2523 | uint32_t FindInsertionEntry(uint32_t hash); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2524 | |
| 2525 | // Returns the index for an entry (of the key) |
| 2526 | static inline int EntryToIndex(int entry) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2527 | return (entry * kEntrySize) + kElementsStartIndex; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2528 | } |
| 2529 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2530 | // Update the number of elements in the hash table. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2531 | void SetNumberOfElements(int nof) { |
| 2532 | fast_set(this, kNumberOfElementsIndex, Smi::FromInt(nof)); |
| 2533 | } |
| 2534 | |
kasperl@chromium.org | edf0cd1 | 2010-01-05 13:29:12 +0000 | [diff] [blame] | 2535 | // Update the number of deleted elements in the hash table. |
| 2536 | void SetNumberOfDeletedElements(int nod) { |
| 2537 | fast_set(this, kNumberOfDeletedElementsIndex, Smi::FromInt(nod)); |
| 2538 | } |
| 2539 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2540 | // Sets the capacity of the hash table. |
| 2541 | void SetCapacity(int capacity) { |
| 2542 | // To scale a computed hash code to fit within the hash table, we |
| 2543 | // use bit-wise AND with a mask, so the capacity must be positive |
| 2544 | // and non-zero. |
| 2545 | ASSERT(capacity > 0); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2546 | ASSERT(capacity <= kMaxCapacity); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2547 | fast_set(this, kCapacityIndex, Smi::FromInt(capacity)); |
| 2548 | } |
| 2549 | |
| 2550 | |
| 2551 | // Returns probe entry. |
| 2552 | static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size) { |
| 2553 | ASSERT(IsPowerOf2(size)); |
| 2554 | return (hash + GetProbeOffset(number)) & (size - 1); |
| 2555 | } |
| 2556 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2557 | static uint32_t FirstProbe(uint32_t hash, uint32_t size) { |
| 2558 | return hash & (size - 1); |
| 2559 | } |
| 2560 | |
| 2561 | static uint32_t NextProbe(uint32_t last, uint32_t number, uint32_t size) { |
| 2562 | return (last + number) & (size - 1); |
| 2563 | } |
| 2564 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2565 | // Ensure enough space for n additional elements. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2566 | MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2567 | }; |
| 2568 | |
| 2569 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2570 | |
| 2571 | // HashTableKey is an abstract superclass for virtual key behavior. |
| 2572 | class HashTableKey { |
| 2573 | public: |
| 2574 | // Returns whether the other object matches this key. |
| 2575 | virtual bool IsMatch(Object* other) = 0; |
| 2576 | // Returns the hash value for this key. |
| 2577 | virtual uint32_t Hash() = 0; |
| 2578 | // Returns the hash value for object. |
| 2579 | virtual uint32_t HashForObject(Object* key) = 0; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2580 | // Returns the key object for storing into the hash table. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2581 | // If allocations fails a failure object is returned. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2582 | MUST_USE_RESULT virtual MaybeObject* AsObject() = 0; |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2583 | // Required. |
| 2584 | virtual ~HashTableKey() {} |
| 2585 | }; |
| 2586 | |
| 2587 | class SymbolTableShape { |
| 2588 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2589 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2590 | return key->IsMatch(value); |
| 2591 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2592 | static inline uint32_t Hash(HashTableKey* key) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2593 | return key->Hash(); |
| 2594 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2595 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2596 | return key->HashForObject(object); |
| 2597 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2598 | MUST_USE_RESULT static inline MaybeObject* AsObject(HashTableKey* key) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2599 | return key->AsObject(); |
| 2600 | } |
| 2601 | |
| 2602 | static const int kPrefixSize = 0; |
| 2603 | static const int kEntrySize = 1; |
| 2604 | }; |
| 2605 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2606 | class SeqAsciiString; |
| 2607 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2608 | // SymbolTable. |
| 2609 | // |
| 2610 | // No special elements in the prefix and the element size is 1 |
| 2611 | // because only the symbol itself (the key) needs to be stored. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2612 | class SymbolTable: public HashTable<SymbolTableShape, HashTableKey*> { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2613 | public: |
| 2614 | // Find symbol in the symbol table. If it is not there yet, it is |
| 2615 | // added. The return value is the symbol table which might have |
| 2616 | // been enlarged. If the return value is not a failure, the symbol |
| 2617 | // pointer *s is set to the symbol found. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2618 | MUST_USE_RESULT MaybeObject* LookupSymbol(Vector<const char> str, Object** s); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 2619 | MUST_USE_RESULT MaybeObject* LookupAsciiSymbol(Vector<const char> str, |
| 2620 | Object** s); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2621 | MUST_USE_RESULT MaybeObject* LookupSubStringAsciiSymbol( |
| 2622 | Handle<SeqAsciiString> str, |
| 2623 | int from, |
| 2624 | int length, |
| 2625 | Object** s); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 2626 | MUST_USE_RESULT MaybeObject* LookupTwoByteSymbol(Vector<const uc16> str, |
| 2627 | Object** s); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2628 | MUST_USE_RESULT MaybeObject* LookupString(String* key, Object** s); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2629 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2630 | // Looks up a symbol that is equal to the given string and returns |
| 2631 | // true if it is found, assigning the symbol to the given output |
| 2632 | // parameter. |
| 2633 | bool LookupSymbolIfExists(String* str, String** symbol); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 2634 | bool LookupTwoCharsSymbolIfExists(uint32_t c1, uint32_t c2, String** symbol); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2635 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2636 | // Casting. |
| 2637 | static inline SymbolTable* cast(Object* obj); |
| 2638 | |
| 2639 | private: |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2640 | MUST_USE_RESULT MaybeObject* LookupKey(HashTableKey* key, Object** s); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2641 | |
| 2642 | DISALLOW_IMPLICIT_CONSTRUCTORS(SymbolTable); |
| 2643 | }; |
| 2644 | |
| 2645 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2646 | class MapCacheShape { |
| 2647 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2648 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2649 | return key->IsMatch(value); |
| 2650 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2651 | static inline uint32_t Hash(HashTableKey* key) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2652 | return key->Hash(); |
| 2653 | } |
| 2654 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2655 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2656 | return key->HashForObject(object); |
| 2657 | } |
| 2658 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2659 | MUST_USE_RESULT static inline MaybeObject* AsObject(HashTableKey* key) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2660 | return key->AsObject(); |
| 2661 | } |
| 2662 | |
| 2663 | static const int kPrefixSize = 0; |
| 2664 | static const int kEntrySize = 2; |
| 2665 | }; |
| 2666 | |
| 2667 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2668 | // MapCache. |
| 2669 | // |
| 2670 | // Maps keys that are a fixed array of symbols to a map. |
| 2671 | // Used for canonicalize maps for object literals. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2672 | class MapCache: public HashTable<MapCacheShape, HashTableKey*> { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2673 | public: |
| 2674 | // Find cached value for a string key, otherwise return null. |
| 2675 | Object* Lookup(FixedArray* key); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2676 | MUST_USE_RESULT MaybeObject* Put(FixedArray* key, Map* value); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2677 | static inline MapCache* cast(Object* obj); |
| 2678 | |
| 2679 | private: |
| 2680 | DISALLOW_IMPLICIT_CONSTRUCTORS(MapCache); |
| 2681 | }; |
| 2682 | |
| 2683 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2684 | template <typename Shape, typename Key> |
| 2685 | class Dictionary: public HashTable<Shape, Key> { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2686 | public: |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2687 | static inline Dictionary<Shape, Key>* cast(Object* obj) { |
| 2688 | return reinterpret_cast<Dictionary<Shape, Key>*>(obj); |
| 2689 | } |
| 2690 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2691 | // Returns the value at entry. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2692 | Object* ValueAt(int entry) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 2693 | return this->get(HashTable<Shape, Key>::EntryToIndex(entry)+1); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2694 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2695 | |
| 2696 | // Set the value for entry. |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2697 | // Returns false if the put wasn't performed due to property being read only. |
| 2698 | // Returns true on successful put. |
| 2699 | bool ValueAtPut(int entry, Object* value) { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2700 | // Check that this value can actually be written. |
| 2701 | PropertyDetails details = DetailsAt(entry); |
| 2702 | // If a value has not been initilized we allow writing to it even if |
| 2703 | // 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] | 2704 | if (details.IsReadOnly() && !ValueAt(entry)->IsTheHole()) { |
| 2705 | return false; |
| 2706 | } |
| 2707 | this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 1, value); |
| 2708 | return true; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2709 | } |
| 2710 | |
| 2711 | // Returns the property details for the property at entry. |
| 2712 | PropertyDetails DetailsAt(int entry) { |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 2713 | 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] | 2714 | return PropertyDetails( |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 2715 | Smi::cast(this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 2))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2716 | } |
| 2717 | |
| 2718 | // Set the details for entry. |
| 2719 | void DetailsAtPut(int entry, PropertyDetails value) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 2720 | this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 2, value.AsSmi()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2721 | } |
| 2722 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2723 | // Sorting support |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2724 | void CopyValuesTo(FixedArray* elements); |
| 2725 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2726 | // Delete a property from the dictionary. |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2727 | Object* DeleteProperty(int entry, JSObject::DeleteMode mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2728 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2729 | // Returns the number of elements in the dictionary filtering out properties |
| 2730 | // with the specified attributes. |
| 2731 | int NumberOfElementsFilterAttributes(PropertyAttributes filter); |
| 2732 | |
| 2733 | // Returns the number of enumerable elements in the dictionary. |
| 2734 | int NumberOfEnumElements(); |
| 2735 | |
| 2736 | // Copies keys to preallocated fixed array. |
| 2737 | void CopyKeysTo(FixedArray* storage, PropertyAttributes filter); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2738 | // Fill in details for properties into storage. |
| 2739 | void CopyKeysTo(FixedArray* storage); |
| 2740 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2741 | // Accessors for next enumeration index. |
| 2742 | void SetNextEnumerationIndex(int index) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 2743 | this->fast_set(this, kNextEnumerationIndexIndex, Smi::FromInt(index)); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2744 | } |
| 2745 | |
| 2746 | int NextEnumerationIndex() { |
| 2747 | return Smi::cast(FixedArray::get(kNextEnumerationIndexIndex))->value(); |
| 2748 | } |
| 2749 | |
| 2750 | // Returns a new array for dictionary usage. Might return Failure. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2751 | MUST_USE_RESULT static MaybeObject* Allocate(int at_least_space_for); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2752 | |
| 2753 | // Ensure enough space for n additional elements. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2754 | MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2755 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2756 | #ifdef OBJECT_PRINT |
| 2757 | inline void Print() { |
| 2758 | Print(stdout); |
| 2759 | } |
| 2760 | void Print(FILE* out); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2761 | #endif |
| 2762 | // Returns the key (slow). |
| 2763 | Object* SlowReverseLookup(Object* value); |
| 2764 | |
| 2765 | // Sets the entry to (key, value) pair. |
| 2766 | inline void SetEntry(int entry, |
| 2767 | Object* key, |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2768 | Object* value); |
| 2769 | inline void SetEntry(int entry, |
| 2770 | Object* key, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2771 | Object* value, |
| 2772 | PropertyDetails details); |
| 2773 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2774 | MUST_USE_RESULT MaybeObject* Add(Key key, |
| 2775 | Object* value, |
| 2776 | PropertyDetails details); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2777 | |
| 2778 | protected: |
| 2779 | // Generic at put operation. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2780 | MUST_USE_RESULT MaybeObject* AtPut(Key key, Object* value); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2781 | |
| 2782 | // Add entry to dictionary. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2783 | MUST_USE_RESULT MaybeObject* AddEntry(Key key, |
| 2784 | Object* value, |
| 2785 | PropertyDetails details, |
| 2786 | uint32_t hash); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2787 | |
| 2788 | // Generate new enumeration indices to avoid enumeration index overflow. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2789 | MUST_USE_RESULT MaybeObject* GenerateNewEnumerationIndices(); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2790 | static const int kMaxNumberKeyIndex = |
| 2791 | HashTable<Shape, Key>::kPrefixStartIndex; |
| 2792 | static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1; |
| 2793 | }; |
| 2794 | |
| 2795 | |
| 2796 | class StringDictionaryShape { |
| 2797 | public: |
| 2798 | static inline bool IsMatch(String* key, Object* other); |
| 2799 | static inline uint32_t Hash(String* key); |
| 2800 | static inline uint32_t HashForObject(String* key, Object* object); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2801 | MUST_USE_RESULT static inline MaybeObject* AsObject(String* key); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2802 | static const int kPrefixSize = 2; |
| 2803 | static const int kEntrySize = 3; |
| 2804 | static const bool kIsEnumerable = true; |
| 2805 | }; |
| 2806 | |
| 2807 | |
| 2808 | class StringDictionary: public Dictionary<StringDictionaryShape, String*> { |
| 2809 | public: |
| 2810 | static inline StringDictionary* cast(Object* obj) { |
| 2811 | ASSERT(obj->IsDictionary()); |
| 2812 | return reinterpret_cast<StringDictionary*>(obj); |
| 2813 | } |
| 2814 | |
| 2815 | // Copies enumerable keys to preallocated fixed array. |
| 2816 | void CopyEnumKeysTo(FixedArray* storage, FixedArray* sort_array); |
| 2817 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2818 | // For transforming properties of a JSObject. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2819 | MUST_USE_RESULT MaybeObject* TransformPropertiesToFastFor( |
| 2820 | JSObject* obj, |
| 2821 | int unused_property_fields); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2822 | |
| 2823 | // Find entry for key otherwise return kNotFound. Optimzed version of |
| 2824 | // HashTable::FindEntry. |
| 2825 | int FindEntry(String* key); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2826 | }; |
| 2827 | |
| 2828 | |
| 2829 | class NumberDictionaryShape { |
| 2830 | public: |
| 2831 | static inline bool IsMatch(uint32_t key, Object* other); |
| 2832 | static inline uint32_t Hash(uint32_t key); |
| 2833 | static inline uint32_t HashForObject(uint32_t key, Object* object); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2834 | MUST_USE_RESULT static inline MaybeObject* AsObject(uint32_t key); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2835 | static const int kPrefixSize = 2; |
| 2836 | static const int kEntrySize = 3; |
| 2837 | static const bool kIsEnumerable = false; |
| 2838 | }; |
| 2839 | |
| 2840 | |
| 2841 | class NumberDictionary: public Dictionary<NumberDictionaryShape, uint32_t> { |
| 2842 | public: |
| 2843 | static NumberDictionary* cast(Object* obj) { |
| 2844 | ASSERT(obj->IsDictionary()); |
| 2845 | return reinterpret_cast<NumberDictionary*>(obj); |
| 2846 | } |
| 2847 | |
| 2848 | // Type specific at put (default NONE attributes is used when adding). |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2849 | MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value); |
| 2850 | MUST_USE_RESULT MaybeObject* AddNumberEntry(uint32_t key, |
| 2851 | Object* value, |
| 2852 | PropertyDetails details); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2853 | |
| 2854 | // Set an existing entry or add a new one if needed. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2855 | MUST_USE_RESULT MaybeObject* Set(uint32_t key, |
| 2856 | Object* value, |
| 2857 | PropertyDetails details); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2858 | |
| 2859 | void UpdateMaxNumberKey(uint32_t key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2860 | |
| 2861 | // If slow elements are required we will never go back to fast-case |
| 2862 | // for the elements kept in this dictionary. We require slow |
| 2863 | // 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] | 2864 | // kRequiresSlowElementsLimit or set_requires_slow_elements() has been called |
| 2865 | // when defining a getter or setter with a number key. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2866 | inline bool requires_slow_elements(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2867 | inline void set_requires_slow_elements(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2868 | |
| 2869 | // Get the value of the max number key that has been added to this |
| 2870 | // dictionary. max_number_key can only be called if |
| 2871 | // requires_slow_elements returns false. |
| 2872 | inline uint32_t max_number_key(); |
| 2873 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2874 | // Remove all entries were key is a number and (from <= key && key < to). |
| 2875 | void RemoveNumberEntries(uint32_t from, uint32_t to); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2876 | |
| 2877 | // Bit masks. |
| 2878 | static const int kRequiresSlowElementsMask = 1; |
| 2879 | static const int kRequiresSlowElementsTagSize = 1; |
| 2880 | static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2881 | }; |
| 2882 | |
| 2883 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2884 | // JSFunctionResultCache caches results of some JSFunction invocation. |
| 2885 | // It is a fixed array with fixed structure: |
| 2886 | // [0]: factory function |
| 2887 | // [1]: finger index |
| 2888 | // [2]: current cache size |
| 2889 | // [3]: dummy field. |
| 2890 | // The rest of array are key/value pairs. |
| 2891 | class JSFunctionResultCache: public FixedArray { |
| 2892 | public: |
| 2893 | static const int kFactoryIndex = 0; |
| 2894 | static const int kFingerIndex = kFactoryIndex + 1; |
| 2895 | static const int kCacheSizeIndex = kFingerIndex + 1; |
| 2896 | static const int kDummyIndex = kCacheSizeIndex + 1; |
| 2897 | static const int kEntriesIndex = kDummyIndex + 1; |
antonm@chromium.org | 397e23c | 2010-04-21 12:00:05 +0000 | [diff] [blame] | 2898 | |
| 2899 | static const int kEntrySize = 2; // key + value |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2900 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2901 | static const int kFactoryOffset = kHeaderSize; |
| 2902 | static const int kFingerOffset = kFactoryOffset + kPointerSize; |
| 2903 | static const int kCacheSizeOffset = kFingerOffset + kPointerSize; |
| 2904 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2905 | inline void MakeZeroSize(); |
| 2906 | inline void Clear(); |
| 2907 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2908 | inline int size(); |
| 2909 | inline void set_size(int size); |
| 2910 | inline int finger_index(); |
| 2911 | inline void set_finger_index(int finger_index); |
| 2912 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2913 | // Casting |
| 2914 | static inline JSFunctionResultCache* cast(Object* obj); |
| 2915 | |
| 2916 | #ifdef DEBUG |
| 2917 | void JSFunctionResultCacheVerify(); |
| 2918 | #endif |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2919 | }; |
| 2920 | |
| 2921 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2922 | // The cache for maps used by normalized (dictionary mode) objects. |
| 2923 | // Such maps do not have property descriptors, so a typical program |
| 2924 | // needs very limited number of distinct normalized maps. |
| 2925 | class NormalizedMapCache: public FixedArray { |
| 2926 | public: |
| 2927 | static const int kEntries = 64; |
| 2928 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2929 | MUST_USE_RESULT MaybeObject* Get(JSObject* object, |
| 2930 | PropertyNormalizationMode mode); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2931 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2932 | void Clear(); |
| 2933 | |
| 2934 | // Casting |
| 2935 | static inline NormalizedMapCache* cast(Object* obj); |
| 2936 | |
| 2937 | #ifdef DEBUG |
| 2938 | void NormalizedMapCacheVerify(); |
| 2939 | #endif |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2940 | }; |
| 2941 | |
| 2942 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2943 | // ByteArray represents fixed sized byte arrays. Used by the outside world, |
| 2944 | // such as PCRE, and also by the memory allocator and garbage collector to |
| 2945 | // fill in free blocks in the heap. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2946 | class ByteArray: public HeapObject { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2947 | public: |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2948 | // [length]: length of the array. |
| 2949 | inline int length(); |
| 2950 | inline void set_length(int value); |
| 2951 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2952 | // Setter and getter. |
| 2953 | inline byte get(int index); |
| 2954 | inline void set(int index, byte value); |
| 2955 | |
| 2956 | // Treat contents as an int array. |
| 2957 | inline int get_int(int index); |
| 2958 | |
| 2959 | static int SizeFor(int length) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2960 | return OBJECT_POINTER_ALIGN(kHeaderSize + length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2961 | } |
| 2962 | // We use byte arrays for free blocks in the heap. Given a desired size in |
| 2963 | // bytes that is a multiple of the word size and big enough to hold a byte |
| 2964 | // array, this function returns the number of elements a byte array should |
| 2965 | // have. |
| 2966 | static int LengthFor(int size_in_bytes) { |
| 2967 | ASSERT(IsAligned(size_in_bytes, kPointerSize)); |
| 2968 | ASSERT(size_in_bytes >= kHeaderSize); |
| 2969 | return size_in_bytes - kHeaderSize; |
| 2970 | } |
| 2971 | |
| 2972 | // Returns data start address. |
| 2973 | inline Address GetDataStartAddress(); |
| 2974 | |
| 2975 | // Returns a pointer to the ByteArray object for a given data start address. |
| 2976 | static inline ByteArray* FromDataStartAddress(Address address); |
| 2977 | |
| 2978 | // Casting. |
| 2979 | static inline ByteArray* cast(Object* obj); |
| 2980 | |
| 2981 | // Dispatched behavior. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2982 | inline int ByteArraySize() { |
| 2983 | return SizeFor(this->length()); |
| 2984 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2985 | #ifdef OBJECT_PRINT |
| 2986 | inline void ByteArrayPrint() { |
| 2987 | ByteArrayPrint(stdout); |
| 2988 | } |
| 2989 | void ByteArrayPrint(FILE* out); |
| 2990 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2991 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2992 | void ByteArrayVerify(); |
| 2993 | #endif |
| 2994 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2995 | // Layout description. |
| 2996 | // Length is smi tagged when it is stored. |
| 2997 | static const int kLengthOffset = HeapObject::kHeaderSize; |
| 2998 | static const int kHeaderSize = kLengthOffset + kPointerSize; |
| 2999 | |
| 3000 | static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 3001 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3002 | // Maximal memory consumption for a single ByteArray. |
| 3003 | static const int kMaxSize = 512 * MB; |
| 3004 | // Maximal length of a single ByteArray. |
| 3005 | static const int kMaxLength = kMaxSize - kHeaderSize; |
| 3006 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3007 | private: |
| 3008 | DISALLOW_IMPLICIT_CONSTRUCTORS(ByteArray); |
| 3009 | }; |
| 3010 | |
| 3011 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3012 | // An ExternalArray represents a fixed-size array of primitive values |
| 3013 | // which live outside the JavaScript heap. Its subclasses are used to |
| 3014 | // implement the CanvasArray types being defined in the WebGL |
| 3015 | // specification. As of this writing the first public draft is not yet |
| 3016 | // available, but Khronos members can access the draft at: |
| 3017 | // https://cvs.khronos.org/svn/repos/3dweb/trunk/doc/spec/WebGL-spec.html |
| 3018 | // |
| 3019 | // The semantics of these arrays differ from CanvasPixelArray. |
| 3020 | // Out-of-range values passed to the setter are converted via a C |
| 3021 | // cast, not clamping. Out-of-range indices cause exceptions to be |
| 3022 | // raised rather than being silently ignored. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3023 | class ExternalArray: public HeapObject { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3024 | public: |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3025 | // [length]: length of the array. |
| 3026 | inline int length(); |
| 3027 | inline void set_length(int value); |
| 3028 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3029 | // [external_pointer]: The pointer to the external memory area backing this |
| 3030 | // external array. |
| 3031 | DECL_ACCESSORS(external_pointer, void) // Pointer to the data store. |
| 3032 | |
| 3033 | // Casting. |
| 3034 | static inline ExternalArray* cast(Object* obj); |
| 3035 | |
| 3036 | // Maximal acceptable length for an external array. |
| 3037 | static const int kMaxLength = 0x3fffffff; |
| 3038 | |
| 3039 | // ExternalArray headers are not quadword aligned. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3040 | static const int kLengthOffset = HeapObject::kHeaderSize; |
| 3041 | static const int kExternalPointerOffset = |
| 3042 | POINTER_SIZE_ALIGN(kLengthOffset + kIntSize); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3043 | static const int kHeaderSize = kExternalPointerOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3044 | static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3045 | |
| 3046 | private: |
| 3047 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalArray); |
| 3048 | }; |
| 3049 | |
| 3050 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3051 | // A ExternalPixelArray represents a fixed-size byte array with special |
| 3052 | // semantics used for implementing the CanvasPixelArray object. Please see the |
| 3053 | // specification at: |
| 3054 | |
| 3055 | // http://www.whatwg.org/specs/web-apps/current-work/ |
| 3056 | // multipage/the-canvas-element.html#canvaspixelarray |
| 3057 | // In particular, write access clamps the value written to 0 or 255 if the |
| 3058 | // value written is outside this range. |
| 3059 | class ExternalPixelArray: public ExternalArray { |
| 3060 | public: |
| 3061 | inline uint8_t* external_pixel_pointer(); |
| 3062 | |
| 3063 | // Setter and getter. |
| 3064 | inline uint8_t get(int index); |
| 3065 | inline void set(int index, uint8_t value); |
| 3066 | |
| 3067 | // This accessor applies the correct conversion from Smi, HeapNumber and |
| 3068 | // undefined and clamps the converted value between 0 and 255. |
| 3069 | Object* SetValue(uint32_t index, Object* value); |
| 3070 | |
| 3071 | // Casting. |
| 3072 | static inline ExternalPixelArray* cast(Object* obj); |
| 3073 | |
| 3074 | #ifdef OBJECT_PRINT |
| 3075 | inline void ExternalPixelArrayPrint() { |
| 3076 | ExternalPixelArrayPrint(stdout); |
| 3077 | } |
| 3078 | void ExternalPixelArrayPrint(FILE* out); |
| 3079 | #endif |
| 3080 | #ifdef DEBUG |
| 3081 | void ExternalPixelArrayVerify(); |
| 3082 | #endif // DEBUG |
| 3083 | |
| 3084 | private: |
| 3085 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalPixelArray); |
| 3086 | }; |
| 3087 | |
| 3088 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3089 | class ExternalByteArray: public ExternalArray { |
| 3090 | public: |
| 3091 | // Setter and getter. |
| 3092 | inline int8_t get(int index); |
| 3093 | inline void set(int index, int8_t value); |
| 3094 | |
| 3095 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3096 | // and undefined. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3097 | MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3098 | |
| 3099 | // Casting. |
| 3100 | static inline ExternalByteArray* cast(Object* obj); |
| 3101 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3102 | #ifdef OBJECT_PRINT |
| 3103 | inline void ExternalByteArrayPrint() { |
| 3104 | ExternalByteArrayPrint(stdout); |
| 3105 | } |
| 3106 | void ExternalByteArrayPrint(FILE* out); |
| 3107 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3108 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3109 | void ExternalByteArrayVerify(); |
| 3110 | #endif // DEBUG |
| 3111 | |
| 3112 | private: |
| 3113 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalByteArray); |
| 3114 | }; |
| 3115 | |
| 3116 | |
| 3117 | class ExternalUnsignedByteArray: public ExternalArray { |
| 3118 | public: |
| 3119 | // Setter and getter. |
| 3120 | inline uint8_t get(int index); |
| 3121 | inline void set(int index, uint8_t value); |
| 3122 | |
| 3123 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3124 | // and undefined. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3125 | MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3126 | |
| 3127 | // Casting. |
| 3128 | static inline ExternalUnsignedByteArray* cast(Object* obj); |
| 3129 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3130 | #ifdef OBJECT_PRINT |
| 3131 | inline void ExternalUnsignedByteArrayPrint() { |
| 3132 | ExternalUnsignedByteArrayPrint(stdout); |
| 3133 | } |
| 3134 | void ExternalUnsignedByteArrayPrint(FILE* out); |
| 3135 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3136 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3137 | void ExternalUnsignedByteArrayVerify(); |
| 3138 | #endif // DEBUG |
| 3139 | |
| 3140 | private: |
| 3141 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedByteArray); |
| 3142 | }; |
| 3143 | |
| 3144 | |
| 3145 | class ExternalShortArray: public ExternalArray { |
| 3146 | public: |
| 3147 | // Setter and getter. |
| 3148 | inline int16_t get(int index); |
| 3149 | inline void set(int index, int16_t value); |
| 3150 | |
| 3151 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3152 | // and undefined. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3153 | MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3154 | |
| 3155 | // Casting. |
| 3156 | static inline ExternalShortArray* cast(Object* obj); |
| 3157 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3158 | #ifdef OBJECT_PRINT |
| 3159 | inline void ExternalShortArrayPrint() { |
| 3160 | ExternalShortArrayPrint(stdout); |
| 3161 | } |
| 3162 | void ExternalShortArrayPrint(FILE* out); |
| 3163 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3164 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3165 | void ExternalShortArrayVerify(); |
| 3166 | #endif // DEBUG |
| 3167 | |
| 3168 | private: |
| 3169 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalShortArray); |
| 3170 | }; |
| 3171 | |
| 3172 | |
| 3173 | class ExternalUnsignedShortArray: public ExternalArray { |
| 3174 | public: |
| 3175 | // Setter and getter. |
| 3176 | inline uint16_t get(int index); |
| 3177 | inline void set(int index, uint16_t value); |
| 3178 | |
| 3179 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3180 | // and undefined. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3181 | MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3182 | |
| 3183 | // Casting. |
| 3184 | static inline ExternalUnsignedShortArray* cast(Object* obj); |
| 3185 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3186 | #ifdef OBJECT_PRINT |
| 3187 | inline void ExternalUnsignedShortArrayPrint() { |
| 3188 | ExternalUnsignedShortArrayPrint(stdout); |
| 3189 | } |
| 3190 | void ExternalUnsignedShortArrayPrint(FILE* out); |
| 3191 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3192 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3193 | void ExternalUnsignedShortArrayVerify(); |
| 3194 | #endif // DEBUG |
| 3195 | |
| 3196 | private: |
| 3197 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedShortArray); |
| 3198 | }; |
| 3199 | |
| 3200 | |
| 3201 | class ExternalIntArray: public ExternalArray { |
| 3202 | public: |
| 3203 | // Setter and getter. |
| 3204 | inline int32_t get(int index); |
| 3205 | inline void set(int index, int32_t value); |
| 3206 | |
| 3207 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3208 | // and undefined. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3209 | MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3210 | |
| 3211 | // Casting. |
| 3212 | static inline ExternalIntArray* cast(Object* obj); |
| 3213 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3214 | #ifdef OBJECT_PRINT |
| 3215 | inline void ExternalIntArrayPrint() { |
| 3216 | ExternalIntArrayPrint(stdout); |
| 3217 | } |
| 3218 | void ExternalIntArrayPrint(FILE* out); |
| 3219 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3220 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3221 | void ExternalIntArrayVerify(); |
| 3222 | #endif // DEBUG |
| 3223 | |
| 3224 | private: |
| 3225 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalIntArray); |
| 3226 | }; |
| 3227 | |
| 3228 | |
| 3229 | class ExternalUnsignedIntArray: public ExternalArray { |
| 3230 | public: |
| 3231 | // Setter and getter. |
| 3232 | inline uint32_t get(int index); |
| 3233 | inline void set(int index, uint32_t value); |
| 3234 | |
| 3235 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3236 | // and undefined. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3237 | MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3238 | |
| 3239 | // Casting. |
| 3240 | static inline ExternalUnsignedIntArray* cast(Object* obj); |
| 3241 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3242 | #ifdef OBJECT_PRINT |
| 3243 | inline void ExternalUnsignedIntArrayPrint() { |
| 3244 | ExternalUnsignedIntArrayPrint(stdout); |
| 3245 | } |
| 3246 | void ExternalUnsignedIntArrayPrint(FILE* out); |
| 3247 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3248 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3249 | void ExternalUnsignedIntArrayVerify(); |
| 3250 | #endif // DEBUG |
| 3251 | |
| 3252 | private: |
| 3253 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedIntArray); |
| 3254 | }; |
| 3255 | |
| 3256 | |
| 3257 | class ExternalFloatArray: public ExternalArray { |
| 3258 | public: |
| 3259 | // Setter and getter. |
| 3260 | inline float get(int index); |
| 3261 | inline void set(int index, float value); |
| 3262 | |
| 3263 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3264 | // and undefined. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3265 | MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3266 | |
| 3267 | // Casting. |
| 3268 | static inline ExternalFloatArray* cast(Object* obj); |
| 3269 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3270 | #ifdef OBJECT_PRINT |
| 3271 | inline void ExternalFloatArrayPrint() { |
| 3272 | ExternalFloatArrayPrint(stdout); |
| 3273 | } |
| 3274 | void ExternalFloatArrayPrint(FILE* out); |
| 3275 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3276 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3277 | void ExternalFloatArrayVerify(); |
| 3278 | #endif // DEBUG |
| 3279 | |
| 3280 | private: |
| 3281 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalFloatArray); |
| 3282 | }; |
| 3283 | |
| 3284 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 3285 | class ExternalDoubleArray: public ExternalArray { |
| 3286 | public: |
| 3287 | // Setter and getter. |
| 3288 | inline double get(int index); |
| 3289 | inline void set(int index, double value); |
| 3290 | |
| 3291 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3292 | // and undefined. |
| 3293 | MaybeObject* SetValue(uint32_t index, Object* value); |
| 3294 | |
| 3295 | // Casting. |
| 3296 | static inline ExternalDoubleArray* cast(Object* obj); |
| 3297 | |
| 3298 | #ifdef OBJECT_PRINT |
| 3299 | inline void ExternalDoubleArrayPrint() { |
| 3300 | ExternalDoubleArrayPrint(stdout); |
| 3301 | } |
| 3302 | void ExternalDoubleArrayPrint(FILE* out); |
| 3303 | #endif // OBJECT_PRINT |
| 3304 | #ifdef DEBUG |
| 3305 | void ExternalDoubleArrayVerify(); |
| 3306 | #endif // DEBUG |
| 3307 | |
| 3308 | private: |
| 3309 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalDoubleArray); |
| 3310 | }; |
| 3311 | |
| 3312 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3313 | // DeoptimizationInputData is a fixed array used to hold the deoptimization |
| 3314 | // data for code generated by the Hydrogen/Lithium compiler. It also |
| 3315 | // contains information about functions that were inlined. If N different |
| 3316 | // functions were inlined then first N elements of the literal array will |
| 3317 | // contain these functions. |
| 3318 | // |
| 3319 | // It can be empty. |
| 3320 | class DeoptimizationInputData: public FixedArray { |
| 3321 | public: |
| 3322 | // Layout description. Indices in the array. |
| 3323 | static const int kTranslationByteArrayIndex = 0; |
| 3324 | static const int kInlinedFunctionCountIndex = 1; |
| 3325 | static const int kLiteralArrayIndex = 2; |
| 3326 | static const int kOsrAstIdIndex = 3; |
| 3327 | static const int kOsrPcOffsetIndex = 4; |
| 3328 | static const int kFirstDeoptEntryIndex = 5; |
| 3329 | |
| 3330 | // Offsets of deopt entry elements relative to the start of the entry. |
| 3331 | static const int kAstIdOffset = 0; |
| 3332 | static const int kTranslationIndexOffset = 1; |
| 3333 | static const int kArgumentsStackHeightOffset = 2; |
| 3334 | static const int kDeoptEntrySize = 3; |
| 3335 | |
| 3336 | // Simple element accessors. |
| 3337 | #define DEFINE_ELEMENT_ACCESSORS(name, type) \ |
| 3338 | type* name() { \ |
| 3339 | return type::cast(get(k##name##Index)); \ |
| 3340 | } \ |
| 3341 | void Set##name(type* value) { \ |
| 3342 | set(k##name##Index, value); \ |
| 3343 | } |
| 3344 | |
| 3345 | DEFINE_ELEMENT_ACCESSORS(TranslationByteArray, ByteArray) |
| 3346 | DEFINE_ELEMENT_ACCESSORS(InlinedFunctionCount, Smi) |
| 3347 | DEFINE_ELEMENT_ACCESSORS(LiteralArray, FixedArray) |
| 3348 | DEFINE_ELEMENT_ACCESSORS(OsrAstId, Smi) |
| 3349 | DEFINE_ELEMENT_ACCESSORS(OsrPcOffset, Smi) |
| 3350 | |
| 3351 | // Unchecked accessor to be used during GC. |
| 3352 | FixedArray* UncheckedLiteralArray() { |
| 3353 | return reinterpret_cast<FixedArray*>(get(kLiteralArrayIndex)); |
| 3354 | } |
| 3355 | |
| 3356 | #undef DEFINE_ELEMENT_ACCESSORS |
| 3357 | |
| 3358 | // Accessors for elements of the ith deoptimization entry. |
| 3359 | #define DEFINE_ENTRY_ACCESSORS(name, type) \ |
| 3360 | type* name(int i) { \ |
| 3361 | return type::cast(get(IndexForEntry(i) + k##name##Offset)); \ |
| 3362 | } \ |
| 3363 | void Set##name(int i, type* value) { \ |
| 3364 | set(IndexForEntry(i) + k##name##Offset, value); \ |
| 3365 | } |
| 3366 | |
| 3367 | DEFINE_ENTRY_ACCESSORS(AstId, Smi) |
| 3368 | DEFINE_ENTRY_ACCESSORS(TranslationIndex, Smi) |
| 3369 | DEFINE_ENTRY_ACCESSORS(ArgumentsStackHeight, Smi) |
| 3370 | |
| 3371 | #undef DEFINE_ENTRY_ACCESSORS |
| 3372 | |
| 3373 | int DeoptCount() { |
| 3374 | return (length() - kFirstDeoptEntryIndex) / kDeoptEntrySize; |
| 3375 | } |
| 3376 | |
| 3377 | // Allocates a DeoptimizationInputData. |
| 3378 | MUST_USE_RESULT static MaybeObject* Allocate(int deopt_entry_count, |
| 3379 | PretenureFlag pretenure); |
| 3380 | |
| 3381 | // Casting. |
| 3382 | static inline DeoptimizationInputData* cast(Object* obj); |
| 3383 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3384 | #ifdef OBJECT_PRINT |
| 3385 | void DeoptimizationInputDataPrint(FILE* out); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3386 | #endif |
| 3387 | |
| 3388 | private: |
| 3389 | static int IndexForEntry(int i) { |
| 3390 | return kFirstDeoptEntryIndex + (i * kDeoptEntrySize); |
| 3391 | } |
| 3392 | |
| 3393 | static int LengthFor(int entry_count) { |
| 3394 | return IndexForEntry(entry_count); |
| 3395 | } |
| 3396 | }; |
| 3397 | |
| 3398 | |
| 3399 | // DeoptimizationOutputData is a fixed array used to hold the deoptimization |
| 3400 | // data for code generated by the full compiler. |
| 3401 | // The format of the these objects is |
| 3402 | // [i * 2]: Ast ID for ith deoptimization. |
| 3403 | // [i * 2 + 1]: PC and state of ith deoptimization |
| 3404 | class DeoptimizationOutputData: public FixedArray { |
| 3405 | public: |
| 3406 | int DeoptPoints() { return length() / 2; } |
| 3407 | Smi* AstId(int index) { return Smi::cast(get(index * 2)); } |
| 3408 | void SetAstId(int index, Smi* id) { set(index * 2, id); } |
| 3409 | Smi* PcAndState(int index) { return Smi::cast(get(1 + index * 2)); } |
| 3410 | void SetPcAndState(int index, Smi* offset) { set(1 + index * 2, offset); } |
| 3411 | |
| 3412 | static int LengthOfFixedArray(int deopt_points) { |
| 3413 | return deopt_points * 2; |
| 3414 | } |
| 3415 | |
| 3416 | // Allocates a DeoptimizationOutputData. |
| 3417 | MUST_USE_RESULT static MaybeObject* Allocate(int number_of_deopt_points, |
| 3418 | PretenureFlag pretenure); |
| 3419 | |
| 3420 | // Casting. |
| 3421 | static inline DeoptimizationOutputData* cast(Object* obj); |
| 3422 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3423 | #ifdef OBJECT_PRINT |
| 3424 | void DeoptimizationOutputDataPrint(FILE* out); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3425 | #endif |
| 3426 | }; |
| 3427 | |
| 3428 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3429 | class SafepointEntry; |
| 3430 | |
| 3431 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3432 | // Code describes objects with on-the-fly generated machine code. |
| 3433 | class Code: public HeapObject { |
| 3434 | public: |
| 3435 | // Opaque data type for encapsulating code flags like kind, inline |
| 3436 | // cache state, and arguments count. |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 3437 | // FLAGS_MIN_VALUE and FLAGS_MAX_VALUE are specified to ensure that |
| 3438 | // enumeration type has correct value range (see Issue 830 for more details). |
| 3439 | enum Flags { |
| 3440 | FLAGS_MIN_VALUE = kMinInt, |
| 3441 | FLAGS_MAX_VALUE = kMaxInt |
| 3442 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3443 | |
| 3444 | enum Kind { |
| 3445 | FUNCTION, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3446 | OPTIMIZED_FUNCTION, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3447 | STUB, |
| 3448 | BUILTIN, |
| 3449 | LOAD_IC, |
| 3450 | KEYED_LOAD_IC, |
| 3451 | CALL_IC, |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3452 | KEYED_CALL_IC, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3453 | STORE_IC, |
| 3454 | KEYED_STORE_IC, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3455 | UNARY_OP_IC, |
| 3456 | BINARY_OP_IC, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3457 | COMPARE_IC, |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3458 | // 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] | 3459 | // Flags. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3460 | |
| 3461 | // Pseudo-kinds. |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 3462 | REGEXP = BUILTIN, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3463 | FIRST_IC_KIND = LOAD_IC, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3464 | LAST_IC_KIND = COMPARE_IC |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3465 | }; |
| 3466 | |
| 3467 | enum { |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 3468 | NUMBER_OF_KINDS = LAST_IC_KIND + 1 |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3469 | }; |
| 3470 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3471 | typedef int ExtraICState; |
| 3472 | |
| 3473 | static const ExtraICState kNoExtraICState = 0; |
| 3474 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 3475 | #ifdef ENABLE_DISASSEMBLER |
| 3476 | // Printing |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3477 | static const char* Kind2String(Kind kind); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 3478 | static const char* ICState2String(InlineCacheState state); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 3479 | static const char* PropertyType2String(PropertyType type); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3480 | static void PrintExtraICState(FILE* out, Kind kind, ExtraICState extra); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3481 | inline void Disassemble(const char* name) { |
| 3482 | Disassemble(name, stdout); |
| 3483 | } |
| 3484 | void Disassemble(const char* name, FILE* out); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 3485 | #endif // ENABLE_DISASSEMBLER |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3486 | |
| 3487 | // [instruction_size]: Size of the native instructions |
| 3488 | inline int instruction_size(); |
| 3489 | inline void set_instruction_size(int value); |
| 3490 | |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 3491 | // [relocation_info]: Code relocation information |
| 3492 | DECL_ACCESSORS(relocation_info, ByteArray) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3493 | void InvalidateRelocation(); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 3494 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3495 | // [deoptimization_data]: Array containing data for deopt. |
| 3496 | DECL_ACCESSORS(deoptimization_data, FixedArray) |
| 3497 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3498 | // [code_flushing_candidate]: Field only used during garbage |
| 3499 | // collection to hold code flushing candidates. The contents of this |
| 3500 | // field does not have to be traced during garbage collection since |
| 3501 | // it is only used by the garbage collector itself. |
| 3502 | DECL_ACCESSORS(next_code_flushing_candidate, Object) |
| 3503 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3504 | // Unchecked accessors to be used during GC. |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 3505 | inline ByteArray* unchecked_relocation_info(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3506 | inline FixedArray* unchecked_deoptimization_data(); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 3507 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3508 | inline int relocation_size(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3509 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3510 | // [flags]: Various code flags. |
| 3511 | inline Flags flags(); |
| 3512 | inline void set_flags(Flags flags); |
| 3513 | |
| 3514 | // [flags]: Access to specific code flags. |
| 3515 | inline Kind kind(); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3516 | inline InlineCacheState ic_state(); // Only valid for IC stubs. |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3517 | inline ExtraICState extra_ic_state(); // Only valid for IC stubs. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 3518 | inline InLoopFlag ic_in_loop(); // Only valid for IC stubs. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3519 | inline PropertyType type(); // Only valid for monomorphic IC stubs. |
| 3520 | inline int arguments_count(); // Only valid for call IC stubs. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3521 | |
| 3522 | // Testers for IC stub kinds. |
| 3523 | inline bool is_inline_cache_stub(); |
| 3524 | inline bool is_load_stub() { return kind() == LOAD_IC; } |
| 3525 | inline bool is_keyed_load_stub() { return kind() == KEYED_LOAD_IC; } |
| 3526 | inline bool is_store_stub() { return kind() == STORE_IC; } |
| 3527 | inline bool is_keyed_store_stub() { return kind() == KEYED_STORE_IC; } |
| 3528 | inline bool is_call_stub() { return kind() == CALL_IC; } |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3529 | inline bool is_keyed_call_stub() { return kind() == KEYED_CALL_IC; } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3530 | inline bool is_unary_op_stub() { |
| 3531 | return kind() == UNARY_OP_IC; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3532 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3533 | inline bool is_binary_op_stub() { |
| 3534 | return kind() == BINARY_OP_IC; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3535 | } |
| 3536 | inline bool is_compare_ic_stub() { return kind() == COMPARE_IC; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3537 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3538 | // [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] | 3539 | inline int major_key(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3540 | inline void set_major_key(int value); |
| 3541 | |
| 3542 | // [optimizable]: For FUNCTION kind, tells if it is optimizable. |
| 3543 | inline bool optimizable(); |
| 3544 | inline void set_optimizable(bool value); |
| 3545 | |
| 3546 | // [has_deoptimization_support]: For FUNCTION kind, tells if it has |
| 3547 | // deoptimization support. |
| 3548 | inline bool has_deoptimization_support(); |
| 3549 | inline void set_has_deoptimization_support(bool value); |
| 3550 | |
| 3551 | // [allow_osr_at_loop_nesting_level]: For FUNCTION kind, tells for |
| 3552 | // how long the function has been marked for OSR and therefore which |
| 3553 | // level of loop nesting we are willing to do on-stack replacement |
| 3554 | // for. |
| 3555 | inline void set_allow_osr_at_loop_nesting_level(int level); |
| 3556 | inline int allow_osr_at_loop_nesting_level(); |
| 3557 | |
| 3558 | // [stack_slots]: For kind OPTIMIZED_FUNCTION, the number of stack slots |
| 3559 | // reserved in the code prologue. |
| 3560 | inline unsigned stack_slots(); |
| 3561 | inline void set_stack_slots(unsigned slots); |
| 3562 | |
| 3563 | // [safepoint_table_start]: For kind OPTIMIZED_CODE, the offset in |
| 3564 | // the instruction stream where the safepoint table starts. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3565 | inline unsigned safepoint_table_offset(); |
| 3566 | inline void set_safepoint_table_offset(unsigned offset); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3567 | |
| 3568 | // [stack_check_table_start]: For kind FUNCTION, the offset in the |
| 3569 | // instruction stream where the stack check table starts. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3570 | inline unsigned stack_check_table_offset(); |
| 3571 | inline void set_stack_check_table_offset(unsigned offset); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3572 | |
| 3573 | // [check type]: For kind CALL_IC, tells how to check if the |
| 3574 | // receiver is valid for the given call. |
| 3575 | inline CheckType check_type(); |
| 3576 | inline void set_check_type(CheckType value); |
| 3577 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3578 | // [type-recording unary op type]: For all UNARY_OP_IC. |
| 3579 | inline byte unary_op_type(); |
| 3580 | inline void set_unary_op_type(byte value); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3581 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3582 | // [type-recording binary op type]: For all TYPE_RECORDING_BINARY_OP_IC. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3583 | inline byte binary_op_type(); |
| 3584 | inline void set_binary_op_type(byte value); |
| 3585 | inline byte binary_op_result_type(); |
| 3586 | inline void set_binary_op_result_type(byte value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3587 | |
| 3588 | // [compare state]: For kind compare IC stubs, tells what state the |
| 3589 | // stub is in. |
| 3590 | inline byte compare_state(); |
| 3591 | inline void set_compare_state(byte value); |
| 3592 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3593 | // Get the safepoint entry for the given pc. |
| 3594 | SafepointEntry GetSafepointEntry(Address pc); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3595 | |
| 3596 | // Mark this code object as not having a stack check table. Assumes kind |
| 3597 | // is FUNCTION. |
| 3598 | void SetNoStackCheckTable(); |
| 3599 | |
| 3600 | // Find the first map in an IC stub. |
| 3601 | Map* FindFirstMap(); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3602 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3603 | // Flags operations. |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3604 | static inline Flags ComputeFlags( |
| 3605 | Kind kind, |
| 3606 | InLoopFlag in_loop = NOT_IN_LOOP, |
| 3607 | InlineCacheState ic_state = UNINITIALIZED, |
| 3608 | ExtraICState extra_ic_state = kNoExtraICState, |
| 3609 | PropertyType type = NORMAL, |
| 3610 | int argc = -1, |
| 3611 | InlineCacheHolderFlag holder = OWN_MAP); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3612 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3613 | static inline Flags ComputeMonomorphicFlags( |
| 3614 | Kind kind, |
| 3615 | PropertyType type, |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3616 | ExtraICState extra_ic_state = kNoExtraICState, |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3617 | InlineCacheHolderFlag holder = OWN_MAP, |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3618 | InLoopFlag in_loop = NOT_IN_LOOP, |
| 3619 | int argc = -1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3620 | |
| 3621 | static inline Kind ExtractKindFromFlags(Flags flags); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3622 | static inline InlineCacheState ExtractICStateFromFlags(Flags flags); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3623 | static inline ExtraICState ExtractExtraICStateFromFlags(Flags flags); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3624 | static inline InLoopFlag ExtractICInLoopFromFlags(Flags flags); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3625 | static inline PropertyType ExtractTypeFromFlags(Flags flags); |
| 3626 | static inline int ExtractArgumentsCountFromFlags(Flags flags); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3627 | static inline InlineCacheHolderFlag ExtractCacheHolderFromFlags(Flags flags); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3628 | static inline Flags RemoveTypeFromFlags(Flags flags); |
| 3629 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 3630 | // Convert a target address into a code object. |
| 3631 | static inline Code* GetCodeFromTargetAddress(Address address); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3632 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 3633 | // Convert an entry address into an object. |
| 3634 | static inline Object* GetObjectFromEntryAddress(Address location_of_address); |
| 3635 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3636 | // Returns the address of the first instruction. |
| 3637 | inline byte* instruction_start(); |
| 3638 | |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 3639 | // Returns the address right after the last instruction. |
| 3640 | inline byte* instruction_end(); |
| 3641 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3642 | // Returns the size of the instructions, padding, and relocation information. |
| 3643 | inline int body_size(); |
| 3644 | |
| 3645 | // Returns the address of the first relocation info (read backwards!). |
| 3646 | inline byte* relocation_start(); |
| 3647 | |
| 3648 | // Code entry point. |
| 3649 | inline byte* entry(); |
| 3650 | |
| 3651 | // Returns true if pc is inside this object's instructions. |
| 3652 | inline bool contains(byte* pc); |
| 3653 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3654 | // Relocate the code by delta bytes. Called to signal that this code |
| 3655 | // object has been moved by delta bytes. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3656 | void Relocate(intptr_t delta); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3657 | |
| 3658 | // Migrate code described by desc. |
| 3659 | void CopyFrom(const CodeDesc& desc); |
| 3660 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 3661 | // Returns the object size for a given body (used for allocation). |
| 3662 | static int SizeFor(int body_size) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3663 | ASSERT_SIZE_TAG_ALIGNED(body_size); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 3664 | return RoundUp(kHeaderSize + body_size, kCodeAlignment); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3665 | } |
| 3666 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3667 | // Calculate the size of the code object to report for log events. This takes |
| 3668 | // the layout of the code object into account. |
| 3669 | int ExecutableSize() { |
| 3670 | // 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] | 3671 | ASSERT_EQ(static_cast<int>(instruction_start() - address()), |
| 3672 | Code::kHeaderSize); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3673 | return instruction_size() + Code::kHeaderSize; |
| 3674 | } |
| 3675 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3676 | // Locating source position. |
| 3677 | int SourcePosition(Address pc); |
| 3678 | int SourceStatementPosition(Address pc); |
| 3679 | |
| 3680 | // Casting. |
| 3681 | static inline Code* cast(Object* obj); |
| 3682 | |
| 3683 | // Dispatched behavior. |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 3684 | int CodeSize() { return SizeFor(body_size()); } |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3685 | inline void CodeIterateBody(ObjectVisitor* v); |
| 3686 | |
| 3687 | template<typename StaticVisitor> |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3688 | inline void CodeIterateBody(Heap* heap); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3689 | #ifdef OBJECT_PRINT |
| 3690 | inline void CodePrint() { |
| 3691 | CodePrint(stdout); |
| 3692 | } |
| 3693 | void CodePrint(FILE* out); |
| 3694 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3695 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3696 | void CodeVerify(); |
| 3697 | #endif |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3698 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3699 | // Returns the isolate/heap this code object belongs to. |
| 3700 | inline Isolate* isolate(); |
| 3701 | inline Heap* heap(); |
| 3702 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3703 | // Max loop nesting marker used to postpose OSR. We don't take loop |
| 3704 | // nesting that is deeper than 5 levels into account. |
| 3705 | static const int kMaxLoopNestingMarker = 6; |
| 3706 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3707 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 3708 | static const int kInstructionSizeOffset = HeapObject::kHeaderSize; |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 3709 | static const int kRelocationInfoOffset = kInstructionSizeOffset + kIntSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3710 | static const int kDeoptimizationDataOffset = |
| 3711 | kRelocationInfoOffset + kPointerSize; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3712 | static const int kNextCodeFlushingCandidateOffset = |
| 3713 | kDeoptimizationDataOffset + kPointerSize; |
| 3714 | static const int kFlagsOffset = |
| 3715 | kNextCodeFlushingCandidateOffset + kPointerSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3716 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3717 | static const int kKindSpecificFlagsOffset = kFlagsOffset + kIntSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3718 | static const int kKindSpecificFlagsSize = 2 * kIntSize; |
| 3719 | |
| 3720 | static const int kHeaderPaddingStart = kKindSpecificFlagsOffset + |
| 3721 | kKindSpecificFlagsSize; |
| 3722 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3723 | // Add padding to align the instruction start following right after |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 3724 | // the Code object header. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3725 | static const int kHeaderSize = |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3726 | (kHeaderPaddingStart + kCodeAlignmentMask) & ~kCodeAlignmentMask; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3727 | |
| 3728 | // Byte offsets within kKindSpecificFlagsOffset. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3729 | static const int kStubMajorKeyOffset = kKindSpecificFlagsOffset; |
| 3730 | static const int kOptimizableOffset = kKindSpecificFlagsOffset; |
| 3731 | static const int kStackSlotsOffset = kKindSpecificFlagsOffset; |
| 3732 | static const int kCheckTypeOffset = kKindSpecificFlagsOffset; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3733 | static const int kExternalArrayTypeOffset = kKindSpecificFlagsOffset; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3734 | |
| 3735 | static const int kCompareStateOffset = kStubMajorKeyOffset + 1; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3736 | static const int kUnaryOpTypeOffset = kStubMajorKeyOffset + 1; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3737 | static const int kBinaryOpTypeOffset = kStubMajorKeyOffset + 1; |
| 3738 | static const int kHasDeoptimizationSupportOffset = kOptimizableOffset + 1; |
| 3739 | |
| 3740 | static const int kBinaryOpReturnTypeOffset = kBinaryOpTypeOffset + 1; |
| 3741 | static const int kAllowOSRAtLoopNestingLevelOffset = |
| 3742 | kHasDeoptimizationSupportOffset + 1; |
| 3743 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3744 | static const int kSafepointTableOffsetOffset = kStackSlotsOffset + kIntSize; |
| 3745 | static const int kStackCheckTableOffsetOffset = kStackSlotsOffset + kIntSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3746 | |
| 3747 | // Flags layout. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3748 | static const int kFlagsICStateShift = 0; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3749 | static const int kFlagsICInLoopShift = 3; |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3750 | static const int kFlagsTypeShift = 4; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3751 | static const int kFlagsKindShift = 8; |
| 3752 | static const int kFlagsICHolderShift = 12; |
| 3753 | static const int kFlagsExtraICStateShift = 13; |
| 3754 | static const int kFlagsArgumentsCountShift = 15; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3755 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3756 | static const int kFlagsICStateMask = 0x00000007; // 00000000111 |
| 3757 | static const int kFlagsICInLoopMask = 0x00000008; // 00000001000 |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3758 | static const int kFlagsTypeMask = 0x000000F0; // 00001110000 |
| 3759 | static const int kFlagsKindMask = 0x00000F00; // 11110000000 |
| 3760 | static const int kFlagsCacheInPrototypeMapMask = 0x00001000; |
| 3761 | static const int kFlagsExtraICStateMask = 0x00006000; |
| 3762 | static const int kFlagsArgumentsCountMask = 0xFFFF8000; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3763 | |
| 3764 | static const int kFlagsNotUsedInLookup = |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3765 | (kFlagsICInLoopMask | kFlagsTypeMask | kFlagsCacheInPrototypeMapMask); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3766 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3767 | private: |
| 3768 | DISALLOW_IMPLICIT_CONSTRUCTORS(Code); |
| 3769 | }; |
| 3770 | |
| 3771 | |
| 3772 | // All heap objects have a Map that describes their structure. |
| 3773 | // A Map contains information about: |
| 3774 | // - Size information about the object |
| 3775 | // - How to iterate over an object (for garbage collection) |
| 3776 | class Map: public HeapObject { |
| 3777 | public: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3778 | // Instance size. |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 3779 | // Size in bytes or kVariableSizeSentinel if instances do not have |
| 3780 | // a fixed size. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3781 | inline int instance_size(); |
| 3782 | inline void set_instance_size(int value); |
| 3783 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3784 | // Count of properties allocated in the object. |
| 3785 | inline int inobject_properties(); |
| 3786 | inline void set_inobject_properties(int value); |
| 3787 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 3788 | // Count of property fields pre-allocated in the object when first allocated. |
| 3789 | inline int pre_allocated_property_fields(); |
| 3790 | inline void set_pre_allocated_property_fields(int value); |
| 3791 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3792 | // Instance type. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3793 | inline InstanceType instance_type(); |
| 3794 | inline void set_instance_type(InstanceType value); |
| 3795 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3796 | // Tells how many unused property fields are available in the |
| 3797 | // instance (only used for JSObject in fast mode). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3798 | inline int unused_property_fields(); |
| 3799 | inline void set_unused_property_fields(int value); |
| 3800 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3801 | // Bit field. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3802 | inline byte bit_field(); |
| 3803 | inline void set_bit_field(byte value); |
| 3804 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3805 | // Bit field 2. |
| 3806 | inline byte bit_field2(); |
| 3807 | inline void set_bit_field2(byte value); |
| 3808 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3809 | // Bit field 3. |
| 3810 | // TODO(1399): It should be possible to make room for bit_field3 in the map |
| 3811 | // without overloading the instance descriptors field (and storing it in the |
| 3812 | // DescriptorArray when the map has one). |
| 3813 | inline int bit_field3(); |
| 3814 | inline void set_bit_field3(int value); |
| 3815 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3816 | // Tells whether the object in the prototype property will be used |
| 3817 | // for instances created from this function. If the prototype |
| 3818 | // property is set to a value that is not a JSObject, the prototype |
| 3819 | // property will not be used to create instances of the function. |
| 3820 | // See ECMA-262, 13.2.2. |
| 3821 | inline void set_non_instance_prototype(bool value); |
| 3822 | inline bool has_non_instance_prototype(); |
| 3823 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 3824 | // Tells whether function has special prototype property. If not, prototype |
| 3825 | // property will not be created when accessed (will return undefined), |
| 3826 | // and construction from this function will not be allowed. |
| 3827 | inline void set_function_with_prototype(bool value); |
| 3828 | inline bool function_with_prototype(); |
| 3829 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3830 | // Tells whether the instance with this map should be ignored by the |
| 3831 | // __proto__ accessor. |
| 3832 | inline void set_is_hidden_prototype() { |
| 3833 | set_bit_field(bit_field() | (1 << kIsHiddenPrototype)); |
| 3834 | } |
| 3835 | |
| 3836 | inline bool is_hidden_prototype() { |
| 3837 | return ((1 << kIsHiddenPrototype) & bit_field()) != 0; |
| 3838 | } |
| 3839 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3840 | // Records and queries whether the instance has a named interceptor. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3841 | inline void set_has_named_interceptor() { |
| 3842 | set_bit_field(bit_field() | (1 << kHasNamedInterceptor)); |
| 3843 | } |
| 3844 | |
| 3845 | inline bool has_named_interceptor() { |
| 3846 | return ((1 << kHasNamedInterceptor) & bit_field()) != 0; |
| 3847 | } |
| 3848 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3849 | // Records and queries whether the instance has an indexed interceptor. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3850 | inline void set_has_indexed_interceptor() { |
| 3851 | set_bit_field(bit_field() | (1 << kHasIndexedInterceptor)); |
| 3852 | } |
| 3853 | |
| 3854 | inline bool has_indexed_interceptor() { |
| 3855 | return ((1 << kHasIndexedInterceptor) & bit_field()) != 0; |
| 3856 | } |
| 3857 | |
| 3858 | // Tells whether the instance is undetectable. |
| 3859 | // An undetectable object is a special class of JSObject: 'typeof' operator |
| 3860 | // returns undefined, ToBoolean returns false. Otherwise it behaves like |
| 3861 | // a normal JS object. It is useful for implementing undetectable |
| 3862 | // document.all in Firefox & Safari. |
| 3863 | // See https://bugzilla.mozilla.org/show_bug.cgi?id=248549. |
| 3864 | inline void set_is_undetectable() { |
| 3865 | set_bit_field(bit_field() | (1 << kIsUndetectable)); |
| 3866 | } |
| 3867 | |
| 3868 | inline bool is_undetectable() { |
| 3869 | return ((1 << kIsUndetectable) & bit_field()) != 0; |
| 3870 | } |
| 3871 | |
| 3872 | // Tells whether the instance has a call-as-function handler. |
| 3873 | inline void set_has_instance_call_handler() { |
| 3874 | set_bit_field(bit_field() | (1 << kHasInstanceCallHandler)); |
| 3875 | } |
| 3876 | |
| 3877 | inline bool has_instance_call_handler() { |
| 3878 | return ((1 << kHasInstanceCallHandler) & bit_field()) != 0; |
| 3879 | } |
| 3880 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3881 | inline void set_is_extensible(bool value); |
| 3882 | inline bool is_extensible(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3883 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 3884 | inline void set_elements_kind(JSObject::ElementsKind elements_kind) { |
| 3885 | ASSERT(elements_kind < JSObject::kElementsKindCount); |
| 3886 | ASSERT(JSObject::kElementsKindCount <= (1 << kElementsKindBitCount)); |
| 3887 | set_bit_field2((bit_field2() & ~kElementsKindMask) | |
| 3888 | (elements_kind << kElementsKindShift)); |
| 3889 | ASSERT(this->elements_kind() == elements_kind); |
| 3890 | } |
| 3891 | |
| 3892 | inline JSObject::ElementsKind elements_kind() { |
| 3893 | return static_cast<JSObject::ElementsKind>( |
| 3894 | (bit_field2() & kElementsKindMask) >> kElementsKindShift); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3895 | } |
| 3896 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 3897 | inline bool has_fast_elements() { |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 3898 | return elements_kind() == JSObject::FAST_ELEMENTS; |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3899 | } |
| 3900 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame^] | 3901 | inline bool has_fast_double_elements() { |
| 3902 | return elements_kind() == JSObject::FAST_DOUBLE_ELEMENTS; |
| 3903 | } |
| 3904 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3905 | inline bool has_external_array_elements() { |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 3906 | JSObject::ElementsKind kind(elements_kind()); |
| 3907 | return kind >= JSObject::FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND && |
| 3908 | kind <= JSObject::LAST_EXTERNAL_ARRAY_ELEMENTS_KIND; |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3909 | } |
| 3910 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3911 | // Tells whether the map is attached to SharedFunctionInfo |
| 3912 | // (for inobject slack tracking). |
| 3913 | inline void set_attached_to_shared_function_info(bool value); |
| 3914 | |
| 3915 | inline bool attached_to_shared_function_info(); |
| 3916 | |
| 3917 | // Tells whether the map is shared between objects that may have different |
| 3918 | // behavior. If true, the map should never be modified, instead a clone |
| 3919 | // should be created and modified. |
| 3920 | inline void set_is_shared(bool value); |
| 3921 | |
| 3922 | inline bool is_shared(); |
| 3923 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3924 | // Tells whether the instance needs security checks when accessing its |
| 3925 | // properties. |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 3926 | inline void set_is_access_check_needed(bool access_check_needed); |
| 3927 | inline bool is_access_check_needed(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3928 | |
| 3929 | // [prototype]: implicit prototype object. |
| 3930 | DECL_ACCESSORS(prototype, Object) |
| 3931 | |
| 3932 | // [constructor]: points back to the function responsible for this map. |
| 3933 | DECL_ACCESSORS(constructor, Object) |
| 3934 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3935 | inline JSFunction* unchecked_constructor(); |
| 3936 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3937 | // Should only be called by the code that initializes map to set initial valid |
| 3938 | // value of the instance descriptor member. |
| 3939 | inline void init_instance_descriptors(); |
| 3940 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3941 | // [instance descriptors]: describes the object. |
| 3942 | DECL_ACCESSORS(instance_descriptors, DescriptorArray) |
| 3943 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3944 | // Sets the instance descriptor array for the map to be an empty descriptor |
| 3945 | // array. |
| 3946 | inline void clear_instance_descriptors(); |
| 3947 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3948 | // [stub cache]: contains stubs compiled for this map. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3949 | DECL_ACCESSORS(code_cache, Object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3950 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 3951 | // [prototype transitions]: cache of prototype transitions. |
| 3952 | // Prototype transition is a transition that happens |
| 3953 | // when we change object's prototype to a new one. |
| 3954 | // Cache format: |
| 3955 | // 0: finger - index of the first free cell in the cache |
| 3956 | // 1 + 2 * i: prototype |
| 3957 | // 2 + 2 * i: target map |
| 3958 | DECL_ACCESSORS(prototype_transitions, FixedArray) |
| 3959 | inline FixedArray* unchecked_prototype_transitions(); |
| 3960 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 3961 | static const int kProtoTransitionHeaderSize = 1; |
| 3962 | static const int kProtoTransitionNumberOfEntriesOffset = 0; |
| 3963 | static const int kProtoTransitionElementsPerEntry = 2; |
| 3964 | static const int kProtoTransitionPrototypeOffset = 0; |
| 3965 | static const int kProtoTransitionMapOffset = 1; |
| 3966 | |
| 3967 | inline int NumberOfProtoTransitions() { |
| 3968 | FixedArray* cache = unchecked_prototype_transitions(); |
| 3969 | if (cache->length() == 0) return 0; |
| 3970 | return |
| 3971 | Smi::cast(cache->get(kProtoTransitionNumberOfEntriesOffset))->value(); |
| 3972 | } |
| 3973 | |
| 3974 | inline void SetNumberOfProtoTransitions(int value) { |
| 3975 | FixedArray* cache = unchecked_prototype_transitions(); |
| 3976 | ASSERT(cache->length() != 0); |
| 3977 | cache->set_unchecked(kProtoTransitionNumberOfEntriesOffset, |
| 3978 | Smi::FromInt(value)); |
| 3979 | } |
| 3980 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3981 | // Lookup in the map's instance descriptors and fill out the result |
| 3982 | // with the given holder if the name is found. The holder may be |
| 3983 | // NULL when this function is used from the compiler. |
| 3984 | void LookupInDescriptors(JSObject* holder, |
| 3985 | String* name, |
| 3986 | LookupResult* result); |
| 3987 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3988 | MUST_USE_RESULT MaybeObject* CopyDropDescriptors(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3989 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3990 | MUST_USE_RESULT MaybeObject* CopyNormalized(PropertyNormalizationMode mode, |
| 3991 | NormalizedMapSharingMode sharing); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3992 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 3993 | // Returns a copy of the map, with all transitions dropped from the |
| 3994 | // instance descriptors. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3995 | MUST_USE_RESULT MaybeObject* CopyDropTransitions(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 3996 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame^] | 3997 | // 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] | 3998 | // 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^] | 3999 | // descriptors and the ElementsKind set to FAST_ELEMENTS. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4000 | MUST_USE_RESULT inline MaybeObject* GetFastElementsMap(); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 4001 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame^] | 4002 | // Returns this map if it already has fast elements that are doubles, |
| 4003 | // otherwise returns a copy of the map, with all transitions dropped from the |
| 4004 | // descriptors and the ElementsKind set to FAST_DOUBLE_ELEMENTS. |
| 4005 | MUST_USE_RESULT inline MaybeObject* GetFastDoubleElementsMap(); |
| 4006 | |
| 4007 | // Returns this map if already has dictionary elements, otherwise returns a |
| 4008 | // copy of the map, with all transitions dropped from the descriptors and the |
| 4009 | // ElementsKind set to DICTIONARY_ELEMENTS. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4010 | MUST_USE_RESULT inline MaybeObject* GetSlowElementsMap(); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 4011 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4012 | // 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^] | 4013 | // ElementsKind set to one of the value corresponding to array_type. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4014 | MUST_USE_RESULT MaybeObject* GetExternalArrayElementsMap( |
| 4015 | ExternalArrayType array_type, |
| 4016 | bool safe_to_add_transition); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4017 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4018 | // Returns the property index for name (only valid for FAST MODE). |
| 4019 | int PropertyIndexFor(String* name); |
| 4020 | |
| 4021 | // Returns the next free property index (only valid for FAST MODE). |
| 4022 | int NextFreePropertyIndex(); |
| 4023 | |
| 4024 | // Returns the number of properties described in instance_descriptors. |
| 4025 | int NumberOfDescribedProperties(); |
| 4026 | |
| 4027 | // Casting. |
| 4028 | static inline Map* cast(Object* obj); |
| 4029 | |
| 4030 | // Locate an accessor in the instance descriptor. |
| 4031 | AccessorDescriptor* FindAccessor(String* name); |
| 4032 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4033 | // Code cache operations. |
| 4034 | |
| 4035 | // Clears the code cache. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4036 | inline void ClearCodeCache(Heap* heap); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4037 | |
| 4038 | // Update code cache. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4039 | MUST_USE_RESULT MaybeObject* UpdateCodeCache(String* name, Code* code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4040 | |
| 4041 | // Returns the found code or undefined if absent. |
| 4042 | Object* FindInCodeCache(String* name, Code::Flags flags); |
| 4043 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4044 | // Returns the non-negative index of the code object if it is in the |
| 4045 | // cache and -1 otherwise. |
sgjesse@chromium.org | 99a37fa | 2010-03-11 09:23:46 +0000 | [diff] [blame] | 4046 | int IndexInCodeCache(Object* name, Code* code); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4047 | |
| 4048 | // 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] | 4049 | void RemoveFromCodeCache(String* name, Code* code, int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4050 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 4051 | // For every transition in this map, makes the transition's |
| 4052 | // target's prototype pointer point back to this map. |
| 4053 | // This is undone in MarkCompactCollector::ClearNonLiveTransitions(). |
| 4054 | void CreateBackPointers(); |
| 4055 | |
| 4056 | // Set all map transitions from this map to dead maps to null. |
| 4057 | // Also, restore the original prototype on the targets of these |
| 4058 | // transitions, so that we do not process this map again while |
| 4059 | // following back pointers. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4060 | void ClearNonLiveTransitions(Heap* heap, Object* real_prototype); |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 4061 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 4062 | // Computes a hash value for this map, to be used in HashTables and such. |
| 4063 | int Hash(); |
| 4064 | |
| 4065 | // Compares this map to another to see if they describe equivalent objects. |
| 4066 | // If |mode| is set to CLEAR_INOBJECT_PROPERTIES, |other| is treated as if |
| 4067 | // it had exactly zero inobject properties. |
| 4068 | // The "shared" flags of both this map and |other| are ignored. |
| 4069 | bool EquivalentToForNormalization(Map* other, PropertyNormalizationMode mode); |
| 4070 | |
| 4071 | // Returns true if this map and |other| describe equivalent objects. |
| 4072 | // The "shared" flags of both this map and |other| are ignored. |
| 4073 | bool EquivalentTo(Map* other) { |
| 4074 | return EquivalentToForNormalization(other, KEEP_INOBJECT_PROPERTIES); |
| 4075 | } |
| 4076 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4077 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4078 | #ifdef OBJECT_PRINT |
| 4079 | inline void MapPrint() { |
| 4080 | MapPrint(stdout); |
| 4081 | } |
| 4082 | void MapPrint(FILE* out); |
| 4083 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4084 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4085 | void MapVerify(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4086 | void SharedMapVerify(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4087 | #endif |
| 4088 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4089 | inline int visitor_id(); |
| 4090 | inline void set_visitor_id(int visitor_id); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4091 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4092 | // Returns the isolate/heap this map belongs to. |
| 4093 | inline Isolate* isolate(); |
| 4094 | inline Heap* heap(); |
| 4095 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4096 | typedef void (*TraverseCallback)(Map* map, void* data); |
| 4097 | |
| 4098 | void TraverseTransitionTree(TraverseCallback callback, void* data); |
| 4099 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 4100 | static const int kMaxCachedPrototypeTransitions = 256; |
| 4101 | |
| 4102 | Object* GetPrototypeTransition(Object* prototype); |
| 4103 | |
| 4104 | MaybeObject* PutPrototypeTransition(Object* prototype, Map* map); |
| 4105 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4106 | static const int kMaxPreAllocatedPropertyFields = 255; |
| 4107 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4108 | // Layout description. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4109 | static const int kInstanceSizesOffset = HeapObject::kHeaderSize; |
| 4110 | static const int kInstanceAttributesOffset = kInstanceSizesOffset + kIntSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4111 | static const int kPrototypeOffset = kInstanceAttributesOffset + kIntSize; |
| 4112 | static const int kConstructorOffset = kPrototypeOffset + kPointerSize; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4113 | // Storage for instance descriptors is overloaded to also contain additional |
| 4114 | // map flags when unused (bit_field3). When the map has instance descriptors, |
| 4115 | // the flags are transferred to the instance descriptor array and accessed |
| 4116 | // through an extra indirection. |
| 4117 | // TODO(1399): It should be possible to make room for bit_field3 in the map |
| 4118 | // without overloading the instance descriptors field, but the map is |
| 4119 | // currently perfectly aligned to 32 bytes and extending it at all would |
| 4120 | // double its size. After the increment GC work lands, this size restriction |
| 4121 | // could be loosened and bit_field3 moved directly back in the map. |
| 4122 | static const int kInstanceDescriptorsOrBitField3Offset = |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4123 | kConstructorOffset + kPointerSize; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4124 | static const int kCodeCacheOffset = |
| 4125 | kInstanceDescriptorsOrBitField3Offset + kPointerSize; |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 4126 | static const int kPrototypeTransitionsOffset = |
| 4127 | kCodeCacheOffset + kPointerSize; |
| 4128 | static const int kPadStart = kPrototypeTransitionsOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4129 | static const int kSize = MAP_POINTER_ALIGN(kPadStart); |
| 4130 | |
| 4131 | // Layout of pointer fields. Heap iteration code relies on them |
| 4132 | // being continiously allocated. |
| 4133 | static const int kPointerFieldsBeginOffset = Map::kPrototypeOffset; |
| 4134 | static const int kPointerFieldsEndOffset = |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 4135 | Map::kPrototypeTransitionsOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4136 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4137 | // Byte offsets within kInstanceSizesOffset. |
| 4138 | static const int kInstanceSizeOffset = kInstanceSizesOffset + 0; |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 4139 | static const int kInObjectPropertiesByte = 1; |
| 4140 | static const int kInObjectPropertiesOffset = |
| 4141 | kInstanceSizesOffset + kInObjectPropertiesByte; |
| 4142 | static const int kPreAllocatedPropertyFieldsByte = 2; |
| 4143 | static const int kPreAllocatedPropertyFieldsOffset = |
| 4144 | kInstanceSizesOffset + kPreAllocatedPropertyFieldsByte; |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 4145 | static const int kVisitorIdByte = 3; |
| 4146 | static const int kVisitorIdOffset = kInstanceSizesOffset + kVisitorIdByte; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4147 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4148 | // Byte offsets within kInstanceAttributesOffset attributes. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4149 | static const int kInstanceTypeOffset = kInstanceAttributesOffset + 0; |
| 4150 | static const int kUnusedPropertyFieldsOffset = kInstanceAttributesOffset + 1; |
| 4151 | static const int kBitFieldOffset = kInstanceAttributesOffset + 2; |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 4152 | static const int kBitField2Offset = kInstanceAttributesOffset + 3; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4153 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4154 | STATIC_CHECK(kInstanceTypeOffset == Internals::kMapInstanceTypeOffset); |
| 4155 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4156 | // Bit positions for bit field. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 4157 | 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] | 4158 | static const int kHasNonInstancePrototype = 1; |
| 4159 | static const int kIsHiddenPrototype = 2; |
| 4160 | static const int kHasNamedInterceptor = 3; |
| 4161 | static const int kHasIndexedInterceptor = 4; |
| 4162 | static const int kIsUndetectable = 5; |
| 4163 | static const int kHasInstanceCallHandler = 6; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4164 | static const int kIsAccessCheckNeeded = 7; |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 4165 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 4166 | // Bit positions for bit field 2 |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4167 | static const int kIsExtensible = 0; |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 4168 | static const int kFunctionWithPrototype = 1; |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4169 | static const int kStringWrapperSafeForDefaultValueOf = 2; |
| 4170 | static const int kAttachedToSharedFunctionInfo = 3; |
| 4171 | // No bits can be used after kElementsKindFirstBit, they are all reserved for |
| 4172 | // storing ElementKind. for anything other than storing the ElementKind. |
| 4173 | static const int kElementsKindShift = 4; |
| 4174 | static const int kElementsKindBitCount = 4; |
| 4175 | |
| 4176 | // Derived values from bit field 2 |
| 4177 | static const int kElementsKindMask = (-1 << kElementsKindShift) & |
| 4178 | ((1 << (kElementsKindShift + kElementsKindBitCount)) - 1); |
| 4179 | static const int8_t kMaximumBitField2FastElementValue = static_cast<int8_t>( |
| 4180 | (JSObject::FAST_ELEMENTS + 1) << Map::kElementsKindShift) - 1; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4181 | |
| 4182 | // Bit positions for bit field 3 |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4183 | static const int kIsShared = 0; |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 4184 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4185 | // Layout of the default cache. It holds alternating name and code objects. |
| 4186 | static const int kCodeCacheEntrySize = 2; |
| 4187 | static const int kCodeCacheEntryNameOffset = 0; |
| 4188 | static const int kCodeCacheEntryCodeOffset = 1; |
| 4189 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4190 | typedef FixedBodyDescriptor<kPointerFieldsBeginOffset, |
| 4191 | kPointerFieldsEndOffset, |
| 4192 | kSize> BodyDescriptor; |
| 4193 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4194 | private: |
| 4195 | DISALLOW_IMPLICIT_CONSTRUCTORS(Map); |
| 4196 | }; |
| 4197 | |
| 4198 | |
| 4199 | // An abstract superclass, a marker class really, for simple structure classes. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4200 | // 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] | 4201 | // identified in the type system. |
| 4202 | class Struct: public HeapObject { |
| 4203 | public: |
| 4204 | inline void InitializeBody(int object_size); |
| 4205 | static inline Struct* cast(Object* that); |
| 4206 | }; |
| 4207 | |
| 4208 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 4209 | // Script describes a script which has been added to the VM. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4210 | class Script: public Struct { |
| 4211 | public: |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 4212 | // Script types. |
| 4213 | enum Type { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 4214 | TYPE_NATIVE = 0, |
| 4215 | TYPE_EXTENSION = 1, |
| 4216 | TYPE_NORMAL = 2 |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 4217 | }; |
| 4218 | |
| 4219 | // Script compilation types. |
| 4220 | enum CompilationType { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 4221 | COMPILATION_TYPE_HOST = 0, |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 4222 | COMPILATION_TYPE_EVAL = 1 |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 4223 | }; |
| 4224 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4225 | // [source]: the script source. |
| 4226 | DECL_ACCESSORS(source, Object) |
| 4227 | |
| 4228 | // [name]: the script name. |
| 4229 | DECL_ACCESSORS(name, Object) |
| 4230 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4231 | // [id]: the script id. |
| 4232 | DECL_ACCESSORS(id, Object) |
| 4233 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4234 | // [line_offset]: script line offset in resource from where it was extracted. |
| 4235 | DECL_ACCESSORS(line_offset, Smi) |
| 4236 | |
| 4237 | // [column_offset]: script column offset in resource from where it was |
| 4238 | // extracted. |
| 4239 | DECL_ACCESSORS(column_offset, Smi) |
| 4240 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 4241 | // [data]: additional data associated with this script. |
| 4242 | DECL_ACCESSORS(data, Object) |
| 4243 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4244 | // [context_data]: context data for the context this script was compiled in. |
| 4245 | DECL_ACCESSORS(context_data, Object) |
| 4246 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4247 | // [wrapper]: the wrapper cache. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 4248 | DECL_ACCESSORS(wrapper, Foreign) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4249 | |
| 4250 | // [type]: the script type. |
| 4251 | DECL_ACCESSORS(type, Smi) |
| 4252 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 4253 | // [compilation]: how the the script was compiled. |
| 4254 | DECL_ACCESSORS(compilation_type, Smi) |
| 4255 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4256 | // [line_ends]: FixedArray of line ends positions. |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 4257 | DECL_ACCESSORS(line_ends, Object) |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 4258 | |
sgjesse@chromium.org | 9818059 | 2009-12-02 08:17:28 +0000 | [diff] [blame] | 4259 | // [eval_from_shared]: for eval scripts the shared funcion info for the |
| 4260 | // function from which eval was called. |
| 4261 | DECL_ACCESSORS(eval_from_shared, Object) |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 4262 | |
| 4263 | // [eval_from_instructions_offset]: the instruction offset in the code for the |
| 4264 | // function from which eval was called where eval was called. |
| 4265 | DECL_ACCESSORS(eval_from_instructions_offset, Smi) |
| 4266 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4267 | static inline Script* cast(Object* obj); |
| 4268 | |
sgjesse@chromium.org | 152a0b0 | 2009-10-07 13:50:16 +0000 | [diff] [blame] | 4269 | // If script source is an external string, check that the underlying |
| 4270 | // resource is accessible. Otherwise, always return true. |
| 4271 | inline bool HasValidSource(); |
| 4272 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4273 | #ifdef OBJECT_PRINT |
| 4274 | inline void ScriptPrint() { |
| 4275 | ScriptPrint(stdout); |
| 4276 | } |
| 4277 | void ScriptPrint(FILE* out); |
| 4278 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4279 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4280 | void ScriptVerify(); |
| 4281 | #endif |
| 4282 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 4283 | static const int kSourceOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4284 | static const int kNameOffset = kSourceOffset + kPointerSize; |
| 4285 | static const int kLineOffsetOffset = kNameOffset + kPointerSize; |
| 4286 | static const int kColumnOffsetOffset = kLineOffsetOffset + kPointerSize; |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 4287 | static const int kDataOffset = kColumnOffsetOffset + kPointerSize; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4288 | static const int kContextOffset = kDataOffset + kPointerSize; |
| 4289 | static const int kWrapperOffset = kContextOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4290 | static const int kTypeOffset = kWrapperOffset + kPointerSize; |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 4291 | static const int kCompilationTypeOffset = kTypeOffset + kPointerSize; |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 4292 | static const int kLineEndsOffset = kCompilationTypeOffset + kPointerSize; |
| 4293 | static const int kIdOffset = kLineEndsOffset + kPointerSize; |
sgjesse@chromium.org | 9818059 | 2009-12-02 08:17:28 +0000 | [diff] [blame] | 4294 | static const int kEvalFromSharedOffset = kIdOffset + kPointerSize; |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 4295 | static const int kEvalFrominstructionsOffsetOffset = |
sgjesse@chromium.org | 9818059 | 2009-12-02 08:17:28 +0000 | [diff] [blame] | 4296 | kEvalFromSharedOffset + kPointerSize; |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 4297 | static const int kSize = kEvalFrominstructionsOffsetOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4298 | |
| 4299 | private: |
| 4300 | DISALLOW_IMPLICIT_CONSTRUCTORS(Script); |
| 4301 | }; |
| 4302 | |
| 4303 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4304 | // List of builtin functions we want to identify to improve code |
| 4305 | // generation. |
| 4306 | // |
| 4307 | // Each entry has a name of a global object property holding an object |
| 4308 | // optionally followed by ".prototype", a name of a builtin function |
| 4309 | // on the object (the one the id is set for), and a label. |
| 4310 | // |
| 4311 | // Installation of ids for the selected builtin functions is handled |
| 4312 | // by the bootstrapper. |
| 4313 | // |
| 4314 | // NOTE: Order is important: math functions should be at the end of |
| 4315 | // the list and MathFloor should be the first math function. |
| 4316 | #define FUNCTIONS_WITH_ID_LIST(V) \ |
| 4317 | V(Array.prototype, push, ArrayPush) \ |
| 4318 | V(Array.prototype, pop, ArrayPop) \ |
| 4319 | V(String.prototype, charCodeAt, StringCharCodeAt) \ |
| 4320 | V(String.prototype, charAt, StringCharAt) \ |
| 4321 | V(String, fromCharCode, StringFromCharCode) \ |
| 4322 | V(Math, floor, MathFloor) \ |
| 4323 | V(Math, round, MathRound) \ |
| 4324 | V(Math, ceil, MathCeil) \ |
| 4325 | V(Math, abs, MathAbs) \ |
| 4326 | V(Math, log, MathLog) \ |
| 4327 | V(Math, sin, MathSin) \ |
| 4328 | V(Math, cos, MathCos) \ |
| 4329 | V(Math, tan, MathTan) \ |
| 4330 | V(Math, asin, MathASin) \ |
| 4331 | V(Math, acos, MathACos) \ |
| 4332 | V(Math, atan, MathATan) \ |
| 4333 | V(Math, exp, MathExp) \ |
| 4334 | V(Math, sqrt, MathSqrt) \ |
| 4335 | V(Math, pow, MathPow) |
| 4336 | |
| 4337 | |
| 4338 | enum BuiltinFunctionId { |
| 4339 | #define DECLARE_FUNCTION_ID(ignored1, ignore2, name) \ |
| 4340 | k##name, |
| 4341 | FUNCTIONS_WITH_ID_LIST(DECLARE_FUNCTION_ID) |
| 4342 | #undef DECLARE_FUNCTION_ID |
| 4343 | // Fake id for a special case of Math.pow. Note, it continues the |
| 4344 | // list of math functions. |
| 4345 | kMathPowHalf, |
| 4346 | kFirstMathFunctionId = kMathFloor |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4347 | }; |
| 4348 | |
| 4349 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4350 | // SharedFunctionInfo describes the JSFunction information that can be |
| 4351 | // shared by multiple instances of the function. |
| 4352 | class SharedFunctionInfo: public HeapObject { |
| 4353 | public: |
| 4354 | // [name]: Function name. |
| 4355 | DECL_ACCESSORS(name, Object) |
| 4356 | |
| 4357 | // [code]: Function code. |
| 4358 | DECL_ACCESSORS(code, Code) |
| 4359 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4360 | // [scope_info]: Scope info. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 4361 | DECL_ACCESSORS(scope_info, SerializedScopeInfo) |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4362 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 4363 | // [construct stub]: Code stub for constructing instances of this function. |
| 4364 | DECL_ACCESSORS(construct_stub, Code) |
| 4365 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 4366 | inline Code* unchecked_code(); |
| 4367 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4368 | // Returns if this function has been compiled to native code yet. |
| 4369 | inline bool is_compiled(); |
| 4370 | |
| 4371 | // [length]: The function length - usually the number of declared parameters. |
| 4372 | // Use up to 2^30 parameters. |
| 4373 | inline int length(); |
| 4374 | inline void set_length(int value); |
| 4375 | |
| 4376 | // [formal parameter count]: The declared number of parameters. |
| 4377 | inline int formal_parameter_count(); |
| 4378 | inline void set_formal_parameter_count(int value); |
| 4379 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4380 | // Set the formal parameter count so the function code will be |
| 4381 | // called without using argument adaptor frames. |
| 4382 | inline void DontAdaptArguments(); |
| 4383 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4384 | // [expected_nof_properties]: Expected number of properties for the function. |
| 4385 | inline int expected_nof_properties(); |
| 4386 | inline void set_expected_nof_properties(int value); |
| 4387 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4388 | // Inobject slack tracking is the way to reclaim unused inobject space. |
| 4389 | // |
| 4390 | // The instance size is initially determined by adding some slack to |
| 4391 | // expected_nof_properties (to allow for a few extra properties added |
| 4392 | // after the constructor). There is no guarantee that the extra space |
| 4393 | // will not be wasted. |
| 4394 | // |
| 4395 | // Here is the algorithm to reclaim the unused inobject space: |
| 4396 | // - Detect the first constructor call for this SharedFunctionInfo. |
| 4397 | // When it happens enter the "in progress" state: remember the |
| 4398 | // constructor's initial_map and install a special construct stub that |
| 4399 | // counts constructor calls. |
| 4400 | // - While the tracking is in progress create objects filled with |
| 4401 | // one_pointer_filler_map instead of undefined_value. This way they can be |
| 4402 | // resized quickly and safely. |
| 4403 | // - Once enough (kGenerousAllocationCount) objects have been created |
| 4404 | // compute the 'slack' (traverse the map transition tree starting from the |
| 4405 | // initial_map and find the lowest value of unused_property_fields). |
| 4406 | // - Traverse the transition tree again and decrease the instance size |
| 4407 | // of every map. Existing objects will resize automatically (they are |
| 4408 | // filled with one_pointer_filler_map). All further allocations will |
| 4409 | // use the adjusted instance size. |
| 4410 | // - Decrease expected_nof_properties so that an allocations made from |
| 4411 | // another context will use the adjusted instance size too. |
| 4412 | // - Exit "in progress" state by clearing the reference to the initial_map |
| 4413 | // and setting the regular construct stub (generic or inline). |
| 4414 | // |
| 4415 | // The above is the main event sequence. Some special cases are possible |
| 4416 | // while the tracking is in progress: |
| 4417 | // |
| 4418 | // - GC occurs. |
| 4419 | // Check if the initial_map is referenced by any live objects (except this |
| 4420 | // SharedFunctionInfo). If it is, continue tracking as usual. |
| 4421 | // If it is not, clear the reference and reset the tracking state. The |
| 4422 | // tracking will be initiated again on the next constructor call. |
| 4423 | // |
| 4424 | // - The constructor is called from another context. |
| 4425 | // Immediately complete the tracking, perform all the necessary changes |
| 4426 | // to maps. This is necessary because there is no efficient way to track |
| 4427 | // multiple initial_maps. |
| 4428 | // Proceed to create an object in the current context (with the adjusted |
| 4429 | // size). |
| 4430 | // |
| 4431 | // - A different constructor function sharing the same SharedFunctionInfo is |
| 4432 | // called in the same context. This could be another closure in the same |
| 4433 | // context, or the first function could have been disposed. |
| 4434 | // This is handled the same way as the previous case. |
| 4435 | // |
| 4436 | // Important: inobject slack tracking is not attempted during the snapshot |
| 4437 | // creation. |
| 4438 | |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 4439 | static const int kGenerousAllocationCount = 8; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4440 | |
| 4441 | // [construction_count]: Counter for constructor calls made during |
| 4442 | // the tracking phase. |
| 4443 | inline int construction_count(); |
| 4444 | inline void set_construction_count(int value); |
| 4445 | |
| 4446 | // [initial_map]: initial map of the first function called as a constructor. |
| 4447 | // Saved for the duration of the tracking phase. |
| 4448 | // This is a weak link (GC resets it to undefined_value if no other live |
| 4449 | // object reference this map). |
| 4450 | DECL_ACCESSORS(initial_map, Object) |
| 4451 | |
| 4452 | // True if the initial_map is not undefined and the countdown stub is |
| 4453 | // installed. |
| 4454 | inline bool IsInobjectSlackTrackingInProgress(); |
| 4455 | |
| 4456 | // Starts the tracking. |
| 4457 | // Stores the initial map and installs the countdown stub. |
| 4458 | // IsInobjectSlackTrackingInProgress is normally true after this call, |
| 4459 | // except when tracking have not been started (e.g. the map has no unused |
| 4460 | // properties or the snapshot is being built). |
| 4461 | void StartInobjectSlackTracking(Map* map); |
| 4462 | |
| 4463 | // Completes the tracking. |
| 4464 | // IsInobjectSlackTrackingInProgress is false after this call. |
| 4465 | void CompleteInobjectSlackTracking(); |
| 4466 | |
| 4467 | // Clears the initial_map before the GC marking phase to ensure the reference |
| 4468 | // is weak. IsInobjectSlackTrackingInProgress is false after this call. |
| 4469 | void DetachInitialMap(); |
| 4470 | |
| 4471 | // Restores the link to the initial map after the GC marking phase. |
| 4472 | // IsInobjectSlackTrackingInProgress is true after this call. |
| 4473 | void AttachInitialMap(Map* map); |
| 4474 | |
| 4475 | // False if there are definitely no live objects created from this function. |
| 4476 | // True if live objects _may_ exist (existence not guaranteed). |
| 4477 | // May go back from true to false after GC. |
| 4478 | inline bool live_objects_may_exist(); |
| 4479 | |
| 4480 | inline void set_live_objects_may_exist(bool value); |
| 4481 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4482 | // [instance class name]: class name for instances. |
| 4483 | DECL_ACCESSORS(instance_class_name, Object) |
| 4484 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 4485 | // [function data]: This field holds some additional data for function. |
| 4486 | // Currently it either has FunctionTemplateInfo to make benefit the API |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4487 | // or Smi identifying a builtin function. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4488 | // In the long run we don't want all functions to have this field but |
| 4489 | // we can fix that when we have a better model for storing hidden data |
| 4490 | // on objects. |
| 4491 | DECL_ACCESSORS(function_data, Object) |
| 4492 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 4493 | inline bool IsApiFunction(); |
| 4494 | inline FunctionTemplateInfo* get_api_func_data(); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4495 | inline bool HasBuiltinFunctionId(); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4496 | inline BuiltinFunctionId builtin_function_id(); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 4497 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4498 | // [script info]: Script from which the function originates. |
| 4499 | DECL_ACCESSORS(script, Object) |
| 4500 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4501 | // [num_literals]: Number of literals used by this function. |
| 4502 | inline int num_literals(); |
| 4503 | inline void set_num_literals(int value); |
| 4504 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4505 | // [start_position_and_type]: Field used to store both the source code |
| 4506 | // position, whether or not the function is a function expression, |
| 4507 | // and whether or not the function is a toplevel function. The two |
| 4508 | // least significants bit indicates whether the function is an |
| 4509 | // expression and the rest contains the source code position. |
| 4510 | inline int start_position_and_type(); |
| 4511 | inline void set_start_position_and_type(int value); |
| 4512 | |
| 4513 | // [debug info]: Debug information. |
| 4514 | DECL_ACCESSORS(debug_info, Object) |
| 4515 | |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 4516 | // [inferred name]: Name inferred from variable or property |
| 4517 | // assignment of this function. Used to facilitate debugging and |
| 4518 | // profiling of JavaScript code written in OO style, where almost |
| 4519 | // all functions are anonymous but are assigned to object |
| 4520 | // properties. |
| 4521 | DECL_ACCESSORS(inferred_name, String) |
| 4522 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 4523 | // The function's name if it is non-empty, otherwise the inferred name. |
| 4524 | String* DebugName(); |
| 4525 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4526 | // Position of the 'function' token in the script source. |
| 4527 | inline int function_token_position(); |
| 4528 | inline void set_function_token_position(int function_token_position); |
| 4529 | |
| 4530 | // Position of this function in the script source. |
| 4531 | inline int start_position(); |
| 4532 | inline void set_start_position(int start_position); |
| 4533 | |
| 4534 | // End position of this function in the script source. |
| 4535 | inline int end_position(); |
| 4536 | inline void set_end_position(int end_position); |
| 4537 | |
| 4538 | // Is this function a function expression in the source code. |
| 4539 | inline bool is_expression(); |
| 4540 | inline void set_is_expression(bool value); |
| 4541 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 4542 | // Is this function a top-level function (scripts, evals). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4543 | inline bool is_toplevel(); |
| 4544 | inline void set_is_toplevel(bool value); |
| 4545 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4546 | // Bit field containing various information collected by the compiler to |
| 4547 | // drive optimization. |
| 4548 | inline int compiler_hints(); |
| 4549 | inline void set_compiler_hints(int value); |
| 4550 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4551 | // A counter used to determine when to stress the deoptimizer with a |
| 4552 | // deopt. |
| 4553 | inline Smi* deopt_counter(); |
| 4554 | inline void set_deopt_counter(Smi* counter); |
| 4555 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4556 | // Add information on assignments of the form this.x = ...; |
| 4557 | void SetThisPropertyAssignmentsInfo( |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4558 | bool has_only_simple_this_property_assignments, |
| 4559 | FixedArray* this_property_assignments); |
| 4560 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4561 | // Clear information on assignments of the form this.x = ...; |
| 4562 | void ClearThisPropertyAssignmentsInfo(); |
| 4563 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4564 | // Indicate that this function only consists of assignments of the form |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4565 | // this.x = y; where y is either a constant or refers to an argument. |
| 4566 | inline bool has_only_simple_this_property_assignments(); |
| 4567 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 4568 | // Indicates if this function can be lazy compiled. |
| 4569 | // This is used to determine if we can safely flush code from a function |
| 4570 | // when doing GC if we expect that the function will no longer be used. |
| 4571 | inline bool allows_lazy_compilation(); |
| 4572 | inline void set_allows_lazy_compilation(bool flag); |
| 4573 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 4574 | // Indicates how many full GCs this function has survived with assigned |
| 4575 | // code object. Used to determine when it is relatively safe to flush |
| 4576 | // this code object and replace it with lazy compilation stub. |
| 4577 | // Age is reset when GC notices that the code object is referenced |
| 4578 | // from the stack or compilation cache. |
| 4579 | inline int code_age(); |
| 4580 | inline void set_code_age(int age); |
| 4581 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4582 | // Indicates whether optimizations have been disabled for this |
| 4583 | // shared function info. If a function is repeatedly optimized or if |
| 4584 | // we cannot optimize the function we disable optimization to avoid |
| 4585 | // spending time attempting to optimize it again. |
| 4586 | inline bool optimization_disabled(); |
| 4587 | inline void set_optimization_disabled(bool value); |
| 4588 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4589 | // Indicates whether the function is a strict mode function. |
| 4590 | inline bool strict_mode(); |
| 4591 | inline void set_strict_mode(bool value); |
| 4592 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4593 | // Indicates whether the function is a native function. |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 4594 | // These needs special threatment in .call and .apply since |
| 4595 | // null passed as the receiver should not be translated to the |
| 4596 | // global object. |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4597 | inline bool native(); |
| 4598 | inline void set_native(bool value); |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 4599 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4600 | // Indicates whether or not the code in the shared function support |
| 4601 | // deoptimization. |
| 4602 | inline bool has_deoptimization_support(); |
| 4603 | |
| 4604 | // Enable deoptimization support through recompiled code. |
| 4605 | void EnableDeoptimizationSupport(Code* recompiled); |
| 4606 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 4607 | // Disable (further) attempted optimization of all functions sharing this |
| 4608 | // shared function info. The function is the one we actually tried to |
| 4609 | // optimize. |
| 4610 | void DisableOptimization(JSFunction* function); |
| 4611 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4612 | // Lookup the bailout ID and ASSERT that it exists in the non-optimized |
| 4613 | // code, returns whether it asserted (i.e., always true if assertions are |
| 4614 | // disabled). |
| 4615 | bool VerifyBailoutId(int id); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 4616 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4617 | // Check whether a inlined constructor can be generated with the given |
| 4618 | // prototype. |
| 4619 | bool CanGenerateInlineConstructor(Object* prototype); |
| 4620 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 4621 | // Prevents further attempts to generate inline constructors. |
| 4622 | // To be called if generation failed for any reason. |
| 4623 | void ForbidInlineConstructor(); |
| 4624 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4625 | // For functions which only contains this property assignments this provides |
| 4626 | // access to the names for the properties assigned. |
| 4627 | DECL_ACCESSORS(this_property_assignments, Object) |
| 4628 | inline int this_property_assignments_count(); |
| 4629 | inline void set_this_property_assignments_count(int value); |
| 4630 | String* GetThisPropertyAssignmentName(int index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4631 | bool IsThisPropertyAssignmentArgument(int index); |
| 4632 | int GetThisPropertyAssignmentArgument(int index); |
| 4633 | Object* GetThisPropertyAssignmentConstant(int index); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4634 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4635 | // [source code]: Source code for the function. |
| 4636 | bool HasSourceCode(); |
| 4637 | Object* GetSourceCode(); |
| 4638 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4639 | inline int opt_count(); |
| 4640 | inline void set_opt_count(int opt_count); |
| 4641 | |
| 4642 | // Source size of this function. |
| 4643 | int SourceSize(); |
| 4644 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4645 | // Calculate the instance size. |
| 4646 | int CalculateInstanceSize(); |
| 4647 | |
| 4648 | // Calculate the number of in-object properties. |
| 4649 | int CalculateInObjectProperties(); |
| 4650 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4651 | // Dispatched behavior. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4652 | // Set max_length to -1 for unlimited length. |
| 4653 | void SourceCodePrint(StringStream* accumulator, int max_length); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4654 | #ifdef OBJECT_PRINT |
| 4655 | inline void SharedFunctionInfoPrint() { |
| 4656 | SharedFunctionInfoPrint(stdout); |
| 4657 | } |
| 4658 | void SharedFunctionInfoPrint(FILE* out); |
| 4659 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4660 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4661 | void SharedFunctionInfoVerify(); |
| 4662 | #endif |
| 4663 | |
| 4664 | // Casting. |
| 4665 | static inline SharedFunctionInfo* cast(Object* obj); |
| 4666 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4667 | // Constants. |
| 4668 | static const int kDontAdaptArgumentsSentinel = -1; |
| 4669 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4670 | // Layout description. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4671 | // Pointer fields. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 4672 | static const int kNameOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4673 | static const int kCodeOffset = kNameOffset + kPointerSize; |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4674 | static const int kScopeInfoOffset = kCodeOffset + kPointerSize; |
| 4675 | static const int kConstructStubOffset = kScopeInfoOffset + kPointerSize; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4676 | static const int kInstanceClassNameOffset = |
| 4677 | kConstructStubOffset + kPointerSize; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 4678 | static const int kFunctionDataOffset = |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4679 | kInstanceClassNameOffset + kPointerSize; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 4680 | static const int kScriptOffset = kFunctionDataOffset + kPointerSize; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4681 | static const int kDebugInfoOffset = kScriptOffset + kPointerSize; |
| 4682 | static const int kInferredNameOffset = kDebugInfoOffset + kPointerSize; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4683 | static const int kInitialMapOffset = |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4684 | kInferredNameOffset + kPointerSize; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4685 | static const int kThisPropertyAssignmentsOffset = |
| 4686 | kInitialMapOffset + kPointerSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4687 | static const int kDeoptCounterOffset = |
| 4688 | kThisPropertyAssignmentsOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4689 | #if V8_HOST_ARCH_32_BIT |
| 4690 | // Smi fields. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4691 | static const int kLengthOffset = |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4692 | kDeoptCounterOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4693 | static const int kFormalParameterCountOffset = kLengthOffset + kPointerSize; |
| 4694 | static const int kExpectedNofPropertiesOffset = |
| 4695 | kFormalParameterCountOffset + kPointerSize; |
| 4696 | static const int kNumLiteralsOffset = |
| 4697 | kExpectedNofPropertiesOffset + kPointerSize; |
| 4698 | static const int kStartPositionAndTypeOffset = |
| 4699 | kNumLiteralsOffset + kPointerSize; |
| 4700 | static const int kEndPositionOffset = |
| 4701 | kStartPositionAndTypeOffset + kPointerSize; |
| 4702 | static const int kFunctionTokenPositionOffset = |
| 4703 | kEndPositionOffset + kPointerSize; |
| 4704 | static const int kCompilerHintsOffset = |
| 4705 | kFunctionTokenPositionOffset + kPointerSize; |
| 4706 | static const int kThisPropertyAssignmentsCountOffset = |
| 4707 | kCompilerHintsOffset + kPointerSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4708 | static const int kOptCountOffset = |
| 4709 | kThisPropertyAssignmentsCountOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4710 | // Total size. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4711 | static const int kSize = kOptCountOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4712 | #else |
| 4713 | // The only reason to use smi fields instead of int fields |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4714 | // is to allow iteration without maps decoding during |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4715 | // garbage collections. |
| 4716 | // To avoid wasting space on 64-bit architectures we use |
| 4717 | // the following trick: we group integer fields into pairs |
| 4718 | // First integer in each pair is shifted left by 1. |
| 4719 | // By doing this we guarantee that LSB of each kPointerSize aligned |
| 4720 | // word is not set and thus this word cannot be treated as pointer |
| 4721 | // to HeapObject during old space traversal. |
| 4722 | static const int kLengthOffset = |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4723 | kDeoptCounterOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4724 | static const int kFormalParameterCountOffset = |
| 4725 | kLengthOffset + kIntSize; |
| 4726 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4727 | static const int kExpectedNofPropertiesOffset = |
| 4728 | kFormalParameterCountOffset + kIntSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4729 | static const int kNumLiteralsOffset = |
| 4730 | kExpectedNofPropertiesOffset + kIntSize; |
| 4731 | |
| 4732 | static const int kEndPositionOffset = |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4733 | kNumLiteralsOffset + kIntSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4734 | static const int kStartPositionAndTypeOffset = |
| 4735 | kEndPositionOffset + kIntSize; |
| 4736 | |
| 4737 | static const int kFunctionTokenPositionOffset = |
| 4738 | kStartPositionAndTypeOffset + kIntSize; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4739 | static const int kCompilerHintsOffset = |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4740 | kFunctionTokenPositionOffset + kIntSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4741 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4742 | static const int kThisPropertyAssignmentsCountOffset = |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4743 | kCompilerHintsOffset + kIntSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4744 | static const int kOptCountOffset = |
| 4745 | kThisPropertyAssignmentsCountOffset + kIntSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4746 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4747 | // Total size. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4748 | static const int kSize = kOptCountOffset + kIntSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4749 | |
| 4750 | #endif |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4751 | |
| 4752 | // The construction counter for inobject slack tracking is stored in the |
| 4753 | // most significant byte of compiler_hints which is otherwise unused. |
| 4754 | // Its offset depends on the endian-ness of the architecture. |
| 4755 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 4756 | static const int kConstructionCountOffset = kCompilerHintsOffset + 3; |
| 4757 | #elif __BYTE_ORDER == __BIG_ENDIAN |
| 4758 | static const int kConstructionCountOffset = kCompilerHintsOffset + 0; |
| 4759 | #else |
| 4760 | #error Unknown byte ordering |
| 4761 | #endif |
| 4762 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4763 | static const int kAlignedSize = POINTER_SIZE_ALIGN(kSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4764 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4765 | typedef FixedBodyDescriptor<kNameOffset, |
| 4766 | kThisPropertyAssignmentsOffset + kPointerSize, |
| 4767 | kSize> BodyDescriptor; |
| 4768 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4769 | // Bit positions in start_position_and_type. |
| 4770 | // The source code start position is in the 30 most significant bits of |
| 4771 | // the start_position_and_type field. |
| 4772 | static const int kIsExpressionBit = 0; |
| 4773 | static const int kIsTopLevelBit = 1; |
| 4774 | static const int kStartPositionShift = 2; |
| 4775 | static const int kStartPositionMask = ~((1 << kStartPositionShift) - 1); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 4776 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4777 | // Bit positions in compiler_hints. |
ager@chromium.org | b9a1545 | 2009-11-11 09:55:05 +0000 | [diff] [blame] | 4778 | static const int kHasOnlySimpleThisPropertyAssignments = 0; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4779 | static const int kAllowLazyCompilation = 1; |
| 4780 | static const int kLiveObjectsMayExist = 2; |
| 4781 | static const int kCodeAgeShift = 3; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4782 | static const int kCodeAgeMask = 0x7; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4783 | static const int kOptimizationDisabled = 6; |
| 4784 | static const int kStrictModeFunction = 7; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4785 | static const int kNative = 8; |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4786 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4787 | private: |
| 4788 | #if V8_HOST_ARCH_32_BIT |
| 4789 | // On 32 bit platforms, compiler hints is a smi. |
| 4790 | static const int kCompilerHintsSmiTagSize = kSmiTagSize; |
| 4791 | static const int kCompilerHintsSize = kPointerSize; |
| 4792 | #else |
| 4793 | // On 64 bit platforms, compiler hints is not a smi, see comment above. |
| 4794 | static const int kCompilerHintsSmiTagSize = 0; |
| 4795 | static const int kCompilerHintsSize = kIntSize; |
| 4796 | #endif |
| 4797 | |
| 4798 | public: |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 4799 | // Constants for optimizing codegen for strict mode function and |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4800 | // native tests. |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4801 | // Allows to use byte-widgh instructions. |
| 4802 | static const int kStrictModeBitWithinByte = |
| 4803 | (kStrictModeFunction + kCompilerHintsSmiTagSize) % kBitsPerByte; |
| 4804 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4805 | static const int kNativeBitWithinByte = |
| 4806 | (kNative + kCompilerHintsSmiTagSize) % kBitsPerByte; |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 4807 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4808 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 4809 | static const int kStrictModeByteOffset = kCompilerHintsOffset + |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 4810 | (kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4811 | static const int kNativeByteOffset = kCompilerHintsOffset + |
| 4812 | (kNative + kCompilerHintsSmiTagSize) / kBitsPerByte; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4813 | #elif __BYTE_ORDER == __BIG_ENDIAN |
| 4814 | static const int kStrictModeByteOffset = kCompilerHintsOffset + |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 4815 | (kCompilerHintsSize - 1) - |
| 4816 | ((kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4817 | static const int kNativeByteOffset = kCompilerHintsOffset + |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 4818 | (kCompilerHintsSize - 1) - |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4819 | ((kNative + kCompilerHintsSmiTagSize) / kBitsPerByte); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4820 | #else |
| 4821 | #error Unknown byte ordering |
| 4822 | #endif |
| 4823 | |
| 4824 | private: |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 4825 | DISALLOW_IMPLICIT_CONSTRUCTORS(SharedFunctionInfo); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4826 | }; |
| 4827 | |
| 4828 | |
| 4829 | // JSFunction describes JavaScript functions. |
| 4830 | class JSFunction: public JSObject { |
| 4831 | public: |
| 4832 | // [prototype_or_initial_map]: |
| 4833 | DECL_ACCESSORS(prototype_or_initial_map, Object) |
| 4834 | |
| 4835 | // [shared_function_info]: The information about the function that |
| 4836 | // can be shared by instances. |
| 4837 | DECL_ACCESSORS(shared, SharedFunctionInfo) |
| 4838 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 4839 | inline SharedFunctionInfo* unchecked_shared(); |
| 4840 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4841 | // [context]: The context for this function. |
| 4842 | inline Context* context(); |
| 4843 | inline Object* unchecked_context(); |
| 4844 | inline void set_context(Object* context); |
| 4845 | |
| 4846 | // [code]: The generated code object for this function. Executed |
| 4847 | // when the function is invoked, e.g. foo() or new foo(). See |
| 4848 | // [[Call]] and [[Construct]] description in ECMA-262, section |
| 4849 | // 8.6.2, page 27. |
| 4850 | inline Code* code(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4851 | inline void set_code(Code* code); |
| 4852 | inline void ReplaceCode(Code* code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4853 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 4854 | inline Code* unchecked_code(); |
| 4855 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 4856 | // Tells whether this function is builtin. |
| 4857 | inline bool IsBuiltin(); |
| 4858 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4859 | // Tells whether or not the function needs arguments adaption. |
| 4860 | inline bool NeedsArgumentsAdaption(); |
| 4861 | |
| 4862 | // Tells whether or not this function has been optimized. |
| 4863 | inline bool IsOptimized(); |
| 4864 | |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 4865 | // Tells whether or not this function can be optimized. |
| 4866 | inline bool IsOptimizable(); |
| 4867 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4868 | // Mark this function for lazy recompilation. The function will be |
| 4869 | // recompiled the next time it is executed. |
| 4870 | void MarkForLazyRecompilation(); |
| 4871 | |
| 4872 | // Tells whether or not the function is already marked for lazy |
| 4873 | // recompilation. |
| 4874 | inline bool IsMarkedForLazyRecompilation(); |
| 4875 | |
| 4876 | // Compute a hash code for the source code of this function. |
| 4877 | uint32_t SourceHash(); |
| 4878 | |
| 4879 | // Check whether or not this function is inlineable. |
| 4880 | bool IsInlineable(); |
| 4881 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4882 | // [literals]: Fixed array holding the materialized literals. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 4883 | // |
| 4884 | // If the function contains object, regexp or array literals, the |
| 4885 | // literals array prefix contains the object, regexp, and array |
| 4886 | // function to be used when creating these literals. This is |
| 4887 | // necessary so that we do not dynamically lookup the object, regexp |
| 4888 | // or array functions. Performing a dynamic lookup, we might end up |
| 4889 | // using the functions from a new context that we should not have |
| 4890 | // access to. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4891 | DECL_ACCESSORS(literals, FixedArray) |
| 4892 | |
| 4893 | // The initial map for an object created by this constructor. |
| 4894 | inline Map* initial_map(); |
| 4895 | inline void set_initial_map(Map* value); |
| 4896 | inline bool has_initial_map(); |
| 4897 | |
| 4898 | // Get and set the prototype property on a JSFunction. If the |
| 4899 | // function has an initial map the prototype is set on the initial |
| 4900 | // map. Otherwise, the prototype is put in the initial map field |
| 4901 | // until an initial map is needed. |
| 4902 | inline bool has_prototype(); |
| 4903 | inline bool has_instance_prototype(); |
| 4904 | inline Object* prototype(); |
| 4905 | inline Object* instance_prototype(); |
| 4906 | Object* SetInstancePrototype(Object* value); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4907 | MUST_USE_RESULT MaybeObject* SetPrototype(Object* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4908 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 4909 | // After prototype is removed, it will not be created when accessed, and |
| 4910 | // [[Construct]] from this function will not be allowed. |
| 4911 | Object* RemovePrototype(); |
| 4912 | inline bool should_have_prototype(); |
| 4913 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4914 | // Accessor for this function's initial map's [[class]] |
| 4915 | // property. This is primarily used by ECMA native functions. This |
| 4916 | // method sets the class_name field of this function's initial map |
| 4917 | // to a given value. It creates an initial map if this function does |
| 4918 | // not have one. Note that this method does not copy the initial map |
| 4919 | // if it has one already, but simply replaces it with the new value. |
| 4920 | // Instances created afterwards will have a map whose [[class]] is |
| 4921 | // set to 'value', but there is no guarantees on instances created |
| 4922 | // before. |
| 4923 | Object* SetInstanceClassName(String* name); |
| 4924 | |
| 4925 | // Returns if this function has been compiled to native code yet. |
| 4926 | inline bool is_compiled(); |
| 4927 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4928 | // [next_function_link]: Field for linking functions. This list is treated as |
| 4929 | // a weak list by the GC. |
| 4930 | DECL_ACCESSORS(next_function_link, Object) |
| 4931 | |
| 4932 | // Prints the name of the function using PrintF. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4933 | inline void PrintName() { |
| 4934 | PrintName(stdout); |
| 4935 | } |
| 4936 | void PrintName(FILE* out); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4937 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4938 | // Casting. |
| 4939 | static inline JSFunction* cast(Object* obj); |
| 4940 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 4941 | // Iterates the objects, including code objects indirectly referenced |
| 4942 | // through pointers to the first instruction in the code object. |
| 4943 | void JSFunctionIterateBody(int object_size, ObjectVisitor* v); |
| 4944 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4945 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4946 | #ifdef OBJECT_PRINT |
| 4947 | inline void JSFunctionPrint() { |
| 4948 | JSFunctionPrint(stdout); |
| 4949 | } |
| 4950 | void JSFunctionPrint(FILE* out); |
| 4951 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4952 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4953 | void JSFunctionVerify(); |
| 4954 | #endif |
| 4955 | |
| 4956 | // Returns the number of allocated literals. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4957 | inline int NumberOfLiterals(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4958 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 4959 | // Retrieve the global context from a function's literal array. |
| 4960 | static Context* GlobalContextFromLiterals(FixedArray* literals); |
| 4961 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4962 | // Layout descriptors. The last property (from kNonWeakFieldsEndOffset to |
| 4963 | // kSize) is weak and has special handling during garbage collection. |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 4964 | static const int kCodeEntryOffset = JSObject::kHeaderSize; |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4965 | static const int kPrototypeOrInitialMapOffset = |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 4966 | kCodeEntryOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4967 | static const int kSharedFunctionInfoOffset = |
| 4968 | kPrototypeOrInitialMapOffset + kPointerSize; |
| 4969 | static const int kContextOffset = kSharedFunctionInfoOffset + kPointerSize; |
| 4970 | static const int kLiteralsOffset = kContextOffset + kPointerSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4971 | static const int kNonWeakFieldsEndOffset = kLiteralsOffset + kPointerSize; |
| 4972 | static const int kNextFunctionLinkOffset = kNonWeakFieldsEndOffset; |
| 4973 | static const int kSize = kNextFunctionLinkOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4974 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 4975 | // Layout of the literals array. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 4976 | static const int kLiteralsPrefixSize = 1; |
| 4977 | static const int kLiteralGlobalContextIndex = 0; |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 4978 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4979 | private: |
| 4980 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunction); |
| 4981 | }; |
| 4982 | |
| 4983 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4984 | // JSGlobalProxy's prototype must be a JSGlobalObject or null, |
| 4985 | // and the prototype is hidden. JSGlobalProxy always delegates |
| 4986 | // property accesses to its prototype if the prototype is not null. |
| 4987 | // |
| 4988 | // A JSGlobalProxy can be reinitialized which will preserve its identity. |
| 4989 | // |
| 4990 | // Accessing a JSGlobalProxy requires security check. |
| 4991 | |
| 4992 | class JSGlobalProxy : public JSObject { |
| 4993 | public: |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 4994 | // [context]: the owner global context of this global proxy object. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4995 | // It is null value if this object is not used by any context. |
| 4996 | DECL_ACCESSORS(context, Object) |
| 4997 | |
| 4998 | // Casting. |
| 4999 | static inline JSGlobalProxy* cast(Object* obj); |
| 5000 | |
| 5001 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5002 | #ifdef OBJECT_PRINT |
| 5003 | inline void JSGlobalProxyPrint() { |
| 5004 | JSGlobalProxyPrint(stdout); |
| 5005 | } |
| 5006 | void JSGlobalProxyPrint(FILE* out); |
| 5007 | #endif |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5008 | #ifdef DEBUG |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5009 | void JSGlobalProxyVerify(); |
| 5010 | #endif |
| 5011 | |
| 5012 | // Layout description. |
| 5013 | static const int kContextOffset = JSObject::kHeaderSize; |
| 5014 | static const int kSize = kContextOffset + kPointerSize; |
| 5015 | |
| 5016 | private: |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5017 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalProxy); |
| 5018 | }; |
| 5019 | |
| 5020 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5021 | // Forward declaration. |
| 5022 | class JSBuiltinsObject; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5023 | class JSGlobalPropertyCell; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5024 | |
| 5025 | // Common super class for JavaScript global objects and the special |
| 5026 | // builtins global objects. |
| 5027 | class GlobalObject: public JSObject { |
| 5028 | public: |
| 5029 | // [builtins]: the object holding the runtime routines written in JS. |
| 5030 | DECL_ACCESSORS(builtins, JSBuiltinsObject) |
| 5031 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 5032 | // [global context]: the global context corresponding to this global object. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5033 | DECL_ACCESSORS(global_context, Context) |
| 5034 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5035 | // [global receiver]: the global receiver object of the context |
| 5036 | DECL_ACCESSORS(global_receiver, JSObject) |
| 5037 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 5038 | // Retrieve the property cell used to store a property. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5039 | JSGlobalPropertyCell* GetPropertyCell(LookupResult* result); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 5040 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5041 | // This is like GetProperty, but is used when you know the lookup won't fail |
| 5042 | // by throwing an exception. This is for the debug and builtins global |
| 5043 | // objects, where it is known which properties can be expected to be present |
| 5044 | // on the object. |
| 5045 | Object* GetPropertyNoExceptionThrown(String* key) { |
| 5046 | Object* answer = GetProperty(key)->ToObjectUnchecked(); |
| 5047 | return answer; |
| 5048 | } |
| 5049 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 5050 | // 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] | 5051 | MUST_USE_RESULT MaybeObject* EnsurePropertyCell(String* name); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 5052 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5053 | // Casting. |
| 5054 | static inline GlobalObject* cast(Object* obj); |
| 5055 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5056 | // Layout description. |
| 5057 | static const int kBuiltinsOffset = JSObject::kHeaderSize; |
| 5058 | static const int kGlobalContextOffset = kBuiltinsOffset + kPointerSize; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5059 | static const int kGlobalReceiverOffset = kGlobalContextOffset + kPointerSize; |
| 5060 | static const int kHeaderSize = kGlobalReceiverOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5061 | |
| 5062 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5063 | friend class AGCCVersionRequiresThisClassToHaveAFriendSoHereItIs; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5064 | |
| 5065 | DISALLOW_IMPLICIT_CONSTRUCTORS(GlobalObject); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5066 | }; |
| 5067 | |
| 5068 | |
| 5069 | // JavaScript global object. |
| 5070 | class JSGlobalObject: public GlobalObject { |
| 5071 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5072 | // Casting. |
| 5073 | static inline JSGlobalObject* cast(Object* obj); |
| 5074 | |
| 5075 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5076 | #ifdef OBJECT_PRINT |
| 5077 | inline void JSGlobalObjectPrint() { |
| 5078 | JSGlobalObjectPrint(stdout); |
| 5079 | } |
| 5080 | void JSGlobalObjectPrint(FILE* out); |
| 5081 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5082 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5083 | void JSGlobalObjectVerify(); |
| 5084 | #endif |
| 5085 | |
| 5086 | // Layout description. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5087 | static const int kSize = GlobalObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5088 | |
| 5089 | private: |
| 5090 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalObject); |
| 5091 | }; |
| 5092 | |
| 5093 | |
| 5094 | // Builtins global object which holds the runtime routines written in |
| 5095 | // JavaScript. |
| 5096 | class JSBuiltinsObject: public GlobalObject { |
| 5097 | public: |
| 5098 | // Accessors for the runtime routines written in JavaScript. |
| 5099 | inline Object* javascript_builtin(Builtins::JavaScript id); |
| 5100 | inline void set_javascript_builtin(Builtins::JavaScript id, Object* value); |
| 5101 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5102 | // Accessors for code of the runtime routines written in JavaScript. |
| 5103 | inline Code* javascript_builtin_code(Builtins::JavaScript id); |
| 5104 | inline void set_javascript_builtin_code(Builtins::JavaScript id, Code* value); |
| 5105 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5106 | // Casting. |
| 5107 | static inline JSBuiltinsObject* cast(Object* obj); |
| 5108 | |
| 5109 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5110 | #ifdef OBJECT_PRINT |
| 5111 | inline void JSBuiltinsObjectPrint() { |
| 5112 | JSBuiltinsObjectPrint(stdout); |
| 5113 | } |
| 5114 | void JSBuiltinsObjectPrint(FILE* out); |
| 5115 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5116 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5117 | void JSBuiltinsObjectVerify(); |
| 5118 | #endif |
| 5119 | |
| 5120 | // Layout description. The size of the builtins object includes |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5121 | // room for two pointers per runtime routine written in javascript |
| 5122 | // (function and code object). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5123 | static const int kJSBuiltinsCount = Builtins::id_count; |
| 5124 | static const int kJSBuiltinsOffset = GlobalObject::kHeaderSize; |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5125 | static const int kJSBuiltinsCodeOffset = |
| 5126 | GlobalObject::kHeaderSize + (kJSBuiltinsCount * kPointerSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5127 | static const int kSize = |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5128 | kJSBuiltinsCodeOffset + (kJSBuiltinsCount * kPointerSize); |
| 5129 | |
| 5130 | static int OffsetOfFunctionWithId(Builtins::JavaScript id) { |
| 5131 | return kJSBuiltinsOffset + id * kPointerSize; |
| 5132 | } |
| 5133 | |
| 5134 | static int OffsetOfCodeWithId(Builtins::JavaScript id) { |
| 5135 | return kJSBuiltinsCodeOffset + id * kPointerSize; |
| 5136 | } |
| 5137 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5138 | private: |
| 5139 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSBuiltinsObject); |
| 5140 | }; |
| 5141 | |
| 5142 | |
| 5143 | // Representation for JS Wrapper objects, String, Number, Boolean, Date, etc. |
| 5144 | class JSValue: public JSObject { |
| 5145 | public: |
| 5146 | // [value]: the object being wrapped. |
| 5147 | DECL_ACCESSORS(value, Object) |
| 5148 | |
| 5149 | // Casting. |
| 5150 | static inline JSValue* cast(Object* obj); |
| 5151 | |
| 5152 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5153 | #ifdef OBJECT_PRINT |
| 5154 | inline void JSValuePrint() { |
| 5155 | JSValuePrint(stdout); |
| 5156 | } |
| 5157 | void JSValuePrint(FILE* out); |
| 5158 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5159 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5160 | void JSValueVerify(); |
| 5161 | #endif |
| 5162 | |
| 5163 | // Layout description. |
| 5164 | static const int kValueOffset = JSObject::kHeaderSize; |
| 5165 | static const int kSize = kValueOffset + kPointerSize; |
| 5166 | |
| 5167 | private: |
| 5168 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSValue); |
| 5169 | }; |
| 5170 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 5171 | |
| 5172 | // Representation of message objects used for error reporting through |
| 5173 | // the API. The messages are formatted in JavaScript so this object is |
| 5174 | // a real JavaScript object. The information used for formatting the |
| 5175 | // error messages are not directly accessible from JavaScript to |
| 5176 | // prevent leaking information to user code called during error |
| 5177 | // formatting. |
| 5178 | class JSMessageObject: public JSObject { |
| 5179 | public: |
| 5180 | // [type]: the type of error message. |
| 5181 | DECL_ACCESSORS(type, String) |
| 5182 | |
| 5183 | // [arguments]: the arguments for formatting the error message. |
| 5184 | DECL_ACCESSORS(arguments, JSArray) |
| 5185 | |
| 5186 | // [script]: the script from which the error message originated. |
| 5187 | DECL_ACCESSORS(script, Object) |
| 5188 | |
| 5189 | // [stack_trace]: the stack trace for this error message. |
| 5190 | DECL_ACCESSORS(stack_trace, Object) |
| 5191 | |
| 5192 | // [stack_frames]: an array of stack frames for this error object. |
| 5193 | DECL_ACCESSORS(stack_frames, Object) |
| 5194 | |
| 5195 | // [start_position]: the start position in the script for the error message. |
| 5196 | inline int start_position(); |
| 5197 | inline void set_start_position(int value); |
| 5198 | |
| 5199 | // [end_position]: the end position in the script for the error message. |
| 5200 | inline int end_position(); |
| 5201 | inline void set_end_position(int value); |
| 5202 | |
| 5203 | // Casting. |
| 5204 | static inline JSMessageObject* cast(Object* obj); |
| 5205 | |
| 5206 | // Dispatched behavior. |
| 5207 | #ifdef OBJECT_PRINT |
| 5208 | inline void JSMessageObjectPrint() { |
| 5209 | JSMessageObjectPrint(stdout); |
| 5210 | } |
| 5211 | void JSMessageObjectPrint(FILE* out); |
| 5212 | #endif |
| 5213 | #ifdef DEBUG |
| 5214 | void JSMessageObjectVerify(); |
| 5215 | #endif |
| 5216 | |
| 5217 | // Layout description. |
| 5218 | static const int kTypeOffset = JSObject::kHeaderSize; |
| 5219 | static const int kArgumentsOffset = kTypeOffset + kPointerSize; |
| 5220 | static const int kScriptOffset = kArgumentsOffset + kPointerSize; |
| 5221 | static const int kStackTraceOffset = kScriptOffset + kPointerSize; |
| 5222 | static const int kStackFramesOffset = kStackTraceOffset + kPointerSize; |
| 5223 | static const int kStartPositionOffset = kStackFramesOffset + kPointerSize; |
| 5224 | static const int kEndPositionOffset = kStartPositionOffset + kPointerSize; |
| 5225 | static const int kSize = kEndPositionOffset + kPointerSize; |
| 5226 | |
| 5227 | typedef FixedBodyDescriptor<HeapObject::kMapOffset, |
| 5228 | kStackFramesOffset + kPointerSize, |
| 5229 | kSize> BodyDescriptor; |
| 5230 | }; |
| 5231 | |
| 5232 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5233 | // Regular expressions |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5234 | // The regular expression holds a single reference to a FixedArray in |
| 5235 | // the kDataOffset field. |
| 5236 | // The FixedArray contains the following data: |
| 5237 | // - tag : type of regexp implementation (not compiled yet, atom or irregexp) |
| 5238 | // - reference to the original source string |
| 5239 | // - reference to the original flag string |
| 5240 | // If it is an atom regexp |
| 5241 | // - a reference to a literal string to search for |
| 5242 | // If it is an irregexp regexp: |
| 5243 | // - a reference to code for ASCII inputs (bytecode or compiled). |
| 5244 | // - a reference to code for UC16 inputs (bytecode or compiled). |
| 5245 | // - max number of registers used by irregexp implementations. |
| 5246 | // - number of capture registers (output values) of the regexp. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5247 | class JSRegExp: public JSObject { |
| 5248 | public: |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5249 | // Meaning of Type: |
| 5250 | // 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] | 5251 | // ATOM: A simple string to match against using an indexOf operation. |
| 5252 | // IRREGEXP: Compiled with Irregexp. |
| 5253 | // IRREGEXP_NATIVE: Compiled to native code with Irregexp. |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 5254 | enum Type { NOT_COMPILED, ATOM, IRREGEXP }; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5255 | enum Flag { NONE = 0, GLOBAL = 1, IGNORE_CASE = 2, MULTILINE = 4 }; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5256 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5257 | class Flags { |
| 5258 | public: |
| 5259 | explicit Flags(uint32_t value) : value_(value) { } |
| 5260 | bool is_global() { return (value_ & GLOBAL) != 0; } |
| 5261 | bool is_ignore_case() { return (value_ & IGNORE_CASE) != 0; } |
| 5262 | bool is_multiline() { return (value_ & MULTILINE) != 0; } |
| 5263 | uint32_t value() { return value_; } |
| 5264 | private: |
| 5265 | uint32_t value_; |
| 5266 | }; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5267 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5268 | DECL_ACCESSORS(data, Object) |
| 5269 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5270 | inline Type TypeTag(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 5271 | inline int CaptureCount(); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5272 | inline Flags GetFlags(); |
| 5273 | inline String* Pattern(); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5274 | inline Object* DataAt(int index); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5275 | // Set implementation data after the object has been prepared. |
| 5276 | inline void SetDataAt(int index, Object* value); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 5277 | static int code_index(bool is_ascii) { |
| 5278 | if (is_ascii) { |
| 5279 | return kIrregexpASCIICodeIndex; |
| 5280 | } else { |
| 5281 | return kIrregexpUC16CodeIndex; |
| 5282 | } |
| 5283 | } |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5284 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5285 | static inline JSRegExp* cast(Object* obj); |
| 5286 | |
| 5287 | // Dispatched behavior. |
| 5288 | #ifdef DEBUG |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5289 | void JSRegExpVerify(); |
| 5290 | #endif |
| 5291 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5292 | static const int kDataOffset = JSObject::kHeaderSize; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5293 | static const int kSize = kDataOffset + kPointerSize; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5294 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5295 | // Indices in the data array. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5296 | static const int kTagIndex = 0; |
| 5297 | static const int kSourceIndex = kTagIndex + 1; |
| 5298 | static const int kFlagsIndex = kSourceIndex + 1; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5299 | static const int kDataIndex = kFlagsIndex + 1; |
| 5300 | // The data fields are used in different ways depending on the |
| 5301 | // value of the tag. |
| 5302 | // Atom regexps (literal strings). |
| 5303 | static const int kAtomPatternIndex = kDataIndex; |
| 5304 | |
| 5305 | static const int kAtomDataSize = kAtomPatternIndex + 1; |
| 5306 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 5307 | // Irregexp compiled code or bytecode for ASCII. If compilation |
| 5308 | // fails, this fields hold an exception object that should be |
| 5309 | // thrown if the regexp is used again. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5310 | static const int kIrregexpASCIICodeIndex = kDataIndex; |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 5311 | // Irregexp compiled code or bytecode for UC16. If compilation |
| 5312 | // fails, this fields hold an exception object that should be |
| 5313 | // thrown if the regexp is used again. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5314 | static const int kIrregexpUC16CodeIndex = kDataIndex + 1; |
| 5315 | // Maximal number of registers used by either ASCII or UC16. |
| 5316 | // Only used to check that there is enough stack space |
| 5317 | static const int kIrregexpMaxRegisterCountIndex = kDataIndex + 2; |
| 5318 | // Number of captures in the compiled regexp. |
| 5319 | static const int kIrregexpCaptureCountIndex = kDataIndex + 3; |
| 5320 | |
| 5321 | static const int kIrregexpDataSize = kIrregexpCaptureCountIndex + 1; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5322 | |
| 5323 | // Offsets directly into the data fixed array. |
| 5324 | static const int kDataTagOffset = |
| 5325 | FixedArray::kHeaderSize + kTagIndex * kPointerSize; |
| 5326 | static const int kDataAsciiCodeOffset = |
| 5327 | FixedArray::kHeaderSize + kIrregexpASCIICodeIndex * kPointerSize; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5328 | static const int kDataUC16CodeOffset = |
| 5329 | FixedArray::kHeaderSize + kIrregexpUC16CodeIndex * kPointerSize; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5330 | static const int kIrregexpCaptureCountOffset = |
| 5331 | FixedArray::kHeaderSize + kIrregexpCaptureCountIndex * kPointerSize; |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 5332 | |
| 5333 | // In-object fields. |
| 5334 | static const int kSourceFieldIndex = 0; |
| 5335 | static const int kGlobalFieldIndex = 1; |
| 5336 | static const int kIgnoreCaseFieldIndex = 2; |
| 5337 | static const int kMultilineFieldIndex = 3; |
| 5338 | static const int kLastIndexFieldIndex = 4; |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 5339 | static const int kInObjectFieldCount = 5; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5340 | }; |
| 5341 | |
| 5342 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 5343 | class CompilationCacheShape { |
| 5344 | public: |
| 5345 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 5346 | return key->IsMatch(value); |
| 5347 | } |
| 5348 | |
| 5349 | static inline uint32_t Hash(HashTableKey* key) { |
| 5350 | return key->Hash(); |
| 5351 | } |
| 5352 | |
| 5353 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 5354 | return key->HashForObject(object); |
| 5355 | } |
| 5356 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5357 | MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 5358 | return key->AsObject(); |
| 5359 | } |
| 5360 | |
| 5361 | static const int kPrefixSize = 0; |
| 5362 | static const int kEntrySize = 2; |
| 5363 | }; |
| 5364 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5365 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 5366 | class CompilationCacheTable: public HashTable<CompilationCacheShape, |
| 5367 | HashTableKey*> { |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5368 | public: |
| 5369 | // Find cached value for a string key, otherwise return null. |
| 5370 | Object* Lookup(String* src); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 5371 | Object* LookupEval(String* src, Context* context, StrictModeFlag strict_mode); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5372 | Object* LookupRegExp(String* source, JSRegExp::Flags flags); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5373 | MaybeObject* Put(String* src, Object* value); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 5374 | MaybeObject* PutEval(String* src, |
| 5375 | Context* context, |
| 5376 | SharedFunctionInfo* value); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5377 | MaybeObject* PutRegExp(String* src, JSRegExp::Flags flags, FixedArray* value); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5378 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5379 | // Remove given value from cache. |
| 5380 | void Remove(Object* value); |
| 5381 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5382 | static inline CompilationCacheTable* cast(Object* obj); |
| 5383 | |
| 5384 | private: |
| 5385 | DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheTable); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5386 | }; |
| 5387 | |
| 5388 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5389 | class CodeCache: public Struct { |
| 5390 | public: |
| 5391 | DECL_ACCESSORS(default_cache, FixedArray) |
| 5392 | DECL_ACCESSORS(normal_type_cache, Object) |
| 5393 | |
| 5394 | // Add the code object to the cache. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5395 | MUST_USE_RESULT MaybeObject* Update(String* name, Code* code); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5396 | |
| 5397 | // Lookup code object in the cache. Returns code object if found and undefined |
| 5398 | // if not. |
| 5399 | Object* Lookup(String* name, Code::Flags flags); |
| 5400 | |
| 5401 | // Get the internal index of a code object in the cache. Returns -1 if the |
| 5402 | // code object is not in that cache. This index can be used to later call |
| 5403 | // RemoveByIndex. The cache cannot be modified between a call to GetIndex and |
| 5404 | // RemoveByIndex. |
sgjesse@chromium.org | 99a37fa | 2010-03-11 09:23:46 +0000 | [diff] [blame] | 5405 | int GetIndex(Object* name, Code* code); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5406 | |
| 5407 | // Remove an object from the cache with the provided internal index. |
sgjesse@chromium.org | 99a37fa | 2010-03-11 09:23:46 +0000 | [diff] [blame] | 5408 | void RemoveByIndex(Object* name, Code* code, int index); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5409 | |
| 5410 | static inline CodeCache* cast(Object* obj); |
| 5411 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5412 | #ifdef OBJECT_PRINT |
| 5413 | inline void CodeCachePrint() { |
| 5414 | CodeCachePrint(stdout); |
| 5415 | } |
| 5416 | void CodeCachePrint(FILE* out); |
| 5417 | #endif |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5418 | #ifdef DEBUG |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5419 | void CodeCacheVerify(); |
| 5420 | #endif |
| 5421 | |
| 5422 | static const int kDefaultCacheOffset = HeapObject::kHeaderSize; |
| 5423 | static const int kNormalTypeCacheOffset = |
| 5424 | kDefaultCacheOffset + kPointerSize; |
| 5425 | static const int kSize = kNormalTypeCacheOffset + kPointerSize; |
| 5426 | |
| 5427 | private: |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5428 | MUST_USE_RESULT MaybeObject* UpdateDefaultCache(String* name, Code* code); |
| 5429 | MUST_USE_RESULT MaybeObject* UpdateNormalTypeCache(String* name, Code* code); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5430 | Object* LookupDefaultCache(String* name, Code::Flags flags); |
| 5431 | Object* LookupNormalTypeCache(String* name, Code::Flags flags); |
| 5432 | |
| 5433 | // Code cache layout of the default cache. Elements are alternating name and |
| 5434 | // code objects for non normal load/store/call IC's. |
| 5435 | static const int kCodeCacheEntrySize = 2; |
| 5436 | static const int kCodeCacheEntryNameOffset = 0; |
| 5437 | static const int kCodeCacheEntryCodeOffset = 1; |
| 5438 | |
| 5439 | DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCache); |
| 5440 | }; |
| 5441 | |
| 5442 | |
| 5443 | class CodeCacheHashTableShape { |
| 5444 | public: |
| 5445 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 5446 | return key->IsMatch(value); |
| 5447 | } |
| 5448 | |
| 5449 | static inline uint32_t Hash(HashTableKey* key) { |
| 5450 | return key->Hash(); |
| 5451 | } |
| 5452 | |
| 5453 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 5454 | return key->HashForObject(object); |
| 5455 | } |
| 5456 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5457 | MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5458 | return key->AsObject(); |
| 5459 | } |
| 5460 | |
| 5461 | static const int kPrefixSize = 0; |
| 5462 | static const int kEntrySize = 2; |
| 5463 | }; |
| 5464 | |
| 5465 | |
| 5466 | class CodeCacheHashTable: public HashTable<CodeCacheHashTableShape, |
| 5467 | HashTableKey*> { |
| 5468 | public: |
| 5469 | Object* Lookup(String* name, Code::Flags flags); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5470 | MUST_USE_RESULT MaybeObject* Put(String* name, Code* code); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5471 | |
| 5472 | int GetIndex(String* name, Code::Flags flags); |
| 5473 | void RemoveByIndex(int index); |
| 5474 | |
| 5475 | static inline CodeCacheHashTable* cast(Object* obj); |
| 5476 | |
| 5477 | // Initial size of the fixed array backing the hash table. |
| 5478 | static const int kInitialSize = 64; |
| 5479 | |
| 5480 | private: |
| 5481 | DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCacheHashTable); |
| 5482 | }; |
| 5483 | |
| 5484 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 5485 | class PolymorphicCodeCache: public Struct { |
| 5486 | public: |
| 5487 | DECL_ACCESSORS(cache, Object) |
| 5488 | |
| 5489 | MUST_USE_RESULT MaybeObject* Update(MapList* maps, |
| 5490 | Code::Flags flags, |
| 5491 | Code* code); |
| 5492 | Object* Lookup(MapList* maps, Code::Flags flags); |
| 5493 | |
| 5494 | static inline PolymorphicCodeCache* cast(Object* obj); |
| 5495 | |
| 5496 | #ifdef OBJECT_PRINT |
| 5497 | inline void PolymorphicCodeCachePrint() { |
| 5498 | PolymorphicCodeCachePrint(stdout); |
| 5499 | } |
| 5500 | void PolymorphicCodeCachePrint(FILE* out); |
| 5501 | #endif |
| 5502 | #ifdef DEBUG |
| 5503 | void PolymorphicCodeCacheVerify(); |
| 5504 | #endif |
| 5505 | |
| 5506 | static const int kCacheOffset = HeapObject::kHeaderSize; |
| 5507 | static const int kSize = kCacheOffset + kPointerSize; |
| 5508 | |
| 5509 | private: |
| 5510 | DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCache); |
| 5511 | }; |
| 5512 | |
| 5513 | |
| 5514 | class PolymorphicCodeCacheHashTable |
| 5515 | : public HashTable<CodeCacheHashTableShape, HashTableKey*> { |
| 5516 | public: |
| 5517 | Object* Lookup(MapList* maps, int code_kind); |
| 5518 | MUST_USE_RESULT MaybeObject* Put(MapList* maps, int code_kind, Code* code); |
| 5519 | |
| 5520 | static inline PolymorphicCodeCacheHashTable* cast(Object* obj); |
| 5521 | |
| 5522 | static const int kInitialSize = 64; |
| 5523 | private: |
| 5524 | DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCacheHashTable); |
| 5525 | }; |
| 5526 | |
| 5527 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5528 | enum AllowNullsFlag {ALLOW_NULLS, DISALLOW_NULLS}; |
| 5529 | enum RobustnessFlag {ROBUST_STRING_TRAVERSAL, FAST_STRING_TRAVERSAL}; |
| 5530 | |
| 5531 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5532 | class StringHasher { |
| 5533 | public: |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 5534 | explicit inline StringHasher(int length); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5535 | |
| 5536 | // Returns true if the hash of this string can be computed without |
| 5537 | // looking at the contents. |
| 5538 | inline bool has_trivial_hash(); |
| 5539 | |
| 5540 | // Add a character to the hash and update the array index calculation. |
| 5541 | inline void AddCharacter(uc32 c); |
| 5542 | |
| 5543 | // Adds a character to the hash but does not update the array index |
| 5544 | // calculation. This can only be called when it has been verified |
| 5545 | // that the input is not an array index. |
| 5546 | inline void AddCharacterNoIndex(uc32 c); |
| 5547 | |
| 5548 | // Returns the value to store in the hash field of a string with |
| 5549 | // the given length and contents. |
| 5550 | uint32_t GetHashField(); |
| 5551 | |
| 5552 | // Returns true if the characters seen so far make up a legal array |
| 5553 | // index. |
| 5554 | bool is_array_index() { return is_array_index_; } |
| 5555 | |
| 5556 | bool is_valid() { return is_valid_; } |
| 5557 | |
| 5558 | void invalidate() { is_valid_ = false; } |
| 5559 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 5560 | // Calculated hash value for a string consisting of 1 to |
| 5561 | // String::kMaxArrayIndexSize digits with no leading zeros (except "0"). |
| 5562 | // value is represented decimal value. |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 5563 | static uint32_t MakeArrayIndexHash(uint32_t value, int length); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 5564 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5565 | private: |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5566 | uint32_t array_index() { |
| 5567 | ASSERT(is_array_index()); |
| 5568 | return array_index_; |
| 5569 | } |
| 5570 | |
| 5571 | inline uint32_t GetHash(); |
| 5572 | |
| 5573 | int length_; |
| 5574 | uint32_t raw_running_hash_; |
| 5575 | uint32_t array_index_; |
| 5576 | bool is_array_index_; |
| 5577 | bool is_first_char_; |
| 5578 | bool is_valid_; |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 5579 | friend class TwoCharHashTableKey; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5580 | }; |
| 5581 | |
| 5582 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5583 | // Calculates string hash. |
| 5584 | template <typename schar> |
| 5585 | inline uint32_t HashSequentialString(const schar* chars, int length); |
| 5586 | |
| 5587 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 5588 | // The characteristics of a string are stored in its map. Retrieving these |
| 5589 | // few bits of information is moderately expensive, involving two memory |
| 5590 | // loads where the second is dependent on the first. To improve efficiency |
| 5591 | // the shape of the string is given its own class so that it can be retrieved |
| 5592 | // once and used for several string operations. A StringShape is small enough |
| 5593 | // 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] | 5594 | // string can potentially alter its shape. Also be aware that a GC caused by |
| 5595 | // 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] | 5596 | // shortcutting. Keeping these restrictions in mind has proven to be error- |
| 5597 | // prone and so we no longer put StringShapes in variables unless there is a |
| 5598 | // concrete performance benefit at that particular point in the code. |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 5599 | class StringShape BASE_EMBEDDED { |
| 5600 | public: |
| 5601 | inline explicit StringShape(String* s); |
| 5602 | inline explicit StringShape(Map* s); |
| 5603 | inline explicit StringShape(InstanceType t); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 5604 | inline bool IsSequential(); |
| 5605 | inline bool IsExternal(); |
| 5606 | inline bool IsCons(); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 5607 | inline bool IsExternalAscii(); |
| 5608 | inline bool IsExternalTwoByte(); |
| 5609 | inline bool IsSequentialAscii(); |
| 5610 | inline bool IsSequentialTwoByte(); |
| 5611 | inline bool IsSymbol(); |
| 5612 | inline StringRepresentationTag representation_tag(); |
| 5613 | inline uint32_t full_representation_tag(); |
| 5614 | inline uint32_t size_tag(); |
| 5615 | #ifdef DEBUG |
| 5616 | inline uint32_t type() { return type_; } |
| 5617 | inline void invalidate() { valid_ = false; } |
| 5618 | inline bool valid() { return valid_; } |
| 5619 | #else |
| 5620 | inline void invalidate() { } |
| 5621 | #endif |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 5622 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 5623 | private: |
| 5624 | uint32_t type_; |
| 5625 | #ifdef DEBUG |
| 5626 | inline void set_valid() { valid_ = true; } |
| 5627 | bool valid_; |
| 5628 | #else |
| 5629 | inline void set_valid() { } |
| 5630 | #endif |
| 5631 | }; |
| 5632 | |
| 5633 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5634 | // The String abstract class captures JavaScript string values: |
| 5635 | // |
| 5636 | // Ecma-262: |
| 5637 | // 4.3.16 String Value |
| 5638 | // A string value is a member of the type String and is a finite |
| 5639 | // ordered sequence of zero or more 16-bit unsigned integer values. |
| 5640 | // |
| 5641 | // All string values have a length field. |
| 5642 | class String: public HeapObject { |
| 5643 | public: |
| 5644 | // Get and set the length of the string. |
| 5645 | inline int length(); |
| 5646 | inline void set_length(int value); |
| 5647 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5648 | // Get and set the hash field of the string. |
| 5649 | inline uint32_t hash_field(); |
| 5650 | inline void set_hash_field(uint32_t value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5651 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 5652 | inline bool IsAsciiRepresentation(); |
| 5653 | inline bool IsTwoByteRepresentation(); |
| 5654 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 5655 | // Returns whether this string has ascii chars, i.e. all of them can |
| 5656 | // be ascii encoded. This might be the case even if the string is |
| 5657 | // two-byte. Such strings may appear when the embedder prefers |
| 5658 | // two-byte external representations even for ascii data. |
ricow@chromium.org | aa1b616 | 2010-03-29 07:44:58 +0000 | [diff] [blame] | 5659 | // |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 5660 | // NOTE: this should be considered only a hint. False negatives are |
| 5661 | // possible. |
| 5662 | inline bool HasOnlyAsciiChars(); |
ricow@chromium.org | aa1b616 | 2010-03-29 07:44:58 +0000 | [diff] [blame] | 5663 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5664 | // Get and set individual two byte chars in the string. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 5665 | inline void Set(int index, uint16_t value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5666 | // Get individual two byte char in the string. Repeated calls |
| 5667 | // to this method are not efficient unless the string is flat. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 5668 | inline uint16_t Get(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5669 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5670 | // Try to flatten the string. Checks first inline to see if it is |
| 5671 | // necessary. Does nothing if the string is not a cons string. |
| 5672 | // Flattening allocates a sequential string with the same data as |
| 5673 | // the given string and mutates the cons string to a degenerate |
| 5674 | // form, where the first component is the new sequential string and |
| 5675 | // the second component is the empty string. If allocation fails, |
| 5676 | // this function returns a failure. If flattening succeeds, this |
| 5677 | // function returns the sequential string that is now the first |
| 5678 | // component of the cons string. |
| 5679 | // |
| 5680 | // Degenerate cons strings are handled specially by the garbage |
| 5681 | // collector (see IsShortcutCandidate). |
| 5682 | // |
| 5683 | // Use FlattenString from Handles.cc to flatten even in case an |
| 5684 | // allocation failure happens. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5685 | inline MaybeObject* TryFlatten(PretenureFlag pretenure = NOT_TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5686 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5687 | // Convenience function. Has exactly the same behavior as |
| 5688 | // TryFlatten(), except in the case of failure returns the original |
| 5689 | // string. |
| 5690 | inline String* TryFlattenGetString(PretenureFlag pretenure = NOT_TENURED); |
| 5691 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5692 | Vector<const char> ToAsciiVector(); |
| 5693 | Vector<const uc16> ToUC16Vector(); |
| 5694 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5695 | // Mark the string as an undetectable object. It only applies to |
| 5696 | // ascii and two byte string types. |
| 5697 | bool MarkAsUndetectable(); |
| 5698 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 5699 | // Return a substring. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5700 | MUST_USE_RESULT MaybeObject* SubString(int from, |
| 5701 | int to, |
| 5702 | PretenureFlag pretenure = NOT_TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5703 | |
| 5704 | // String equality operations. |
| 5705 | inline bool Equals(String* other); |
| 5706 | bool IsEqualTo(Vector<const char> str); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 5707 | bool IsAsciiEqualTo(Vector<const char> str); |
| 5708 | bool IsTwoByteEqualTo(Vector<const uc16> str); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5709 | |
| 5710 | // Return a UTF8 representation of the string. The string is null |
| 5711 | // terminated but may optionally contain nulls. Length is returned |
| 5712 | // in length_output if length_output is not a null pointer The string |
| 5713 | // should be nearly flat, otherwise the performance of this method may |
| 5714 | // be very slow (quadratic in the length). Setting robustness_flag to |
| 5715 | // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
| 5716 | // handles unexpected data without causing assert failures and it does not |
| 5717 | // do any heap allocations. This is useful when printing stack traces. |
| 5718 | SmartPointer<char> ToCString(AllowNullsFlag allow_nulls, |
| 5719 | RobustnessFlag robustness_flag, |
| 5720 | int offset, |
| 5721 | int length, |
| 5722 | int* length_output = 0); |
| 5723 | SmartPointer<char> ToCString( |
| 5724 | AllowNullsFlag allow_nulls = DISALLOW_NULLS, |
| 5725 | RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL, |
| 5726 | int* length_output = 0); |
| 5727 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5728 | int Utf8Length(); |
| 5729 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5730 | // Return a 16 bit Unicode representation of the string. |
| 5731 | // The string should be nearly flat, otherwise the performance of |
| 5732 | // of this method may be very bad. Setting robustness_flag to |
| 5733 | // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
| 5734 | // handles unexpected data without causing assert failures and it does not |
| 5735 | // do any heap allocations. This is useful when printing stack traces. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 5736 | SmartPointer<uc16> ToWideCString( |
| 5737 | RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5738 | |
| 5739 | // Tells whether the hash code has been computed. |
| 5740 | inline bool HasHashCode(); |
| 5741 | |
| 5742 | // Returns a hash value used for the property table |
| 5743 | inline uint32_t Hash(); |
| 5744 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5745 | static uint32_t ComputeHashField(unibrow::CharacterStream* buffer, |
| 5746 | int length); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5747 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5748 | static bool ComputeArrayIndex(unibrow::CharacterStream* buffer, |
| 5749 | uint32_t* index, |
| 5750 | int length); |
| 5751 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 5752 | // Externalization. |
| 5753 | bool MakeExternal(v8::String::ExternalStringResource* resource); |
| 5754 | bool MakeExternal(v8::String::ExternalAsciiStringResource* resource); |
| 5755 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5756 | // Conversion. |
| 5757 | inline bool AsArrayIndex(uint32_t* index); |
| 5758 | |
| 5759 | // Casting. |
| 5760 | static inline String* cast(Object* obj); |
| 5761 | |
| 5762 | void PrintOn(FILE* out); |
| 5763 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5764 | // For use during stack traces. Performs rudimentary sanity check. |
| 5765 | bool LooksValid(); |
| 5766 | |
| 5767 | // Dispatched behavior. |
| 5768 | void StringShortPrint(StringStream* accumulator); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5769 | #ifdef OBJECT_PRINT |
| 5770 | inline void StringPrint() { |
| 5771 | StringPrint(stdout); |
| 5772 | } |
| 5773 | void StringPrint(FILE* out); |
| 5774 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5775 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5776 | void StringVerify(); |
| 5777 | #endif |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 5778 | inline bool IsFlat(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5779 | |
| 5780 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5781 | static const int kLengthOffset = HeapObject::kHeaderSize; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 5782 | static const int kHashFieldOffset = kLengthOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5783 | static const int kSize = kHashFieldOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5784 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 5785 | // Maximum number of characters to consider when trying to convert a string |
| 5786 | // value into an array index. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5787 | static const int kMaxArrayIndexSize = 10; |
| 5788 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5789 | // Max ascii char code. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5790 | static const int kMaxAsciiCharCode = unibrow::Utf8::kMaxOneByteChar; |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 5791 | static const unsigned kMaxAsciiCharCodeU = unibrow::Utf8::kMaxOneByteChar; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 5792 | static const int kMaxUC16CharCode = 0xffff; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5793 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 5794 | // Minimum length for a cons string. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5795 | static const int kMinNonFlatLength = 13; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5796 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5797 | // Mask constant for checking if a string has a computed hash code |
| 5798 | // and if it is an array index. The least significant bit indicates |
| 5799 | // whether a hash code has been computed. If the hash code has been |
| 5800 | // computed the 2nd bit tells whether the string can be used as an |
| 5801 | // array index. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5802 | static const int kHashNotComputedMask = 1; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5803 | static const int kIsNotArrayIndexMask = 1 << 1; |
| 5804 | static const int kNofHashBitFields = 2; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5805 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5806 | // Shift constant retrieving hash code from hash field. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5807 | static const int kHashShift = kNofHashBitFields; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5808 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5809 | // Array index strings this short can keep their index in the hash |
| 5810 | // field. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5811 | static const int kMaxCachedArrayIndexLength = 7; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5812 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5813 | // For strings which are array indexes the hash value has the string length |
| 5814 | // mixed into the hash, mainly to avoid a hash value of zero which would be |
| 5815 | // 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] | 5816 | static const int kArrayIndexValueBits = 24; |
| 5817 | static const int kArrayIndexLengthBits = |
| 5818 | kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields; |
| 5819 | |
| 5820 | STATIC_CHECK((kArrayIndexLengthBits > 0)); |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 5821 | STATIC_CHECK(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits)); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5822 | |
| 5823 | static const int kArrayIndexHashLengthShift = |
| 5824 | kArrayIndexValueBits + kNofHashBitFields; |
| 5825 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5826 | static const int kArrayIndexHashMask = (1 << kArrayIndexHashLengthShift) - 1; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5827 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5828 | static const int kArrayIndexValueMask = |
| 5829 | ((1 << kArrayIndexValueBits) - 1) << kHashShift; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 5830 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5831 | // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we |
| 5832 | // could use a mask to test if the length of string is less than or equal to |
| 5833 | // kMaxCachedArrayIndexLength. |
| 5834 | STATIC_CHECK(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1)); |
| 5835 | |
| 5836 | static const int kContainsCachedArrayIndexMask = |
| 5837 | (~kMaxCachedArrayIndexLength << kArrayIndexHashLengthShift) | |
| 5838 | kIsNotArrayIndexMask; |
| 5839 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5840 | // 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] | 5841 | static const int kEmptyHashField = |
| 5842 | kIsNotArrayIndexMask | kHashNotComputedMask; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5843 | |
| 5844 | // Value of hash field containing computed hash equal to zero. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5845 | static const int kZeroHash = kIsNotArrayIndexMask; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5846 | |
| 5847 | // Maximal string length. |
| 5848 | static const int kMaxLength = (1 << (32 - 2)) - 1; |
| 5849 | |
| 5850 | // Max length for computing hash. For strings longer than this limit the |
| 5851 | // string length is used as the hash value. |
| 5852 | static const int kMaxHashCalcLength = 16383; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5853 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 5854 | // Limit for truncation in short printing. |
| 5855 | static const int kMaxShortPrintLength = 1024; |
| 5856 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5857 | // Support for regular expressions. |
| 5858 | const uc16* GetTwoByteData(); |
| 5859 | const uc16* GetTwoByteData(unsigned start); |
| 5860 | |
| 5861 | // Support for StringInputBuffer |
| 5862 | static const unibrow::byte* ReadBlock(String* input, |
| 5863 | unibrow::byte* util_buffer, |
| 5864 | unsigned capacity, |
| 5865 | unsigned* remaining, |
| 5866 | unsigned* offset); |
| 5867 | static const unibrow::byte* ReadBlock(String** input, |
| 5868 | unibrow::byte* util_buffer, |
| 5869 | unsigned capacity, |
| 5870 | unsigned* remaining, |
| 5871 | unsigned* offset); |
| 5872 | |
| 5873 | // Helper function for flattening strings. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5874 | template <typename sinkchar> |
| 5875 | static void WriteToFlat(String* source, |
| 5876 | sinkchar* sink, |
| 5877 | int from, |
| 5878 | int to); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5879 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 5880 | static inline bool IsAscii(const char* chars, int length) { |
| 5881 | const char* limit = chars + length; |
| 5882 | #ifdef V8_HOST_CAN_READ_UNALIGNED |
| 5883 | ASSERT(kMaxAsciiCharCode == 0x7F); |
| 5884 | const uintptr_t non_ascii_mask = kUintptrAllBitsSet / 0xFF * 0x80; |
| 5885 | while (chars <= limit - sizeof(uintptr_t)) { |
| 5886 | if (*reinterpret_cast<const uintptr_t*>(chars) & non_ascii_mask) { |
| 5887 | return false; |
| 5888 | } |
| 5889 | chars += sizeof(uintptr_t); |
| 5890 | } |
| 5891 | #endif |
| 5892 | while (chars < limit) { |
| 5893 | if (static_cast<uint8_t>(*chars) > kMaxAsciiCharCodeU) return false; |
| 5894 | ++chars; |
| 5895 | } |
| 5896 | return true; |
| 5897 | } |
| 5898 | |
| 5899 | static inline bool IsAscii(const uc16* chars, int length) { |
| 5900 | const uc16* limit = chars + length; |
| 5901 | while (chars < limit) { |
| 5902 | if (*chars > kMaxAsciiCharCodeU) return false; |
| 5903 | ++chars; |
| 5904 | } |
| 5905 | return true; |
| 5906 | } |
| 5907 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5908 | protected: |
| 5909 | class ReadBlockBuffer { |
| 5910 | public: |
| 5911 | ReadBlockBuffer(unibrow::byte* util_buffer_, |
| 5912 | unsigned cursor_, |
| 5913 | unsigned capacity_, |
| 5914 | unsigned remaining_) : |
| 5915 | util_buffer(util_buffer_), |
| 5916 | cursor(cursor_), |
| 5917 | capacity(capacity_), |
| 5918 | remaining(remaining_) { |
| 5919 | } |
| 5920 | unibrow::byte* util_buffer; |
| 5921 | unsigned cursor; |
| 5922 | unsigned capacity; |
| 5923 | unsigned remaining; |
| 5924 | }; |
| 5925 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5926 | static inline const unibrow::byte* ReadBlock(String* input, |
| 5927 | ReadBlockBuffer* buffer, |
| 5928 | unsigned* offset, |
| 5929 | unsigned max_chars); |
| 5930 | static void ReadBlockIntoBuffer(String* input, |
| 5931 | ReadBlockBuffer* buffer, |
| 5932 | unsigned* offset_ptr, |
| 5933 | unsigned max_chars); |
| 5934 | |
| 5935 | private: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5936 | // Try to flatten the top level ConsString that is hiding behind this |
| 5937 | // string. This is a no-op unless the string is a ConsString. Flatten |
| 5938 | // mutates the ConsString and might return a failure. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5939 | MUST_USE_RESULT MaybeObject* SlowTryFlatten(PretenureFlag pretenure); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5940 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5941 | static inline bool IsHashFieldComputed(uint32_t field); |
| 5942 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5943 | // Slow case of String::Equals. This implementation works on any strings |
| 5944 | // but it is most efficient on strings that are almost flat. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 5945 | bool SlowEquals(String* other); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5946 | |
| 5947 | // Slow case of AsArrayIndex. |
| 5948 | bool SlowAsArrayIndex(uint32_t* index); |
| 5949 | |
| 5950 | // Compute and set the hash code. |
| 5951 | uint32_t ComputeAndSetHash(); |
| 5952 | |
| 5953 | DISALLOW_IMPLICIT_CONSTRUCTORS(String); |
| 5954 | }; |
| 5955 | |
| 5956 | |
| 5957 | // The SeqString abstract class captures sequential string values. |
| 5958 | class SeqString: public String { |
| 5959 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5960 | // Casting. |
| 5961 | static inline SeqString* cast(Object* obj); |
| 5962 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5963 | private: |
| 5964 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString); |
| 5965 | }; |
| 5966 | |
| 5967 | |
| 5968 | // The AsciiString class captures sequential ascii string objects. |
| 5969 | // Each character in the AsciiString is an ascii character. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5970 | class SeqAsciiString: public SeqString { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5971 | public: |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 5972 | static const bool kHasAsciiEncoding = true; |
| 5973 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5974 | // Dispatched behavior. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5975 | inline uint16_t SeqAsciiStringGet(int index); |
| 5976 | inline void SeqAsciiStringSet(int index, uint16_t value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5977 | |
| 5978 | // Get the address of the characters in this string. |
| 5979 | inline Address GetCharsAddress(); |
| 5980 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5981 | inline char* GetChars(); |
| 5982 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5983 | // Casting |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5984 | static inline SeqAsciiString* cast(Object* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5985 | |
| 5986 | // Garbage collection support. This method is called by the |
| 5987 | // garbage collector to compute the actual size of an AsciiString |
| 5988 | // instance. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 5989 | inline int SeqAsciiStringSize(InstanceType instance_type); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5990 | |
| 5991 | // Computes the size for an AsciiString instance of a given length. |
| 5992 | static int SizeFor(int length) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5993 | return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5994 | } |
| 5995 | |
| 5996 | // Layout description. |
| 5997 | static const int kHeaderSize = String::kSize; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5998 | static const int kAlignedSize = POINTER_SIZE_ALIGN(kHeaderSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5999 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 6000 | // Maximal memory usage for a single sequential ASCII string. |
| 6001 | static const int kMaxSize = 512 * MB; |
| 6002 | // Maximal length of a single sequential ASCII string. |
| 6003 | // Q.v. String::kMaxLength which is the maximal size of concatenated strings. |
| 6004 | static const int kMaxLength = (kMaxSize - kHeaderSize); |
| 6005 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6006 | // Support for StringInputBuffer. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6007 | inline void SeqAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 6008 | unsigned* offset, |
| 6009 | unsigned chars); |
| 6010 | inline const unibrow::byte* SeqAsciiStringReadBlock(unsigned* remaining, |
| 6011 | unsigned* offset, |
| 6012 | unsigned chars); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6013 | |
| 6014 | private: |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6015 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqAsciiString); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6016 | }; |
| 6017 | |
| 6018 | |
| 6019 | // The TwoByteString class captures sequential unicode string objects. |
| 6020 | // Each character in the TwoByteString is a two-byte uint16_t. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6021 | class SeqTwoByteString: public SeqString { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6022 | public: |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 6023 | static const bool kHasAsciiEncoding = false; |
| 6024 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6025 | // Dispatched behavior. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6026 | inline uint16_t SeqTwoByteStringGet(int index); |
| 6027 | inline void SeqTwoByteStringSet(int index, uint16_t value); |
| 6028 | |
| 6029 | // Get the address of the characters in this string. |
| 6030 | inline Address GetCharsAddress(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6031 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 6032 | inline uc16* GetChars(); |
| 6033 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6034 | // For regexp code. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6035 | const uint16_t* SeqTwoByteStringGetData(unsigned start); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6036 | |
| 6037 | // Casting |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6038 | static inline SeqTwoByteString* cast(Object* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6039 | |
| 6040 | // Garbage collection support. This method is called by the |
| 6041 | // garbage collector to compute the actual size of a TwoByteString |
| 6042 | // instance. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 6043 | inline int SeqTwoByteStringSize(InstanceType instance_type); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6044 | |
| 6045 | // Computes the size for a TwoByteString instance of a given length. |
| 6046 | static int SizeFor(int length) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6047 | return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6048 | } |
| 6049 | |
| 6050 | // Layout description. |
| 6051 | static const int kHeaderSize = String::kSize; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 6052 | static const int kAlignedSize = POINTER_SIZE_ALIGN(kHeaderSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6053 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 6054 | // Maximal memory usage for a single sequential two-byte string. |
| 6055 | static const int kMaxSize = 512 * MB; |
| 6056 | // Maximal length of a single sequential two-byte string. |
| 6057 | // Q.v. String::kMaxLength which is the maximal size of concatenated strings. |
| 6058 | static const int kMaxLength = (kMaxSize - kHeaderSize) / sizeof(uint16_t); |
| 6059 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6060 | // Support for StringInputBuffer. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6061 | inline void SeqTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 6062 | unsigned* offset_ptr, |
| 6063 | unsigned chars); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6064 | |
| 6065 | private: |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6066 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqTwoByteString); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6067 | }; |
| 6068 | |
| 6069 | |
| 6070 | // The ConsString class describes string values built by using the |
| 6071 | // addition operator on strings. A ConsString is a pair where the |
| 6072 | // first and second components are pointers to other string values. |
| 6073 | // One or both components of a ConsString can be pointers to other |
| 6074 | // ConsStrings, creating a binary tree of ConsStrings where the leaves |
| 6075 | // are non-ConsString string values. The string value represented by |
| 6076 | // a ConsString can be obtained by concatenating the leaf string |
| 6077 | // values in a left-to-right depth-first traversal of the tree. |
| 6078 | class ConsString: public String { |
| 6079 | public: |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 6080 | // First string of the cons cell. |
| 6081 | inline String* first(); |
| 6082 | // Doesn't check that the result is a string, even in debug mode. This is |
| 6083 | // useful during GC where the mark bits confuse the checks. |
| 6084 | inline Object* unchecked_first(); |
| 6085 | inline void set_first(String* first, |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6086 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6087 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 6088 | // Second string of the cons cell. |
| 6089 | inline String* second(); |
| 6090 | // Doesn't check that the result is a string, even in debug mode. This is |
| 6091 | // useful during GC where the mark bits confuse the checks. |
| 6092 | inline Object* unchecked_second(); |
| 6093 | inline void set_second(String* second, |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6094 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6095 | |
| 6096 | // Dispatched behavior. |
| 6097 | uint16_t ConsStringGet(int index); |
| 6098 | |
| 6099 | // Casting. |
| 6100 | static inline ConsString* cast(Object* obj); |
| 6101 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6102 | // Layout description. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 6103 | static const int kFirstOffset = POINTER_SIZE_ALIGN(String::kSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6104 | static const int kSecondOffset = kFirstOffset + kPointerSize; |
| 6105 | static const int kSize = kSecondOffset + kPointerSize; |
| 6106 | |
| 6107 | // Support for StringInputBuffer. |
| 6108 | inline const unibrow::byte* ConsStringReadBlock(ReadBlockBuffer* buffer, |
| 6109 | unsigned* offset_ptr, |
| 6110 | unsigned chars); |
| 6111 | inline void ConsStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 6112 | unsigned* offset_ptr, |
| 6113 | unsigned chars); |
| 6114 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 6115 | // Minimum length for a cons string. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6116 | static const int kMinLength = 13; |
| 6117 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 6118 | typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize> |
| 6119 | BodyDescriptor; |
| 6120 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6121 | private: |
| 6122 | DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString); |
| 6123 | }; |
| 6124 | |
| 6125 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6126 | // The ExternalString class describes string values that are backed by |
| 6127 | // a string resource that lies outside the V8 heap. ExternalStrings |
| 6128 | // consist of the length field common to all strings, a pointer to the |
| 6129 | // external resource. It is important to ensure (externally) that the |
| 6130 | // resource is not deallocated while the ExternalString is live in the |
| 6131 | // V8 heap. |
| 6132 | // |
| 6133 | // The API expects that all ExternalStrings are created through the |
| 6134 | // API. Therefore, ExternalStrings should not be used internally. |
| 6135 | class ExternalString: public String { |
| 6136 | public: |
| 6137 | // Casting |
| 6138 | static inline ExternalString* cast(Object* obj); |
| 6139 | |
| 6140 | // Layout description. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 6141 | static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6142 | static const int kSize = kResourceOffset + kPointerSize; |
| 6143 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 6144 | STATIC_CHECK(kResourceOffset == Internals::kStringResourceOffset); |
| 6145 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6146 | private: |
| 6147 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString); |
| 6148 | }; |
| 6149 | |
| 6150 | |
| 6151 | // The ExternalAsciiString class is an external string backed by an |
| 6152 | // ASCII string. |
| 6153 | class ExternalAsciiString: public ExternalString { |
| 6154 | public: |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 6155 | static const bool kHasAsciiEncoding = true; |
| 6156 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6157 | typedef v8::String::ExternalAsciiStringResource Resource; |
| 6158 | |
| 6159 | // The underlying resource. |
| 6160 | inline Resource* resource(); |
| 6161 | inline void set_resource(Resource* buffer); |
| 6162 | |
| 6163 | // Dispatched behavior. |
| 6164 | uint16_t ExternalAsciiStringGet(int index); |
| 6165 | |
| 6166 | // Casting. |
| 6167 | static inline ExternalAsciiString* cast(Object* obj); |
| 6168 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6169 | // Garbage collection support. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 6170 | inline void ExternalAsciiStringIterateBody(ObjectVisitor* v); |
| 6171 | |
| 6172 | template<typename StaticVisitor> |
| 6173 | inline void ExternalAsciiStringIterateBody(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6174 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6175 | // Support for StringInputBuffer. |
| 6176 | const unibrow::byte* ExternalAsciiStringReadBlock(unsigned* remaining, |
| 6177 | unsigned* offset, |
| 6178 | unsigned chars); |
| 6179 | inline void ExternalAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 6180 | unsigned* offset, |
| 6181 | unsigned chars); |
| 6182 | |
| 6183 | private: |
| 6184 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalAsciiString); |
| 6185 | }; |
| 6186 | |
| 6187 | |
| 6188 | // The ExternalTwoByteString class is an external string backed by a UTF-16 |
| 6189 | // encoded string. |
| 6190 | class ExternalTwoByteString: public ExternalString { |
| 6191 | public: |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 6192 | static const bool kHasAsciiEncoding = false; |
| 6193 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6194 | typedef v8::String::ExternalStringResource Resource; |
| 6195 | |
| 6196 | // The underlying string resource. |
| 6197 | inline Resource* resource(); |
| 6198 | inline void set_resource(Resource* buffer); |
| 6199 | |
| 6200 | // Dispatched behavior. |
| 6201 | uint16_t ExternalTwoByteStringGet(int index); |
| 6202 | |
| 6203 | // For regexp code. |
| 6204 | const uint16_t* ExternalTwoByteStringGetData(unsigned start); |
| 6205 | |
| 6206 | // Casting. |
| 6207 | static inline ExternalTwoByteString* cast(Object* obj); |
| 6208 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6209 | // Garbage collection support. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 6210 | inline void ExternalTwoByteStringIterateBody(ObjectVisitor* v); |
| 6211 | |
| 6212 | template<typename StaticVisitor> |
| 6213 | inline void ExternalTwoByteStringIterateBody(); |
| 6214 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6215 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6216 | // Support for StringInputBuffer. |
| 6217 | void ExternalTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 6218 | unsigned* offset_ptr, |
| 6219 | unsigned chars); |
| 6220 | |
| 6221 | private: |
| 6222 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalTwoByteString); |
| 6223 | }; |
| 6224 | |
| 6225 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6226 | // Utility superclass for stack-allocated objects that must be updated |
| 6227 | // on gc. It provides two ways for the gc to update instances, either |
| 6228 | // iterating or updating after gc. |
| 6229 | class Relocatable BASE_EMBEDDED { |
| 6230 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6231 | explicit inline Relocatable(Isolate* isolate); |
| 6232 | inline virtual ~Relocatable(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6233 | virtual void IterateInstance(ObjectVisitor* v) { } |
| 6234 | virtual void PostGarbageCollection() { } |
| 6235 | |
| 6236 | static void PostGarbageCollectionProcessing(); |
| 6237 | static int ArchiveSpacePerThread(); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6238 | static char* ArchiveState(Isolate* isolate, char* to); |
| 6239 | static char* RestoreState(Isolate* isolate, char* from); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6240 | static void Iterate(ObjectVisitor* v); |
| 6241 | static void Iterate(ObjectVisitor* v, Relocatable* top); |
| 6242 | static char* Iterate(ObjectVisitor* v, char* t); |
| 6243 | private: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6244 | Isolate* isolate_; |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6245 | Relocatable* prev_; |
| 6246 | }; |
| 6247 | |
| 6248 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 6249 | // A flat string reader provides random access to the contents of a |
| 6250 | // string independent of the character width of the string. The handle |
| 6251 | // must be valid as long as the reader is being used. |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6252 | class FlatStringReader : public Relocatable { |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 6253 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6254 | FlatStringReader(Isolate* isolate, Handle<String> str); |
| 6255 | FlatStringReader(Isolate* isolate, Vector<const char> input); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6256 | void PostGarbageCollection(); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 6257 | inline uc32 Get(int index); |
| 6258 | int length() { return length_; } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 6259 | private: |
| 6260 | String** str_; |
| 6261 | bool is_ascii_; |
| 6262 | int length_; |
| 6263 | const void* start_; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 6264 | }; |
| 6265 | |
| 6266 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6267 | // Note that StringInputBuffers are not valid across a GC! To fix this |
| 6268 | // it would have to store a String Handle instead of a String* and |
| 6269 | // AsciiStringReadBlock would have to be modified to use memcpy. |
| 6270 | // |
| 6271 | // StringInputBuffer is able to traverse any string regardless of how |
| 6272 | // deeply nested a sequence of ConsStrings it is made of. However, |
| 6273 | // performance will be better if deep strings are flattened before they |
| 6274 | // are traversed. Since flattening requires memory allocation this is |
| 6275 | // not always desirable, however (esp. in debugging situations). |
| 6276 | class StringInputBuffer: public unibrow::InputBuffer<String, String*, 1024> { |
| 6277 | public: |
| 6278 | virtual void Seek(unsigned pos); |
| 6279 | inline StringInputBuffer(): unibrow::InputBuffer<String, String*, 1024>() {} |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 6280 | explicit inline StringInputBuffer(String* backing): |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6281 | unibrow::InputBuffer<String, String*, 1024>(backing) {} |
| 6282 | }; |
| 6283 | |
| 6284 | |
| 6285 | class SafeStringInputBuffer |
| 6286 | : public unibrow::InputBuffer<String, String**, 256> { |
| 6287 | public: |
| 6288 | virtual void Seek(unsigned pos); |
| 6289 | inline SafeStringInputBuffer() |
| 6290 | : unibrow::InputBuffer<String, String**, 256>() {} |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 6291 | explicit inline SafeStringInputBuffer(String** backing) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6292 | : unibrow::InputBuffer<String, String**, 256>(backing) {} |
| 6293 | }; |
| 6294 | |
| 6295 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6296 | template <typename T> |
| 6297 | class VectorIterator { |
| 6298 | public: |
| 6299 | VectorIterator(T* d, int l) : data_(Vector<const T>(d, l)), index_(0) { } |
| 6300 | explicit VectorIterator(Vector<const T> data) : data_(data), index_(0) { } |
| 6301 | T GetNext() { return data_[index_++]; } |
| 6302 | bool has_more() { return index_ < data_.length(); } |
| 6303 | private: |
| 6304 | Vector<const T> data_; |
| 6305 | int index_; |
| 6306 | }; |
| 6307 | |
| 6308 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6309 | // The Oddball describes objects null, undefined, true, and false. |
| 6310 | class Oddball: public HeapObject { |
| 6311 | public: |
| 6312 | // [to_string]: Cached to_string computed at startup. |
| 6313 | DECL_ACCESSORS(to_string, String) |
| 6314 | |
| 6315 | // [to_number]: Cached to_number computed at startup. |
| 6316 | DECL_ACCESSORS(to_number, Object) |
| 6317 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6318 | inline byte kind(); |
| 6319 | inline void set_kind(byte kind); |
| 6320 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6321 | // Casting. |
| 6322 | static inline Oddball* cast(Object* obj); |
| 6323 | |
| 6324 | // Dispatched behavior. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6325 | #ifdef DEBUG |
| 6326 | void OddballVerify(); |
| 6327 | #endif |
| 6328 | |
| 6329 | // Initialize the fields. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 6330 | MUST_USE_RESULT MaybeObject* Initialize(const char* to_string, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6331 | Object* to_number, |
| 6332 | byte kind); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6333 | |
| 6334 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6335 | static const int kToStringOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6336 | static const int kToNumberOffset = kToStringOffset + kPointerSize; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6337 | static const int kKindOffset = kToNumberOffset + kPointerSize; |
| 6338 | static const int kSize = kKindOffset + kPointerSize; |
| 6339 | |
| 6340 | static const byte kFalse = 0; |
| 6341 | static const byte kTrue = 1; |
| 6342 | static const byte kNotBooleanMask = ~1; |
| 6343 | static const byte kTheHole = 2; |
| 6344 | static const byte kNull = 3; |
| 6345 | static const byte kArgumentMarker = 4; |
| 6346 | static const byte kUndefined = 5; |
| 6347 | static const byte kOther = 6; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6348 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 6349 | typedef FixedBodyDescriptor<kToStringOffset, |
| 6350 | kToNumberOffset + kPointerSize, |
| 6351 | kSize> BodyDescriptor; |
| 6352 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6353 | private: |
| 6354 | DISALLOW_IMPLICIT_CONSTRUCTORS(Oddball); |
| 6355 | }; |
| 6356 | |
| 6357 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6358 | class JSGlobalPropertyCell: public HeapObject { |
| 6359 | public: |
| 6360 | // [value]: value of the global property. |
| 6361 | DECL_ACCESSORS(value, Object) |
| 6362 | |
| 6363 | // Casting. |
| 6364 | static inline JSGlobalPropertyCell* cast(Object* obj); |
| 6365 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6366 | #ifdef DEBUG |
| 6367 | void JSGlobalPropertyCellVerify(); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6368 | #endif |
| 6369 | #ifdef OBJECT_PRINT |
| 6370 | inline void JSGlobalPropertyCellPrint() { |
| 6371 | JSGlobalPropertyCellPrint(stdout); |
| 6372 | } |
| 6373 | void JSGlobalPropertyCellPrint(FILE* out); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6374 | #endif |
| 6375 | |
| 6376 | // Layout description. |
| 6377 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 6378 | static const int kSize = kValueOffset + kPointerSize; |
| 6379 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 6380 | typedef FixedBodyDescriptor<kValueOffset, |
| 6381 | kValueOffset + kPointerSize, |
| 6382 | kSize> BodyDescriptor; |
| 6383 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 6384 | // Returns the isolate/heap this cell object belongs to. |
| 6385 | inline Isolate* isolate(); |
| 6386 | inline Heap* heap(); |
| 6387 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6388 | private: |
| 6389 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalPropertyCell); |
| 6390 | }; |
| 6391 | |
| 6392 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6393 | // The JSProxy describes EcmaScript Harmony proxies |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 6394 | class JSProxy: public JSReceiver { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6395 | public: |
| 6396 | // [handler]: The handler property. |
| 6397 | DECL_ACCESSORS(handler, Object) |
| 6398 | |
| 6399 | // Casting. |
| 6400 | static inline JSProxy* cast(Object* obj); |
| 6401 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 6402 | MUST_USE_RESULT MaybeObject* SetPropertyWithHandler( |
| 6403 | String* name_raw, |
| 6404 | Object* value_raw, |
| 6405 | PropertyAttributes attributes, |
| 6406 | StrictModeFlag strict_mode); |
| 6407 | |
| 6408 | MUST_USE_RESULT PropertyAttributes GetPropertyAttributeWithHandler( |
| 6409 | JSReceiver* receiver, |
| 6410 | String* name_raw, |
| 6411 | bool* has_exception); |
| 6412 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6413 | // Dispatched behavior. |
| 6414 | #ifdef OBJECT_PRINT |
| 6415 | inline void JSProxyPrint() { |
| 6416 | JSProxyPrint(stdout); |
| 6417 | } |
| 6418 | void JSProxyPrint(FILE* out); |
| 6419 | #endif |
| 6420 | #ifdef DEBUG |
| 6421 | void JSProxyVerify(); |
| 6422 | #endif |
| 6423 | |
| 6424 | // Layout description. |
| 6425 | static const int kHandlerOffset = HeapObject::kHeaderSize; |
| 6426 | static const int kSize = kHandlerOffset + kPointerSize; |
| 6427 | |
| 6428 | typedef FixedBodyDescriptor<kHandlerOffset, |
| 6429 | kHandlerOffset + kPointerSize, |
| 6430 | kSize> BodyDescriptor; |
| 6431 | |
| 6432 | private: |
| 6433 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxy); |
| 6434 | }; |
| 6435 | |
| 6436 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 6437 | // TODO(rossberg): Only a stub for now. |
| 6438 | class JSFunctionProxy: public JSProxy { |
| 6439 | public: |
| 6440 | // Casting. |
| 6441 | static inline JSFunctionProxy* cast(Object* obj); |
| 6442 | |
| 6443 | private: |
| 6444 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunctionProxy); |
| 6445 | }; |
| 6446 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6447 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6448 | // Foreign describes objects pointing from JavaScript to C structures. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 6449 | // Since they cannot contain references to JS HeapObjects they can be |
| 6450 | // placed in old_data_space. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6451 | class Foreign: public HeapObject { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6452 | public: |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6453 | // [address]: field containing the address. |
| 6454 | inline Address address(); |
| 6455 | inline void set_address(Address value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6456 | |
| 6457 | // Casting. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6458 | static inline Foreign* cast(Object* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6459 | |
| 6460 | // Dispatched behavior. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6461 | inline void ForeignIterateBody(ObjectVisitor* v); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 6462 | |
| 6463 | template<typename StaticVisitor> |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6464 | inline void ForeignIterateBody(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 6465 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6466 | #ifdef OBJECT_PRINT |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6467 | inline void ForeignPrint() { |
| 6468 | ForeignPrint(stdout); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6469 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6470 | void ForeignPrint(FILE* out); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6471 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6472 | #ifdef DEBUG |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6473 | void ForeignVerify(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6474 | #endif |
| 6475 | |
| 6476 | // Layout description. |
| 6477 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6478 | static const int kAddressOffset = HeapObject::kHeaderSize; |
| 6479 | static const int kSize = kAddressOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6480 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6481 | STATIC_CHECK(kAddressOffset == Internals::kForeignAddressOffset); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 6482 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6483 | private: |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6484 | DISALLOW_IMPLICIT_CONSTRUCTORS(Foreign); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6485 | }; |
| 6486 | |
| 6487 | |
| 6488 | // The JSArray describes JavaScript Arrays |
| 6489 | // Such an array can be in one of two modes: |
| 6490 | // - fast, backing storage is a FixedArray and length <= elements.length(); |
| 6491 | // Please note: push and pop can be used to grow and shrink the array. |
| 6492 | // - slow, backing storage is a HashTable with numbers as keys. |
| 6493 | class JSArray: public JSObject { |
| 6494 | public: |
| 6495 | // [length]: The length property. |
| 6496 | DECL_ACCESSORS(length, Object) |
| 6497 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 6498 | // Overload the length setter to skip write barrier when the length |
| 6499 | // is set to a smi. This matches the set function on FixedArray. |
| 6500 | inline void set_length(Smi* length); |
| 6501 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 6502 | MUST_USE_RESULT MaybeObject* JSArrayUpdateLengthFromIndex(uint32_t index, |
| 6503 | Object* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6504 | |
| 6505 | // Initialize the array with the given capacity. The function may |
| 6506 | // fail due to out-of-memory situations, but only if the requested |
| 6507 | // capacity is non-zero. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 6508 | MUST_USE_RESULT MaybeObject* Initialize(int capacity); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6509 | |
| 6510 | // Set the content of the array to the content of storage. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6511 | inline void SetContent(FixedArray* storage); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6512 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6513 | // Casting. |
| 6514 | static inline JSArray* cast(Object* obj); |
| 6515 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6516 | // Uses handles. Ensures that the fixed array backing the JSArray has at |
| 6517 | // least the stated size. |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 6518 | inline void EnsureSize(int minimum_size_of_backing_fixed_array); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6519 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6520 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6521 | #ifdef OBJECT_PRINT |
| 6522 | inline void JSArrayPrint() { |
| 6523 | JSArrayPrint(stdout); |
| 6524 | } |
| 6525 | void JSArrayPrint(FILE* out); |
| 6526 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6527 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6528 | void JSArrayVerify(); |
| 6529 | #endif |
| 6530 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6531 | // Number of element slots to pre-allocate for an empty array. |
| 6532 | static const int kPreallocatedArrayElements = 4; |
| 6533 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6534 | // Layout description. |
| 6535 | static const int kLengthOffset = JSObject::kHeaderSize; |
| 6536 | static const int kSize = kLengthOffset + kPointerSize; |
| 6537 | |
| 6538 | private: |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 6539 | // Expand the fixed array backing of a fast-case JSArray to at least |
| 6540 | // the requested size. |
| 6541 | void Expand(int minimum_size_of_backing_fixed_array); |
| 6542 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6543 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSArray); |
| 6544 | }; |
| 6545 | |
| 6546 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 6547 | // JSRegExpResult is just a JSArray with a specific initial map. |
| 6548 | // This initial map adds in-object properties for "index" and "input" |
| 6549 | // properties, as assigned by RegExp.prototype.exec, which allows |
| 6550 | // faster creation of RegExp exec results. |
| 6551 | // This class just holds constants used when creating the result. |
| 6552 | // After creation the result must be treated as a JSArray in all regards. |
| 6553 | class JSRegExpResult: public JSArray { |
| 6554 | public: |
| 6555 | // Offsets of object fields. |
| 6556 | static const int kIndexOffset = JSArray::kSize; |
| 6557 | static const int kInputOffset = kIndexOffset + kPointerSize; |
| 6558 | static const int kSize = kInputOffset + kPointerSize; |
| 6559 | // Indices of in-object properties. |
| 6560 | static const int kIndexIndex = 0; |
| 6561 | static const int kInputIndex = 1; |
| 6562 | private: |
| 6563 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSRegExpResult); |
| 6564 | }; |
| 6565 | |
| 6566 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 6567 | // An accessor must have a getter, but can have no setter. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6568 | // |
| 6569 | // When setting a property, V8 searches accessors in prototypes. |
| 6570 | // If an accessor was found and it does not have a setter, |
| 6571 | // the request is ignored. |
| 6572 | // |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 6573 | // If the accessor in the prototype has the READ_ONLY property attribute, then |
| 6574 | // a new value is added to the local object when the property is set. |
| 6575 | // This shadows the accessor in the prototype. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6576 | class AccessorInfo: public Struct { |
| 6577 | public: |
| 6578 | DECL_ACCESSORS(getter, Object) |
| 6579 | DECL_ACCESSORS(setter, Object) |
| 6580 | DECL_ACCESSORS(data, Object) |
| 6581 | DECL_ACCESSORS(name, Object) |
| 6582 | DECL_ACCESSORS(flag, Smi) |
| 6583 | |
| 6584 | inline bool all_can_read(); |
| 6585 | inline void set_all_can_read(bool value); |
| 6586 | |
| 6587 | inline bool all_can_write(); |
| 6588 | inline void set_all_can_write(bool value); |
| 6589 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 6590 | inline bool prohibits_overwriting(); |
| 6591 | inline void set_prohibits_overwriting(bool value); |
| 6592 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6593 | inline PropertyAttributes property_attributes(); |
| 6594 | inline void set_property_attributes(PropertyAttributes attributes); |
| 6595 | |
| 6596 | static inline AccessorInfo* cast(Object* obj); |
| 6597 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6598 | #ifdef OBJECT_PRINT |
| 6599 | inline void AccessorInfoPrint() { |
| 6600 | AccessorInfoPrint(stdout); |
| 6601 | } |
| 6602 | void AccessorInfoPrint(FILE* out); |
| 6603 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6604 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6605 | void AccessorInfoVerify(); |
| 6606 | #endif |
| 6607 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6608 | static const int kGetterOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6609 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 6610 | static const int kDataOffset = kSetterOffset + kPointerSize; |
| 6611 | static const int kNameOffset = kDataOffset + kPointerSize; |
| 6612 | static const int kFlagOffset = kNameOffset + kPointerSize; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 6613 | static const int kSize = kFlagOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6614 | |
| 6615 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6616 | // Bit positions in flag. |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 6617 | static const int kAllCanReadBit = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6618 | static const int kAllCanWriteBit = 1; |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 6619 | static const int kProhibitsOverwritingBit = 2; |
| 6620 | class AttributesField: public BitField<PropertyAttributes, 3, 3> {}; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 6621 | |
| 6622 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorInfo); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6623 | }; |
| 6624 | |
| 6625 | |
| 6626 | class AccessCheckInfo: public Struct { |
| 6627 | public: |
| 6628 | DECL_ACCESSORS(named_callback, Object) |
| 6629 | DECL_ACCESSORS(indexed_callback, Object) |
| 6630 | DECL_ACCESSORS(data, Object) |
| 6631 | |
| 6632 | static inline AccessCheckInfo* cast(Object* obj); |
| 6633 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6634 | #ifdef OBJECT_PRINT |
| 6635 | inline void AccessCheckInfoPrint() { |
| 6636 | AccessCheckInfoPrint(stdout); |
| 6637 | } |
| 6638 | void AccessCheckInfoPrint(FILE* out); |
| 6639 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6640 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6641 | void AccessCheckInfoVerify(); |
| 6642 | #endif |
| 6643 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6644 | static const int kNamedCallbackOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6645 | static const int kIndexedCallbackOffset = kNamedCallbackOffset + kPointerSize; |
| 6646 | static const int kDataOffset = kIndexedCallbackOffset + kPointerSize; |
| 6647 | static const int kSize = kDataOffset + kPointerSize; |
| 6648 | |
| 6649 | private: |
| 6650 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessCheckInfo); |
| 6651 | }; |
| 6652 | |
| 6653 | |
| 6654 | class InterceptorInfo: public Struct { |
| 6655 | public: |
| 6656 | DECL_ACCESSORS(getter, Object) |
| 6657 | DECL_ACCESSORS(setter, Object) |
| 6658 | DECL_ACCESSORS(query, Object) |
| 6659 | DECL_ACCESSORS(deleter, Object) |
| 6660 | DECL_ACCESSORS(enumerator, Object) |
| 6661 | DECL_ACCESSORS(data, Object) |
| 6662 | |
| 6663 | static inline InterceptorInfo* cast(Object* obj); |
| 6664 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6665 | #ifdef OBJECT_PRINT |
| 6666 | inline void InterceptorInfoPrint() { |
| 6667 | InterceptorInfoPrint(stdout); |
| 6668 | } |
| 6669 | void InterceptorInfoPrint(FILE* out); |
| 6670 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6671 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6672 | void InterceptorInfoVerify(); |
| 6673 | #endif |
| 6674 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6675 | static const int kGetterOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6676 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 6677 | static const int kQueryOffset = kSetterOffset + kPointerSize; |
| 6678 | static const int kDeleterOffset = kQueryOffset + kPointerSize; |
| 6679 | static const int kEnumeratorOffset = kDeleterOffset + kPointerSize; |
| 6680 | static const int kDataOffset = kEnumeratorOffset + kPointerSize; |
| 6681 | static const int kSize = kDataOffset + kPointerSize; |
| 6682 | |
| 6683 | private: |
| 6684 | DISALLOW_IMPLICIT_CONSTRUCTORS(InterceptorInfo); |
| 6685 | }; |
| 6686 | |
| 6687 | |
| 6688 | class CallHandlerInfo: public Struct { |
| 6689 | public: |
| 6690 | DECL_ACCESSORS(callback, Object) |
| 6691 | DECL_ACCESSORS(data, Object) |
| 6692 | |
| 6693 | static inline CallHandlerInfo* cast(Object* obj); |
| 6694 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6695 | #ifdef OBJECT_PRINT |
| 6696 | inline void CallHandlerInfoPrint() { |
| 6697 | CallHandlerInfoPrint(stdout); |
| 6698 | } |
| 6699 | void CallHandlerInfoPrint(FILE* out); |
| 6700 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6701 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6702 | void CallHandlerInfoVerify(); |
| 6703 | #endif |
| 6704 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6705 | static const int kCallbackOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6706 | static const int kDataOffset = kCallbackOffset + kPointerSize; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 6707 | static const int kSize = kDataOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6708 | |
| 6709 | private: |
| 6710 | DISALLOW_IMPLICIT_CONSTRUCTORS(CallHandlerInfo); |
| 6711 | }; |
| 6712 | |
| 6713 | |
| 6714 | class TemplateInfo: public Struct { |
| 6715 | public: |
| 6716 | DECL_ACCESSORS(tag, Object) |
| 6717 | DECL_ACCESSORS(property_list, Object) |
| 6718 | |
| 6719 | #ifdef DEBUG |
| 6720 | void TemplateInfoVerify(); |
| 6721 | #endif |
| 6722 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6723 | static const int kTagOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6724 | static const int kPropertyListOffset = kTagOffset + kPointerSize; |
| 6725 | static const int kHeaderSize = kPropertyListOffset + kPointerSize; |
| 6726 | protected: |
| 6727 | friend class AGCCVersionRequiresThisClassToHaveAFriendSoHereItIs; |
| 6728 | DISALLOW_IMPLICIT_CONSTRUCTORS(TemplateInfo); |
| 6729 | }; |
| 6730 | |
| 6731 | |
| 6732 | class FunctionTemplateInfo: public TemplateInfo { |
| 6733 | public: |
| 6734 | DECL_ACCESSORS(serial_number, Object) |
| 6735 | DECL_ACCESSORS(call_code, Object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6736 | DECL_ACCESSORS(property_accessors, Object) |
| 6737 | DECL_ACCESSORS(prototype_template, Object) |
| 6738 | DECL_ACCESSORS(parent_template, Object) |
| 6739 | DECL_ACCESSORS(named_property_handler, Object) |
| 6740 | DECL_ACCESSORS(indexed_property_handler, Object) |
| 6741 | DECL_ACCESSORS(instance_template, Object) |
| 6742 | DECL_ACCESSORS(class_name, Object) |
| 6743 | DECL_ACCESSORS(signature, Object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6744 | DECL_ACCESSORS(instance_call_handler, Object) |
| 6745 | DECL_ACCESSORS(access_check_info, Object) |
| 6746 | DECL_ACCESSORS(flag, Smi) |
| 6747 | |
| 6748 | // Following properties use flag bits. |
| 6749 | DECL_BOOLEAN_ACCESSORS(hidden_prototype) |
| 6750 | DECL_BOOLEAN_ACCESSORS(undetectable) |
| 6751 | // If the bit is set, object instances created by this function |
| 6752 | // requires access check. |
| 6753 | DECL_BOOLEAN_ACCESSORS(needs_access_check) |
| 6754 | |
| 6755 | static inline FunctionTemplateInfo* cast(Object* obj); |
| 6756 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6757 | #ifdef OBJECT_PRINT |
| 6758 | inline void FunctionTemplateInfoPrint() { |
| 6759 | FunctionTemplateInfoPrint(stdout); |
| 6760 | } |
| 6761 | void FunctionTemplateInfoPrint(FILE* out); |
| 6762 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6763 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6764 | void FunctionTemplateInfoVerify(); |
| 6765 | #endif |
| 6766 | |
| 6767 | static const int kSerialNumberOffset = TemplateInfo::kHeaderSize; |
| 6768 | static const int kCallCodeOffset = kSerialNumberOffset + kPointerSize; |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 6769 | static const int kPropertyAccessorsOffset = kCallCodeOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6770 | static const int kPrototypeTemplateOffset = |
| 6771 | kPropertyAccessorsOffset + kPointerSize; |
| 6772 | static const int kParentTemplateOffset = |
| 6773 | kPrototypeTemplateOffset + kPointerSize; |
| 6774 | static const int kNamedPropertyHandlerOffset = |
| 6775 | kParentTemplateOffset + kPointerSize; |
| 6776 | static const int kIndexedPropertyHandlerOffset = |
| 6777 | kNamedPropertyHandlerOffset + kPointerSize; |
| 6778 | static const int kInstanceTemplateOffset = |
| 6779 | kIndexedPropertyHandlerOffset + kPointerSize; |
| 6780 | static const int kClassNameOffset = kInstanceTemplateOffset + kPointerSize; |
| 6781 | static const int kSignatureOffset = kClassNameOffset + kPointerSize; |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 6782 | static const int kInstanceCallHandlerOffset = kSignatureOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6783 | static const int kAccessCheckInfoOffset = |
| 6784 | kInstanceCallHandlerOffset + kPointerSize; |
| 6785 | static const int kFlagOffset = kAccessCheckInfoOffset + kPointerSize; |
| 6786 | static const int kSize = kFlagOffset + kPointerSize; |
| 6787 | |
| 6788 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6789 | // Bit position in the flag, from least significant bit position. |
| 6790 | static const int kHiddenPrototypeBit = 0; |
| 6791 | static const int kUndetectableBit = 1; |
| 6792 | static const int kNeedsAccessCheckBit = 2; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 6793 | |
| 6794 | DISALLOW_IMPLICIT_CONSTRUCTORS(FunctionTemplateInfo); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6795 | }; |
| 6796 | |
| 6797 | |
| 6798 | class ObjectTemplateInfo: public TemplateInfo { |
| 6799 | public: |
| 6800 | DECL_ACCESSORS(constructor, Object) |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 6801 | DECL_ACCESSORS(internal_field_count, Object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6802 | |
| 6803 | static inline ObjectTemplateInfo* cast(Object* obj); |
| 6804 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6805 | #ifdef OBJECT_PRINT |
| 6806 | inline void ObjectTemplateInfoPrint() { |
| 6807 | ObjectTemplateInfoPrint(stdout); |
| 6808 | } |
| 6809 | void ObjectTemplateInfoPrint(FILE* out); |
| 6810 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6811 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6812 | void ObjectTemplateInfoVerify(); |
| 6813 | #endif |
| 6814 | |
| 6815 | static const int kConstructorOffset = TemplateInfo::kHeaderSize; |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 6816 | static const int kInternalFieldCountOffset = |
| 6817 | kConstructorOffset + kPointerSize; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 6818 | static const int kSize = kInternalFieldCountOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6819 | }; |
| 6820 | |
| 6821 | |
| 6822 | class SignatureInfo: public Struct { |
| 6823 | public: |
| 6824 | DECL_ACCESSORS(receiver, Object) |
| 6825 | DECL_ACCESSORS(args, Object) |
| 6826 | |
| 6827 | static inline SignatureInfo* cast(Object* obj); |
| 6828 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6829 | #ifdef OBJECT_PRINT |
| 6830 | inline void SignatureInfoPrint() { |
| 6831 | SignatureInfoPrint(stdout); |
| 6832 | } |
| 6833 | void SignatureInfoPrint(FILE* out); |
| 6834 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6835 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6836 | void SignatureInfoVerify(); |
| 6837 | #endif |
| 6838 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6839 | static const int kReceiverOffset = Struct::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6840 | static const int kArgsOffset = kReceiverOffset + kPointerSize; |
| 6841 | static const int kSize = kArgsOffset + kPointerSize; |
| 6842 | |
| 6843 | private: |
| 6844 | DISALLOW_IMPLICIT_CONSTRUCTORS(SignatureInfo); |
| 6845 | }; |
| 6846 | |
| 6847 | |
| 6848 | class TypeSwitchInfo: public Struct { |
| 6849 | public: |
| 6850 | DECL_ACCESSORS(types, Object) |
| 6851 | |
| 6852 | static inline TypeSwitchInfo* cast(Object* obj); |
| 6853 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6854 | #ifdef OBJECT_PRINT |
| 6855 | inline void TypeSwitchInfoPrint() { |
| 6856 | TypeSwitchInfoPrint(stdout); |
| 6857 | } |
| 6858 | void TypeSwitchInfoPrint(FILE* out); |
| 6859 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6860 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6861 | void TypeSwitchInfoVerify(); |
| 6862 | #endif |
| 6863 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6864 | static const int kTypesOffset = Struct::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6865 | static const int kSize = kTypesOffset + kPointerSize; |
| 6866 | }; |
| 6867 | |
| 6868 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 6869 | #ifdef ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 6870 | // The DebugInfo class holds additional information for a function being |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6871 | // debugged. |
| 6872 | class DebugInfo: public Struct { |
| 6873 | public: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 6874 | // The shared function info for the source being debugged. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6875 | DECL_ACCESSORS(shared, SharedFunctionInfo) |
| 6876 | // Code object for the original code. |
| 6877 | DECL_ACCESSORS(original_code, Code) |
| 6878 | // Code object for the patched code. This code object is the code object |
| 6879 | // currently active for the function. |
| 6880 | DECL_ACCESSORS(code, Code) |
| 6881 | // Fixed array holding status information for each active break point. |
| 6882 | DECL_ACCESSORS(break_points, FixedArray) |
| 6883 | |
| 6884 | // Check if there is a break point at a code position. |
| 6885 | bool HasBreakPoint(int code_position); |
| 6886 | // Get the break point info object for a code position. |
| 6887 | Object* GetBreakPointInfo(int code_position); |
| 6888 | // Clear a break point. |
| 6889 | static void ClearBreakPoint(Handle<DebugInfo> debug_info, |
| 6890 | int code_position, |
| 6891 | Handle<Object> break_point_object); |
| 6892 | // Set a break point. |
| 6893 | static void SetBreakPoint(Handle<DebugInfo> debug_info, int code_position, |
| 6894 | int source_position, int statement_position, |
| 6895 | Handle<Object> break_point_object); |
| 6896 | // Get the break point objects for a code position. |
| 6897 | Object* GetBreakPointObjects(int code_position); |
| 6898 | // Find the break point info holding this break point object. |
| 6899 | static Object* FindBreakPointInfo(Handle<DebugInfo> debug_info, |
| 6900 | Handle<Object> break_point_object); |
| 6901 | // Get the number of break points for this function. |
| 6902 | int GetBreakPointCount(); |
| 6903 | |
| 6904 | static inline DebugInfo* cast(Object* obj); |
| 6905 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6906 | #ifdef OBJECT_PRINT |
| 6907 | inline void DebugInfoPrint() { |
| 6908 | DebugInfoPrint(stdout); |
| 6909 | } |
| 6910 | void DebugInfoPrint(FILE* out); |
| 6911 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6912 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6913 | void DebugInfoVerify(); |
| 6914 | #endif |
| 6915 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6916 | static const int kSharedFunctionInfoIndex = Struct::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6917 | static const int kOriginalCodeIndex = kSharedFunctionInfoIndex + kPointerSize; |
| 6918 | static const int kPatchedCodeIndex = kOriginalCodeIndex + kPointerSize; |
| 6919 | static const int kActiveBreakPointsCountIndex = |
| 6920 | kPatchedCodeIndex + kPointerSize; |
| 6921 | static const int kBreakPointsStateIndex = |
| 6922 | kActiveBreakPointsCountIndex + kPointerSize; |
| 6923 | static const int kSize = kBreakPointsStateIndex + kPointerSize; |
| 6924 | |
| 6925 | private: |
| 6926 | static const int kNoBreakPointInfo = -1; |
| 6927 | |
| 6928 | // Lookup the index in the break_points array for a code position. |
| 6929 | int GetBreakPointInfoIndex(int code_position); |
| 6930 | |
| 6931 | DISALLOW_IMPLICIT_CONSTRUCTORS(DebugInfo); |
| 6932 | }; |
| 6933 | |
| 6934 | |
| 6935 | // The BreakPointInfo class holds information for break points set in a |
| 6936 | // function. The DebugInfo object holds a BreakPointInfo object for each code |
| 6937 | // position with one or more break points. |
| 6938 | class BreakPointInfo: public Struct { |
| 6939 | public: |
| 6940 | // The position in the code for the break point. |
| 6941 | DECL_ACCESSORS(code_position, Smi) |
| 6942 | // The position in the source for the break position. |
| 6943 | DECL_ACCESSORS(source_position, Smi) |
| 6944 | // The position in the source for the last statement before this break |
| 6945 | // position. |
| 6946 | DECL_ACCESSORS(statement_position, Smi) |
| 6947 | // List of related JavaScript break points. |
| 6948 | DECL_ACCESSORS(break_point_objects, Object) |
| 6949 | |
| 6950 | // Removes a break point. |
| 6951 | static void ClearBreakPoint(Handle<BreakPointInfo> info, |
| 6952 | Handle<Object> break_point_object); |
| 6953 | // Set a break point. |
| 6954 | static void SetBreakPoint(Handle<BreakPointInfo> info, |
| 6955 | Handle<Object> break_point_object); |
| 6956 | // Check if break point info has this break point object. |
| 6957 | static bool HasBreakPointObject(Handle<BreakPointInfo> info, |
| 6958 | Handle<Object> break_point_object); |
| 6959 | // Get the number of break points for this code position. |
| 6960 | int GetBreakPointCount(); |
| 6961 | |
| 6962 | static inline BreakPointInfo* cast(Object* obj); |
| 6963 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6964 | #ifdef OBJECT_PRINT |
| 6965 | inline void BreakPointInfoPrint() { |
| 6966 | BreakPointInfoPrint(stdout); |
| 6967 | } |
| 6968 | void BreakPointInfoPrint(FILE* out); |
| 6969 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6970 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6971 | void BreakPointInfoVerify(); |
| 6972 | #endif |
| 6973 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6974 | static const int kCodePositionIndex = Struct::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6975 | static const int kSourcePositionIndex = kCodePositionIndex + kPointerSize; |
| 6976 | static const int kStatementPositionIndex = |
| 6977 | kSourcePositionIndex + kPointerSize; |
| 6978 | static const int kBreakPointObjectsIndex = |
| 6979 | kStatementPositionIndex + kPointerSize; |
| 6980 | static const int kSize = kBreakPointObjectsIndex + kPointerSize; |
| 6981 | |
| 6982 | private: |
| 6983 | DISALLOW_IMPLICIT_CONSTRUCTORS(BreakPointInfo); |
| 6984 | }; |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 6985 | #endif // ENABLE_DEBUGGER_SUPPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6986 | |
| 6987 | |
| 6988 | #undef DECL_BOOLEAN_ACCESSORS |
| 6989 | #undef DECL_ACCESSORS |
| 6990 | |
| 6991 | |
| 6992 | // Abstract base class for visiting, and optionally modifying, the |
| 6993 | // pointers contained in Objects. Used in GC and serialization/deserialization. |
| 6994 | class ObjectVisitor BASE_EMBEDDED { |
| 6995 | public: |
| 6996 | virtual ~ObjectVisitor() {} |
| 6997 | |
| 6998 | // Visits a contiguous arrays of pointers in the half-open range |
| 6999 | // [start, end). Any or all of the values may be modified on return. |
| 7000 | virtual void VisitPointers(Object** start, Object** end) = 0; |
| 7001 | |
| 7002 | // To allow lazy clearing of inline caches the visitor has |
| 7003 | // a rich interface for iterating over Code objects.. |
| 7004 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7005 | // Visits a code target in the instruction stream. |
| 7006 | virtual void VisitCodeTarget(RelocInfo* rinfo); |
| 7007 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 7008 | // Visits a code entry in a JS function. |
| 7009 | virtual void VisitCodeEntry(Address entry_address); |
| 7010 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7011 | // Visits a global property cell reference in the instruction stream. |
| 7012 | virtual void VisitGlobalPropertyCell(RelocInfo* rinfo); |
| 7013 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7014 | // Visits a runtime entry in the instruction stream. |
| 7015 | virtual void VisitRuntimeEntry(RelocInfo* rinfo) {} |
| 7016 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7017 | // Visits the resource of an ASCII or two-byte string. |
| 7018 | virtual void VisitExternalAsciiString( |
| 7019 | v8::String::ExternalAsciiStringResource** resource) {} |
| 7020 | virtual void VisitExternalTwoByteString( |
| 7021 | v8::String::ExternalStringResource** resource) {} |
| 7022 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7023 | // Visits a debug call target in the instruction stream. |
| 7024 | virtual void VisitDebugTarget(RelocInfo* rinfo); |
| 7025 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7026 | // Handy shorthand for visiting a single pointer. |
| 7027 | virtual void VisitPointer(Object** p) { VisitPointers(p, p + 1); } |
| 7028 | |
| 7029 | // Visits a contiguous arrays of external references (references to the C++ |
| 7030 | // heap) in the half-open range [start, end). Any or all of the values |
| 7031 | // may be modified on return. |
| 7032 | virtual void VisitExternalReferences(Address* start, Address* end) {} |
| 7033 | |
| 7034 | inline void VisitExternalReference(Address* p) { |
| 7035 | VisitExternalReferences(p, p + 1); |
| 7036 | } |
| 7037 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 7038 | // Visits a handle that has an embedder-assigned class ID. |
| 7039 | virtual void VisitEmbedderReference(Object** p, uint16_t class_id) {} |
| 7040 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7041 | #ifdef DEBUG |
| 7042 | // Intended for serialization/deserialization checking: insert, or |
| 7043 | // check for the presence of, a tag at this position in the stream. |
| 7044 | virtual void Synchronize(const char* tag) {} |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 7045 | #else |
| 7046 | inline void Synchronize(const char* tag) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7047 | #endif |
| 7048 | }; |
| 7049 | |
| 7050 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 7051 | class StructBodyDescriptor : public |
| 7052 | FlexibleBodyDescriptor<HeapObject::kHeaderSize> { |
| 7053 | public: |
| 7054 | static inline int SizeOf(Map* map, HeapObject* object) { |
| 7055 | return map->instance_size(); |
| 7056 | } |
| 7057 | }; |
| 7058 | |
| 7059 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7060 | // BooleanBit is a helper class for setting and getting a bit in an |
| 7061 | // integer or Smi. |
| 7062 | class BooleanBit : public AllStatic { |
| 7063 | public: |
| 7064 | static inline bool get(Smi* smi, int bit_position) { |
| 7065 | return get(smi->value(), bit_position); |
| 7066 | } |
| 7067 | |
| 7068 | static inline bool get(int value, int bit_position) { |
| 7069 | return (value & (1 << bit_position)) != 0; |
| 7070 | } |
| 7071 | |
| 7072 | static inline Smi* set(Smi* smi, int bit_position, bool v) { |
| 7073 | return Smi::FromInt(set(smi->value(), bit_position, v)); |
| 7074 | } |
| 7075 | |
| 7076 | static inline int set(int value, int bit_position, bool v) { |
| 7077 | if (v) { |
| 7078 | value |= (1 << bit_position); |
| 7079 | } else { |
| 7080 | value &= ~(1 << bit_position); |
| 7081 | } |
| 7082 | return value; |
| 7083 | } |
| 7084 | }; |
| 7085 | |
| 7086 | } } // namespace v8::internal |
| 7087 | |
| 7088 | #endif // V8_OBJECTS_H_ |