ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1 | // Copyright 2010 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 | |
| 31 | #include "builtins.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 32 | #include "smart-pointer.h" |
| 33 | #include "unicode-inl.h" |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 34 | #if V8_TARGET_ARCH_ARM |
| 35 | #include "arm/constants-arm.h" |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 36 | #elif V8_TARGET_ARCH_MIPS |
| 37 | #include "mips/constants-mips.h" |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 38 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 39 | |
| 40 | // |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 41 | // 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] | 42 | // |
| 43 | // Inheritance hierarchy: |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 44 | // - MaybeObject (an object or a failure) |
| 45 | // - Failure (immediate for marking failed operation) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 46 | // - Object |
| 47 | // - Smi (immediate small integer) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 48 | // - HeapObject (superclass for everything allocated in the heap) |
| 49 | // - JSObject |
| 50 | // - JSArray |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 51 | // - JSRegExp |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 52 | // - JSFunction |
| 53 | // - GlobalObject |
| 54 | // - JSGlobalObject |
| 55 | // - JSBuiltinsObject |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 56 | // - JSGlobalProxy |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 57 | // - JSValue |
| 58 | // - ByteArray |
| 59 | // - PixelArray |
| 60 | // - ExternalArray |
| 61 | // - ExternalByteArray |
| 62 | // - ExternalUnsignedByteArray |
| 63 | // - ExternalShortArray |
| 64 | // - ExternalUnsignedShortArray |
| 65 | // - ExternalIntArray |
| 66 | // - ExternalUnsignedIntArray |
| 67 | // - ExternalFloatArray |
| 68 | // - FixedArray |
| 69 | // - DescriptorArray |
| 70 | // - HashTable |
| 71 | // - Dictionary |
| 72 | // - SymbolTable |
| 73 | // - CompilationCacheTable |
| 74 | // - CodeCacheHashTable |
| 75 | // - MapCache |
| 76 | // - Context |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 77 | // - JSFunctionResultCache |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 78 | // - SerializedScopeInfo |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 79 | // - String |
| 80 | // - SeqString |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 81 | // - SeqAsciiString |
| 82 | // - SeqTwoByteString |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 83 | // - ConsString |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 84 | // - ExternalString |
| 85 | // - ExternalAsciiString |
| 86 | // - ExternalTwoByteString |
| 87 | // - HeapNumber |
| 88 | // - Code |
| 89 | // - Map |
| 90 | // - Oddball |
| 91 | // - Proxy |
| 92 | // - SharedFunctionInfo |
| 93 | // - Struct |
| 94 | // - AccessorInfo |
| 95 | // - AccessCheckInfo |
| 96 | // - InterceptorInfo |
| 97 | // - CallHandlerInfo |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 98 | // - TemplateInfo |
| 99 | // - FunctionTemplateInfo |
| 100 | // - ObjectTemplateInfo |
| 101 | // - Script |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 102 | // - SignatureInfo |
| 103 | // - TypeSwitchInfo |
| 104 | // - DebugInfo |
| 105 | // - BreakPointInfo |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 106 | // - CodeCache |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 107 | // |
| 108 | // Formats of Object*: |
| 109 | // Smi: [31 bit signed int] 0 |
| 110 | // HeapObject: [32 bit direct pointer] (4 byte aligned) | 01 |
| 111 | // Failure: [30 bit signed int] 11 |
| 112 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 113 | // Ecma-262 3rd 8.6.1 |
| 114 | enum PropertyAttributes { |
| 115 | NONE = v8::None, |
| 116 | READ_ONLY = v8::ReadOnly, |
| 117 | DONT_ENUM = v8::DontEnum, |
| 118 | DONT_DELETE = v8::DontDelete, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 119 | 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] | 120 | // ABSENT can never be stored in or returned from a descriptor's attributes |
| 121 | // bitfield. It is only used as a return value meaning the attributes of |
| 122 | // a non-existent property. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 123 | }; |
| 124 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 125 | namespace v8 { |
| 126 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 127 | |
| 128 | |
| 129 | // PropertyDetails captures type and attributes for a property. |
| 130 | // They are used both in property dictionaries and instance descriptors. |
| 131 | class PropertyDetails BASE_EMBEDDED { |
| 132 | public: |
| 133 | |
| 134 | PropertyDetails(PropertyAttributes attributes, |
| 135 | PropertyType type, |
| 136 | int index = 0) { |
| 137 | ASSERT(TypeField::is_valid(type)); |
| 138 | ASSERT(AttributesField::is_valid(attributes)); |
| 139 | ASSERT(IndexField::is_valid(index)); |
| 140 | |
| 141 | value_ = TypeField::encode(type) |
| 142 | | AttributesField::encode(attributes) |
| 143 | | IndexField::encode(index); |
| 144 | |
| 145 | ASSERT(type == this->type()); |
| 146 | ASSERT(attributes == this->attributes()); |
| 147 | ASSERT(index == this->index()); |
| 148 | } |
| 149 | |
| 150 | // Conversion for storing details as Object*. |
| 151 | inline PropertyDetails(Smi* smi); |
| 152 | inline Smi* AsSmi(); |
| 153 | |
| 154 | PropertyType type() { return TypeField::decode(value_); } |
| 155 | |
| 156 | bool IsTransition() { |
| 157 | PropertyType t = type(); |
| 158 | ASSERT(t != INTERCEPTOR); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 159 | return t == MAP_TRANSITION || t == CONSTANT_TRANSITION; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 160 | } |
| 161 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 162 | bool IsProperty() { |
| 163 | return type() < FIRST_PHANTOM_PROPERTY_TYPE; |
| 164 | } |
| 165 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 166 | PropertyAttributes attributes() { return AttributesField::decode(value_); } |
| 167 | |
| 168 | int index() { return IndexField::decode(value_); } |
| 169 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 170 | inline PropertyDetails AsDeleted(); |
| 171 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 172 | static bool IsValidIndex(int index) { return IndexField::is_valid(index); } |
| 173 | |
| 174 | bool IsReadOnly() { return (attributes() & READ_ONLY) != 0; } |
| 175 | bool IsDontDelete() { return (attributes() & DONT_DELETE) != 0; } |
| 176 | bool IsDontEnum() { return (attributes() & DONT_ENUM) != 0; } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 177 | bool IsDeleted() { return DeletedField::decode(value_) != 0;} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 178 | |
| 179 | // Bit fields in value_ (type, shift, size). Must be public so the |
| 180 | // constants can be embedded in generated code. |
| 181 | class TypeField: public BitField<PropertyType, 0, 3> {}; |
| 182 | class AttributesField: public BitField<PropertyAttributes, 3, 3> {}; |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 183 | class DeletedField: public BitField<uint32_t, 6, 1> {}; |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 184 | class IndexField: public BitField<uint32_t, 7, 32-7> {}; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 185 | |
| 186 | static const int kInitialIndex = 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 187 | private: |
| 188 | uint32_t value_; |
| 189 | }; |
| 190 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 191 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 192 | // Setter that skips the write barrier if mode is SKIP_WRITE_BARRIER. |
| 193 | enum WriteBarrierMode { SKIP_WRITE_BARRIER, UPDATE_WRITE_BARRIER }; |
| 194 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 195 | |
| 196 | // PropertyNormalizationMode is used to specify whether to keep |
| 197 | // inobject properties when normalizing properties of a JSObject. |
| 198 | enum PropertyNormalizationMode { |
| 199 | CLEAR_INOBJECT_PROPERTIES, |
| 200 | KEEP_INOBJECT_PROPERTIES |
| 201 | }; |
| 202 | |
| 203 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 204 | // NormalizedMapSharingMode is used to specify whether a map may be shared |
| 205 | // by different objects with normalized properties. |
| 206 | enum NormalizedMapSharingMode { |
| 207 | UNIQUE_NORMALIZED_MAP, |
| 208 | SHARED_NORMALIZED_MAP |
| 209 | }; |
| 210 | |
| 211 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 212 | // Instance size sentinel for objects of variable size. |
| 213 | static const int kVariableSizeSentinel = 0; |
| 214 | |
| 215 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 216 | // All Maps have a field instance_type containing a InstanceType. |
| 217 | // It describes the type of the instances. |
| 218 | // |
| 219 | // As an example, a JavaScript object is a heap object and its map |
| 220 | // instance_type is JS_OBJECT_TYPE. |
| 221 | // |
| 222 | // The names of the string instance types are intended to systematically |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 223 | // mirror their encoding in the instance_type field of the map. The default |
| 224 | // encoding is considered TWO_BYTE. It is not mentioned in the name. ASCII |
| 225 | // encoding is mentioned explicitly in the name. Likewise, the default |
| 226 | // representation is considered sequential. It is not mentioned in the |
| 227 | // name. The other representations (eg, CONS, EXTERNAL) are explicitly |
| 228 | // mentioned. Finally, the string is either a SYMBOL_TYPE (if it is a |
| 229 | // symbol) or a STRING_TYPE (if it is not a symbol). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 230 | // |
| 231 | // NOTE: The following things are some that depend on the string types having |
| 232 | // instance_types that are less than those of all other types: |
| 233 | // HeapObject::Size, HeapObject::IterateBody, the typeof operator, and |
| 234 | // Object::IsString. |
| 235 | // |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 236 | // NOTE: Everything following JS_VALUE_TYPE is considered a |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 237 | // JSObject for GC purposes. The first four entries here have typeof |
| 238 | // 'object', whereas JS_FUNCTION_TYPE has typeof 'function'. |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 239 | #define INSTANCE_TYPE_LIST_ALL(V) \ |
| 240 | V(SYMBOL_TYPE) \ |
| 241 | V(ASCII_SYMBOL_TYPE) \ |
| 242 | V(CONS_SYMBOL_TYPE) \ |
| 243 | V(CONS_ASCII_SYMBOL_TYPE) \ |
| 244 | V(EXTERNAL_SYMBOL_TYPE) \ |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 245 | V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 246 | V(EXTERNAL_ASCII_SYMBOL_TYPE) \ |
| 247 | V(STRING_TYPE) \ |
| 248 | V(ASCII_STRING_TYPE) \ |
| 249 | V(CONS_STRING_TYPE) \ |
| 250 | V(CONS_ASCII_STRING_TYPE) \ |
| 251 | V(EXTERNAL_STRING_TYPE) \ |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 252 | V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 253 | V(EXTERNAL_ASCII_STRING_TYPE) \ |
| 254 | V(PRIVATE_EXTERNAL_ASCII_STRING_TYPE) \ |
| 255 | \ |
| 256 | V(MAP_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 257 | V(CODE_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 258 | V(ODDBALL_TYPE) \ |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 259 | V(JS_GLOBAL_PROPERTY_CELL_TYPE) \ |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 260 | \ |
| 261 | V(HEAP_NUMBER_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 262 | V(PROXY_TYPE) \ |
| 263 | V(BYTE_ARRAY_TYPE) \ |
| 264 | V(PIXEL_ARRAY_TYPE) \ |
| 265 | /* Note: the order of these external array */ \ |
| 266 | /* types is relied upon in */ \ |
| 267 | /* Object::IsExternalArray(). */ \ |
| 268 | V(EXTERNAL_BYTE_ARRAY_TYPE) \ |
| 269 | V(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE) \ |
| 270 | V(EXTERNAL_SHORT_ARRAY_TYPE) \ |
| 271 | V(EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE) \ |
| 272 | V(EXTERNAL_INT_ARRAY_TYPE) \ |
| 273 | V(EXTERNAL_UNSIGNED_INT_ARRAY_TYPE) \ |
| 274 | V(EXTERNAL_FLOAT_ARRAY_TYPE) \ |
| 275 | V(FILLER_TYPE) \ |
| 276 | \ |
| 277 | V(ACCESSOR_INFO_TYPE) \ |
| 278 | V(ACCESS_CHECK_INFO_TYPE) \ |
| 279 | V(INTERCEPTOR_INFO_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 280 | V(CALL_HANDLER_INFO_TYPE) \ |
| 281 | V(FUNCTION_TEMPLATE_INFO_TYPE) \ |
| 282 | V(OBJECT_TEMPLATE_INFO_TYPE) \ |
| 283 | V(SIGNATURE_INFO_TYPE) \ |
| 284 | V(TYPE_SWITCH_INFO_TYPE) \ |
| 285 | V(SCRIPT_TYPE) \ |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 286 | V(CODE_CACHE_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 287 | \ |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 288 | V(FIXED_ARRAY_TYPE) \ |
| 289 | V(SHARED_FUNCTION_INFO_TYPE) \ |
| 290 | \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 291 | V(JS_VALUE_TYPE) \ |
| 292 | V(JS_OBJECT_TYPE) \ |
| 293 | V(JS_CONTEXT_EXTENSION_OBJECT_TYPE) \ |
| 294 | V(JS_GLOBAL_OBJECT_TYPE) \ |
| 295 | V(JS_BUILTINS_OBJECT_TYPE) \ |
| 296 | V(JS_GLOBAL_PROXY_TYPE) \ |
| 297 | V(JS_ARRAY_TYPE) \ |
| 298 | V(JS_REGEXP_TYPE) \ |
| 299 | \ |
| 300 | V(JS_FUNCTION_TYPE) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 301 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 302 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 303 | #define INSTANCE_TYPE_LIST_DEBUGGER(V) \ |
| 304 | V(DEBUG_INFO_TYPE) \ |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 305 | V(BREAK_POINT_INFO_TYPE) |
| 306 | #else |
| 307 | #define INSTANCE_TYPE_LIST_DEBUGGER(V) |
| 308 | #endif |
| 309 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 310 | #define INSTANCE_TYPE_LIST(V) \ |
| 311 | INSTANCE_TYPE_LIST_ALL(V) \ |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 312 | INSTANCE_TYPE_LIST_DEBUGGER(V) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 313 | |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 314 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 315 | // Since string types are not consecutive, this macro is used to |
| 316 | // iterate over them. |
| 317 | #define STRING_TYPE_LIST(V) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 318 | V(SYMBOL_TYPE, \ |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 319 | kVariableSizeSentinel, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 320 | symbol, \ |
| 321 | Symbol) \ |
| 322 | V(ASCII_SYMBOL_TYPE, \ |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 323 | kVariableSizeSentinel, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 324 | ascii_symbol, \ |
| 325 | AsciiSymbol) \ |
| 326 | V(CONS_SYMBOL_TYPE, \ |
| 327 | ConsString::kSize, \ |
| 328 | cons_symbol, \ |
| 329 | ConsSymbol) \ |
| 330 | V(CONS_ASCII_SYMBOL_TYPE, \ |
| 331 | ConsString::kSize, \ |
| 332 | cons_ascii_symbol, \ |
| 333 | ConsAsciiSymbol) \ |
| 334 | V(EXTERNAL_SYMBOL_TYPE, \ |
| 335 | ExternalTwoByteString::kSize, \ |
| 336 | external_symbol, \ |
| 337 | ExternalSymbol) \ |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 338 | V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \ |
| 339 | ExternalTwoByteString::kSize, \ |
| 340 | external_symbol_with_ascii_data, \ |
| 341 | ExternalSymbolWithAsciiData) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 342 | V(EXTERNAL_ASCII_SYMBOL_TYPE, \ |
| 343 | ExternalAsciiString::kSize, \ |
| 344 | external_ascii_symbol, \ |
| 345 | ExternalAsciiSymbol) \ |
| 346 | V(STRING_TYPE, \ |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 347 | kVariableSizeSentinel, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 348 | string, \ |
| 349 | String) \ |
| 350 | V(ASCII_STRING_TYPE, \ |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 351 | kVariableSizeSentinel, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 352 | ascii_string, \ |
| 353 | AsciiString) \ |
| 354 | V(CONS_STRING_TYPE, \ |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 355 | ConsString::kSize, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 356 | cons_string, \ |
| 357 | ConsString) \ |
| 358 | V(CONS_ASCII_STRING_TYPE, \ |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 359 | ConsString::kSize, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 360 | cons_ascii_string, \ |
| 361 | ConsAsciiString) \ |
| 362 | V(EXTERNAL_STRING_TYPE, \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 363 | ExternalTwoByteString::kSize, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 364 | external_string, \ |
| 365 | ExternalString) \ |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 366 | V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \ |
| 367 | ExternalTwoByteString::kSize, \ |
| 368 | external_string_with_ascii_data, \ |
| 369 | ExternalStringWithAsciiData) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 370 | V(EXTERNAL_ASCII_STRING_TYPE, \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 371 | ExternalAsciiString::kSize, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 372 | external_ascii_string, \ |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 373 | ExternalAsciiString) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 374 | |
| 375 | // A struct is a simple object a set of object-valued fields. Including an |
| 376 | // object type in this causes the compiler to generate most of the boilerplate |
| 377 | // code for the class including allocation and garbage collection routines, |
| 378 | // casts and predicates. All you need to define is the class, methods and |
| 379 | // object verification routines. Easy, no? |
| 380 | // |
| 381 | // Note that for subtle reasons related to the ordering or numerical values of |
| 382 | // type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST |
| 383 | // manually. |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 384 | #define STRUCT_LIST_ALL(V) \ |
| 385 | V(ACCESSOR_INFO, AccessorInfo, accessor_info) \ |
| 386 | V(ACCESS_CHECK_INFO, AccessCheckInfo, access_check_info) \ |
| 387 | V(INTERCEPTOR_INFO, InterceptorInfo, interceptor_info) \ |
| 388 | V(CALL_HANDLER_INFO, CallHandlerInfo, call_handler_info) \ |
| 389 | V(FUNCTION_TEMPLATE_INFO, FunctionTemplateInfo, function_template_info) \ |
| 390 | V(OBJECT_TEMPLATE_INFO, ObjectTemplateInfo, object_template_info) \ |
| 391 | V(SIGNATURE_INFO, SignatureInfo, signature_info) \ |
| 392 | V(TYPE_SWITCH_INFO, TypeSwitchInfo, type_switch_info) \ |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 393 | V(SCRIPT, Script, script) \ |
| 394 | V(CODE_CACHE, CodeCache, code_cache) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 395 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 396 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 397 | #define STRUCT_LIST_DEBUGGER(V) \ |
| 398 | V(DEBUG_INFO, DebugInfo, debug_info) \ |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 399 | V(BREAK_POINT_INFO, BreakPointInfo, break_point_info) |
| 400 | #else |
| 401 | #define STRUCT_LIST_DEBUGGER(V) |
| 402 | #endif |
| 403 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 404 | #define STRUCT_LIST(V) \ |
| 405 | STRUCT_LIST_ALL(V) \ |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 406 | STRUCT_LIST_DEBUGGER(V) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 407 | |
| 408 | // We use the full 8 bits of the instance_type field to encode heap object |
| 409 | // instance types. The high-order bit (bit 7) is set if the object is not a |
| 410 | // string, and cleared if it is a string. |
| 411 | const uint32_t kIsNotStringMask = 0x80; |
| 412 | const uint32_t kStringTag = 0x0; |
| 413 | const uint32_t kNotStringTag = 0x80; |
| 414 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 415 | // Bit 6 indicates that the object is a symbol (if set) or not (if cleared). |
| 416 | // There are not enough types that the non-string types (with bit 7 set) can |
| 417 | // have bit 6 set too. |
| 418 | const uint32_t kIsSymbolMask = 0x40; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 419 | const uint32_t kNotSymbolTag = 0x0; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 420 | const uint32_t kSymbolTag = 0x40; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 421 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 422 | // If bit 7 is clear then bit 2 indicates whether the string consists of |
| 423 | // two-byte characters or one-byte characters. |
| 424 | const uint32_t kStringEncodingMask = 0x4; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 425 | const uint32_t kTwoByteStringTag = 0x0; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 426 | const uint32_t kAsciiStringTag = 0x4; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 427 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 428 | // 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] | 429 | // of the string. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 430 | const uint32_t kStringRepresentationMask = 0x03; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 431 | enum StringRepresentationTag { |
| 432 | kSeqStringTag = 0x0, |
| 433 | kConsStringTag = 0x1, |
sgjesse@chromium.org | 82dbbab | 2010-06-02 08:57:44 +0000 | [diff] [blame] | 434 | kExternalStringTag = 0x2 |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 435 | }; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 436 | const uint32_t kIsConsStringMask = 0x1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 437 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 438 | // If bit 7 is clear, then bit 3 indicates whether this two-byte |
| 439 | // string actually contains ascii data. |
| 440 | const uint32_t kAsciiDataHintMask = 0x08; |
| 441 | const uint32_t kAsciiDataHintTag = 0x08; |
| 442 | |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 443 | |
| 444 | // A ConsString with an empty string as the right side is a candidate |
| 445 | // for being shortcut by the garbage collector unless it is a |
| 446 | // symbol. It's not common to have non-flat symbols, so we do not |
| 447 | // shortcut them thereby avoiding turning symbols into strings. See |
| 448 | // heap.cc and mark-compact.cc. |
| 449 | const uint32_t kShortcutTypeMask = |
| 450 | kIsNotStringMask | |
| 451 | kIsSymbolMask | |
| 452 | kStringRepresentationMask; |
| 453 | const uint32_t kShortcutTypeTag = kConsStringTag; |
| 454 | |
| 455 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 456 | enum InstanceType { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 457 | // String types. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 458 | SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kSeqStringTag, |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 459 | ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kSeqStringTag, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 460 | CONS_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kConsStringTag, |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 461 | CONS_ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kConsStringTag, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 462 | EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kExternalStringTag, |
| 463 | EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE = |
| 464 | kTwoByteStringTag | kSymbolTag | kExternalStringTag | kAsciiDataHintTag, |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 465 | EXTERNAL_ASCII_SYMBOL_TYPE = |
| 466 | kAsciiStringTag | kSymbolTag | kExternalStringTag, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 467 | STRING_TYPE = kTwoByteStringTag | kSeqStringTag, |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 468 | ASCII_STRING_TYPE = kAsciiStringTag | kSeqStringTag, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 469 | CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag, |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 470 | CONS_ASCII_STRING_TYPE = kAsciiStringTag | kConsStringTag, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 471 | EXTERNAL_STRING_TYPE = kTwoByteStringTag | kExternalStringTag, |
| 472 | EXTERNAL_STRING_WITH_ASCII_DATA_TYPE = |
| 473 | kTwoByteStringTag | kExternalStringTag | kAsciiDataHintTag, |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 474 | EXTERNAL_ASCII_STRING_TYPE = kAsciiStringTag | kExternalStringTag, |
| 475 | PRIVATE_EXTERNAL_ASCII_STRING_TYPE = EXTERNAL_ASCII_STRING_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 476 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 477 | // Objects allocated in their own spaces (never in new space). |
| 478 | MAP_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 479 | CODE_TYPE, |
| 480 | ODDBALL_TYPE, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 481 | JS_GLOBAL_PROPERTY_CELL_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 482 | |
| 483 | // "Data", objects that cannot contain non-map-word pointers to heap |
| 484 | // objects. |
| 485 | HEAP_NUMBER_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 486 | PROXY_TYPE, |
| 487 | BYTE_ARRAY_TYPE, |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 488 | PIXEL_ARRAY_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 489 | EXTERNAL_BYTE_ARRAY_TYPE, // FIRST_EXTERNAL_ARRAY_TYPE |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 490 | EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE, |
| 491 | EXTERNAL_SHORT_ARRAY_TYPE, |
| 492 | EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE, |
| 493 | EXTERNAL_INT_ARRAY_TYPE, |
| 494 | EXTERNAL_UNSIGNED_INT_ARRAY_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 495 | EXTERNAL_FLOAT_ARRAY_TYPE, // LAST_EXTERNAL_ARRAY_TYPE |
| 496 | FILLER_TYPE, // LAST_DATA_TYPE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 497 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 498 | // Structs. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 499 | ACCESSOR_INFO_TYPE, |
| 500 | ACCESS_CHECK_INFO_TYPE, |
| 501 | INTERCEPTOR_INFO_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 502 | CALL_HANDLER_INFO_TYPE, |
| 503 | FUNCTION_TEMPLATE_INFO_TYPE, |
| 504 | OBJECT_TEMPLATE_INFO_TYPE, |
| 505 | SIGNATURE_INFO_TYPE, |
| 506 | TYPE_SWITCH_INFO_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 507 | SCRIPT_TYPE, |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 508 | CODE_CACHE_TYPE, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 509 | // The following two instance types are only used when ENABLE_DEBUGGER_SUPPORT |
| 510 | // is defined. However as include/v8.h contain some of the instance type |
| 511 | // constants always having them avoids them getting different numbers |
| 512 | // depending on whether ENABLE_DEBUGGER_SUPPORT is defined or not. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 513 | DEBUG_INFO_TYPE, |
| 514 | BREAK_POINT_INFO_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 | FIXED_ARRAY_TYPE, |
| 517 | SHARED_FUNCTION_INFO_TYPE, |
| 518 | |
| 519 | JS_VALUE_TYPE, // FIRST_JS_OBJECT_TYPE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 520 | JS_OBJECT_TYPE, |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 521 | JS_CONTEXT_EXTENSION_OBJECT_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 522 | JS_GLOBAL_OBJECT_TYPE, |
| 523 | JS_BUILTINS_OBJECT_TYPE, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 524 | JS_GLOBAL_PROXY_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 525 | JS_ARRAY_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 526 | JS_REGEXP_TYPE, // LAST_JS_OBJECT_TYPE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 527 | |
| 528 | JS_FUNCTION_TYPE, |
| 529 | |
| 530 | // Pseudo-types |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 531 | FIRST_TYPE = 0x0, |
| 532 | LAST_TYPE = JS_FUNCTION_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 533 | INVALID_TYPE = FIRST_TYPE - 1, |
| 534 | FIRST_NONSTRING_TYPE = MAP_TYPE, |
| 535 | // Boundaries for testing for an external array. |
| 536 | FIRST_EXTERNAL_ARRAY_TYPE = EXTERNAL_BYTE_ARRAY_TYPE, |
| 537 | LAST_EXTERNAL_ARRAY_TYPE = EXTERNAL_FLOAT_ARRAY_TYPE, |
| 538 | // Boundary for promotion to old data space/old pointer space. |
| 539 | LAST_DATA_TYPE = FILLER_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 540 | // Boundaries for testing the type is a JavaScript "object". Note that |
| 541 | // function objects are not counted as objects, even though they are |
| 542 | // implemented as such; only values whose typeof is "object" are included. |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 543 | FIRST_JS_OBJECT_TYPE = JS_VALUE_TYPE, |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 544 | LAST_JS_OBJECT_TYPE = JS_REGEXP_TYPE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 545 | }; |
| 546 | |
| 547 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 548 | STATIC_CHECK(JS_OBJECT_TYPE == Internals::kJSObjectType); |
| 549 | STATIC_CHECK(FIRST_NONSTRING_TYPE == Internals::kFirstNonstringType); |
| 550 | STATIC_CHECK(PROXY_TYPE == Internals::kProxyType); |
| 551 | |
| 552 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 553 | enum CompareResult { |
| 554 | LESS = -1, |
| 555 | EQUAL = 0, |
| 556 | GREATER = 1, |
| 557 | |
| 558 | NOT_EQUAL = GREATER |
| 559 | }; |
| 560 | |
| 561 | |
| 562 | #define DECL_BOOLEAN_ACCESSORS(name) \ |
| 563 | inline bool name(); \ |
| 564 | inline void set_##name(bool value); \ |
| 565 | |
| 566 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 567 | #define DECL_ACCESSORS(name, type) \ |
| 568 | inline type* name(); \ |
| 569 | inline void set_##name(type* value, \ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 570 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 571 | |
| 572 | |
| 573 | class StringStream; |
| 574 | class ObjectVisitor; |
| 575 | |
| 576 | struct ValueInfo : public Malloced { |
| 577 | ValueInfo() : type(FIRST_TYPE), ptr(NULL), str(NULL), number(0) { } |
| 578 | InstanceType type; |
| 579 | Object* ptr; |
| 580 | const char* str; |
| 581 | double number; |
| 582 | }; |
| 583 | |
| 584 | |
| 585 | // A template-ized version of the IsXXX functions. |
| 586 | template <class C> static inline bool Is(Object* obj); |
| 587 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 588 | class MaybeObject BASE_EMBEDDED { |
| 589 | public: |
| 590 | inline bool IsFailure(); |
| 591 | inline bool IsRetryAfterGC(); |
| 592 | inline bool IsOutOfMemory(); |
| 593 | inline bool IsException(); |
| 594 | INLINE(bool IsTheHole()); |
| 595 | inline bool ToObject(Object** obj) { |
| 596 | if (IsFailure()) return false; |
| 597 | *obj = reinterpret_cast<Object*>(this); |
| 598 | return true; |
| 599 | } |
| 600 | inline Object* ToObjectUnchecked() { |
| 601 | ASSERT(!IsFailure()); |
| 602 | return reinterpret_cast<Object*>(this); |
| 603 | } |
| 604 | inline Object* ToObjectChecked() { |
| 605 | CHECK(!IsFailure()); |
| 606 | return reinterpret_cast<Object*>(this); |
| 607 | } |
| 608 | |
| 609 | #ifdef DEBUG |
| 610 | // Prints this object with details. |
| 611 | void Print(); |
| 612 | void PrintLn(); |
| 613 | // Verifies the object. |
| 614 | void Verify(); |
| 615 | #endif |
| 616 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 617 | |
| 618 | // Object is the abstract superclass for all classes in the |
| 619 | // object hierarchy. |
| 620 | // Object does not use any virtual functions to avoid the |
| 621 | // allocation of the C++ vtable. |
| 622 | // Since Smi and Failure are subclasses of Object no |
| 623 | // data members can be present in Object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 624 | class Object : public MaybeObject { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 625 | public: |
| 626 | // Type testing. |
| 627 | inline bool IsSmi(); |
| 628 | inline bool IsHeapObject(); |
| 629 | inline bool IsHeapNumber(); |
| 630 | inline bool IsString(); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 631 | inline bool IsSymbol(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 632 | // See objects-inl.h for more details |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 633 | inline bool IsSeqString(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 634 | inline bool IsExternalString(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 635 | inline bool IsExternalTwoByteString(); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 636 | inline bool IsExternalAsciiString(); |
| 637 | inline bool IsSeqTwoByteString(); |
| 638 | inline bool IsSeqAsciiString(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 639 | inline bool IsConsString(); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 640 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 641 | inline bool IsNumber(); |
| 642 | inline bool IsByteArray(); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 643 | inline bool IsPixelArray(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 644 | inline bool IsExternalArray(); |
| 645 | inline bool IsExternalByteArray(); |
| 646 | inline bool IsExternalUnsignedByteArray(); |
| 647 | inline bool IsExternalShortArray(); |
| 648 | inline bool IsExternalUnsignedShortArray(); |
| 649 | inline bool IsExternalIntArray(); |
| 650 | inline bool IsExternalUnsignedIntArray(); |
| 651 | inline bool IsExternalFloatArray(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 652 | inline bool IsJSObject(); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 653 | inline bool IsJSContextExtensionObject(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 654 | inline bool IsMap(); |
| 655 | inline bool IsFixedArray(); |
| 656 | inline bool IsDescriptorArray(); |
| 657 | inline bool IsContext(); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 658 | inline bool IsCatchContext(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 659 | inline bool IsGlobalContext(); |
| 660 | inline bool IsJSFunction(); |
| 661 | inline bool IsCode(); |
| 662 | inline bool IsOddball(); |
| 663 | inline bool IsSharedFunctionInfo(); |
| 664 | inline bool IsJSValue(); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 665 | inline bool IsStringWrapper(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 666 | inline bool IsProxy(); |
| 667 | inline bool IsBoolean(); |
| 668 | inline bool IsJSArray(); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 669 | inline bool IsJSRegExp(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 670 | inline bool IsHashTable(); |
| 671 | inline bool IsDictionary(); |
| 672 | inline bool IsSymbolTable(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 673 | inline bool IsJSFunctionResultCache(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 674 | inline bool IsNormalizedMapCache(); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 675 | inline bool IsCompilationCacheTable(); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 676 | inline bool IsCodeCacheHashTable(); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 677 | inline bool IsMapCache(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 678 | inline bool IsPrimitive(); |
| 679 | inline bool IsGlobalObject(); |
| 680 | inline bool IsJSGlobalObject(); |
| 681 | inline bool IsJSBuiltinsObject(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 682 | inline bool IsJSGlobalProxy(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 683 | inline bool IsUndetectableObject(); |
| 684 | inline bool IsAccessCheckNeeded(); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 685 | inline bool IsJSGlobalPropertyCell(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 686 | |
| 687 | // Returns true if this object is an instance of the specified |
| 688 | // function template. |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 689 | inline bool IsInstanceOf(FunctionTemplateInfo* type); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 690 | |
| 691 | inline bool IsStruct(); |
| 692 | #define DECLARE_STRUCT_PREDICATE(NAME, Name, name) inline bool Is##Name(); |
| 693 | STRUCT_LIST(DECLARE_STRUCT_PREDICATE) |
| 694 | #undef DECLARE_STRUCT_PREDICATE |
| 695 | |
| 696 | // Oddball testing. |
| 697 | INLINE(bool IsUndefined()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 698 | INLINE(bool IsNull()); |
| 699 | INLINE(bool IsTrue()); |
| 700 | INLINE(bool IsFalse()); |
| 701 | |
| 702 | // Extract the number. |
| 703 | inline double Number(); |
| 704 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 705 | inline bool HasSpecificClassOf(String* name); |
| 706 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 707 | MUST_USE_RESULT MaybeObject* ToObject(); // ECMA-262 9.9. |
| 708 | Object* ToBoolean(); // ECMA-262 9.2. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 709 | |
| 710 | // Convert to a JSObject if needed. |
| 711 | // global_context is used when creating wrapper object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 712 | MUST_USE_RESULT MaybeObject* ToObject(Context* global_context); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 713 | |
| 714 | // Converts this to a Smi if possible. |
| 715 | // Failure is returned otherwise. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 716 | MUST_USE_RESULT inline MaybeObject* ToSmi(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 717 | |
| 718 | void Lookup(String* name, LookupResult* result); |
| 719 | |
| 720 | // Property access. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 721 | MUST_USE_RESULT inline MaybeObject* GetProperty(String* key); |
| 722 | MUST_USE_RESULT inline MaybeObject* GetProperty( |
| 723 | String* key, |
| 724 | PropertyAttributes* attributes); |
| 725 | MUST_USE_RESULT MaybeObject* GetPropertyWithReceiver( |
| 726 | Object* receiver, |
| 727 | String* key, |
| 728 | PropertyAttributes* attributes); |
| 729 | MUST_USE_RESULT MaybeObject* GetProperty(Object* receiver, |
| 730 | LookupResult* result, |
| 731 | String* key, |
| 732 | PropertyAttributes* attributes); |
| 733 | MUST_USE_RESULT MaybeObject* GetPropertyWithCallback(Object* receiver, |
| 734 | Object* structure, |
| 735 | String* name, |
| 736 | Object* holder); |
| 737 | MUST_USE_RESULT MaybeObject* GetPropertyWithDefinedGetter(Object* receiver, |
| 738 | JSFunction* getter); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 739 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 740 | inline MaybeObject* GetElement(uint32_t index); |
| 741 | // For use when we know that no exception can be thrown. |
| 742 | inline Object* GetElementNoExceptionThrown(uint32_t index); |
| 743 | MaybeObject* GetElementWithReceiver(Object* receiver, uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 744 | |
| 745 | // Return the object's prototype (might be Heap::null_value()). |
| 746 | Object* GetPrototype(); |
| 747 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 748 | // Tries to convert an object to an array index. Returns true and sets |
| 749 | // the output parameter if it succeeds. |
| 750 | inline bool ToArrayIndex(uint32_t* index); |
| 751 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 752 | // Returns true if this is a JSValue containing a string and the index is |
| 753 | // < the length of the string. Used to implement [] on strings. |
| 754 | inline bool IsStringObjectWithCharacterAt(uint32_t index); |
| 755 | |
| 756 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 757 | // Verify a pointer is a valid object pointer. |
| 758 | static void VerifyPointer(Object* p); |
| 759 | #endif |
| 760 | |
| 761 | // Prints this object without details. |
| 762 | void ShortPrint(); |
| 763 | |
| 764 | // Prints this object without details to a message accumulator. |
| 765 | void ShortPrint(StringStream* accumulator); |
| 766 | |
| 767 | // Casting: This cast is only needed to satisfy macros in objects-inl.h. |
| 768 | static Object* cast(Object* value) { return value; } |
| 769 | |
| 770 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 771 | 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] | 772 | |
| 773 | private: |
| 774 | DISALLOW_IMPLICIT_CONSTRUCTORS(Object); |
| 775 | }; |
| 776 | |
| 777 | |
| 778 | // Smi represents integer Numbers that can be stored in 31 bits. |
| 779 | // 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] | 780 | // 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] | 781 | // For long smis it has the following format: |
| 782 | // [32 bit signed int] [31 bits zero padding] 0 |
| 783 | // Smi stands for small integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 784 | class Smi: public Object { |
| 785 | public: |
| 786 | // Returns the integer value. |
| 787 | inline int value(); |
| 788 | |
| 789 | // Convert a value to a Smi object. |
| 790 | static inline Smi* FromInt(int value); |
| 791 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 792 | static inline Smi* FromIntptr(intptr_t value); |
| 793 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 794 | // Returns whether value can be represented in a Smi. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 795 | static inline bool IsValid(intptr_t value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 796 | |
| 797 | // Casting. |
| 798 | static inline Smi* cast(Object* object); |
| 799 | |
| 800 | // Dispatched behavior. |
| 801 | void SmiPrint(); |
| 802 | void SmiPrint(StringStream* accumulator); |
| 803 | #ifdef DEBUG |
| 804 | void SmiVerify(); |
| 805 | #endif |
| 806 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 807 | static const int kMinValue = (-1 << (kSmiValueSize - 1)); |
| 808 | static const int kMaxValue = -(kMinValue + 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 809 | |
| 810 | private: |
| 811 | DISALLOW_IMPLICIT_CONSTRUCTORS(Smi); |
| 812 | }; |
| 813 | |
| 814 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 815 | // Failure is used for reporting out of memory situations and |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 816 | // propagating exceptions through the runtime system. Failure objects |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 817 | // are transient and cannot occur as part of the object graph. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 818 | // |
| 819 | // Failures are a single word, encoded as follows: |
| 820 | // +-------------------------+---+--+--+ |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 821 | // |.........unused..........|sss|tt|11| |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 822 | // +-------------------------+---+--+--+ |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 823 | // 7 6 4 32 10 |
| 824 | // |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 825 | // |
| 826 | // The low two bits, 0-1, are the failure tag, 11. The next two bits, |
| 827 | // 2-3, are a failure type tag 'tt' with possible values: |
| 828 | // 00 RETRY_AFTER_GC |
| 829 | // 01 EXCEPTION |
| 830 | // 10 INTERNAL_ERROR |
| 831 | // 11 OUT_OF_MEMORY_EXCEPTION |
| 832 | // |
| 833 | // The next three bits, 4-6, are an allocation space tag 'sss'. The |
| 834 | // allocation space tag is 000 for all failure types except |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 835 | // RETRY_AFTER_GC. For RETRY_AFTER_GC, the possible values are the |
| 836 | // allocation spaces (the encoding is found in globals.h). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 837 | |
| 838 | // Failure type tag info. |
| 839 | const int kFailureTypeTagSize = 2; |
| 840 | const int kFailureTypeTagMask = (1 << kFailureTypeTagSize) - 1; |
| 841 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 842 | class Failure: public MaybeObject { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 843 | public: |
| 844 | // RuntimeStubs assumes EXCEPTION = 1 in the compiler-generated code. |
| 845 | enum Type { |
| 846 | RETRY_AFTER_GC = 0, |
| 847 | EXCEPTION = 1, // Returning this marker tells the real exception |
| 848 | // is in Top::pending_exception. |
| 849 | INTERNAL_ERROR = 2, |
| 850 | OUT_OF_MEMORY_EXCEPTION = 3 |
| 851 | }; |
| 852 | |
| 853 | inline Type type() const; |
| 854 | |
| 855 | // Returns the space that needs to be collected for RetryAfterGC failures. |
| 856 | inline AllocationSpace allocation_space() const; |
| 857 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 858 | inline bool IsInternalError() const; |
| 859 | inline bool IsOutOfMemoryException() const; |
| 860 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 861 | static inline Failure* RetryAfterGC(AllocationSpace space); |
| 862 | static inline Failure* RetryAfterGC(); // NEW_SPACE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 863 | static inline Failure* Exception(); |
| 864 | static inline Failure* InternalError(); |
| 865 | static inline Failure* OutOfMemoryException(); |
| 866 | // Casting. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 867 | static inline Failure* cast(MaybeObject* object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 868 | |
| 869 | // Dispatched behavior. |
| 870 | void FailurePrint(); |
| 871 | void FailurePrint(StringStream* accumulator); |
| 872 | #ifdef DEBUG |
| 873 | void FailureVerify(); |
| 874 | #endif |
| 875 | |
| 876 | private: |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 877 | inline intptr_t value() const; |
| 878 | static inline Failure* Construct(Type type, intptr_t value = 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 879 | |
| 880 | DISALLOW_IMPLICIT_CONSTRUCTORS(Failure); |
| 881 | }; |
| 882 | |
| 883 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 884 | // Heap objects typically have a map pointer in their first word. However, |
| 885 | // during GC other data (eg, mark bits, forwarding addresses) is sometimes |
| 886 | // encoded in the first word. The class MapWord is an abstraction of the |
| 887 | // value in a heap object's first word. |
| 888 | class MapWord BASE_EMBEDDED { |
| 889 | public: |
| 890 | // Normal state: the map word contains a map pointer. |
| 891 | |
| 892 | // Create a map word from a map pointer. |
| 893 | static inline MapWord FromMap(Map* map); |
| 894 | |
| 895 | // View this map word as a map pointer. |
| 896 | inline Map* ToMap(); |
| 897 | |
| 898 | |
| 899 | // Scavenge collection: the map word of live objects in the from space |
| 900 | // contains a forwarding address (a heap object pointer in the to space). |
| 901 | |
| 902 | // True if this map word is a forwarding address for a scavenge |
| 903 | // collection. Only valid during a scavenge collection (specifically, |
| 904 | // when all map words are heap object pointers, ie. not during a full GC). |
| 905 | inline bool IsForwardingAddress(); |
| 906 | |
| 907 | // Create a map word from a forwarding address. |
| 908 | static inline MapWord FromForwardingAddress(HeapObject* object); |
| 909 | |
| 910 | // View this map word as a forwarding address. |
| 911 | inline HeapObject* ToForwardingAddress(); |
| 912 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 913 | // Marking phase of full collection: the map word of live objects is |
| 914 | // marked, and may be marked as overflowed (eg, the object is live, its |
| 915 | // children have not been visited, and it does not fit in the marking |
| 916 | // stack). |
| 917 | |
| 918 | // True if this map word's mark bit is set. |
| 919 | inline bool IsMarked(); |
| 920 | |
| 921 | // Return this map word but with its mark bit set. |
| 922 | inline void SetMark(); |
| 923 | |
| 924 | // Return this map word but with its mark bit cleared. |
| 925 | inline void ClearMark(); |
| 926 | |
| 927 | // True if this map word's overflow bit is set. |
| 928 | inline bool IsOverflowed(); |
| 929 | |
| 930 | // Return this map word but with its overflow bit set. |
| 931 | inline void SetOverflow(); |
| 932 | |
| 933 | // Return this map word but with its overflow bit cleared. |
| 934 | inline void ClearOverflow(); |
| 935 | |
| 936 | |
| 937 | // Compacting phase of a full compacting collection: the map word of live |
| 938 | // objects contains an encoding of the original map address along with the |
| 939 | // forwarding address (represented as an offset from the first live object |
| 940 | // in the same page as the (old) object address). |
| 941 | |
| 942 | // Create a map word from a map address and a forwarding address offset. |
| 943 | static inline MapWord EncodeAddress(Address map_address, int offset); |
| 944 | |
| 945 | // Return the map address encoded in this map word. |
| 946 | inline Address DecodeMapAddress(MapSpace* map_space); |
| 947 | |
| 948 | // Return the forwarding offset encoded in this map word. |
| 949 | inline int DecodeOffset(); |
| 950 | |
| 951 | |
| 952 | // During serialization: the map word is used to hold an encoded |
| 953 | // address, and possibly a mark bit (set and cleared with SetMark |
| 954 | // and ClearMark). |
| 955 | |
| 956 | // Create a map word from an encoded address. |
| 957 | static inline MapWord FromEncodedAddress(Address address); |
| 958 | |
| 959 | inline Address ToEncodedAddress(); |
| 960 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 961 | // Bits used by the marking phase of the garbage collector. |
| 962 | // |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 963 | // 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] | 964 | // bits are tagged as '01' (kHeapObjectTag). We reuse the last two bits to |
| 965 | // mark an object as live and/or overflowed: |
| 966 | // last bit = 0, marked as alive |
| 967 | // second bit = 1, overflowed |
| 968 | // An object is only marked as overflowed when it is marked as live while |
| 969 | // the marking stack is overflowed. |
| 970 | static const int kMarkingBit = 0; // marking bit |
| 971 | static const int kMarkingMask = (1 << kMarkingBit); // marking mask |
| 972 | static const int kOverflowBit = 1; // overflow bit |
| 973 | static const int kOverflowMask = (1 << kOverflowBit); // overflow mask |
| 974 | |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 975 | // Forwarding pointers and map pointer encoding. On 32 bit all the bits are |
| 976 | // used. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 977 | // +-----------------+------------------+-----------------+ |
| 978 | // |forwarding offset|page offset of map|page index of map| |
| 979 | // +-----------------+------------------+-----------------+ |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 980 | // ^ ^ ^ |
| 981 | // | | | |
| 982 | // | | kMapPageIndexBits |
| 983 | // | kMapPageOffsetBits |
| 984 | // kForwardingOffsetBits |
| 985 | static const int kMapPageOffsetBits = kPageSizeBits - kMapAlignmentBits; |
| 986 | static const int kForwardingOffsetBits = kPageSizeBits - kObjectAlignmentBits; |
| 987 | #ifdef V8_HOST_ARCH_64_BIT |
| 988 | static const int kMapPageIndexBits = 16; |
| 989 | #else |
| 990 | // Use all the 32-bits to encode on a 32-bit platform. |
| 991 | static const int kMapPageIndexBits = |
| 992 | 32 - (kMapPageOffsetBits + kForwardingOffsetBits); |
| 993 | #endif |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 994 | |
| 995 | static const int kMapPageIndexShift = 0; |
| 996 | static const int kMapPageOffsetShift = |
| 997 | kMapPageIndexShift + kMapPageIndexBits; |
| 998 | static const int kForwardingOffsetShift = |
| 999 | kMapPageOffsetShift + kMapPageOffsetBits; |
| 1000 | |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 1001 | // Bit masks covering the different parts the encoding. |
| 1002 | static const uintptr_t kMapPageIndexMask = |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1003 | (1 << kMapPageOffsetShift) - 1; |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 1004 | static const uintptr_t kMapPageOffsetMask = |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1005 | ((1 << kForwardingOffsetShift) - 1) & ~kMapPageIndexMask; |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 1006 | static const uintptr_t kForwardingOffsetMask = |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1007 | ~(kMapPageIndexMask | kMapPageOffsetMask); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1008 | |
| 1009 | private: |
| 1010 | // HeapObject calls the private constructor and directly reads the value. |
| 1011 | friend class HeapObject; |
| 1012 | |
| 1013 | explicit MapWord(uintptr_t value) : value_(value) {} |
| 1014 | |
| 1015 | uintptr_t value_; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1016 | }; |
| 1017 | |
| 1018 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1019 | // HeapObject is the superclass for all classes describing heap allocated |
| 1020 | // objects. |
| 1021 | class HeapObject: public Object { |
| 1022 | public: |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1023 | // [map]: Contains a map which contains the object's reflective |
| 1024 | // information. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1025 | inline Map* map(); |
| 1026 | inline void set_map(Map* value); |
| 1027 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1028 | // During garbage collection, the map word of a heap object does not |
| 1029 | // necessarily contain a map pointer. |
| 1030 | inline MapWord map_word(); |
| 1031 | inline void set_map_word(MapWord map_word); |
| 1032 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1033 | // Converts an address to a HeapObject pointer. |
| 1034 | static inline HeapObject* FromAddress(Address address); |
| 1035 | |
| 1036 | // Returns the address of this HeapObject. |
| 1037 | inline Address address(); |
| 1038 | |
| 1039 | // Iterates over pointers contained in the object (including the Map) |
| 1040 | void Iterate(ObjectVisitor* v); |
| 1041 | |
| 1042 | // Iterates over all pointers contained in the object except the |
| 1043 | // first map pointer. The object type is given in the first |
| 1044 | // parameter. This function does not access the map pointer in the |
| 1045 | // object, and so is safe to call while the map pointer is modified. |
| 1046 | void IterateBody(InstanceType type, int object_size, ObjectVisitor* v); |
| 1047 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1048 | // Returns the heap object's size in bytes |
| 1049 | inline int Size(); |
| 1050 | |
| 1051 | // Given a heap object's map pointer, returns the heap size in bytes |
| 1052 | // Useful when the map pointer field is used for other purposes. |
| 1053 | // GC internal. |
| 1054 | inline int SizeFromMap(Map* map); |
| 1055 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1056 | // Support for the marking heap objects during the marking phase of GC. |
| 1057 | // True if the object is marked live. |
| 1058 | inline bool IsMarked(); |
| 1059 | |
| 1060 | // Mutate this object's map pointer to indicate that the object is live. |
| 1061 | inline void SetMark(); |
| 1062 | |
| 1063 | // Mutate this object's map pointer to remove the indication that the |
| 1064 | // object is live (ie, partially restore the map pointer). |
| 1065 | inline void ClearMark(); |
| 1066 | |
| 1067 | // True if this object is marked as overflowed. Overflowed objects have |
| 1068 | // been reached and marked during marking of the heap, but their children |
| 1069 | // have not necessarily been marked and they have not been pushed on the |
| 1070 | // marking stack. |
| 1071 | inline bool IsOverflowed(); |
| 1072 | |
| 1073 | // Mutate this object's map pointer to indicate that the object is |
| 1074 | // overflowed. |
| 1075 | inline void SetOverflow(); |
| 1076 | |
| 1077 | // Mutate this object's map pointer to remove the indication that the |
| 1078 | // object is overflowed (ie, partially restore the map pointer). |
| 1079 | inline void ClearOverflow(); |
| 1080 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 1081 | // Returns the field at offset in obj, as a read/write Object* reference. |
| 1082 | // 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] | 1083 | // Does not invoke write barrier, so should only be assigned to |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 1084 | // during marking GC. |
| 1085 | static inline Object** RawField(HeapObject* obj, int offset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1086 | |
| 1087 | // Casting. |
| 1088 | static inline HeapObject* cast(Object* obj); |
| 1089 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1090 | // Return the write barrier mode for this. Callers of this function |
| 1091 | // must be able to present a reference to an AssertNoAllocation |
| 1092 | // object as a sign that they are not going to use this function |
| 1093 | // from code that allocates and thus invalidates the returned write |
| 1094 | // barrier mode. |
| 1095 | inline WriteBarrierMode GetWriteBarrierMode(const AssertNoAllocation&); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1096 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1097 | // Dispatched behavior. |
| 1098 | void HeapObjectShortPrint(StringStream* accumulator); |
| 1099 | #ifdef DEBUG |
| 1100 | void HeapObjectPrint(); |
| 1101 | void HeapObjectVerify(); |
| 1102 | inline void VerifyObjectField(int offset); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1103 | inline void VerifySmiField(int offset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1104 | |
| 1105 | void PrintHeader(const char* id); |
| 1106 | |
| 1107 | // Verify a pointer is a valid HeapObject pointer that points to object |
| 1108 | // areas in the heap. |
| 1109 | static void VerifyHeapPointer(Object* p); |
| 1110 | #endif |
| 1111 | |
| 1112 | // Layout description. |
| 1113 | // First field in a heap object is map. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1114 | static const int kMapOffset = Object::kHeaderSize; |
| 1115 | static const int kHeaderSize = kMapOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1116 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1117 | STATIC_CHECK(kMapOffset == Internals::kHeapObjectMapOffset); |
| 1118 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1119 | protected: |
| 1120 | // helpers for calling an ObjectVisitor to iterate over pointers in the |
| 1121 | // half-open range [start, end) specified as integer offsets |
| 1122 | inline void IteratePointers(ObjectVisitor* v, int start, int end); |
| 1123 | // as above, for the single element at "offset" |
| 1124 | inline void IteratePointer(ObjectVisitor* v, int offset); |
| 1125 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1126 | private: |
| 1127 | DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject); |
| 1128 | }; |
| 1129 | |
| 1130 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1131 | #define SLOT_ADDR(obj, offset) \ |
| 1132 | reinterpret_cast<Object**>((obj)->address() + offset) |
| 1133 | |
| 1134 | // This class describes a body of an object of a fixed size |
| 1135 | // in which all pointer fields are located in the [start_offset, end_offset) |
| 1136 | // interval. |
| 1137 | template<int start_offset, int end_offset, int size> |
| 1138 | class FixedBodyDescriptor { |
| 1139 | public: |
| 1140 | static const int kStartOffset = start_offset; |
| 1141 | static const int kEndOffset = end_offset; |
| 1142 | static const int kSize = size; |
| 1143 | |
| 1144 | static inline void IterateBody(HeapObject* obj, ObjectVisitor* v); |
| 1145 | |
| 1146 | template<typename StaticVisitor> |
| 1147 | static inline void IterateBody(HeapObject* obj) { |
| 1148 | StaticVisitor::VisitPointers(SLOT_ADDR(obj, start_offset), |
| 1149 | SLOT_ADDR(obj, end_offset)); |
| 1150 | } |
| 1151 | }; |
| 1152 | |
| 1153 | |
| 1154 | // This class describes a body of an object of a variable size |
| 1155 | // in which all pointer fields are located in the [start_offset, object_size) |
| 1156 | // interval. |
| 1157 | template<int start_offset> |
| 1158 | class FlexibleBodyDescriptor { |
| 1159 | public: |
| 1160 | static const int kStartOffset = start_offset; |
| 1161 | |
| 1162 | static inline void IterateBody(HeapObject* obj, |
| 1163 | int object_size, |
| 1164 | ObjectVisitor* v); |
| 1165 | |
| 1166 | template<typename StaticVisitor> |
| 1167 | static inline void IterateBody(HeapObject* obj, int object_size) { |
| 1168 | StaticVisitor::VisitPointers(SLOT_ADDR(obj, start_offset), |
| 1169 | SLOT_ADDR(obj, object_size)); |
| 1170 | } |
| 1171 | }; |
| 1172 | |
| 1173 | #undef SLOT_ADDR |
| 1174 | |
| 1175 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1176 | // The HeapNumber class describes heap allocated numbers that cannot be |
| 1177 | // represented in a Smi (small integer) |
| 1178 | class HeapNumber: public HeapObject { |
| 1179 | public: |
| 1180 | // [value]: number value. |
| 1181 | inline double value(); |
| 1182 | inline void set_value(double value); |
| 1183 | |
| 1184 | // Casting. |
| 1185 | static inline HeapNumber* cast(Object* obj); |
| 1186 | |
| 1187 | // Dispatched behavior. |
| 1188 | Object* HeapNumberToBoolean(); |
| 1189 | void HeapNumberPrint(); |
| 1190 | void HeapNumberPrint(StringStream* accumulator); |
| 1191 | #ifdef DEBUG |
| 1192 | void HeapNumberVerify(); |
| 1193 | #endif |
| 1194 | |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 1195 | inline int get_exponent(); |
| 1196 | inline int get_sign(); |
| 1197 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1198 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1199 | static const int kValueOffset = HeapObject::kHeaderSize; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1200 | // IEEE doubles are two 32 bit words. The first is just mantissa, the second |
| 1201 | // is a mixture of sign, exponent and mantissa. Our current platforms are all |
| 1202 | // little endian apart from non-EABI arm which is little endian with big |
| 1203 | // endian floating point word ordering! |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1204 | #if !defined(V8_HOST_ARCH_ARM) || defined(USE_ARM_EABI) |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1205 | static const int kMantissaOffset = kValueOffset; |
| 1206 | static const int kExponentOffset = kValueOffset + 4; |
| 1207 | #else |
| 1208 | static const int kMantissaOffset = kValueOffset + 4; |
| 1209 | static const int kExponentOffset = kValueOffset; |
| 1210 | # define BIG_ENDIAN_FLOATING_POINT 1 |
| 1211 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1212 | static const int kSize = kValueOffset + kDoubleSize; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1213 | static const uint32_t kSignMask = 0x80000000u; |
| 1214 | static const uint32_t kExponentMask = 0x7ff00000u; |
| 1215 | static const uint32_t kMantissaMask = 0xfffffu; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1216 | static const int kMantissaBits = 52; |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1217 | static const int kExponentBits = 11; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1218 | static const int kExponentBias = 1023; |
| 1219 | static const int kExponentShift = 20; |
| 1220 | static const int kMantissaBitsInTopWord = 20; |
| 1221 | static const int kNonMantissaBitsInTopWord = 12; |
| 1222 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1223 | private: |
| 1224 | DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumber); |
| 1225 | }; |
| 1226 | |
| 1227 | |
| 1228 | // The JSObject describes real heap allocated JavaScript objects with |
| 1229 | // properties. |
| 1230 | // Note that the map of JSObject changes during execution to enable inline |
| 1231 | // caching. |
| 1232 | class JSObject: public HeapObject { |
| 1233 | public: |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1234 | enum DeleteMode { NORMAL_DELETION, FORCE_DELETION }; |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1235 | enum ElementsKind { |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1236 | // The only "fast" kind. |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1237 | FAST_ELEMENTS, |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1238 | // All the kinds below are "slow". |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1239 | DICTIONARY_ELEMENTS, |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1240 | PIXEL_ELEMENTS, |
| 1241 | EXTERNAL_BYTE_ELEMENTS, |
| 1242 | EXTERNAL_UNSIGNED_BYTE_ELEMENTS, |
| 1243 | EXTERNAL_SHORT_ELEMENTS, |
| 1244 | EXTERNAL_UNSIGNED_SHORT_ELEMENTS, |
| 1245 | EXTERNAL_INT_ELEMENTS, |
| 1246 | EXTERNAL_UNSIGNED_INT_ELEMENTS, |
| 1247 | EXTERNAL_FLOAT_ELEMENTS |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1248 | }; |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1249 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1250 | // [properties]: Backing storage for properties. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1251 | // 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] | 1252 | // slow case. |
| 1253 | DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1254 | inline void initialize_properties(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1255 | inline bool HasFastProperties(); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 1256 | inline StringDictionary* property_dictionary(); // Gets slow properties. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1257 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1258 | // [elements]: The elements (properties with names that are integers). |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1259 | // |
| 1260 | // Elements can be in two general modes: fast and slow. Each mode |
| 1261 | // corrensponds to a set of object representations of elements that |
| 1262 | // have something in common. |
| 1263 | // |
| 1264 | // In the fast mode elements is a FixedArray and so each element can |
| 1265 | // be quickly accessed. This fact is used in the generated code. The |
| 1266 | // elements array can have one of the two maps in this mode: |
| 1267 | // fixed_array_map or fixed_cow_array_map (for copy-on-write |
| 1268 | // arrays). In the latter case the elements array may be shared by a |
| 1269 | // few objects and so before writing to any element the array must |
| 1270 | // be copied. Use EnsureWritableFastElements in this case. |
| 1271 | // |
| 1272 | // In the slow mode elements is either a NumberDictionary or a |
| 1273 | // PixelArray or an ExternalArray. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1274 | DECL_ACCESSORS(elements, HeapObject) |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1275 | inline void initialize_elements(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1276 | MUST_USE_RESULT inline MaybeObject* ResetElements(); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1277 | inline ElementsKind GetElementsKind(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1278 | inline bool HasFastElements(); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1279 | inline bool HasDictionaryElements(); |
| 1280 | inline bool HasPixelElements(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1281 | inline bool HasExternalArrayElements(); |
| 1282 | inline bool HasExternalByteElements(); |
| 1283 | inline bool HasExternalUnsignedByteElements(); |
| 1284 | inline bool HasExternalShortElements(); |
| 1285 | inline bool HasExternalUnsignedShortElements(); |
| 1286 | inline bool HasExternalIntElements(); |
| 1287 | inline bool HasExternalUnsignedIntElements(); |
| 1288 | inline bool HasExternalFloatElements(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1289 | inline bool AllowsSetElementsLength(); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 1290 | inline NumberDictionary* element_dictionary(); // Gets slow elements. |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1291 | // Requires: this->HasFastElements(). |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1292 | MUST_USE_RESULT inline MaybeObject* EnsureWritableFastElements(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1293 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 1294 | // Collects elements starting at index 0. |
| 1295 | // Undefined values are placed after non-undefined values. |
| 1296 | // Returns the number of non-undefined values. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1297 | MUST_USE_RESULT MaybeObject* PrepareElementsForSort(uint32_t limit); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 1298 | // As PrepareElementsForSort, but only on objects where elements is |
| 1299 | // a dictionary, and it will stay a dictionary. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1300 | MUST_USE_RESULT MaybeObject* PrepareSlowElementsForSort(uint32_t limit); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 1301 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1302 | MUST_USE_RESULT MaybeObject* SetProperty(String* key, |
| 1303 | Object* value, |
| 1304 | PropertyAttributes attributes); |
| 1305 | MUST_USE_RESULT MaybeObject* SetProperty(LookupResult* result, |
| 1306 | String* key, |
| 1307 | Object* value, |
| 1308 | PropertyAttributes attributes); |
| 1309 | MUST_USE_RESULT MaybeObject* SetPropertyWithFailedAccessCheck( |
| 1310 | LookupResult* result, |
| 1311 | String* name, |
| 1312 | Object* value); |
| 1313 | MUST_USE_RESULT MaybeObject* SetPropertyWithCallback(Object* structure, |
| 1314 | String* name, |
| 1315 | Object* value, |
| 1316 | JSObject* holder); |
| 1317 | MUST_USE_RESULT MaybeObject* SetPropertyWithDefinedSetter(JSFunction* setter, |
| 1318 | Object* value); |
| 1319 | MUST_USE_RESULT MaybeObject* SetPropertyWithInterceptor( |
| 1320 | String* name, |
| 1321 | Object* value, |
| 1322 | PropertyAttributes attributes); |
| 1323 | MUST_USE_RESULT MaybeObject* SetPropertyPostInterceptor( |
| 1324 | String* name, |
| 1325 | Object* value, |
| 1326 | PropertyAttributes attributes); |
| 1327 | MUST_USE_RESULT MaybeObject* IgnoreAttributesAndSetLocalProperty( |
| 1328 | String* key, |
| 1329 | Object* value, |
| 1330 | PropertyAttributes attributes); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1331 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1332 | // Retrieve a value in a normalized object given a lookup result. |
| 1333 | // Handles the special representation of JS global objects. |
| 1334 | Object* GetNormalizedProperty(LookupResult* result); |
| 1335 | |
| 1336 | // Sets the property value in a normalized object given a lookup result. |
| 1337 | // Handles the special representation of JS global objects. |
| 1338 | Object* SetNormalizedProperty(LookupResult* result, Object* value); |
| 1339 | |
| 1340 | // Sets the property value in a normalized object given (key, value, details). |
| 1341 | // Handles the special representation of JS global objects. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1342 | MUST_USE_RESULT MaybeObject* SetNormalizedProperty(String* name, |
| 1343 | Object* value, |
| 1344 | PropertyDetails details); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1345 | |
| 1346 | // Deletes the named property in a normalized object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1347 | MUST_USE_RESULT MaybeObject* DeleteNormalizedProperty(String* name, |
| 1348 | DeleteMode mode); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1349 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1350 | // Returns the class name ([[Class]] property in the specification). |
| 1351 | String* class_name(); |
| 1352 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1353 | // Returns the constructor name (the name (possibly, inferred name) of the |
| 1354 | // function that was used to instantiate the object). |
| 1355 | String* constructor_name(); |
| 1356 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1357 | // Retrieve interceptors. |
| 1358 | InterceptorInfo* GetNamedInterceptor(); |
| 1359 | InterceptorInfo* GetIndexedInterceptor(); |
| 1360 | |
| 1361 | inline PropertyAttributes GetPropertyAttribute(String* name); |
| 1362 | PropertyAttributes GetPropertyAttributeWithReceiver(JSObject* receiver, |
| 1363 | String* name); |
| 1364 | PropertyAttributes GetLocalPropertyAttribute(String* name); |
| 1365 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1366 | MUST_USE_RESULT MaybeObject* DefineAccessor(String* name, |
| 1367 | bool is_getter, |
| 1368 | JSFunction* fun, |
| 1369 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1370 | Object* LookupAccessor(String* name, bool is_getter); |
| 1371 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1372 | MUST_USE_RESULT MaybeObject* DefineAccessor(AccessorInfo* info); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1373 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1374 | // Used from Object::GetProperty(). |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1375 | MaybeObject* GetPropertyWithFailedAccessCheck( |
| 1376 | Object* receiver, |
| 1377 | LookupResult* result, |
| 1378 | String* name, |
| 1379 | PropertyAttributes* attributes); |
| 1380 | MaybeObject* GetPropertyWithInterceptor( |
| 1381 | JSObject* receiver, |
| 1382 | String* name, |
| 1383 | PropertyAttributes* attributes); |
| 1384 | MaybeObject* GetPropertyPostInterceptor( |
| 1385 | JSObject* receiver, |
| 1386 | String* name, |
| 1387 | PropertyAttributes* attributes); |
| 1388 | MaybeObject* GetLocalPropertyPostInterceptor(JSObject* receiver, |
| 1389 | String* name, |
| 1390 | PropertyAttributes* attributes); |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 1391 | |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 1392 | // Returns true if this is an instance of an api function and has |
| 1393 | // been modified since it was created. May give false positives. |
| 1394 | bool IsDirty(); |
| 1395 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1396 | bool HasProperty(String* name) { |
| 1397 | return GetPropertyAttribute(name) != ABSENT; |
| 1398 | } |
| 1399 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1400 | // Can cause a GC if it hits an interceptor. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1401 | bool HasLocalProperty(String* name) { |
| 1402 | return GetLocalPropertyAttribute(name) != ABSENT; |
| 1403 | } |
| 1404 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1405 | // If the receiver is a JSGlobalProxy this method will return its prototype, |
| 1406 | // otherwise the result is the receiver itself. |
| 1407 | inline Object* BypassGlobalProxy(); |
| 1408 | |
| 1409 | // Accessors for hidden properties object. |
| 1410 | // |
| 1411 | // Hidden properties are not local properties of the object itself. |
| 1412 | // Instead they are stored on an auxiliary JSObject stored as a local |
| 1413 | // property with a special name Heap::hidden_symbol(). But if the |
| 1414 | // receiver is a JSGlobalProxy then the auxiliary object is a property |
| 1415 | // of its prototype. |
| 1416 | // |
| 1417 | // Has/Get/SetHiddenPropertiesObject methods don't allow the holder to be |
| 1418 | // a JSGlobalProxy. Use BypassGlobalProxy method above to get to the real |
| 1419 | // holder. |
| 1420 | // |
| 1421 | // These accessors do not touch interceptors or accessors. |
| 1422 | inline bool HasHiddenPropertiesObject(); |
| 1423 | inline Object* GetHiddenPropertiesObject(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1424 | MUST_USE_RESULT inline MaybeObject* SetHiddenPropertiesObject( |
| 1425 | Object* hidden_obj); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1426 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1427 | MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode); |
| 1428 | MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1429 | |
| 1430 | // Tests for the fast common case for property enumeration. |
| 1431 | bool IsSimpleEnum(); |
| 1432 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1433 | // Do we want to keep the elements in fast case when increasing the |
| 1434 | // capacity? |
| 1435 | bool ShouldConvertToSlowElements(int new_capacity); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1436 | // Returns true if the backing storage for the slow-case elements of |
| 1437 | // this object takes up nearly as much space as a fast-case backing |
| 1438 | // storage would. In that case the JSObject should have fast |
| 1439 | // elements. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1440 | bool ShouldConvertToFastElements(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1441 | |
| 1442 | // Return the object's prototype (might be Heap::null_value()). |
| 1443 | inline Object* GetPrototype(); |
| 1444 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1445 | // Set the object's prototype (only JSObject and null are allowed). |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1446 | MUST_USE_RESULT MaybeObject* SetPrototype(Object* value, |
| 1447 | bool skip_hidden_prototypes); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1448 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1449 | // Tells whether the index'th element is present. |
| 1450 | inline bool HasElement(uint32_t index); |
| 1451 | bool HasElementWithReceiver(JSObject* receiver, uint32_t index); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1452 | |
| 1453 | // Tells whether the index'th element is present and how it is stored. |
| 1454 | enum LocalElementType { |
| 1455 | // There is no element with given index. |
| 1456 | UNDEFINED_ELEMENT, |
| 1457 | |
| 1458 | // Element with given index is handled by interceptor. |
| 1459 | INTERCEPTED_ELEMENT, |
| 1460 | |
| 1461 | // Element with given index is character in string. |
| 1462 | STRING_CHARACTER_ELEMENT, |
| 1463 | |
| 1464 | // Element with given index is stored in fast backing store. |
| 1465 | FAST_ELEMENT, |
| 1466 | |
| 1467 | // Element with given index is stored in slow backing store. |
| 1468 | DICTIONARY_ELEMENT |
| 1469 | }; |
| 1470 | |
| 1471 | LocalElementType HasLocalElement(uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1472 | |
| 1473 | bool HasElementWithInterceptor(JSObject* receiver, uint32_t index); |
| 1474 | bool HasElementPostInterceptor(JSObject* receiver, uint32_t index); |
| 1475 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1476 | MUST_USE_RESULT MaybeObject* SetFastElement(uint32_t index, Object* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1477 | |
| 1478 | // Set the index'th array element. |
| 1479 | // A Failure object is returned if GC is needed. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1480 | MUST_USE_RESULT MaybeObject* SetElement(uint32_t index, Object* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1481 | |
| 1482 | // Returns the index'th element. |
| 1483 | // The undefined object if index is out of bounds. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1484 | MaybeObject* GetElementWithReceiver(JSObject* receiver, uint32_t index); |
| 1485 | MaybeObject* GetElementWithInterceptor(JSObject* receiver, uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1486 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1487 | MUST_USE_RESULT MaybeObject* SetFastElementsCapacityAndLength(int capacity, |
| 1488 | int length); |
| 1489 | MUST_USE_RESULT MaybeObject* SetSlowElements(Object* length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1490 | |
| 1491 | // Lookup interceptors are used for handling properties controlled by host |
| 1492 | // objects. |
| 1493 | inline bool HasNamedInterceptor(); |
| 1494 | inline bool HasIndexedInterceptor(); |
| 1495 | |
| 1496 | // Support functions for v8 api (needed for correct interceptor behavior). |
| 1497 | bool HasRealNamedProperty(String* key); |
| 1498 | bool HasRealElementProperty(uint32_t index); |
| 1499 | bool HasRealNamedCallbackProperty(String* key); |
| 1500 | |
| 1501 | // Initializes the array to a certain length |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1502 | MUST_USE_RESULT MaybeObject* SetElementsLength(Object* length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1503 | |
| 1504 | // Get the header size for a JSObject. Used to compute the index of |
| 1505 | // internal fields as well as the number of internal fields. |
| 1506 | inline int GetHeaderSize(); |
| 1507 | |
| 1508 | inline int GetInternalFieldCount(); |
| 1509 | inline Object* GetInternalField(int index); |
| 1510 | inline void SetInternalField(int index, Object* value); |
| 1511 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1512 | // Lookup a property. If found, the result is valid and has |
| 1513 | // detailed information. |
| 1514 | void LocalLookup(String* name, LookupResult* result); |
| 1515 | void Lookup(String* name, LookupResult* result); |
| 1516 | |
| 1517 | // The following lookup functions skip interceptors. |
| 1518 | void LocalLookupRealNamedProperty(String* name, LookupResult* result); |
| 1519 | void LookupRealNamedProperty(String* name, LookupResult* result); |
| 1520 | void LookupRealNamedPropertyInPrototypes(String* name, LookupResult* result); |
| 1521 | void LookupCallbackSetterInPrototypes(String* name, LookupResult* result); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1522 | bool SetElementWithCallbackSetterInPrototypes(uint32_t index, Object* value); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 1523 | void LookupCallback(String* name, LookupResult* result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1524 | |
| 1525 | // Returns the number of properties on this object filtering out properties |
| 1526 | // with the specified attributes (ignoring interceptors). |
| 1527 | int NumberOfLocalProperties(PropertyAttributes filter); |
| 1528 | // Returns the number of enumerable properties (ignoring interceptors). |
| 1529 | int NumberOfEnumProperties(); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 1530 | // Fill in details for properties into storage starting at the specified |
| 1531 | // index. |
| 1532 | void GetLocalPropertyNames(FixedArray* storage, int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1533 | |
| 1534 | // Returns the number of properties on this object filtering out properties |
| 1535 | // with the specified attributes (ignoring interceptors). |
| 1536 | int NumberOfLocalElements(PropertyAttributes filter); |
| 1537 | // Returns the number of enumerable elements (ignoring interceptors). |
| 1538 | int NumberOfEnumElements(); |
| 1539 | // Returns the number of elements on this object filtering out elements |
| 1540 | // with the specified attributes (ignoring interceptors). |
| 1541 | int GetLocalElementKeys(FixedArray* storage, PropertyAttributes filter); |
| 1542 | // Count and fill in the enumerable elements into storage. |
| 1543 | // (storage->length() == NumberOfEnumElements()). |
| 1544 | // If storage is NULL, will count the elements without adding |
| 1545 | // them to any storage. |
| 1546 | // Returns the number of enumerable elements. |
| 1547 | int GetEnumElementKeys(FixedArray* storage); |
| 1548 | |
| 1549 | // Add a property to a fast-case object using a map transition to |
| 1550 | // new_map. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1551 | MUST_USE_RESULT MaybeObject* AddFastPropertyUsingMap(Map* new_map, |
| 1552 | String* name, |
| 1553 | Object* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1554 | |
| 1555 | // 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] | 1556 | // This leaves a CONSTANT_TRANSITION in the old map, and |
| 1557 | // if it is called on a second object with this map, a |
| 1558 | // normal property is added instead, with a map transition. |
| 1559 | // This avoids the creation of many maps with the same constant |
| 1560 | // function, all orphaned. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1561 | MUST_USE_RESULT MaybeObject* AddConstantFunctionProperty( |
| 1562 | String* name, |
| 1563 | JSFunction* function, |
| 1564 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1565 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1566 | MUST_USE_RESULT MaybeObject* ReplaceSlowProperty( |
| 1567 | String* name, |
| 1568 | Object* value, |
| 1569 | PropertyAttributes attributes); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1570 | |
| 1571 | // Converts a descriptor of any other type to a real field, |
| 1572 | // backed by the properties array. Descriptors of visible |
| 1573 | // types, such as CONSTANT_FUNCTION, keep their enumeration order. |
| 1574 | // Converts the descriptor on the original object's map to a |
| 1575 | // 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] | 1576 | MUST_USE_RESULT MaybeObject* ConvertDescriptorToFieldAndMapTransition( |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1577 | String* name, |
| 1578 | Object* new_value, |
| 1579 | PropertyAttributes attributes); |
| 1580 | |
| 1581 | // Converts a descriptor of any other type to a real field, |
| 1582 | // backed by the properties array. Descriptors of visible |
| 1583 | // types, such as CONSTANT_FUNCTION, keep their enumeration order. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1584 | MUST_USE_RESULT MaybeObject* ConvertDescriptorToField( |
| 1585 | String* name, |
| 1586 | Object* new_value, |
| 1587 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1588 | |
| 1589 | // Add a property to a fast-case object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1590 | MUST_USE_RESULT MaybeObject* AddFastProperty(String* name, |
| 1591 | Object* value, |
| 1592 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1593 | |
| 1594 | // Add a property to a slow-case object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1595 | MUST_USE_RESULT MaybeObject* AddSlowProperty(String* name, |
| 1596 | Object* value, |
| 1597 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1598 | |
| 1599 | // Add a property to an object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1600 | MUST_USE_RESULT MaybeObject* AddProperty(String* name, |
| 1601 | Object* value, |
| 1602 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1603 | |
| 1604 | // Convert the object to use the canonical dictionary |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1605 | // representation. If the object is expected to have additional properties |
| 1606 | // added this number can be indicated to have the backing store allocated to |
| 1607 | // an initial capacity for holding these properties. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1608 | MUST_USE_RESULT MaybeObject* NormalizeProperties( |
| 1609 | PropertyNormalizationMode mode, |
| 1610 | int expected_additional_properties); |
| 1611 | MUST_USE_RESULT MaybeObject* NormalizeElements(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1612 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1613 | MUST_USE_RESULT MaybeObject* UpdateMapCodeCache(String* name, Code* code); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1614 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1615 | // Transform slow named properties to fast variants. |
| 1616 | // Returns failure if allocation failed. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1617 | MUST_USE_RESULT MaybeObject* TransformToFastProperties( |
| 1618 | int unused_property_fields); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1619 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1620 | // Access fast-case object properties at index. |
| 1621 | inline Object* FastPropertyAt(int index); |
| 1622 | inline Object* FastPropertyAtPut(int index, Object* value); |
| 1623 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1624 | // Access to in object properties. |
| 1625 | inline Object* InObjectPropertyAt(int index); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1626 | inline Object* InObjectPropertyAtPut(int index, |
| 1627 | Object* value, |
| 1628 | WriteBarrierMode mode |
| 1629 | = UPDATE_WRITE_BARRIER); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1630 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1631 | // initializes the body after properties slot, properties slot is |
| 1632 | // initialized by set_properties |
| 1633 | // Note: this call does not update write barrier, it is caller's |
| 1634 | // reponsibility to ensure that *v* can be collected without WB here. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1635 | inline void InitializeBody(int object_size, Object* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1636 | |
| 1637 | // Check whether this object references another object |
| 1638 | bool ReferencesObject(Object* obj); |
| 1639 | |
| 1640 | // Casting. |
| 1641 | static inline JSObject* cast(Object* obj); |
| 1642 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1643 | // Disalow further properties to be added to the object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1644 | MUST_USE_RESULT MaybeObject* PreventExtensions(); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1645 | |
| 1646 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1647 | // Dispatched behavior. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1648 | void JSObjectShortPrint(StringStream* accumulator); |
| 1649 | #ifdef DEBUG |
| 1650 | void JSObjectPrint(); |
| 1651 | void JSObjectVerify(); |
| 1652 | void PrintProperties(); |
| 1653 | void PrintElements(); |
| 1654 | |
| 1655 | // Structure for collecting spill information about JSObjects. |
| 1656 | class SpillInformation { |
| 1657 | public: |
| 1658 | void Clear(); |
| 1659 | void Print(); |
| 1660 | int number_of_objects_; |
| 1661 | int number_of_objects_with_fast_properties_; |
| 1662 | int number_of_objects_with_fast_elements_; |
| 1663 | int number_of_fast_used_fields_; |
| 1664 | int number_of_fast_unused_fields_; |
| 1665 | int number_of_slow_used_properties_; |
| 1666 | int number_of_slow_unused_properties_; |
| 1667 | int number_of_fast_used_elements_; |
| 1668 | int number_of_fast_unused_elements_; |
| 1669 | int number_of_slow_used_elements_; |
| 1670 | int number_of_slow_unused_elements_; |
| 1671 | }; |
| 1672 | |
| 1673 | void IncrementSpillStatistics(SpillInformation* info); |
| 1674 | #endif |
| 1675 | Object* SlowReverseLookup(Object* value); |
| 1676 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1677 | // Maximal number of fast properties for the JSObject. Used to |
| 1678 | // restrict the number of map transitions to avoid an explosion in |
| 1679 | // the number of maps for objects used as dictionaries. |
| 1680 | inline int MaxFastProperties(); |
| 1681 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 1682 | // Maximal number of elements (numbered 0 .. kMaxElementCount - 1). |
| 1683 | // Also maximal value of JSArray's length property. |
| 1684 | static const uint32_t kMaxElementCount = 0xffffffffu; |
| 1685 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1686 | static const uint32_t kMaxGap = 1024; |
| 1687 | static const int kMaxFastElementsLength = 5000; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1688 | static const int kInitialMaxFastElementArray = 100000; |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1689 | static const int kMaxFastProperties = 8; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1690 | static const int kMaxInstanceSize = 255 * kPointerSize; |
| 1691 | // When extending the backing storage for property values, we increase |
| 1692 | // its size by more than the 1 entry necessary, so sequentially adding fields |
| 1693 | // to the same object requires fewer allocations and copies. |
| 1694 | static const int kFieldsAdded = 3; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1695 | |
| 1696 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1697 | static const int kPropertiesOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1698 | static const int kElementsOffset = kPropertiesOffset + kPointerSize; |
| 1699 | static const int kHeaderSize = kElementsOffset + kPointerSize; |
| 1700 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1701 | STATIC_CHECK(kHeaderSize == Internals::kJSObjectHeaderSize); |
| 1702 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1703 | class BodyDescriptor : public FlexibleBodyDescriptor<kPropertiesOffset> { |
| 1704 | public: |
| 1705 | static inline int SizeOf(Map* map, HeapObject* object); |
| 1706 | }; |
| 1707 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1708 | private: |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1709 | MUST_USE_RESULT MaybeObject* GetElementWithCallback(Object* receiver, |
| 1710 | Object* structure, |
| 1711 | uint32_t index, |
| 1712 | Object* holder); |
| 1713 | MaybeObject* SetElementWithCallback(Object* structure, |
| 1714 | uint32_t index, |
| 1715 | Object* value, |
| 1716 | JSObject* holder); |
| 1717 | MUST_USE_RESULT MaybeObject* SetElementWithInterceptor(uint32_t index, |
| 1718 | Object* value); |
| 1719 | MUST_USE_RESULT MaybeObject* SetElementWithoutInterceptor(uint32_t index, |
| 1720 | Object* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1721 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1722 | MaybeObject* GetElementPostInterceptor(JSObject* receiver, uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1723 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1724 | MUST_USE_RESULT MaybeObject* DeletePropertyPostInterceptor(String* name, |
| 1725 | DeleteMode mode); |
| 1726 | MUST_USE_RESULT MaybeObject* DeletePropertyWithInterceptor(String* name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1727 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1728 | MUST_USE_RESULT MaybeObject* DeleteElementPostInterceptor(uint32_t index, |
| 1729 | DeleteMode mode); |
| 1730 | MUST_USE_RESULT MaybeObject* DeleteElementWithInterceptor(uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1731 | |
| 1732 | PropertyAttributes GetPropertyAttributePostInterceptor(JSObject* receiver, |
| 1733 | String* name, |
| 1734 | bool continue_search); |
| 1735 | PropertyAttributes GetPropertyAttributeWithInterceptor(JSObject* receiver, |
| 1736 | String* name, |
| 1737 | bool continue_search); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 1738 | PropertyAttributes GetPropertyAttributeWithFailedAccessCheck( |
| 1739 | Object* receiver, |
| 1740 | LookupResult* result, |
| 1741 | String* name, |
| 1742 | bool continue_search); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1743 | PropertyAttributes GetPropertyAttribute(JSObject* receiver, |
| 1744 | LookupResult* result, |
| 1745 | String* name, |
| 1746 | bool continue_search); |
| 1747 | |
| 1748 | // Returns true if most of the elements backing storage is used. |
| 1749 | bool HasDenseElements(); |
| 1750 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1751 | bool CanSetCallback(String* name); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1752 | MUST_USE_RESULT MaybeObject* SetElementCallback( |
| 1753 | uint32_t index, |
| 1754 | Object* structure, |
| 1755 | PropertyAttributes attributes); |
| 1756 | MUST_USE_RESULT MaybeObject* SetPropertyCallback( |
| 1757 | String* name, |
| 1758 | Object* structure, |
| 1759 | PropertyAttributes attributes); |
| 1760 | MUST_USE_RESULT MaybeObject* DefineGetterSetter( |
| 1761 | String* name, |
| 1762 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1763 | |
| 1764 | void LookupInDescriptor(String* name, LookupResult* result); |
| 1765 | |
| 1766 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject); |
| 1767 | }; |
| 1768 | |
| 1769 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1770 | // FixedArray describes fixed-sized arrays with element type Object*. |
| 1771 | class FixedArray: public HeapObject { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1772 | public: |
| 1773 | // [length]: length of the array. |
| 1774 | inline int length(); |
| 1775 | inline void set_length(int value); |
| 1776 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1777 | // Setter and getter for elements. |
| 1778 | inline Object* get(int index); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1779 | // Setter that uses write barrier. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1780 | inline void set(int index, Object* value); |
| 1781 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1782 | // Setter that doesn't need write barrier). |
| 1783 | inline void set(int index, Smi* value); |
| 1784 | // Setter with explicit barrier mode. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1785 | inline void set(int index, Object* value, WriteBarrierMode mode); |
| 1786 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1787 | // Setters for frequently used oddballs located in old space. |
| 1788 | inline void set_undefined(int index); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1789 | inline void set_null(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1790 | inline void set_the_hole(int index); |
| 1791 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1792 | // Setters with less debug checks for the GC to use. |
| 1793 | inline void set_unchecked(int index, Smi* value); |
| 1794 | inline void set_null_unchecked(int index); |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1795 | inline void set_unchecked(int index, Object* value, WriteBarrierMode mode); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1796 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1797 | // Gives access to raw memory which stores the array's data. |
| 1798 | inline Object** data_start(); |
| 1799 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1800 | // Copy operations. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1801 | MUST_USE_RESULT inline MaybeObject* Copy(); |
| 1802 | MUST_USE_RESULT MaybeObject* CopySize(int new_length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1803 | |
| 1804 | // Add the elements of a JSArray to this FixedArray. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1805 | MUST_USE_RESULT MaybeObject* AddKeysFromJSArray(JSArray* array); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1806 | |
| 1807 | // Compute the union of this and other. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1808 | MUST_USE_RESULT MaybeObject* UnionOfKeys(FixedArray* other); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1809 | |
| 1810 | // Copy a sub array from the receiver to dest. |
| 1811 | void CopyTo(int pos, FixedArray* dest, int dest_pos, int len); |
| 1812 | |
| 1813 | // Garbage collection support. |
| 1814 | static int SizeFor(int length) { return kHeaderSize + length * kPointerSize; } |
| 1815 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1816 | // Code Generation support. |
| 1817 | static int OffsetOfElementAt(int index) { return SizeFor(index); } |
| 1818 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1819 | // Casting. |
| 1820 | static inline FixedArray* cast(Object* obj); |
| 1821 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1822 | // Layout description. |
| 1823 | // Length is smi tagged when it is stored. |
| 1824 | static const int kLengthOffset = HeapObject::kHeaderSize; |
| 1825 | static const int kHeaderSize = kLengthOffset + kPointerSize; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 1826 | |
| 1827 | // Maximal allowed size, in bytes, of a single FixedArray. |
| 1828 | // Prevents overflowing size computations, as well as extreme memory |
| 1829 | // consumption. |
| 1830 | static const int kMaxSize = 512 * MB; |
| 1831 | // Maximally allowed length of a FixedArray. |
| 1832 | static const int kMaxLength = (kMaxSize - kHeaderSize) / kPointerSize; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1833 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1834 | // Dispatched behavior. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1835 | #ifdef DEBUG |
| 1836 | void FixedArrayPrint(); |
| 1837 | void FixedArrayVerify(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1838 | // Checks if two FixedArrays have identical contents. |
| 1839 | bool IsEqualTo(FixedArray* other); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1840 | #endif |
| 1841 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1842 | // Swap two elements in a pair of arrays. If this array and the |
| 1843 | // numbers array are the same object, the elements are only swapped |
| 1844 | // once. |
| 1845 | void SwapPairs(FixedArray* numbers, int i, int j); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1846 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1847 | // Sort prefix of this array and the numbers array as pairs wrt. the |
| 1848 | // numbers. If the numbers array and the this array are the same |
| 1849 | // object, the prefix of this array is sorted. |
| 1850 | void SortPairs(FixedArray* numbers, uint32_t len); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1851 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1852 | class BodyDescriptor : public FlexibleBodyDescriptor<kHeaderSize> { |
| 1853 | public: |
| 1854 | static inline int SizeOf(Map* map, HeapObject* object) { |
| 1855 | return SizeFor(reinterpret_cast<FixedArray*>(object)->length()); |
| 1856 | } |
| 1857 | }; |
| 1858 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1859 | protected: |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1860 | // Set operation on FixedArray without using write barriers. Can |
| 1861 | // only be used for storing old space objects or smis. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1862 | static inline void fast_set(FixedArray* array, int index, Object* value); |
| 1863 | |
| 1864 | private: |
| 1865 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedArray); |
| 1866 | }; |
| 1867 | |
| 1868 | |
| 1869 | // DescriptorArrays are fixed arrays used to hold instance descriptors. |
| 1870 | // The format of the these objects is: |
| 1871 | // [0]: point to a fixed array with (value, detail) pairs. |
| 1872 | // [1]: next enumeration index (Smi), or pointer to small fixed array: |
| 1873 | // [0]: next enumeration index (Smi) |
| 1874 | // [1]: pointer to fixed array with enum cache |
| 1875 | // [2]: first key |
| 1876 | // [length() - 1]: last key |
| 1877 | // |
| 1878 | class DescriptorArray: public FixedArray { |
| 1879 | public: |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1880 | // Is this the singleton empty_descriptor_array? |
| 1881 | inline bool IsEmpty(); |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 1882 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1883 | // Returns the number of descriptors in the array. |
| 1884 | int number_of_descriptors() { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1885 | return IsEmpty() ? 0 : length() - kFirstIndex; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1886 | } |
| 1887 | |
| 1888 | int NextEnumerationIndex() { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1889 | if (IsEmpty()) return PropertyDetails::kInitialIndex; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1890 | Object* obj = get(kEnumerationIndexIndex); |
| 1891 | if (obj->IsSmi()) { |
| 1892 | return Smi::cast(obj)->value(); |
| 1893 | } else { |
| 1894 | Object* index = FixedArray::cast(obj)->get(kEnumCacheBridgeEnumIndex); |
| 1895 | return Smi::cast(index)->value(); |
| 1896 | } |
| 1897 | } |
| 1898 | |
| 1899 | // Set next enumeration index and flush any enum cache. |
| 1900 | void SetNextEnumerationIndex(int value) { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1901 | if (!IsEmpty()) { |
| 1902 | fast_set(this, kEnumerationIndexIndex, Smi::FromInt(value)); |
| 1903 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1904 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1905 | bool HasEnumCache() { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1906 | return !IsEmpty() && !get(kEnumerationIndexIndex)->IsSmi(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1907 | } |
| 1908 | |
| 1909 | Object* GetEnumCache() { |
| 1910 | ASSERT(HasEnumCache()); |
| 1911 | FixedArray* bridge = FixedArray::cast(get(kEnumerationIndexIndex)); |
| 1912 | return bridge->get(kEnumCacheBridgeCacheIndex); |
| 1913 | } |
| 1914 | |
| 1915 | // Initialize or change the enum cache, |
| 1916 | // using the supplied storage for the small "bridge". |
| 1917 | void SetEnumCache(FixedArray* bridge_storage, FixedArray* new_cache); |
| 1918 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1919 | // Accessors for fetching instance descriptor at descriptor number. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1920 | inline String* GetKey(int descriptor_number); |
| 1921 | inline Object* GetValue(int descriptor_number); |
| 1922 | inline Smi* GetDetails(int descriptor_number); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1923 | inline PropertyType GetType(int descriptor_number); |
| 1924 | inline int GetFieldIndex(int descriptor_number); |
| 1925 | inline JSFunction* GetConstantFunction(int descriptor_number); |
| 1926 | inline Object* GetCallbacksObject(int descriptor_number); |
| 1927 | inline AccessorDescriptor* GetCallbacks(int descriptor_number); |
| 1928 | inline bool IsProperty(int descriptor_number); |
| 1929 | inline bool IsTransition(int descriptor_number); |
| 1930 | inline bool IsNullDescriptor(int descriptor_number); |
| 1931 | inline bool IsDontEnum(int descriptor_number); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1932 | |
| 1933 | // Accessor for complete descriptor. |
| 1934 | inline void Get(int descriptor_number, Descriptor* desc); |
| 1935 | inline void Set(int descriptor_number, Descriptor* desc); |
| 1936 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1937 | // Transfer complete descriptor from another descriptor array to |
| 1938 | // this one. |
| 1939 | inline void CopyFrom(int index, DescriptorArray* src, int src_index); |
| 1940 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1941 | // 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] | 1942 | // remove map transitions. If the descriptor is already present, it is |
| 1943 | // replaced. If a replaced descriptor is a real property (not a transition |
| 1944 | // or null), its enumeration index is kept as is. |
| 1945 | // If adding a real property, map transitions must be removed. If adding |
| 1946 | // 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] | 1947 | MUST_USE_RESULT MaybeObject* CopyInsert(Descriptor* descriptor, |
| 1948 | TransitionFlag transition_flag); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1949 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1950 | // Remove all transitions. Return a copy of the array with all transitions |
| 1951 | // 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] | 1952 | MUST_USE_RESULT MaybeObject* RemoveTransitions(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1953 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1954 | // Sort the instance descriptors by the hash codes of their keys. |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1955 | // Does not check for duplicates. |
| 1956 | void SortUnchecked(); |
| 1957 | |
| 1958 | // Sort the instance descriptors by the hash codes of their keys. |
| 1959 | // Checks the result for duplicates. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1960 | void Sort(); |
| 1961 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1962 | // Search the instance descriptors for given name. |
| 1963 | inline int Search(String* name); |
| 1964 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1965 | // As the above, but uses DescriptorLookupCache and updates it when |
| 1966 | // necessary. |
| 1967 | inline int SearchWithCache(String* name); |
| 1968 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1969 | // Tells whether the name is present int the array. |
| 1970 | bool Contains(String* name) { return kNotFound != Search(name); } |
| 1971 | |
| 1972 | // Perform a binary search in the instance descriptors represented |
| 1973 | // by this fixed array. low and high are descriptor indices. If there |
| 1974 | // are three instance descriptors in this array it should be called |
| 1975 | // with low=0 and high=2. |
| 1976 | int BinarySearch(String* name, int low, int high); |
| 1977 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1978 | // Perform a linear search in the instance descriptors represented |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1979 | // 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] | 1980 | // valid. Does not require the descriptors to be sorted. |
| 1981 | int LinearSearch(String* name, int len); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1982 | |
| 1983 | // Allocates a DescriptorArray, but returns the singleton |
| 1984 | // empty descriptor array object if number_of_descriptors is 0. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1985 | MUST_USE_RESULT static MaybeObject* Allocate(int number_of_descriptors); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1986 | |
| 1987 | // Casting. |
| 1988 | static inline DescriptorArray* cast(Object* obj); |
| 1989 | |
| 1990 | // Constant for denoting key was not found. |
| 1991 | static const int kNotFound = -1; |
| 1992 | |
| 1993 | static const int kContentArrayIndex = 0; |
| 1994 | static const int kEnumerationIndexIndex = 1; |
| 1995 | static const int kFirstIndex = 2; |
| 1996 | |
| 1997 | // The length of the "bridge" to the enum cache. |
| 1998 | static const int kEnumCacheBridgeLength = 2; |
| 1999 | static const int kEnumCacheBridgeEnumIndex = 0; |
| 2000 | static const int kEnumCacheBridgeCacheIndex = 1; |
| 2001 | |
| 2002 | // Layout description. |
| 2003 | static const int kContentArrayOffset = FixedArray::kHeaderSize; |
| 2004 | static const int kEnumerationIndexOffset = kContentArrayOffset + kPointerSize; |
| 2005 | static const int kFirstOffset = kEnumerationIndexOffset + kPointerSize; |
| 2006 | |
| 2007 | // Layout description for the bridge array. |
| 2008 | static const int kEnumCacheBridgeEnumOffset = FixedArray::kHeaderSize; |
| 2009 | static const int kEnumCacheBridgeCacheOffset = |
| 2010 | kEnumCacheBridgeEnumOffset + kPointerSize; |
| 2011 | |
| 2012 | #ifdef DEBUG |
| 2013 | // Print all the descriptors. |
| 2014 | void PrintDescriptors(); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 2015 | |
| 2016 | // Is the descriptor array sorted and without duplicates? |
| 2017 | bool IsSortedNoDuplicates(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2018 | |
| 2019 | // Are two DescriptorArrays equal? |
| 2020 | bool IsEqualTo(DescriptorArray* other); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2021 | #endif |
| 2022 | |
| 2023 | // The maximum number of descriptors we want in a descriptor array (should |
| 2024 | // fit in a page). |
| 2025 | static const int kMaxNumberOfDescriptors = 1024 + 512; |
| 2026 | |
| 2027 | private: |
| 2028 | // Conversion from descriptor number to array indices. |
| 2029 | static int ToKeyIndex(int descriptor_number) { |
| 2030 | return descriptor_number+kFirstIndex; |
| 2031 | } |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 2032 | |
| 2033 | static int ToDetailsIndex(int descriptor_number) { |
| 2034 | return (descriptor_number << 1) + 1; |
| 2035 | } |
| 2036 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2037 | static int ToValueIndex(int descriptor_number) { |
| 2038 | return descriptor_number << 1; |
| 2039 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2040 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2041 | bool is_null_descriptor(int descriptor_number) { |
| 2042 | return PropertyDetails(GetDetails(descriptor_number)).type() == |
| 2043 | NULL_DESCRIPTOR; |
| 2044 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2045 | // Swap operation on FixedArray without using write barriers. |
| 2046 | static inline void fast_swap(FixedArray* array, int first, int second); |
| 2047 | |
| 2048 | // Swap descriptor first and second. |
| 2049 | inline void Swap(int first, int second); |
| 2050 | |
| 2051 | FixedArray* GetContentArray() { |
| 2052 | return FixedArray::cast(get(kContentArrayIndex)); |
| 2053 | } |
| 2054 | DISALLOW_IMPLICIT_CONSTRUCTORS(DescriptorArray); |
| 2055 | }; |
| 2056 | |
| 2057 | |
| 2058 | // HashTable is a subclass of FixedArray that implements a hash table |
| 2059 | // that uses open addressing and quadratic probing. |
| 2060 | // |
| 2061 | // In order for the quadratic probing to work, elements that have not |
| 2062 | // yet been used and elements that have been deleted are |
| 2063 | // distinguished. Probing continues when deleted elements are |
| 2064 | // encountered and stops when unused elements are encountered. |
| 2065 | // |
| 2066 | // - Elements with key == undefined have not been used yet. |
| 2067 | // - Elements with key == null have been deleted. |
| 2068 | // |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2069 | // The hash table class is parameterized with a Shape and a Key. |
| 2070 | // Shape must be a class with the following interface: |
| 2071 | // class ExampleShape { |
| 2072 | // public: |
| 2073 | // // Tells whether key matches other. |
| 2074 | // static bool IsMatch(Key key, Object* other); |
| 2075 | // // Returns the hash value for key. |
| 2076 | // static uint32_t Hash(Key key); |
| 2077 | // // Returns the hash value for object. |
| 2078 | // static uint32_t HashForObject(Key key, Object* object); |
| 2079 | // // Convert key to an object. |
| 2080 | // static inline Object* AsObject(Key key); |
| 2081 | // // The prefix size indicates number of elements in the beginning |
| 2082 | // // of the backing storage. |
| 2083 | // static const int kPrefixSize = ..; |
| 2084 | // // The Element size indicates number of elements per entry. |
| 2085 | // static const int kEntrySize = ..; |
| 2086 | // }; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2087 | // The prefix size indicates an amount of memory in the |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2088 | // beginning of the backing storage that can be used for non-element |
| 2089 | // information by subclasses. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2090 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2091 | template<typename Shape, typename Key> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2092 | class HashTable: public FixedArray { |
| 2093 | public: |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2094 | // Returns the number of elements in the hash table. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2095 | int NumberOfElements() { |
| 2096 | return Smi::cast(get(kNumberOfElementsIndex))->value(); |
| 2097 | } |
| 2098 | |
kasperl@chromium.org | edf0cd1 | 2010-01-05 13:29:12 +0000 | [diff] [blame] | 2099 | // Returns the number of deleted elements in the hash table. |
| 2100 | int NumberOfDeletedElements() { |
| 2101 | return Smi::cast(get(kNumberOfDeletedElementsIndex))->value(); |
| 2102 | } |
| 2103 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2104 | // Returns the capacity of the hash table. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2105 | int Capacity() { |
| 2106 | return Smi::cast(get(kCapacityIndex))->value(); |
| 2107 | } |
| 2108 | |
| 2109 | // 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] | 2110 | // hash table. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2111 | void ElementAdded() { SetNumberOfElements(NumberOfElements() + 1); } |
| 2112 | |
| 2113 | // 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] | 2114 | // a hash table. |
kasperl@chromium.org | edf0cd1 | 2010-01-05 13:29:12 +0000 | [diff] [blame] | 2115 | void ElementRemoved() { |
| 2116 | SetNumberOfElements(NumberOfElements() - 1); |
| 2117 | SetNumberOfDeletedElements(NumberOfDeletedElements() + 1); |
| 2118 | } |
| 2119 | void ElementsRemoved(int n) { |
| 2120 | SetNumberOfElements(NumberOfElements() - n); |
| 2121 | SetNumberOfDeletedElements(NumberOfDeletedElements() + n); |
| 2122 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2123 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2124 | // Returns a new HashTable object. Might return Failure. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2125 | MUST_USE_RESULT static MaybeObject* Allocate( |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2126 | int at_least_space_for, |
| 2127 | PretenureFlag pretenure = NOT_TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2128 | |
| 2129 | // Returns the key at entry. |
| 2130 | Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } |
| 2131 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2132 | // 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] | 2133 | // as keys and can be used to indicate missing or deleted elements. |
| 2134 | bool IsKey(Object* k) { |
| 2135 | return !k->IsNull() && !k->IsUndefined(); |
| 2136 | } |
| 2137 | |
| 2138 | // Garbage collection support. |
| 2139 | void IteratePrefix(ObjectVisitor* visitor); |
| 2140 | void IterateElements(ObjectVisitor* visitor); |
| 2141 | |
| 2142 | // Casting. |
| 2143 | static inline HashTable* cast(Object* obj); |
| 2144 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2145 | // Compute the probe offset (quadratic probing). |
| 2146 | INLINE(static uint32_t GetProbeOffset(uint32_t n)) { |
| 2147 | return (n + n * n) >> 1; |
| 2148 | } |
| 2149 | |
| 2150 | static const int kNumberOfElementsIndex = 0; |
kasperl@chromium.org | edf0cd1 | 2010-01-05 13:29:12 +0000 | [diff] [blame] | 2151 | static const int kNumberOfDeletedElementsIndex = 1; |
| 2152 | static const int kCapacityIndex = 2; |
| 2153 | static const int kPrefixStartIndex = 3; |
| 2154 | static const int kElementsStartIndex = |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2155 | kPrefixStartIndex + Shape::kPrefixSize; |
kasperl@chromium.org | edf0cd1 | 2010-01-05 13:29:12 +0000 | [diff] [blame] | 2156 | static const int kEntrySize = Shape::kEntrySize; |
| 2157 | static const int kElementsStartOffset = |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2158 | kHeaderSize + kElementsStartIndex * kPointerSize; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2159 | static const int kCapacityOffset = |
| 2160 | kHeaderSize + kCapacityIndex * kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2161 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2162 | // Constant used for denoting a absent entry. |
| 2163 | static const int kNotFound = -1; |
| 2164 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2165 | // Maximal capacity of HashTable. Based on maximal length of underlying |
| 2166 | // FixedArray. Staying below kMaxCapacity also ensures that EntryToIndex |
| 2167 | // cannot overflow. |
| 2168 | static const int kMaxCapacity = |
| 2169 | (FixedArray::kMaxLength - kElementsStartOffset) / kEntrySize; |
| 2170 | |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2171 | // Find entry for key otherwise return kNotFound. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2172 | int FindEntry(Key key); |
| 2173 | |
| 2174 | protected: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2175 | |
| 2176 | // Find the entry at which to insert element with the given key that |
| 2177 | // has the given hash value. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2178 | uint32_t FindInsertionEntry(uint32_t hash); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2179 | |
| 2180 | // Returns the index for an entry (of the key) |
| 2181 | static inline int EntryToIndex(int entry) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2182 | return (entry * kEntrySize) + kElementsStartIndex; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2183 | } |
| 2184 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2185 | // Update the number of elements in the hash table. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2186 | void SetNumberOfElements(int nof) { |
| 2187 | fast_set(this, kNumberOfElementsIndex, Smi::FromInt(nof)); |
| 2188 | } |
| 2189 | |
kasperl@chromium.org | edf0cd1 | 2010-01-05 13:29:12 +0000 | [diff] [blame] | 2190 | // Update the number of deleted elements in the hash table. |
| 2191 | void SetNumberOfDeletedElements(int nod) { |
| 2192 | fast_set(this, kNumberOfDeletedElementsIndex, Smi::FromInt(nod)); |
| 2193 | } |
| 2194 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2195 | // Sets the capacity of the hash table. |
| 2196 | void SetCapacity(int capacity) { |
| 2197 | // To scale a computed hash code to fit within the hash table, we |
| 2198 | // use bit-wise AND with a mask, so the capacity must be positive |
| 2199 | // and non-zero. |
| 2200 | ASSERT(capacity > 0); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2201 | ASSERT(capacity <= kMaxCapacity); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2202 | fast_set(this, kCapacityIndex, Smi::FromInt(capacity)); |
| 2203 | } |
| 2204 | |
| 2205 | |
| 2206 | // Returns probe entry. |
| 2207 | static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size) { |
| 2208 | ASSERT(IsPowerOf2(size)); |
| 2209 | return (hash + GetProbeOffset(number)) & (size - 1); |
| 2210 | } |
| 2211 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2212 | static uint32_t FirstProbe(uint32_t hash, uint32_t size) { |
| 2213 | return hash & (size - 1); |
| 2214 | } |
| 2215 | |
| 2216 | static uint32_t NextProbe(uint32_t last, uint32_t number, uint32_t size) { |
| 2217 | return (last + number) & (size - 1); |
| 2218 | } |
| 2219 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2220 | // Ensure enough space for n additional elements. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2221 | MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2222 | }; |
| 2223 | |
| 2224 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2225 | |
| 2226 | // HashTableKey is an abstract superclass for virtual key behavior. |
| 2227 | class HashTableKey { |
| 2228 | public: |
| 2229 | // Returns whether the other object matches this key. |
| 2230 | virtual bool IsMatch(Object* other) = 0; |
| 2231 | // Returns the hash value for this key. |
| 2232 | virtual uint32_t Hash() = 0; |
| 2233 | // Returns the hash value for object. |
| 2234 | virtual uint32_t HashForObject(Object* key) = 0; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2235 | // Returns the key object for storing into the hash table. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2236 | // If allocations fails a failure object is returned. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2237 | MUST_USE_RESULT virtual MaybeObject* AsObject() = 0; |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2238 | // Required. |
| 2239 | virtual ~HashTableKey() {} |
| 2240 | }; |
| 2241 | |
| 2242 | class SymbolTableShape { |
| 2243 | public: |
| 2244 | static bool IsMatch(HashTableKey* key, Object* value) { |
| 2245 | return key->IsMatch(value); |
| 2246 | } |
| 2247 | static uint32_t Hash(HashTableKey* key) { |
| 2248 | return key->Hash(); |
| 2249 | } |
| 2250 | static uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 2251 | return key->HashForObject(object); |
| 2252 | } |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2253 | MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2254 | return key->AsObject(); |
| 2255 | } |
| 2256 | |
| 2257 | static const int kPrefixSize = 0; |
| 2258 | static const int kEntrySize = 1; |
| 2259 | }; |
| 2260 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2261 | // SymbolTable. |
| 2262 | // |
| 2263 | // No special elements in the prefix and the element size is 1 |
| 2264 | // because only the symbol itself (the key) needs to be stored. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2265 | class SymbolTable: public HashTable<SymbolTableShape, HashTableKey*> { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2266 | public: |
| 2267 | // Find symbol in the symbol table. If it is not there yet, it is |
| 2268 | // added. The return value is the symbol table which might have |
| 2269 | // been enlarged. If the return value is not a failure, the symbol |
| 2270 | // pointer *s is set to the symbol found. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2271 | MUST_USE_RESULT MaybeObject* LookupSymbol(Vector<const char> str, Object** s); |
| 2272 | MUST_USE_RESULT MaybeObject* LookupString(String* key, Object** s); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2273 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2274 | // Looks up a symbol that is equal to the given string and returns |
| 2275 | // true if it is found, assigning the symbol to the given output |
| 2276 | // parameter. |
| 2277 | bool LookupSymbolIfExists(String* str, String** symbol); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 2278 | bool LookupTwoCharsSymbolIfExists(uint32_t c1, uint32_t c2, String** symbol); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2279 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2280 | // Casting. |
| 2281 | static inline SymbolTable* cast(Object* obj); |
| 2282 | |
| 2283 | private: |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2284 | MUST_USE_RESULT MaybeObject* LookupKey(HashTableKey* key, Object** s); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2285 | |
| 2286 | DISALLOW_IMPLICIT_CONSTRUCTORS(SymbolTable); |
| 2287 | }; |
| 2288 | |
| 2289 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2290 | class MapCacheShape { |
| 2291 | public: |
| 2292 | static bool IsMatch(HashTableKey* key, Object* value) { |
| 2293 | return key->IsMatch(value); |
| 2294 | } |
| 2295 | static uint32_t Hash(HashTableKey* key) { |
| 2296 | return key->Hash(); |
| 2297 | } |
| 2298 | |
| 2299 | static uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 2300 | return key->HashForObject(object); |
| 2301 | } |
| 2302 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2303 | MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2304 | return key->AsObject(); |
| 2305 | } |
| 2306 | |
| 2307 | static const int kPrefixSize = 0; |
| 2308 | static const int kEntrySize = 2; |
| 2309 | }; |
| 2310 | |
| 2311 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2312 | // MapCache. |
| 2313 | // |
| 2314 | // Maps keys that are a fixed array of symbols to a map. |
| 2315 | // Used for canonicalize maps for object literals. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2316 | class MapCache: public HashTable<MapCacheShape, HashTableKey*> { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2317 | public: |
| 2318 | // Find cached value for a string key, otherwise return null. |
| 2319 | Object* Lookup(FixedArray* key); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2320 | MUST_USE_RESULT MaybeObject* Put(FixedArray* key, Map* value); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2321 | static inline MapCache* cast(Object* obj); |
| 2322 | |
| 2323 | private: |
| 2324 | DISALLOW_IMPLICIT_CONSTRUCTORS(MapCache); |
| 2325 | }; |
| 2326 | |
| 2327 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2328 | template <typename Shape, typename Key> |
| 2329 | class Dictionary: public HashTable<Shape, Key> { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2330 | public: |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2331 | |
| 2332 | static inline Dictionary<Shape, Key>* cast(Object* obj) { |
| 2333 | return reinterpret_cast<Dictionary<Shape, Key>*>(obj); |
| 2334 | } |
| 2335 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2336 | // Returns the value at entry. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2337 | Object* ValueAt(int entry) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 2338 | return this->get(HashTable<Shape, Key>::EntryToIndex(entry)+1); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2339 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2340 | |
| 2341 | // Set the value for entry. |
| 2342 | void ValueAtPut(int entry, Object* value) { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2343 | // Check that this value can actually be written. |
| 2344 | PropertyDetails details = DetailsAt(entry); |
| 2345 | // If a value has not been initilized we allow writing to it even if |
| 2346 | // it is read only (a declared const that has not been initialized). |
| 2347 | if (details.IsReadOnly() && !ValueAt(entry)->IsTheHole()) return; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 2348 | this->set(HashTable<Shape, Key>::EntryToIndex(entry)+1, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2349 | } |
| 2350 | |
| 2351 | // Returns the property details for the property at entry. |
| 2352 | PropertyDetails DetailsAt(int entry) { |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 2353 | 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] | 2354 | return PropertyDetails( |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 2355 | Smi::cast(this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 2))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2356 | } |
| 2357 | |
| 2358 | // Set the details for entry. |
| 2359 | void DetailsAtPut(int entry, PropertyDetails value) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 2360 | this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 2, value.AsSmi()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2361 | } |
| 2362 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2363 | // Sorting support |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2364 | void CopyValuesTo(FixedArray* elements); |
| 2365 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2366 | // Delete a property from the dictionary. |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2367 | Object* DeleteProperty(int entry, JSObject::DeleteMode mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2368 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2369 | // Returns the number of elements in the dictionary filtering out properties |
| 2370 | // with the specified attributes. |
| 2371 | int NumberOfElementsFilterAttributes(PropertyAttributes filter); |
| 2372 | |
| 2373 | // Returns the number of enumerable elements in the dictionary. |
| 2374 | int NumberOfEnumElements(); |
| 2375 | |
| 2376 | // Copies keys to preallocated fixed array. |
| 2377 | void CopyKeysTo(FixedArray* storage, PropertyAttributes filter); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2378 | // Fill in details for properties into storage. |
| 2379 | void CopyKeysTo(FixedArray* storage); |
| 2380 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2381 | // Accessors for next enumeration index. |
| 2382 | void SetNextEnumerationIndex(int index) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 2383 | this->fast_set(this, kNextEnumerationIndexIndex, Smi::FromInt(index)); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2384 | } |
| 2385 | |
| 2386 | int NextEnumerationIndex() { |
| 2387 | return Smi::cast(FixedArray::get(kNextEnumerationIndexIndex))->value(); |
| 2388 | } |
| 2389 | |
| 2390 | // Returns a new array for dictionary usage. Might return Failure. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2391 | MUST_USE_RESULT static MaybeObject* Allocate(int at_least_space_for); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2392 | |
| 2393 | // Ensure enough space for n additional elements. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2394 | MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2395 | |
| 2396 | #ifdef DEBUG |
| 2397 | void Print(); |
| 2398 | #endif |
| 2399 | // Returns the key (slow). |
| 2400 | Object* SlowReverseLookup(Object* value); |
| 2401 | |
| 2402 | // Sets the entry to (key, value) pair. |
| 2403 | inline void SetEntry(int entry, |
| 2404 | Object* key, |
| 2405 | Object* value, |
| 2406 | PropertyDetails details); |
| 2407 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2408 | MUST_USE_RESULT MaybeObject* Add(Key key, |
| 2409 | Object* value, |
| 2410 | PropertyDetails details); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2411 | |
| 2412 | protected: |
| 2413 | // Generic at put operation. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2414 | MUST_USE_RESULT MaybeObject* AtPut(Key key, Object* value); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2415 | |
| 2416 | // Add entry to dictionary. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2417 | MUST_USE_RESULT MaybeObject* AddEntry(Key key, |
| 2418 | Object* value, |
| 2419 | PropertyDetails details, |
| 2420 | uint32_t hash); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2421 | |
| 2422 | // Generate new enumeration indices to avoid enumeration index overflow. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2423 | MUST_USE_RESULT MaybeObject* GenerateNewEnumerationIndices(); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2424 | static const int kMaxNumberKeyIndex = |
| 2425 | HashTable<Shape, Key>::kPrefixStartIndex; |
| 2426 | static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1; |
| 2427 | }; |
| 2428 | |
| 2429 | |
| 2430 | class StringDictionaryShape { |
| 2431 | public: |
| 2432 | static inline bool IsMatch(String* key, Object* other); |
| 2433 | static inline uint32_t Hash(String* key); |
| 2434 | static inline uint32_t HashForObject(String* key, Object* object); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2435 | MUST_USE_RESULT static inline MaybeObject* AsObject(String* key); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2436 | static const int kPrefixSize = 2; |
| 2437 | static const int kEntrySize = 3; |
| 2438 | static const bool kIsEnumerable = true; |
| 2439 | }; |
| 2440 | |
| 2441 | |
| 2442 | class StringDictionary: public Dictionary<StringDictionaryShape, String*> { |
| 2443 | public: |
| 2444 | static inline StringDictionary* cast(Object* obj) { |
| 2445 | ASSERT(obj->IsDictionary()); |
| 2446 | return reinterpret_cast<StringDictionary*>(obj); |
| 2447 | } |
| 2448 | |
| 2449 | // Copies enumerable keys to preallocated fixed array. |
| 2450 | void CopyEnumKeysTo(FixedArray* storage, FixedArray* sort_array); |
| 2451 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2452 | // For transforming properties of a JSObject. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2453 | MUST_USE_RESULT MaybeObject* TransformPropertiesToFastFor( |
| 2454 | JSObject* obj, |
| 2455 | int unused_property_fields); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2456 | |
| 2457 | // Find entry for key otherwise return kNotFound. Optimzed version of |
| 2458 | // HashTable::FindEntry. |
| 2459 | int FindEntry(String* key); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2460 | }; |
| 2461 | |
| 2462 | |
| 2463 | class NumberDictionaryShape { |
| 2464 | public: |
| 2465 | static inline bool IsMatch(uint32_t key, Object* other); |
| 2466 | static inline uint32_t Hash(uint32_t key); |
| 2467 | static inline uint32_t HashForObject(uint32_t key, Object* object); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2468 | MUST_USE_RESULT static inline MaybeObject* AsObject(uint32_t key); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2469 | static const int kPrefixSize = 2; |
| 2470 | static const int kEntrySize = 3; |
| 2471 | static const bool kIsEnumerable = false; |
| 2472 | }; |
| 2473 | |
| 2474 | |
| 2475 | class NumberDictionary: public Dictionary<NumberDictionaryShape, uint32_t> { |
| 2476 | public: |
| 2477 | static NumberDictionary* cast(Object* obj) { |
| 2478 | ASSERT(obj->IsDictionary()); |
| 2479 | return reinterpret_cast<NumberDictionary*>(obj); |
| 2480 | } |
| 2481 | |
| 2482 | // Type specific at put (default NONE attributes is used when adding). |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2483 | MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value); |
| 2484 | MUST_USE_RESULT MaybeObject* AddNumberEntry(uint32_t key, |
| 2485 | Object* value, |
| 2486 | PropertyDetails details); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2487 | |
| 2488 | // Set an existing entry or add a new one if needed. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2489 | MUST_USE_RESULT MaybeObject* Set(uint32_t key, |
| 2490 | Object* value, |
| 2491 | PropertyDetails details); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2492 | |
| 2493 | void UpdateMaxNumberKey(uint32_t key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2494 | |
| 2495 | // If slow elements are required we will never go back to fast-case |
| 2496 | // for the elements kept in this dictionary. We require slow |
| 2497 | // 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] | 2498 | // kRequiresSlowElementsLimit or set_requires_slow_elements() has been called |
| 2499 | // when defining a getter or setter with a number key. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2500 | inline bool requires_slow_elements(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2501 | inline void set_requires_slow_elements(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2502 | |
| 2503 | // Get the value of the max number key that has been added to this |
| 2504 | // dictionary. max_number_key can only be called if |
| 2505 | // requires_slow_elements returns false. |
| 2506 | inline uint32_t max_number_key(); |
| 2507 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2508 | // Remove all entries were key is a number and (from <= key && key < to). |
| 2509 | void RemoveNumberEntries(uint32_t from, uint32_t to); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2510 | |
| 2511 | // Bit masks. |
| 2512 | static const int kRequiresSlowElementsMask = 1; |
| 2513 | static const int kRequiresSlowElementsTagSize = 1; |
| 2514 | static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2515 | }; |
| 2516 | |
| 2517 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2518 | // JSFunctionResultCache caches results of some JSFunction invocation. |
| 2519 | // It is a fixed array with fixed structure: |
| 2520 | // [0]: factory function |
| 2521 | // [1]: finger index |
| 2522 | // [2]: current cache size |
| 2523 | // [3]: dummy field. |
| 2524 | // The rest of array are key/value pairs. |
| 2525 | class JSFunctionResultCache: public FixedArray { |
| 2526 | public: |
| 2527 | static const int kFactoryIndex = 0; |
| 2528 | static const int kFingerIndex = kFactoryIndex + 1; |
| 2529 | static const int kCacheSizeIndex = kFingerIndex + 1; |
| 2530 | static const int kDummyIndex = kCacheSizeIndex + 1; |
| 2531 | static const int kEntriesIndex = kDummyIndex + 1; |
antonm@chromium.org | 397e23c | 2010-04-21 12:00:05 +0000 | [diff] [blame] | 2532 | |
| 2533 | static const int kEntrySize = 2; // key + value |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2534 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2535 | static const int kFactoryOffset = kHeaderSize; |
| 2536 | static const int kFingerOffset = kFactoryOffset + kPointerSize; |
| 2537 | static const int kCacheSizeOffset = kFingerOffset + kPointerSize; |
| 2538 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2539 | inline void MakeZeroSize(); |
| 2540 | inline void Clear(); |
| 2541 | |
| 2542 | // Casting |
| 2543 | static inline JSFunctionResultCache* cast(Object* obj); |
| 2544 | |
| 2545 | #ifdef DEBUG |
| 2546 | void JSFunctionResultCacheVerify(); |
| 2547 | #endif |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2548 | }; |
| 2549 | |
| 2550 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2551 | // The cache for maps used by normalized (dictionary mode) objects. |
| 2552 | // Such maps do not have property descriptors, so a typical program |
| 2553 | // needs very limited number of distinct normalized maps. |
| 2554 | class NormalizedMapCache: public FixedArray { |
| 2555 | public: |
| 2556 | static const int kEntries = 64; |
| 2557 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2558 | MUST_USE_RESULT MaybeObject* Get(JSObject* object, |
| 2559 | PropertyNormalizationMode mode); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2560 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2561 | void Clear(); |
| 2562 | |
| 2563 | // Casting |
| 2564 | static inline NormalizedMapCache* cast(Object* obj); |
| 2565 | |
| 2566 | #ifdef DEBUG |
| 2567 | void NormalizedMapCacheVerify(); |
| 2568 | #endif |
| 2569 | |
| 2570 | private: |
| 2571 | static int Hash(Map* fast); |
| 2572 | |
| 2573 | static bool CheckHit(Map* slow, Map* fast, PropertyNormalizationMode mode); |
| 2574 | }; |
| 2575 | |
| 2576 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2577 | // ByteArray represents fixed sized byte arrays. Used by the outside world, |
| 2578 | // such as PCRE, and also by the memory allocator and garbage collector to |
| 2579 | // fill in free blocks in the heap. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2580 | class ByteArray: public HeapObject { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2581 | public: |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2582 | // [length]: length of the array. |
| 2583 | inline int length(); |
| 2584 | inline void set_length(int value); |
| 2585 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2586 | // Setter and getter. |
| 2587 | inline byte get(int index); |
| 2588 | inline void set(int index, byte value); |
| 2589 | |
| 2590 | // Treat contents as an int array. |
| 2591 | inline int get_int(int index); |
| 2592 | |
| 2593 | static int SizeFor(int length) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2594 | return OBJECT_POINTER_ALIGN(kHeaderSize + length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2595 | } |
| 2596 | // We use byte arrays for free blocks in the heap. Given a desired size in |
| 2597 | // bytes that is a multiple of the word size and big enough to hold a byte |
| 2598 | // array, this function returns the number of elements a byte array should |
| 2599 | // have. |
| 2600 | static int LengthFor(int size_in_bytes) { |
| 2601 | ASSERT(IsAligned(size_in_bytes, kPointerSize)); |
| 2602 | ASSERT(size_in_bytes >= kHeaderSize); |
| 2603 | return size_in_bytes - kHeaderSize; |
| 2604 | } |
| 2605 | |
| 2606 | // Returns data start address. |
| 2607 | inline Address GetDataStartAddress(); |
| 2608 | |
| 2609 | // Returns a pointer to the ByteArray object for a given data start address. |
| 2610 | static inline ByteArray* FromDataStartAddress(Address address); |
| 2611 | |
| 2612 | // Casting. |
| 2613 | static inline ByteArray* cast(Object* obj); |
| 2614 | |
| 2615 | // Dispatched behavior. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2616 | inline int ByteArraySize() { |
| 2617 | return SizeFor(this->length()); |
| 2618 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2619 | #ifdef DEBUG |
| 2620 | void ByteArrayPrint(); |
| 2621 | void ByteArrayVerify(); |
| 2622 | #endif |
| 2623 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2624 | // Layout description. |
| 2625 | // Length is smi tagged when it is stored. |
| 2626 | static const int kLengthOffset = HeapObject::kHeaderSize; |
| 2627 | static const int kHeaderSize = kLengthOffset + kPointerSize; |
| 2628 | |
| 2629 | static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 2630 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2631 | // Maximal memory consumption for a single ByteArray. |
| 2632 | static const int kMaxSize = 512 * MB; |
| 2633 | // Maximal length of a single ByteArray. |
| 2634 | static const int kMaxLength = kMaxSize - kHeaderSize; |
| 2635 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2636 | private: |
| 2637 | DISALLOW_IMPLICIT_CONSTRUCTORS(ByteArray); |
| 2638 | }; |
| 2639 | |
| 2640 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2641 | // A PixelArray represents a fixed-size byte array with special semantics |
| 2642 | // used for implementing the CanvasPixelArray object. Please see the |
| 2643 | // specification at: |
| 2644 | // http://www.whatwg.org/specs/web-apps/current-work/ |
| 2645 | // multipage/the-canvas-element.html#canvaspixelarray |
| 2646 | // In particular, write access clamps the value written to 0 or 255 if the |
| 2647 | // value written is outside this range. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2648 | class PixelArray: public HeapObject { |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2649 | public: |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2650 | // [length]: length of the array. |
| 2651 | inline int length(); |
| 2652 | inline void set_length(int value); |
| 2653 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2654 | // [external_pointer]: The pointer to the external memory area backing this |
| 2655 | // pixel array. |
| 2656 | DECL_ACCESSORS(external_pointer, uint8_t) // Pointer to the data store. |
| 2657 | |
| 2658 | // Setter and getter. |
| 2659 | inline uint8_t get(int index); |
| 2660 | inline void set(int index, uint8_t value); |
| 2661 | |
| 2662 | // This accessor applies the correct conversion from Smi, HeapNumber and |
| 2663 | // undefined and clamps the converted value between 0 and 255. |
| 2664 | Object* SetValue(uint32_t index, Object* value); |
| 2665 | |
| 2666 | // Casting. |
| 2667 | static inline PixelArray* cast(Object* obj); |
| 2668 | |
| 2669 | #ifdef DEBUG |
| 2670 | void PixelArrayPrint(); |
| 2671 | void PixelArrayVerify(); |
| 2672 | #endif // DEBUG |
| 2673 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2674 | // Maximal acceptable length for a pixel array. |
| 2675 | static const int kMaxLength = 0x3fffffff; |
| 2676 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2677 | // PixelArray headers are not quadword aligned. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2678 | static const int kLengthOffset = HeapObject::kHeaderSize; |
| 2679 | static const int kExternalPointerOffset = |
| 2680 | POINTER_SIZE_ALIGN(kLengthOffset + kIntSize); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2681 | static const int kHeaderSize = kExternalPointerOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2682 | static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2683 | |
| 2684 | private: |
| 2685 | DISALLOW_IMPLICIT_CONSTRUCTORS(PixelArray); |
| 2686 | }; |
| 2687 | |
| 2688 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2689 | // An ExternalArray represents a fixed-size array of primitive values |
| 2690 | // which live outside the JavaScript heap. Its subclasses are used to |
| 2691 | // implement the CanvasArray types being defined in the WebGL |
| 2692 | // specification. As of this writing the first public draft is not yet |
| 2693 | // available, but Khronos members can access the draft at: |
| 2694 | // https://cvs.khronos.org/svn/repos/3dweb/trunk/doc/spec/WebGL-spec.html |
| 2695 | // |
| 2696 | // The semantics of these arrays differ from CanvasPixelArray. |
| 2697 | // Out-of-range values passed to the setter are converted via a C |
| 2698 | // cast, not clamping. Out-of-range indices cause exceptions to be |
| 2699 | // raised rather than being silently ignored. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2700 | class ExternalArray: public HeapObject { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2701 | public: |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2702 | // [length]: length of the array. |
| 2703 | inline int length(); |
| 2704 | inline void set_length(int value); |
| 2705 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2706 | // [external_pointer]: The pointer to the external memory area backing this |
| 2707 | // external array. |
| 2708 | DECL_ACCESSORS(external_pointer, void) // Pointer to the data store. |
| 2709 | |
| 2710 | // Casting. |
| 2711 | static inline ExternalArray* cast(Object* obj); |
| 2712 | |
| 2713 | // Maximal acceptable length for an external array. |
| 2714 | static const int kMaxLength = 0x3fffffff; |
| 2715 | |
| 2716 | // ExternalArray headers are not quadword aligned. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2717 | static const int kLengthOffset = HeapObject::kHeaderSize; |
| 2718 | static const int kExternalPointerOffset = |
| 2719 | POINTER_SIZE_ALIGN(kLengthOffset + kIntSize); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2720 | static const int kHeaderSize = kExternalPointerOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2721 | static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2722 | |
| 2723 | private: |
| 2724 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalArray); |
| 2725 | }; |
| 2726 | |
| 2727 | |
| 2728 | class ExternalByteArray: public ExternalArray { |
| 2729 | public: |
| 2730 | // Setter and getter. |
| 2731 | inline int8_t get(int index); |
| 2732 | inline void set(int index, int8_t value); |
| 2733 | |
| 2734 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 2735 | // and undefined. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2736 | MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2737 | |
| 2738 | // Casting. |
| 2739 | static inline ExternalByteArray* cast(Object* obj); |
| 2740 | |
| 2741 | #ifdef DEBUG |
| 2742 | void ExternalByteArrayPrint(); |
| 2743 | void ExternalByteArrayVerify(); |
| 2744 | #endif // DEBUG |
| 2745 | |
| 2746 | private: |
| 2747 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalByteArray); |
| 2748 | }; |
| 2749 | |
| 2750 | |
| 2751 | class ExternalUnsignedByteArray: public ExternalArray { |
| 2752 | public: |
| 2753 | // Setter and getter. |
| 2754 | inline uint8_t get(int index); |
| 2755 | inline void set(int index, uint8_t value); |
| 2756 | |
| 2757 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 2758 | // and undefined. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2759 | MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2760 | |
| 2761 | // Casting. |
| 2762 | static inline ExternalUnsignedByteArray* cast(Object* obj); |
| 2763 | |
| 2764 | #ifdef DEBUG |
| 2765 | void ExternalUnsignedByteArrayPrint(); |
| 2766 | void ExternalUnsignedByteArrayVerify(); |
| 2767 | #endif // DEBUG |
| 2768 | |
| 2769 | private: |
| 2770 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedByteArray); |
| 2771 | }; |
| 2772 | |
| 2773 | |
| 2774 | class ExternalShortArray: public ExternalArray { |
| 2775 | public: |
| 2776 | // Setter and getter. |
| 2777 | inline int16_t get(int index); |
| 2778 | inline void set(int index, int16_t value); |
| 2779 | |
| 2780 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 2781 | // and undefined. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2782 | MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2783 | |
| 2784 | // Casting. |
| 2785 | static inline ExternalShortArray* cast(Object* obj); |
| 2786 | |
| 2787 | #ifdef DEBUG |
| 2788 | void ExternalShortArrayPrint(); |
| 2789 | void ExternalShortArrayVerify(); |
| 2790 | #endif // DEBUG |
| 2791 | |
| 2792 | private: |
| 2793 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalShortArray); |
| 2794 | }; |
| 2795 | |
| 2796 | |
| 2797 | class ExternalUnsignedShortArray: public ExternalArray { |
| 2798 | public: |
| 2799 | // Setter and getter. |
| 2800 | inline uint16_t get(int index); |
| 2801 | inline void set(int index, uint16_t value); |
| 2802 | |
| 2803 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 2804 | // and undefined. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2805 | MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2806 | |
| 2807 | // Casting. |
| 2808 | static inline ExternalUnsignedShortArray* cast(Object* obj); |
| 2809 | |
| 2810 | #ifdef DEBUG |
| 2811 | void ExternalUnsignedShortArrayPrint(); |
| 2812 | void ExternalUnsignedShortArrayVerify(); |
| 2813 | #endif // DEBUG |
| 2814 | |
| 2815 | private: |
| 2816 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedShortArray); |
| 2817 | }; |
| 2818 | |
| 2819 | |
| 2820 | class ExternalIntArray: public ExternalArray { |
| 2821 | public: |
| 2822 | // Setter and getter. |
| 2823 | inline int32_t get(int index); |
| 2824 | inline void set(int index, int32_t value); |
| 2825 | |
| 2826 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 2827 | // and undefined. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2828 | MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2829 | |
| 2830 | // Casting. |
| 2831 | static inline ExternalIntArray* cast(Object* obj); |
| 2832 | |
| 2833 | #ifdef DEBUG |
| 2834 | void ExternalIntArrayPrint(); |
| 2835 | void ExternalIntArrayVerify(); |
| 2836 | #endif // DEBUG |
| 2837 | |
| 2838 | private: |
| 2839 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalIntArray); |
| 2840 | }; |
| 2841 | |
| 2842 | |
| 2843 | class ExternalUnsignedIntArray: public ExternalArray { |
| 2844 | public: |
| 2845 | // Setter and getter. |
| 2846 | inline uint32_t get(int index); |
| 2847 | inline void set(int index, uint32_t value); |
| 2848 | |
| 2849 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 2850 | // and undefined. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2851 | MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2852 | |
| 2853 | // Casting. |
| 2854 | static inline ExternalUnsignedIntArray* cast(Object* obj); |
| 2855 | |
| 2856 | #ifdef DEBUG |
| 2857 | void ExternalUnsignedIntArrayPrint(); |
| 2858 | void ExternalUnsignedIntArrayVerify(); |
| 2859 | #endif // DEBUG |
| 2860 | |
| 2861 | private: |
| 2862 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedIntArray); |
| 2863 | }; |
| 2864 | |
| 2865 | |
| 2866 | class ExternalFloatArray: public ExternalArray { |
| 2867 | public: |
| 2868 | // Setter and getter. |
| 2869 | inline float get(int index); |
| 2870 | inline void set(int index, float value); |
| 2871 | |
| 2872 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 2873 | // and undefined. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2874 | MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2875 | |
| 2876 | // Casting. |
| 2877 | static inline ExternalFloatArray* cast(Object* obj); |
| 2878 | |
| 2879 | #ifdef DEBUG |
| 2880 | void ExternalFloatArrayPrint(); |
| 2881 | void ExternalFloatArrayVerify(); |
| 2882 | #endif // DEBUG |
| 2883 | |
| 2884 | private: |
| 2885 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalFloatArray); |
| 2886 | }; |
| 2887 | |
| 2888 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2889 | // Code describes objects with on-the-fly generated machine code. |
| 2890 | class Code: public HeapObject { |
| 2891 | public: |
| 2892 | // Opaque data type for encapsulating code flags like kind, inline |
| 2893 | // cache state, and arguments count. |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 2894 | // FLAGS_MIN_VALUE and FLAGS_MAX_VALUE are specified to ensure that |
| 2895 | // enumeration type has correct value range (see Issue 830 for more details). |
| 2896 | enum Flags { |
| 2897 | FLAGS_MIN_VALUE = kMinInt, |
| 2898 | FLAGS_MAX_VALUE = kMaxInt |
| 2899 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2900 | |
| 2901 | enum Kind { |
| 2902 | FUNCTION, |
| 2903 | STUB, |
| 2904 | BUILTIN, |
| 2905 | LOAD_IC, |
| 2906 | KEYED_LOAD_IC, |
| 2907 | CALL_IC, |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2908 | KEYED_CALL_IC, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2909 | STORE_IC, |
| 2910 | KEYED_STORE_IC, |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2911 | BINARY_OP_IC, |
| 2912 | // 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] | 2913 | // Flags. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2914 | |
| 2915 | // Pseudo-kinds. |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2916 | REGEXP = BUILTIN, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2917 | FIRST_IC_KIND = LOAD_IC, |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2918 | LAST_IC_KIND = BINARY_OP_IC |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2919 | }; |
| 2920 | |
| 2921 | enum { |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 2922 | NUMBER_OF_KINDS = LAST_IC_KIND + 1 |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2923 | }; |
| 2924 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 2925 | #ifdef ENABLE_DISASSEMBLER |
| 2926 | // Printing |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2927 | static const char* Kind2String(Kind kind); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2928 | static const char* ICState2String(InlineCacheState state); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2929 | static const char* PropertyType2String(PropertyType type); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2930 | void Disassemble(const char* name); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 2931 | #endif // ENABLE_DISASSEMBLER |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2932 | |
| 2933 | // [instruction_size]: Size of the native instructions |
| 2934 | inline int instruction_size(); |
| 2935 | inline void set_instruction_size(int value); |
| 2936 | |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 2937 | // [relocation_info]: Code relocation information |
| 2938 | DECL_ACCESSORS(relocation_info, ByteArray) |
| 2939 | |
| 2940 | // Unchecked accessor to be used during GC. |
| 2941 | inline ByteArray* unchecked_relocation_info(); |
| 2942 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2943 | inline int relocation_size(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2944 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2945 | // [flags]: Various code flags. |
| 2946 | inline Flags flags(); |
| 2947 | inline void set_flags(Flags flags); |
| 2948 | |
| 2949 | // [flags]: Access to specific code flags. |
| 2950 | inline Kind kind(); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2951 | inline InlineCacheState ic_state(); // Only valid for IC stubs. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2952 | inline InLoopFlag ic_in_loop(); // Only valid for IC stubs. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2953 | inline PropertyType type(); // Only valid for monomorphic IC stubs. |
| 2954 | inline int arguments_count(); // Only valid for call IC stubs. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2955 | |
| 2956 | // Testers for IC stub kinds. |
| 2957 | inline bool is_inline_cache_stub(); |
| 2958 | inline bool is_load_stub() { return kind() == LOAD_IC; } |
| 2959 | inline bool is_keyed_load_stub() { return kind() == KEYED_LOAD_IC; } |
| 2960 | inline bool is_store_stub() { return kind() == STORE_IC; } |
| 2961 | inline bool is_keyed_store_stub() { return kind() == KEYED_STORE_IC; } |
| 2962 | inline bool is_call_stub() { return kind() == CALL_IC; } |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2963 | inline bool is_keyed_call_stub() { return kind() == KEYED_CALL_IC; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2964 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2965 | // [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] | 2966 | inline int major_key(); |
| 2967 | inline void set_major_key(int major); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2968 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2969 | // Flags operations. |
| 2970 | static inline Flags ComputeFlags(Kind kind, |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2971 | InLoopFlag in_loop = NOT_IN_LOOP, |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2972 | InlineCacheState ic_state = UNINITIALIZED, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2973 | PropertyType type = NORMAL, |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2974 | int argc = -1, |
| 2975 | InlineCacheHolderFlag holder = OWN_MAP); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2976 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2977 | static inline Flags ComputeMonomorphicFlags( |
| 2978 | Kind kind, |
| 2979 | PropertyType type, |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2980 | InlineCacheHolderFlag holder = OWN_MAP, |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2981 | InLoopFlag in_loop = NOT_IN_LOOP, |
| 2982 | int argc = -1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2983 | |
| 2984 | static inline Kind ExtractKindFromFlags(Flags flags); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2985 | static inline InlineCacheState ExtractICStateFromFlags(Flags flags); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2986 | static inline InLoopFlag ExtractICInLoopFromFlags(Flags flags); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2987 | static inline PropertyType ExtractTypeFromFlags(Flags flags); |
| 2988 | static inline int ExtractArgumentsCountFromFlags(Flags flags); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2989 | static inline InlineCacheHolderFlag ExtractCacheHolderFromFlags(Flags flags); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2990 | static inline Flags RemoveTypeFromFlags(Flags flags); |
| 2991 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 2992 | // Convert a target address into a code object. |
| 2993 | static inline Code* GetCodeFromTargetAddress(Address address); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2994 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 2995 | // Convert an entry address into an object. |
| 2996 | static inline Object* GetObjectFromEntryAddress(Address location_of_address); |
| 2997 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2998 | // Returns the address of the first instruction. |
| 2999 | inline byte* instruction_start(); |
| 3000 | |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 3001 | // Returns the address right after the last instruction. |
| 3002 | inline byte* instruction_end(); |
| 3003 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3004 | // Returns the size of the instructions, padding, and relocation information. |
| 3005 | inline int body_size(); |
| 3006 | |
| 3007 | // Returns the address of the first relocation info (read backwards!). |
| 3008 | inline byte* relocation_start(); |
| 3009 | |
| 3010 | // Code entry point. |
| 3011 | inline byte* entry(); |
| 3012 | |
| 3013 | // Returns true if pc is inside this object's instructions. |
| 3014 | inline bool contains(byte* pc); |
| 3015 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3016 | // Relocate the code by delta bytes. Called to signal that this code |
| 3017 | // object has been moved by delta bytes. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3018 | void Relocate(intptr_t delta); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3019 | |
| 3020 | // Migrate code described by desc. |
| 3021 | void CopyFrom(const CodeDesc& desc); |
| 3022 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 3023 | // Returns the object size for a given body (used for allocation). |
| 3024 | static int SizeFor(int body_size) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3025 | ASSERT_SIZE_TAG_ALIGNED(body_size); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 3026 | return RoundUp(kHeaderSize + body_size, kCodeAlignment); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3027 | } |
| 3028 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3029 | // Calculate the size of the code object to report for log events. This takes |
| 3030 | // the layout of the code object into account. |
| 3031 | int ExecutableSize() { |
| 3032 | // 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] | 3033 | ASSERT_EQ(static_cast<int>(instruction_start() - address()), |
| 3034 | Code::kHeaderSize); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3035 | return instruction_size() + Code::kHeaderSize; |
| 3036 | } |
| 3037 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3038 | // Locating source position. |
| 3039 | int SourcePosition(Address pc); |
| 3040 | int SourceStatementPosition(Address pc); |
| 3041 | |
| 3042 | // Casting. |
| 3043 | static inline Code* cast(Object* obj); |
| 3044 | |
| 3045 | // Dispatched behavior. |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 3046 | int CodeSize() { return SizeFor(body_size()); } |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3047 | inline void CodeIterateBody(ObjectVisitor* v); |
| 3048 | |
| 3049 | template<typename StaticVisitor> |
| 3050 | inline void CodeIterateBody(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3051 | #ifdef DEBUG |
| 3052 | void CodePrint(); |
| 3053 | void CodeVerify(); |
| 3054 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3055 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 3056 | static const int kInstructionSizeOffset = HeapObject::kHeaderSize; |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 3057 | static const int kRelocationInfoOffset = kInstructionSizeOffset + kIntSize; |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 3058 | static const int kFlagsOffset = kRelocationInfoOffset + kPointerSize; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3059 | static const int kKindSpecificFlagsOffset = kFlagsOffset + kIntSize; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3060 | // Add padding to align the instruction start following right after |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 3061 | // the Code object header. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3062 | static const int kHeaderSize = |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3063 | CODE_POINTER_ALIGN(kKindSpecificFlagsOffset + kIntSize); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3064 | |
| 3065 | // Byte offsets within kKindSpecificFlagsOffset. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3066 | static const int kStubMajorKeyOffset = kKindSpecificFlagsOffset + 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3067 | |
| 3068 | // Flags layout. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3069 | static const int kFlagsICStateShift = 0; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3070 | static const int kFlagsICInLoopShift = 3; |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3071 | static const int kFlagsTypeShift = 4; |
| 3072 | static const int kFlagsKindShift = 7; |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3073 | static const int kFlagsICHolderShift = 11; |
| 3074 | static const int kFlagsArgumentsCountShift = 12; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3075 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3076 | static const int kFlagsICStateMask = 0x00000007; // 00000000111 |
| 3077 | static const int kFlagsICInLoopMask = 0x00000008; // 00000001000 |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3078 | static const int kFlagsTypeMask = 0x00000070; // 00001110000 |
| 3079 | static const int kFlagsKindMask = 0x00000780; // 11110000000 |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3080 | static const int kFlagsCacheInPrototypeMapMask = 0x00000800; |
| 3081 | static const int kFlagsArgumentsCountMask = 0xFFFFF000; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3082 | |
| 3083 | static const int kFlagsNotUsedInLookup = |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3084 | (kFlagsICInLoopMask | kFlagsTypeMask | kFlagsCacheInPrototypeMapMask); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3085 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3086 | private: |
| 3087 | DISALLOW_IMPLICIT_CONSTRUCTORS(Code); |
| 3088 | }; |
| 3089 | |
| 3090 | |
| 3091 | // All heap objects have a Map that describes their structure. |
| 3092 | // A Map contains information about: |
| 3093 | // - Size information about the object |
| 3094 | // - How to iterate over an object (for garbage collection) |
| 3095 | class Map: public HeapObject { |
| 3096 | public: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3097 | // Instance size. |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 3098 | // Size in bytes or kVariableSizeSentinel if instances do not have |
| 3099 | // a fixed size. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3100 | inline int instance_size(); |
| 3101 | inline void set_instance_size(int value); |
| 3102 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3103 | // Count of properties allocated in the object. |
| 3104 | inline int inobject_properties(); |
| 3105 | inline void set_inobject_properties(int value); |
| 3106 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 3107 | // Count of property fields pre-allocated in the object when first allocated. |
| 3108 | inline int pre_allocated_property_fields(); |
| 3109 | inline void set_pre_allocated_property_fields(int value); |
| 3110 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3111 | // Instance type. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3112 | inline InstanceType instance_type(); |
| 3113 | inline void set_instance_type(InstanceType value); |
| 3114 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3115 | // Tells how many unused property fields are available in the |
| 3116 | // instance (only used for JSObject in fast mode). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3117 | inline int unused_property_fields(); |
| 3118 | inline void set_unused_property_fields(int value); |
| 3119 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3120 | // Bit field. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3121 | inline byte bit_field(); |
| 3122 | inline void set_bit_field(byte value); |
| 3123 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3124 | // Bit field 2. |
| 3125 | inline byte bit_field2(); |
| 3126 | inline void set_bit_field2(byte value); |
| 3127 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3128 | // Tells whether the object in the prototype property will be used |
| 3129 | // for instances created from this function. If the prototype |
| 3130 | // property is set to a value that is not a JSObject, the prototype |
| 3131 | // property will not be used to create instances of the function. |
| 3132 | // See ECMA-262, 13.2.2. |
| 3133 | inline void set_non_instance_prototype(bool value); |
| 3134 | inline bool has_non_instance_prototype(); |
| 3135 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 3136 | // Tells whether function has special prototype property. If not, prototype |
| 3137 | // property will not be created when accessed (will return undefined), |
| 3138 | // and construction from this function will not be allowed. |
| 3139 | inline void set_function_with_prototype(bool value); |
| 3140 | inline bool function_with_prototype(); |
| 3141 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3142 | // Tells whether the instance with this map should be ignored by the |
| 3143 | // __proto__ accessor. |
| 3144 | inline void set_is_hidden_prototype() { |
| 3145 | set_bit_field(bit_field() | (1 << kIsHiddenPrototype)); |
| 3146 | } |
| 3147 | |
| 3148 | inline bool is_hidden_prototype() { |
| 3149 | return ((1 << kIsHiddenPrototype) & bit_field()) != 0; |
| 3150 | } |
| 3151 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3152 | // Records and queries whether the instance has a named interceptor. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3153 | inline void set_has_named_interceptor() { |
| 3154 | set_bit_field(bit_field() | (1 << kHasNamedInterceptor)); |
| 3155 | } |
| 3156 | |
| 3157 | inline bool has_named_interceptor() { |
| 3158 | return ((1 << kHasNamedInterceptor) & bit_field()) != 0; |
| 3159 | } |
| 3160 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3161 | // Records and queries whether the instance has an indexed interceptor. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3162 | inline void set_has_indexed_interceptor() { |
| 3163 | set_bit_field(bit_field() | (1 << kHasIndexedInterceptor)); |
| 3164 | } |
| 3165 | |
| 3166 | inline bool has_indexed_interceptor() { |
| 3167 | return ((1 << kHasIndexedInterceptor) & bit_field()) != 0; |
| 3168 | } |
| 3169 | |
| 3170 | // Tells whether the instance is undetectable. |
| 3171 | // An undetectable object is a special class of JSObject: 'typeof' operator |
| 3172 | // returns undefined, ToBoolean returns false. Otherwise it behaves like |
| 3173 | // a normal JS object. It is useful for implementing undetectable |
| 3174 | // document.all in Firefox & Safari. |
| 3175 | // See https://bugzilla.mozilla.org/show_bug.cgi?id=248549. |
| 3176 | inline void set_is_undetectable() { |
| 3177 | set_bit_field(bit_field() | (1 << kIsUndetectable)); |
| 3178 | } |
| 3179 | |
| 3180 | inline bool is_undetectable() { |
| 3181 | return ((1 << kIsUndetectable) & bit_field()) != 0; |
| 3182 | } |
| 3183 | |
| 3184 | // Tells whether the instance has a call-as-function handler. |
| 3185 | inline void set_has_instance_call_handler() { |
| 3186 | set_bit_field(bit_field() | (1 << kHasInstanceCallHandler)); |
| 3187 | } |
| 3188 | |
| 3189 | inline bool has_instance_call_handler() { |
| 3190 | return ((1 << kHasInstanceCallHandler) & bit_field()) != 0; |
| 3191 | } |
| 3192 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3193 | inline void set_is_extensible(bool value); |
| 3194 | inline bool is_extensible(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3195 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3196 | // Tells whether the instance has fast elements. |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 3197 | // Equivalent to instance->GetElementsKind() == FAST_ELEMENTS. |
| 3198 | inline void set_has_fast_elements(bool value) { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3199 | if (value) { |
| 3200 | set_bit_field2(bit_field2() | (1 << kHasFastElements)); |
| 3201 | } else { |
| 3202 | set_bit_field2(bit_field2() & ~(1 << kHasFastElements)); |
| 3203 | } |
| 3204 | } |
| 3205 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 3206 | inline bool has_fast_elements() { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3207 | return ((1 << kHasFastElements) & bit_field2()) != 0; |
| 3208 | } |
| 3209 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3210 | // Tells whether the map is attached to SharedFunctionInfo |
| 3211 | // (for inobject slack tracking). |
| 3212 | inline void set_attached_to_shared_function_info(bool value); |
| 3213 | |
| 3214 | inline bool attached_to_shared_function_info(); |
| 3215 | |
| 3216 | // Tells whether the map is shared between objects that may have different |
| 3217 | // behavior. If true, the map should never be modified, instead a clone |
| 3218 | // should be created and modified. |
| 3219 | inline void set_is_shared(bool value); |
| 3220 | |
| 3221 | inline bool is_shared(); |
| 3222 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3223 | // Tells whether the instance needs security checks when accessing its |
| 3224 | // properties. |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 3225 | inline void set_is_access_check_needed(bool access_check_needed); |
| 3226 | inline bool is_access_check_needed(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3227 | |
| 3228 | // [prototype]: implicit prototype object. |
| 3229 | DECL_ACCESSORS(prototype, Object) |
| 3230 | |
| 3231 | // [constructor]: points back to the function responsible for this map. |
| 3232 | DECL_ACCESSORS(constructor, Object) |
| 3233 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3234 | inline JSFunction* unchecked_constructor(); |
| 3235 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3236 | // [instance descriptors]: describes the object. |
| 3237 | DECL_ACCESSORS(instance_descriptors, DescriptorArray) |
| 3238 | |
| 3239 | // [stub cache]: contains stubs compiled for this map. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3240 | DECL_ACCESSORS(code_cache, Object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3241 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3242 | MUST_USE_RESULT MaybeObject* CopyDropDescriptors(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3243 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3244 | MUST_USE_RESULT MaybeObject* CopyNormalized(PropertyNormalizationMode mode, |
| 3245 | NormalizedMapSharingMode sharing); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3246 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 3247 | // Returns a copy of the map, with all transitions dropped from the |
| 3248 | // instance descriptors. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3249 | MUST_USE_RESULT MaybeObject* CopyDropTransitions(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 3250 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3251 | // Returns this map if it has the fast elements bit set, otherwise |
| 3252 | // returns a copy of the map, with all transitions dropped from the |
| 3253 | // descriptors and the fast elements bit set. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3254 | MUST_USE_RESULT inline MaybeObject* GetFastElementsMap(); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3255 | |
| 3256 | // Returns this map if it has the fast elements bit cleared, |
| 3257 | // otherwise returns a copy of the map, with all transitions dropped |
| 3258 | // from the descriptors and the fast elements bit cleared. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3259 | MUST_USE_RESULT inline MaybeObject* GetSlowElementsMap(); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3260 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3261 | // Returns the property index for name (only valid for FAST MODE). |
| 3262 | int PropertyIndexFor(String* name); |
| 3263 | |
| 3264 | // Returns the next free property index (only valid for FAST MODE). |
| 3265 | int NextFreePropertyIndex(); |
| 3266 | |
| 3267 | // Returns the number of properties described in instance_descriptors. |
| 3268 | int NumberOfDescribedProperties(); |
| 3269 | |
| 3270 | // Casting. |
| 3271 | static inline Map* cast(Object* obj); |
| 3272 | |
| 3273 | // Locate an accessor in the instance descriptor. |
| 3274 | AccessorDescriptor* FindAccessor(String* name); |
| 3275 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3276 | // Code cache operations. |
| 3277 | |
| 3278 | // Clears the code cache. |
| 3279 | inline void ClearCodeCache(); |
| 3280 | |
| 3281 | // Update code cache. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3282 | MUST_USE_RESULT MaybeObject* UpdateCodeCache(String* name, Code* code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3283 | |
| 3284 | // Returns the found code or undefined if absent. |
| 3285 | Object* FindInCodeCache(String* name, Code::Flags flags); |
| 3286 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 3287 | // Returns the non-negative index of the code object if it is in the |
| 3288 | // cache and -1 otherwise. |
sgjesse@chromium.org | 99a37fa | 2010-03-11 09:23:46 +0000 | [diff] [blame] | 3289 | int IndexInCodeCache(Object* name, Code* code); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 3290 | |
| 3291 | // 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] | 3292 | void RemoveFromCodeCache(String* name, Code* code, int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3293 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 3294 | // For every transition in this map, makes the transition's |
| 3295 | // target's prototype pointer point back to this map. |
| 3296 | // This is undone in MarkCompactCollector::ClearNonLiveTransitions(). |
| 3297 | void CreateBackPointers(); |
| 3298 | |
| 3299 | // Set all map transitions from this map to dead maps to null. |
| 3300 | // Also, restore the original prototype on the targets of these |
| 3301 | // transitions, so that we do not process this map again while |
| 3302 | // following back pointers. |
| 3303 | void ClearNonLiveTransitions(Object* real_prototype); |
| 3304 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3305 | // Dispatched behavior. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3306 | #ifdef DEBUG |
| 3307 | void MapPrint(); |
| 3308 | void MapVerify(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3309 | void SharedMapVerify(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3310 | #endif |
| 3311 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3312 | inline int visitor_id(); |
| 3313 | inline void set_visitor_id(int visitor_id); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 3314 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3315 | typedef void (*TraverseCallback)(Map* map, void* data); |
| 3316 | |
| 3317 | void TraverseTransitionTree(TraverseCallback callback, void* data); |
| 3318 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 3319 | static const int kMaxPreAllocatedPropertyFields = 255; |
| 3320 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3321 | // Layout description. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3322 | static const int kInstanceSizesOffset = HeapObject::kHeaderSize; |
| 3323 | static const int kInstanceAttributesOffset = kInstanceSizesOffset + kIntSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3324 | static const int kPrototypeOffset = kInstanceAttributesOffset + kIntSize; |
| 3325 | static const int kConstructorOffset = kPrototypeOffset + kPointerSize; |
| 3326 | static const int kInstanceDescriptorsOffset = |
| 3327 | kConstructorOffset + kPointerSize; |
| 3328 | static const int kCodeCacheOffset = kInstanceDescriptorsOffset + kPointerSize; |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 3329 | static const int kPadStart = kCodeCacheOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3330 | static const int kSize = MAP_POINTER_ALIGN(kPadStart); |
| 3331 | |
| 3332 | // Layout of pointer fields. Heap iteration code relies on them |
| 3333 | // being continiously allocated. |
| 3334 | static const int kPointerFieldsBeginOffset = Map::kPrototypeOffset; |
| 3335 | static const int kPointerFieldsEndOffset = |
| 3336 | Map::kCodeCacheOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3337 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3338 | // Byte offsets within kInstanceSizesOffset. |
| 3339 | static const int kInstanceSizeOffset = kInstanceSizesOffset + 0; |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 3340 | static const int kInObjectPropertiesByte = 1; |
| 3341 | static const int kInObjectPropertiesOffset = |
| 3342 | kInstanceSizesOffset + kInObjectPropertiesByte; |
| 3343 | static const int kPreAllocatedPropertyFieldsByte = 2; |
| 3344 | static const int kPreAllocatedPropertyFieldsOffset = |
| 3345 | kInstanceSizesOffset + kPreAllocatedPropertyFieldsByte; |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 3346 | static const int kVisitorIdByte = 3; |
| 3347 | static const int kVisitorIdOffset = kInstanceSizesOffset + kVisitorIdByte; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3348 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3349 | // Byte offsets within kInstanceAttributesOffset attributes. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3350 | static const int kInstanceTypeOffset = kInstanceAttributesOffset + 0; |
| 3351 | static const int kUnusedPropertyFieldsOffset = kInstanceAttributesOffset + 1; |
| 3352 | static const int kBitFieldOffset = kInstanceAttributesOffset + 2; |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3353 | static const int kBitField2Offset = kInstanceAttributesOffset + 3; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3354 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3355 | STATIC_CHECK(kInstanceTypeOffset == Internals::kMapInstanceTypeOffset); |
| 3356 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3357 | // Bit positions for bit field. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 3358 | 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] | 3359 | static const int kHasNonInstancePrototype = 1; |
| 3360 | static const int kIsHiddenPrototype = 2; |
| 3361 | static const int kHasNamedInterceptor = 3; |
| 3362 | static const int kHasIndexedInterceptor = 4; |
| 3363 | static const int kIsUndetectable = 5; |
| 3364 | static const int kHasInstanceCallHandler = 6; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3365 | static const int kIsAccessCheckNeeded = 7; |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3366 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 3367 | // Bit positions for bit field 2 |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3368 | static const int kIsExtensible = 0; |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 3369 | static const int kFunctionWithPrototype = 1; |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3370 | static const int kHasFastElements = 2; |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3371 | static const int kStringWrapperSafeForDefaultValueOf = 3; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3372 | static const int kAttachedToSharedFunctionInfo = 4; |
| 3373 | static const int kIsShared = 5; |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3374 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3375 | // Layout of the default cache. It holds alternating name and code objects. |
| 3376 | static const int kCodeCacheEntrySize = 2; |
| 3377 | static const int kCodeCacheEntryNameOffset = 0; |
| 3378 | static const int kCodeCacheEntryCodeOffset = 1; |
| 3379 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3380 | typedef FixedBodyDescriptor<kPointerFieldsBeginOffset, |
| 3381 | kPointerFieldsEndOffset, |
| 3382 | kSize> BodyDescriptor; |
| 3383 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3384 | private: |
| 3385 | DISALLOW_IMPLICIT_CONSTRUCTORS(Map); |
| 3386 | }; |
| 3387 | |
| 3388 | |
| 3389 | // An abstract superclass, a marker class really, for simple structure classes. |
| 3390 | // It doesn't carry much functionality but allows struct classes to me |
| 3391 | // identified in the type system. |
| 3392 | class Struct: public HeapObject { |
| 3393 | public: |
| 3394 | inline void InitializeBody(int object_size); |
| 3395 | static inline Struct* cast(Object* that); |
| 3396 | }; |
| 3397 | |
| 3398 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 3399 | // Script describes a script which has been added to the VM. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3400 | class Script: public Struct { |
| 3401 | public: |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 3402 | // Script types. |
| 3403 | enum Type { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 3404 | TYPE_NATIVE = 0, |
| 3405 | TYPE_EXTENSION = 1, |
| 3406 | TYPE_NORMAL = 2 |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 3407 | }; |
| 3408 | |
| 3409 | // Script compilation types. |
| 3410 | enum CompilationType { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 3411 | COMPILATION_TYPE_HOST = 0, |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 3412 | COMPILATION_TYPE_EVAL = 1 |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 3413 | }; |
| 3414 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3415 | // [source]: the script source. |
| 3416 | DECL_ACCESSORS(source, Object) |
| 3417 | |
| 3418 | // [name]: the script name. |
| 3419 | DECL_ACCESSORS(name, Object) |
| 3420 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3421 | // [id]: the script id. |
| 3422 | DECL_ACCESSORS(id, Object) |
| 3423 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3424 | // [line_offset]: script line offset in resource from where it was extracted. |
| 3425 | DECL_ACCESSORS(line_offset, Smi) |
| 3426 | |
| 3427 | // [column_offset]: script column offset in resource from where it was |
| 3428 | // extracted. |
| 3429 | DECL_ACCESSORS(column_offset, Smi) |
| 3430 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3431 | // [data]: additional data associated with this script. |
| 3432 | DECL_ACCESSORS(data, Object) |
| 3433 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 3434 | // [context_data]: context data for the context this script was compiled in. |
| 3435 | DECL_ACCESSORS(context_data, Object) |
| 3436 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3437 | // [wrapper]: the wrapper cache. |
| 3438 | DECL_ACCESSORS(wrapper, Proxy) |
| 3439 | |
| 3440 | // [type]: the script type. |
| 3441 | DECL_ACCESSORS(type, Smi) |
| 3442 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 3443 | // [compilation]: how the the script was compiled. |
| 3444 | DECL_ACCESSORS(compilation_type, Smi) |
| 3445 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3446 | // [line_ends]: FixedArray of line ends positions. |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 3447 | DECL_ACCESSORS(line_ends, Object) |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 3448 | |
sgjesse@chromium.org | 9818059 | 2009-12-02 08:17:28 +0000 | [diff] [blame] | 3449 | // [eval_from_shared]: for eval scripts the shared funcion info for the |
| 3450 | // function from which eval was called. |
| 3451 | DECL_ACCESSORS(eval_from_shared, Object) |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 3452 | |
| 3453 | // [eval_from_instructions_offset]: the instruction offset in the code for the |
| 3454 | // function from which eval was called where eval was called. |
| 3455 | DECL_ACCESSORS(eval_from_instructions_offset, Smi) |
| 3456 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3457 | static inline Script* cast(Object* obj); |
| 3458 | |
sgjesse@chromium.org | 152a0b0 | 2009-10-07 13:50:16 +0000 | [diff] [blame] | 3459 | // If script source is an external string, check that the underlying |
| 3460 | // resource is accessible. Otherwise, always return true. |
| 3461 | inline bool HasValidSource(); |
| 3462 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3463 | #ifdef DEBUG |
| 3464 | void ScriptPrint(); |
| 3465 | void ScriptVerify(); |
| 3466 | #endif |
| 3467 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 3468 | static const int kSourceOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3469 | static const int kNameOffset = kSourceOffset + kPointerSize; |
| 3470 | static const int kLineOffsetOffset = kNameOffset + kPointerSize; |
| 3471 | static const int kColumnOffsetOffset = kLineOffsetOffset + kPointerSize; |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3472 | static const int kDataOffset = kColumnOffsetOffset + kPointerSize; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 3473 | static const int kContextOffset = kDataOffset + kPointerSize; |
| 3474 | static const int kWrapperOffset = kContextOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3475 | static const int kTypeOffset = kWrapperOffset + kPointerSize; |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 3476 | static const int kCompilationTypeOffset = kTypeOffset + kPointerSize; |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 3477 | static const int kLineEndsOffset = kCompilationTypeOffset + kPointerSize; |
| 3478 | static const int kIdOffset = kLineEndsOffset + kPointerSize; |
sgjesse@chromium.org | 9818059 | 2009-12-02 08:17:28 +0000 | [diff] [blame] | 3479 | static const int kEvalFromSharedOffset = kIdOffset + kPointerSize; |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 3480 | static const int kEvalFrominstructionsOffsetOffset = |
sgjesse@chromium.org | 9818059 | 2009-12-02 08:17:28 +0000 | [diff] [blame] | 3481 | kEvalFromSharedOffset + kPointerSize; |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 3482 | static const int kSize = kEvalFrominstructionsOffsetOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3483 | |
| 3484 | private: |
| 3485 | DISALLOW_IMPLICIT_CONSTRUCTORS(Script); |
| 3486 | }; |
| 3487 | |
| 3488 | |
| 3489 | // SharedFunctionInfo describes the JSFunction information that can be |
| 3490 | // shared by multiple instances of the function. |
| 3491 | class SharedFunctionInfo: public HeapObject { |
| 3492 | public: |
| 3493 | // [name]: Function name. |
| 3494 | DECL_ACCESSORS(name, Object) |
| 3495 | |
| 3496 | // [code]: Function code. |
| 3497 | DECL_ACCESSORS(code, Code) |
| 3498 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 3499 | // [scope_info]: Scope info. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 3500 | DECL_ACCESSORS(scope_info, SerializedScopeInfo) |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 3501 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 3502 | // [construct stub]: Code stub for constructing instances of this function. |
| 3503 | DECL_ACCESSORS(construct_stub, Code) |
| 3504 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 3505 | inline Code* unchecked_code(); |
| 3506 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3507 | // Returns if this function has been compiled to native code yet. |
| 3508 | inline bool is_compiled(); |
| 3509 | |
| 3510 | // [length]: The function length - usually the number of declared parameters. |
| 3511 | // Use up to 2^30 parameters. |
| 3512 | inline int length(); |
| 3513 | inline void set_length(int value); |
| 3514 | |
| 3515 | // [formal parameter count]: The declared number of parameters. |
| 3516 | inline int formal_parameter_count(); |
| 3517 | inline void set_formal_parameter_count(int value); |
| 3518 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 3519 | // Set the formal parameter count so the function code will be |
| 3520 | // called without using argument adaptor frames. |
| 3521 | inline void DontAdaptArguments(); |
| 3522 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3523 | // [expected_nof_properties]: Expected number of properties for the function. |
| 3524 | inline int expected_nof_properties(); |
| 3525 | inline void set_expected_nof_properties(int value); |
| 3526 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3527 | // Inobject slack tracking is the way to reclaim unused inobject space. |
| 3528 | // |
| 3529 | // The instance size is initially determined by adding some slack to |
| 3530 | // expected_nof_properties (to allow for a few extra properties added |
| 3531 | // after the constructor). There is no guarantee that the extra space |
| 3532 | // will not be wasted. |
| 3533 | // |
| 3534 | // Here is the algorithm to reclaim the unused inobject space: |
| 3535 | // - Detect the first constructor call for this SharedFunctionInfo. |
| 3536 | // When it happens enter the "in progress" state: remember the |
| 3537 | // constructor's initial_map and install a special construct stub that |
| 3538 | // counts constructor calls. |
| 3539 | // - While the tracking is in progress create objects filled with |
| 3540 | // one_pointer_filler_map instead of undefined_value. This way they can be |
| 3541 | // resized quickly and safely. |
| 3542 | // - Once enough (kGenerousAllocationCount) objects have been created |
| 3543 | // compute the 'slack' (traverse the map transition tree starting from the |
| 3544 | // initial_map and find the lowest value of unused_property_fields). |
| 3545 | // - Traverse the transition tree again and decrease the instance size |
| 3546 | // of every map. Existing objects will resize automatically (they are |
| 3547 | // filled with one_pointer_filler_map). All further allocations will |
| 3548 | // use the adjusted instance size. |
| 3549 | // - Decrease expected_nof_properties so that an allocations made from |
| 3550 | // another context will use the adjusted instance size too. |
| 3551 | // - Exit "in progress" state by clearing the reference to the initial_map |
| 3552 | // and setting the regular construct stub (generic or inline). |
| 3553 | // |
| 3554 | // The above is the main event sequence. Some special cases are possible |
| 3555 | // while the tracking is in progress: |
| 3556 | // |
| 3557 | // - GC occurs. |
| 3558 | // Check if the initial_map is referenced by any live objects (except this |
| 3559 | // SharedFunctionInfo). If it is, continue tracking as usual. |
| 3560 | // If it is not, clear the reference and reset the tracking state. The |
| 3561 | // tracking will be initiated again on the next constructor call. |
| 3562 | // |
| 3563 | // - The constructor is called from another context. |
| 3564 | // Immediately complete the tracking, perform all the necessary changes |
| 3565 | // to maps. This is necessary because there is no efficient way to track |
| 3566 | // multiple initial_maps. |
| 3567 | // Proceed to create an object in the current context (with the adjusted |
| 3568 | // size). |
| 3569 | // |
| 3570 | // - A different constructor function sharing the same SharedFunctionInfo is |
| 3571 | // called in the same context. This could be another closure in the same |
| 3572 | // context, or the first function could have been disposed. |
| 3573 | // This is handled the same way as the previous case. |
| 3574 | // |
| 3575 | // Important: inobject slack tracking is not attempted during the snapshot |
| 3576 | // creation. |
| 3577 | |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 3578 | static const int kGenerousAllocationCount = 8; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3579 | |
| 3580 | // [construction_count]: Counter for constructor calls made during |
| 3581 | // the tracking phase. |
| 3582 | inline int construction_count(); |
| 3583 | inline void set_construction_count(int value); |
| 3584 | |
| 3585 | // [initial_map]: initial map of the first function called as a constructor. |
| 3586 | // Saved for the duration of the tracking phase. |
| 3587 | // This is a weak link (GC resets it to undefined_value if no other live |
| 3588 | // object reference this map). |
| 3589 | DECL_ACCESSORS(initial_map, Object) |
| 3590 | |
| 3591 | // True if the initial_map is not undefined and the countdown stub is |
| 3592 | // installed. |
| 3593 | inline bool IsInobjectSlackTrackingInProgress(); |
| 3594 | |
| 3595 | // Starts the tracking. |
| 3596 | // Stores the initial map and installs the countdown stub. |
| 3597 | // IsInobjectSlackTrackingInProgress is normally true after this call, |
| 3598 | // except when tracking have not been started (e.g. the map has no unused |
| 3599 | // properties or the snapshot is being built). |
| 3600 | void StartInobjectSlackTracking(Map* map); |
| 3601 | |
| 3602 | // Completes the tracking. |
| 3603 | // IsInobjectSlackTrackingInProgress is false after this call. |
| 3604 | void CompleteInobjectSlackTracking(); |
| 3605 | |
| 3606 | // Clears the initial_map before the GC marking phase to ensure the reference |
| 3607 | // is weak. IsInobjectSlackTrackingInProgress is false after this call. |
| 3608 | void DetachInitialMap(); |
| 3609 | |
| 3610 | // Restores the link to the initial map after the GC marking phase. |
| 3611 | // IsInobjectSlackTrackingInProgress is true after this call. |
| 3612 | void AttachInitialMap(Map* map); |
| 3613 | |
| 3614 | // False if there are definitely no live objects created from this function. |
| 3615 | // True if live objects _may_ exist (existence not guaranteed). |
| 3616 | // May go back from true to false after GC. |
| 3617 | inline bool live_objects_may_exist(); |
| 3618 | |
| 3619 | inline void set_live_objects_may_exist(bool value); |
| 3620 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3621 | // [instance class name]: class name for instances. |
| 3622 | DECL_ACCESSORS(instance_class_name, Object) |
| 3623 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 3624 | // [function data]: This field holds some additional data for function. |
| 3625 | // Currently it either has FunctionTemplateInfo to make benefit the API |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3626 | // or Smi identifying a custom call generator. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3627 | // In the long run we don't want all functions to have this field but |
| 3628 | // we can fix that when we have a better model for storing hidden data |
| 3629 | // on objects. |
| 3630 | DECL_ACCESSORS(function_data, Object) |
| 3631 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 3632 | inline bool IsApiFunction(); |
| 3633 | inline FunctionTemplateInfo* get_api_func_data(); |
| 3634 | inline bool HasCustomCallGenerator(); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3635 | inline int custom_call_generator_id(); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 3636 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3637 | // [script info]: Script from which the function originates. |
| 3638 | DECL_ACCESSORS(script, Object) |
| 3639 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3640 | // [num_literals]: Number of literals used by this function. |
| 3641 | inline int num_literals(); |
| 3642 | inline void set_num_literals(int value); |
| 3643 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3644 | // [start_position_and_type]: Field used to store both the source code |
| 3645 | // position, whether or not the function is a function expression, |
| 3646 | // and whether or not the function is a toplevel function. The two |
| 3647 | // least significants bit indicates whether the function is an |
| 3648 | // expression and the rest contains the source code position. |
| 3649 | inline int start_position_and_type(); |
| 3650 | inline void set_start_position_and_type(int value); |
| 3651 | |
| 3652 | // [debug info]: Debug information. |
| 3653 | DECL_ACCESSORS(debug_info, Object) |
| 3654 | |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 3655 | // [inferred name]: Name inferred from variable or property |
| 3656 | // assignment of this function. Used to facilitate debugging and |
| 3657 | // profiling of JavaScript code written in OO style, where almost |
| 3658 | // all functions are anonymous but are assigned to object |
| 3659 | // properties. |
| 3660 | DECL_ACCESSORS(inferred_name, String) |
| 3661 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 3662 | // The function's name if it is non-empty, otherwise the inferred name. |
| 3663 | String* DebugName(); |
| 3664 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3665 | // Position of the 'function' token in the script source. |
| 3666 | inline int function_token_position(); |
| 3667 | inline void set_function_token_position(int function_token_position); |
| 3668 | |
| 3669 | // Position of this function in the script source. |
| 3670 | inline int start_position(); |
| 3671 | inline void set_start_position(int start_position); |
| 3672 | |
| 3673 | // End position of this function in the script source. |
| 3674 | inline int end_position(); |
| 3675 | inline void set_end_position(int end_position); |
| 3676 | |
| 3677 | // Is this function a function expression in the source code. |
| 3678 | inline bool is_expression(); |
| 3679 | inline void set_is_expression(bool value); |
| 3680 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 3681 | // Is this function a top-level function (scripts, evals). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3682 | inline bool is_toplevel(); |
| 3683 | inline void set_is_toplevel(bool value); |
| 3684 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 3685 | // Bit field containing various information collected by the compiler to |
| 3686 | // drive optimization. |
| 3687 | inline int compiler_hints(); |
| 3688 | inline void set_compiler_hints(int value); |
| 3689 | |
| 3690 | // Add information on assignments of the form this.x = ...; |
| 3691 | void SetThisPropertyAssignmentsInfo( |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 3692 | bool has_only_simple_this_property_assignments, |
| 3693 | FixedArray* this_property_assignments); |
| 3694 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3695 | // Clear information on assignments of the form this.x = ...; |
| 3696 | void ClearThisPropertyAssignmentsInfo(); |
| 3697 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 3698 | // Indicate that this function only consists of assignments of the form |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 3699 | // this.x = y; where y is either a constant or refers to an argument. |
| 3700 | inline bool has_only_simple_this_property_assignments(); |
| 3701 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3702 | inline bool try_full_codegen(); |
| 3703 | inline void set_try_full_codegen(bool flag); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3704 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 3705 | // Indicates if this function can be lazy compiled. |
| 3706 | // This is used to determine if we can safely flush code from a function |
| 3707 | // when doing GC if we expect that the function will no longer be used. |
| 3708 | inline bool allows_lazy_compilation(); |
| 3709 | inline void set_allows_lazy_compilation(bool flag); |
| 3710 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 3711 | // Indicates how many full GCs this function has survived with assigned |
| 3712 | // code object. Used to determine when it is relatively safe to flush |
| 3713 | // this code object and replace it with lazy compilation stub. |
| 3714 | // Age is reset when GC notices that the code object is referenced |
| 3715 | // from the stack or compilation cache. |
| 3716 | inline int code_age(); |
| 3717 | inline void set_code_age(int age); |
| 3718 | |
| 3719 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3720 | // Check whether a inlined constructor can be generated with the given |
| 3721 | // prototype. |
| 3722 | bool CanGenerateInlineConstructor(Object* prototype); |
| 3723 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 3724 | // Prevents further attempts to generate inline constructors. |
| 3725 | // To be called if generation failed for any reason. |
| 3726 | void ForbidInlineConstructor(); |
| 3727 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 3728 | // For functions which only contains this property assignments this provides |
| 3729 | // access to the names for the properties assigned. |
| 3730 | DECL_ACCESSORS(this_property_assignments, Object) |
| 3731 | inline int this_property_assignments_count(); |
| 3732 | inline void set_this_property_assignments_count(int value); |
| 3733 | String* GetThisPropertyAssignmentName(int index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 3734 | bool IsThisPropertyAssignmentArgument(int index); |
| 3735 | int GetThisPropertyAssignmentArgument(int index); |
| 3736 | Object* GetThisPropertyAssignmentConstant(int index); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 3737 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3738 | // [source code]: Source code for the function. |
| 3739 | bool HasSourceCode(); |
| 3740 | Object* GetSourceCode(); |
| 3741 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 3742 | // Calculate the instance size. |
| 3743 | int CalculateInstanceSize(); |
| 3744 | |
| 3745 | // Calculate the number of in-object properties. |
| 3746 | int CalculateInObjectProperties(); |
| 3747 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3748 | // Dispatched behavior. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3749 | // Set max_length to -1 for unlimited length. |
| 3750 | void SourceCodePrint(StringStream* accumulator, int max_length); |
| 3751 | #ifdef DEBUG |
| 3752 | void SharedFunctionInfoPrint(); |
| 3753 | void SharedFunctionInfoVerify(); |
| 3754 | #endif |
| 3755 | |
| 3756 | // Casting. |
| 3757 | static inline SharedFunctionInfo* cast(Object* obj); |
| 3758 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 3759 | // Constants. |
| 3760 | static const int kDontAdaptArgumentsSentinel = -1; |
| 3761 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3762 | // Layout description. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3763 | // Pointer fields. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 3764 | static const int kNameOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3765 | static const int kCodeOffset = kNameOffset + kPointerSize; |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 3766 | static const int kScopeInfoOffset = kCodeOffset + kPointerSize; |
| 3767 | static const int kConstructStubOffset = kScopeInfoOffset + kPointerSize; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3768 | static const int kInstanceClassNameOffset = |
| 3769 | kConstructStubOffset + kPointerSize; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 3770 | static const int kFunctionDataOffset = |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3771 | kInstanceClassNameOffset + kPointerSize; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 3772 | static const int kScriptOffset = kFunctionDataOffset + kPointerSize; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3773 | static const int kDebugInfoOffset = kScriptOffset + kPointerSize; |
| 3774 | static const int kInferredNameOffset = kDebugInfoOffset + kPointerSize; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3775 | static const int kInitialMapOffset = |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3776 | kInferredNameOffset + kPointerSize; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3777 | static const int kThisPropertyAssignmentsOffset = |
| 3778 | kInitialMapOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3779 | #if V8_HOST_ARCH_32_BIT |
| 3780 | // Smi fields. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3781 | static const int kLengthOffset = |
| 3782 | kThisPropertyAssignmentsOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3783 | static const int kFormalParameterCountOffset = kLengthOffset + kPointerSize; |
| 3784 | static const int kExpectedNofPropertiesOffset = |
| 3785 | kFormalParameterCountOffset + kPointerSize; |
| 3786 | static const int kNumLiteralsOffset = |
| 3787 | kExpectedNofPropertiesOffset + kPointerSize; |
| 3788 | static const int kStartPositionAndTypeOffset = |
| 3789 | kNumLiteralsOffset + kPointerSize; |
| 3790 | static const int kEndPositionOffset = |
| 3791 | kStartPositionAndTypeOffset + kPointerSize; |
| 3792 | static const int kFunctionTokenPositionOffset = |
| 3793 | kEndPositionOffset + kPointerSize; |
| 3794 | static const int kCompilerHintsOffset = |
| 3795 | kFunctionTokenPositionOffset + kPointerSize; |
| 3796 | static const int kThisPropertyAssignmentsCountOffset = |
| 3797 | kCompilerHintsOffset + kPointerSize; |
| 3798 | // Total size. |
| 3799 | static const int kSize = kThisPropertyAssignmentsCountOffset + kPointerSize; |
| 3800 | #else |
| 3801 | // The only reason to use smi fields instead of int fields |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3802 | // is to allow iteration without maps decoding during |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3803 | // garbage collections. |
| 3804 | // To avoid wasting space on 64-bit architectures we use |
| 3805 | // the following trick: we group integer fields into pairs |
| 3806 | // First integer in each pair is shifted left by 1. |
| 3807 | // By doing this we guarantee that LSB of each kPointerSize aligned |
| 3808 | // word is not set and thus this word cannot be treated as pointer |
| 3809 | // to HeapObject during old space traversal. |
| 3810 | static const int kLengthOffset = |
| 3811 | kThisPropertyAssignmentsOffset + kPointerSize; |
| 3812 | static const int kFormalParameterCountOffset = |
| 3813 | kLengthOffset + kIntSize; |
| 3814 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3815 | static const int kExpectedNofPropertiesOffset = |
| 3816 | kFormalParameterCountOffset + kIntSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3817 | static const int kNumLiteralsOffset = |
| 3818 | kExpectedNofPropertiesOffset + kIntSize; |
| 3819 | |
| 3820 | static const int kEndPositionOffset = |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3821 | kNumLiteralsOffset + kIntSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3822 | static const int kStartPositionAndTypeOffset = |
| 3823 | kEndPositionOffset + kIntSize; |
| 3824 | |
| 3825 | static const int kFunctionTokenPositionOffset = |
| 3826 | kStartPositionAndTypeOffset + kIntSize; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3827 | static const int kCompilerHintsOffset = |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3828 | kFunctionTokenPositionOffset + kIntSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3829 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 3830 | static const int kThisPropertyAssignmentsCountOffset = |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3831 | kCompilerHintsOffset + kIntSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3832 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3833 | // Total size. |
| 3834 | static const int kSize = kThisPropertyAssignmentsCountOffset + kIntSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3835 | |
| 3836 | #endif |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3837 | |
| 3838 | // The construction counter for inobject slack tracking is stored in the |
| 3839 | // most significant byte of compiler_hints which is otherwise unused. |
| 3840 | // Its offset depends on the endian-ness of the architecture. |
| 3841 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 3842 | static const int kConstructionCountOffset = kCompilerHintsOffset + 3; |
| 3843 | #elif __BYTE_ORDER == __BIG_ENDIAN |
| 3844 | static const int kConstructionCountOffset = kCompilerHintsOffset + 0; |
| 3845 | #else |
| 3846 | #error Unknown byte ordering |
| 3847 | #endif |
| 3848 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 3849 | static const int kAlignedSize = POINTER_SIZE_ALIGN(kSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3850 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3851 | typedef FixedBodyDescriptor<kNameOffset, |
| 3852 | kThisPropertyAssignmentsOffset + kPointerSize, |
| 3853 | kSize> BodyDescriptor; |
| 3854 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3855 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3856 | // Bit positions in start_position_and_type. |
| 3857 | // The source code start position is in the 30 most significant bits of |
| 3858 | // the start_position_and_type field. |
| 3859 | static const int kIsExpressionBit = 0; |
| 3860 | static const int kIsTopLevelBit = 1; |
| 3861 | static const int kStartPositionShift = 2; |
| 3862 | static const int kStartPositionMask = ~((1 << kStartPositionShift) - 1); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 3863 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 3864 | // Bit positions in compiler_hints. |
ager@chromium.org | b9a1545 | 2009-11-11 09:55:05 +0000 | [diff] [blame] | 3865 | static const int kHasOnlySimpleThisPropertyAssignments = 0; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3866 | static const int kTryFullCodegen = 1; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 3867 | static const int kAllowLazyCompilation = 2; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3868 | static const int kLiveObjectsMayExist = 3; |
| 3869 | static const int kCodeAgeShift = 4; |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 3870 | static const int kCodeAgeMask = 7; |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 3871 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 3872 | DISALLOW_IMPLICIT_CONSTRUCTORS(SharedFunctionInfo); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3873 | }; |
| 3874 | |
| 3875 | |
| 3876 | // JSFunction describes JavaScript functions. |
| 3877 | class JSFunction: public JSObject { |
| 3878 | public: |
| 3879 | // [prototype_or_initial_map]: |
| 3880 | DECL_ACCESSORS(prototype_or_initial_map, Object) |
| 3881 | |
| 3882 | // [shared_function_info]: The information about the function that |
| 3883 | // can be shared by instances. |
| 3884 | DECL_ACCESSORS(shared, SharedFunctionInfo) |
| 3885 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 3886 | inline SharedFunctionInfo* unchecked_shared(); |
| 3887 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3888 | // [context]: The context for this function. |
| 3889 | inline Context* context(); |
| 3890 | inline Object* unchecked_context(); |
| 3891 | inline void set_context(Object* context); |
| 3892 | |
| 3893 | // [code]: The generated code object for this function. Executed |
| 3894 | // when the function is invoked, e.g. foo() or new foo(). See |
| 3895 | // [[Call]] and [[Construct]] description in ECMA-262, section |
| 3896 | // 8.6.2, page 27. |
| 3897 | inline Code* code(); |
| 3898 | inline void set_code(Code* value); |
| 3899 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 3900 | inline Code* unchecked_code(); |
| 3901 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 3902 | // Tells whether this function is builtin. |
| 3903 | inline bool IsBuiltin(); |
| 3904 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3905 | // [literals]: Fixed array holding the materialized literals. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 3906 | // |
| 3907 | // If the function contains object, regexp or array literals, the |
| 3908 | // literals array prefix contains the object, regexp, and array |
| 3909 | // function to be used when creating these literals. This is |
| 3910 | // necessary so that we do not dynamically lookup the object, regexp |
| 3911 | // or array functions. Performing a dynamic lookup, we might end up |
| 3912 | // using the functions from a new context that we should not have |
| 3913 | // access to. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3914 | DECL_ACCESSORS(literals, FixedArray) |
| 3915 | |
| 3916 | // The initial map for an object created by this constructor. |
| 3917 | inline Map* initial_map(); |
| 3918 | inline void set_initial_map(Map* value); |
| 3919 | inline bool has_initial_map(); |
| 3920 | |
| 3921 | // Get and set the prototype property on a JSFunction. If the |
| 3922 | // function has an initial map the prototype is set on the initial |
| 3923 | // map. Otherwise, the prototype is put in the initial map field |
| 3924 | // until an initial map is needed. |
| 3925 | inline bool has_prototype(); |
| 3926 | inline bool has_instance_prototype(); |
| 3927 | inline Object* prototype(); |
| 3928 | inline Object* instance_prototype(); |
| 3929 | Object* SetInstancePrototype(Object* value); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3930 | MUST_USE_RESULT MaybeObject* SetPrototype(Object* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3931 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 3932 | // After prototype is removed, it will not be created when accessed, and |
| 3933 | // [[Construct]] from this function will not be allowed. |
| 3934 | Object* RemovePrototype(); |
| 3935 | inline bool should_have_prototype(); |
| 3936 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3937 | // Accessor for this function's initial map's [[class]] |
| 3938 | // property. This is primarily used by ECMA native functions. This |
| 3939 | // method sets the class_name field of this function's initial map |
| 3940 | // to a given value. It creates an initial map if this function does |
| 3941 | // not have one. Note that this method does not copy the initial map |
| 3942 | // if it has one already, but simply replaces it with the new value. |
| 3943 | // Instances created afterwards will have a map whose [[class]] is |
| 3944 | // set to 'value', but there is no guarantees on instances created |
| 3945 | // before. |
| 3946 | Object* SetInstanceClassName(String* name); |
| 3947 | |
| 3948 | // Returns if this function has been compiled to native code yet. |
| 3949 | inline bool is_compiled(); |
| 3950 | |
| 3951 | // Casting. |
| 3952 | static inline JSFunction* cast(Object* obj); |
| 3953 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 3954 | // Iterates the objects, including code objects indirectly referenced |
| 3955 | // through pointers to the first instruction in the code object. |
| 3956 | void JSFunctionIterateBody(int object_size, ObjectVisitor* v); |
| 3957 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3958 | // Dispatched behavior. |
| 3959 | #ifdef DEBUG |
| 3960 | void JSFunctionPrint(); |
| 3961 | void JSFunctionVerify(); |
| 3962 | #endif |
| 3963 | |
| 3964 | // Returns the number of allocated literals. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 3965 | inline int NumberOfLiterals(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3966 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 3967 | // Retrieve the global context from a function's literal array. |
| 3968 | static Context* GlobalContextFromLiterals(FixedArray* literals); |
| 3969 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3970 | // Layout descriptors. |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 3971 | static const int kCodeEntryOffset = JSObject::kHeaderSize; |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 3972 | static const int kPrototypeOrInitialMapOffset = |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 3973 | kCodeEntryOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3974 | static const int kSharedFunctionInfoOffset = |
| 3975 | kPrototypeOrInitialMapOffset + kPointerSize; |
| 3976 | static const int kContextOffset = kSharedFunctionInfoOffset + kPointerSize; |
| 3977 | static const int kLiteralsOffset = kContextOffset + kPointerSize; |
| 3978 | static const int kSize = kLiteralsOffset + kPointerSize; |
| 3979 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 3980 | // Layout of the literals array. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 3981 | static const int kLiteralsPrefixSize = 1; |
| 3982 | static const int kLiteralGlobalContextIndex = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3983 | private: |
| 3984 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunction); |
| 3985 | }; |
| 3986 | |
| 3987 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3988 | // JSGlobalProxy's prototype must be a JSGlobalObject or null, |
| 3989 | // and the prototype is hidden. JSGlobalProxy always delegates |
| 3990 | // property accesses to its prototype if the prototype is not null. |
| 3991 | // |
| 3992 | // A JSGlobalProxy can be reinitialized which will preserve its identity. |
| 3993 | // |
| 3994 | // Accessing a JSGlobalProxy requires security check. |
| 3995 | |
| 3996 | class JSGlobalProxy : public JSObject { |
| 3997 | public: |
| 3998 | // [context]: the owner global context of this proxy object. |
| 3999 | // It is null value if this object is not used by any context. |
| 4000 | DECL_ACCESSORS(context, Object) |
| 4001 | |
| 4002 | // Casting. |
| 4003 | static inline JSGlobalProxy* cast(Object* obj); |
| 4004 | |
| 4005 | // Dispatched behavior. |
| 4006 | #ifdef DEBUG |
| 4007 | void JSGlobalProxyPrint(); |
| 4008 | void JSGlobalProxyVerify(); |
| 4009 | #endif |
| 4010 | |
| 4011 | // Layout description. |
| 4012 | static const int kContextOffset = JSObject::kHeaderSize; |
| 4013 | static const int kSize = kContextOffset + kPointerSize; |
| 4014 | |
| 4015 | private: |
| 4016 | |
| 4017 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalProxy); |
| 4018 | }; |
| 4019 | |
| 4020 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4021 | // Forward declaration. |
| 4022 | class JSBuiltinsObject; |
| 4023 | |
| 4024 | // Common super class for JavaScript global objects and the special |
| 4025 | // builtins global objects. |
| 4026 | class GlobalObject: public JSObject { |
| 4027 | public: |
| 4028 | // [builtins]: the object holding the runtime routines written in JS. |
| 4029 | DECL_ACCESSORS(builtins, JSBuiltinsObject) |
| 4030 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 4031 | // [global context]: the global context corresponding to this global object. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4032 | DECL_ACCESSORS(global_context, Context) |
| 4033 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4034 | // [global receiver]: the global receiver object of the context |
| 4035 | DECL_ACCESSORS(global_receiver, JSObject) |
| 4036 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 4037 | // Retrieve the property cell used to store a property. |
| 4038 | Object* GetPropertyCell(LookupResult* result); |
| 4039 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4040 | // This is like GetProperty, but is used when you know the lookup won't fail |
| 4041 | // by throwing an exception. This is for the debug and builtins global |
| 4042 | // objects, where it is known which properties can be expected to be present |
| 4043 | // on the object. |
| 4044 | Object* GetPropertyNoExceptionThrown(String* key) { |
| 4045 | Object* answer = GetProperty(key)->ToObjectUnchecked(); |
| 4046 | return answer; |
| 4047 | } |
| 4048 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 4049 | // 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] | 4050 | MUST_USE_RESULT MaybeObject* EnsurePropertyCell(String* name); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 4051 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4052 | // Casting. |
| 4053 | static inline GlobalObject* cast(Object* obj); |
| 4054 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4055 | // Layout description. |
| 4056 | static const int kBuiltinsOffset = JSObject::kHeaderSize; |
| 4057 | static const int kGlobalContextOffset = kBuiltinsOffset + kPointerSize; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4058 | static const int kGlobalReceiverOffset = kGlobalContextOffset + kPointerSize; |
| 4059 | static const int kHeaderSize = kGlobalReceiverOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4060 | |
| 4061 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4062 | friend class AGCCVersionRequiresThisClassToHaveAFriendSoHereItIs; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 4063 | |
| 4064 | DISALLOW_IMPLICIT_CONSTRUCTORS(GlobalObject); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4065 | }; |
| 4066 | |
| 4067 | |
| 4068 | // JavaScript global object. |
| 4069 | class JSGlobalObject: public GlobalObject { |
| 4070 | public: |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 4071 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4072 | // Casting. |
| 4073 | static inline JSGlobalObject* cast(Object* obj); |
| 4074 | |
| 4075 | // Dispatched behavior. |
| 4076 | #ifdef DEBUG |
| 4077 | void JSGlobalObjectPrint(); |
| 4078 | void JSGlobalObjectVerify(); |
| 4079 | #endif |
| 4080 | |
| 4081 | // Layout description. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4082 | static const int kSize = GlobalObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4083 | |
| 4084 | private: |
| 4085 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalObject); |
| 4086 | }; |
| 4087 | |
| 4088 | |
| 4089 | // Builtins global object which holds the runtime routines written in |
| 4090 | // JavaScript. |
| 4091 | class JSBuiltinsObject: public GlobalObject { |
| 4092 | public: |
| 4093 | // Accessors for the runtime routines written in JavaScript. |
| 4094 | inline Object* javascript_builtin(Builtins::JavaScript id); |
| 4095 | inline void set_javascript_builtin(Builtins::JavaScript id, Object* value); |
| 4096 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 4097 | // Accessors for code of the runtime routines written in JavaScript. |
| 4098 | inline Code* javascript_builtin_code(Builtins::JavaScript id); |
| 4099 | inline void set_javascript_builtin_code(Builtins::JavaScript id, Code* value); |
| 4100 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4101 | // Casting. |
| 4102 | static inline JSBuiltinsObject* cast(Object* obj); |
| 4103 | |
| 4104 | // Dispatched behavior. |
| 4105 | #ifdef DEBUG |
| 4106 | void JSBuiltinsObjectPrint(); |
| 4107 | void JSBuiltinsObjectVerify(); |
| 4108 | #endif |
| 4109 | |
| 4110 | // Layout description. The size of the builtins object includes |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 4111 | // room for two pointers per runtime routine written in javascript |
| 4112 | // (function and code object). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4113 | static const int kJSBuiltinsCount = Builtins::id_count; |
| 4114 | static const int kJSBuiltinsOffset = GlobalObject::kHeaderSize; |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 4115 | static const int kJSBuiltinsCodeOffset = |
| 4116 | GlobalObject::kHeaderSize + (kJSBuiltinsCount * kPointerSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4117 | static const int kSize = |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 4118 | kJSBuiltinsCodeOffset + (kJSBuiltinsCount * kPointerSize); |
| 4119 | |
| 4120 | static int OffsetOfFunctionWithId(Builtins::JavaScript id) { |
| 4121 | return kJSBuiltinsOffset + id * kPointerSize; |
| 4122 | } |
| 4123 | |
| 4124 | static int OffsetOfCodeWithId(Builtins::JavaScript id) { |
| 4125 | return kJSBuiltinsCodeOffset + id * kPointerSize; |
| 4126 | } |
| 4127 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4128 | private: |
| 4129 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSBuiltinsObject); |
| 4130 | }; |
| 4131 | |
| 4132 | |
| 4133 | // Representation for JS Wrapper objects, String, Number, Boolean, Date, etc. |
| 4134 | class JSValue: public JSObject { |
| 4135 | public: |
| 4136 | // [value]: the object being wrapped. |
| 4137 | DECL_ACCESSORS(value, Object) |
| 4138 | |
| 4139 | // Casting. |
| 4140 | static inline JSValue* cast(Object* obj); |
| 4141 | |
| 4142 | // Dispatched behavior. |
| 4143 | #ifdef DEBUG |
| 4144 | void JSValuePrint(); |
| 4145 | void JSValueVerify(); |
| 4146 | #endif |
| 4147 | |
| 4148 | // Layout description. |
| 4149 | static const int kValueOffset = JSObject::kHeaderSize; |
| 4150 | static const int kSize = kValueOffset + kPointerSize; |
| 4151 | |
| 4152 | private: |
| 4153 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSValue); |
| 4154 | }; |
| 4155 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 4156 | // Regular expressions |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4157 | // The regular expression holds a single reference to a FixedArray in |
| 4158 | // the kDataOffset field. |
| 4159 | // The FixedArray contains the following data: |
| 4160 | // - tag : type of regexp implementation (not compiled yet, atom or irregexp) |
| 4161 | // - reference to the original source string |
| 4162 | // - reference to the original flag string |
| 4163 | // If it is an atom regexp |
| 4164 | // - a reference to a literal string to search for |
| 4165 | // If it is an irregexp regexp: |
| 4166 | // - a reference to code for ASCII inputs (bytecode or compiled). |
| 4167 | // - a reference to code for UC16 inputs (bytecode or compiled). |
| 4168 | // - max number of registers used by irregexp implementations. |
| 4169 | // - number of capture registers (output values) of the regexp. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 4170 | class JSRegExp: public JSObject { |
| 4171 | public: |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 4172 | // Meaning of Type: |
| 4173 | // 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] | 4174 | // ATOM: A simple string to match against using an indexOf operation. |
| 4175 | // IRREGEXP: Compiled with Irregexp. |
| 4176 | // IRREGEXP_NATIVE: Compiled to native code with Irregexp. |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 4177 | enum Type { NOT_COMPILED, ATOM, IRREGEXP }; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4178 | enum Flag { NONE = 0, GLOBAL = 1, IGNORE_CASE = 2, MULTILINE = 4 }; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 4179 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4180 | class Flags { |
| 4181 | public: |
| 4182 | explicit Flags(uint32_t value) : value_(value) { } |
| 4183 | bool is_global() { return (value_ & GLOBAL) != 0; } |
| 4184 | bool is_ignore_case() { return (value_ & IGNORE_CASE) != 0; } |
| 4185 | bool is_multiline() { return (value_ & MULTILINE) != 0; } |
| 4186 | uint32_t value() { return value_; } |
| 4187 | private: |
| 4188 | uint32_t value_; |
| 4189 | }; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 4190 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 4191 | DECL_ACCESSORS(data, Object) |
| 4192 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4193 | inline Type TypeTag(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4194 | inline int CaptureCount(); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 4195 | inline Flags GetFlags(); |
| 4196 | inline String* Pattern(); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4197 | inline Object* DataAt(int index); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4198 | // Set implementation data after the object has been prepared. |
| 4199 | inline void SetDataAt(int index, Object* value); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 4200 | static int code_index(bool is_ascii) { |
| 4201 | if (is_ascii) { |
| 4202 | return kIrregexpASCIICodeIndex; |
| 4203 | } else { |
| 4204 | return kIrregexpUC16CodeIndex; |
| 4205 | } |
| 4206 | } |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4207 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 4208 | static inline JSRegExp* cast(Object* obj); |
| 4209 | |
| 4210 | // Dispatched behavior. |
| 4211 | #ifdef DEBUG |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 4212 | void JSRegExpVerify(); |
| 4213 | #endif |
| 4214 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4215 | static const int kDataOffset = JSObject::kHeaderSize; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4216 | static const int kSize = kDataOffset + kPointerSize; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4217 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4218 | // Indices in the data array. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4219 | static const int kTagIndex = 0; |
| 4220 | static const int kSourceIndex = kTagIndex + 1; |
| 4221 | static const int kFlagsIndex = kSourceIndex + 1; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4222 | static const int kDataIndex = kFlagsIndex + 1; |
| 4223 | // The data fields are used in different ways depending on the |
| 4224 | // value of the tag. |
| 4225 | // Atom regexps (literal strings). |
| 4226 | static const int kAtomPatternIndex = kDataIndex; |
| 4227 | |
| 4228 | static const int kAtomDataSize = kAtomPatternIndex + 1; |
| 4229 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 4230 | // Irregexp compiled code or bytecode for ASCII. If compilation |
| 4231 | // fails, this fields hold an exception object that should be |
| 4232 | // thrown if the regexp is used again. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4233 | static const int kIrregexpASCIICodeIndex = kDataIndex; |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 4234 | // Irregexp compiled code or bytecode for UC16. If compilation |
| 4235 | // fails, this fields hold an exception object that should be |
| 4236 | // thrown if the regexp is used again. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4237 | static const int kIrregexpUC16CodeIndex = kDataIndex + 1; |
| 4238 | // Maximal number of registers used by either ASCII or UC16. |
| 4239 | // Only used to check that there is enough stack space |
| 4240 | static const int kIrregexpMaxRegisterCountIndex = kDataIndex + 2; |
| 4241 | // Number of captures in the compiled regexp. |
| 4242 | static const int kIrregexpCaptureCountIndex = kDataIndex + 3; |
| 4243 | |
| 4244 | static const int kIrregexpDataSize = kIrregexpCaptureCountIndex + 1; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 4245 | |
| 4246 | // Offsets directly into the data fixed array. |
| 4247 | static const int kDataTagOffset = |
| 4248 | FixedArray::kHeaderSize + kTagIndex * kPointerSize; |
| 4249 | static const int kDataAsciiCodeOffset = |
| 4250 | FixedArray::kHeaderSize + kIrregexpASCIICodeIndex * kPointerSize; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4251 | static const int kDataUC16CodeOffset = |
| 4252 | FixedArray::kHeaderSize + kIrregexpUC16CodeIndex * kPointerSize; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 4253 | static const int kIrregexpCaptureCountOffset = |
| 4254 | FixedArray::kHeaderSize + kIrregexpCaptureCountIndex * kPointerSize; |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 4255 | |
| 4256 | // In-object fields. |
| 4257 | static const int kSourceFieldIndex = 0; |
| 4258 | static const int kGlobalFieldIndex = 1; |
| 4259 | static const int kIgnoreCaseFieldIndex = 2; |
| 4260 | static const int kMultilineFieldIndex = 3; |
| 4261 | static const int kLastIndexFieldIndex = 4; |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 4262 | static const int kInObjectFieldCount = 5; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4263 | }; |
| 4264 | |
| 4265 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4266 | class CompilationCacheShape { |
| 4267 | public: |
| 4268 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 4269 | return key->IsMatch(value); |
| 4270 | } |
| 4271 | |
| 4272 | static inline uint32_t Hash(HashTableKey* key) { |
| 4273 | return key->Hash(); |
| 4274 | } |
| 4275 | |
| 4276 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 4277 | return key->HashForObject(object); |
| 4278 | } |
| 4279 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4280 | MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4281 | return key->AsObject(); |
| 4282 | } |
| 4283 | |
| 4284 | static const int kPrefixSize = 0; |
| 4285 | static const int kEntrySize = 2; |
| 4286 | }; |
| 4287 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 4288 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4289 | class CompilationCacheTable: public HashTable<CompilationCacheShape, |
| 4290 | HashTableKey*> { |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4291 | public: |
| 4292 | // Find cached value for a string key, otherwise return null. |
| 4293 | Object* Lookup(String* src); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 4294 | Object* LookupEval(String* src, Context* context); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4295 | Object* LookupRegExp(String* source, JSRegExp::Flags flags); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4296 | MaybeObject* Put(String* src, Object* value); |
| 4297 | MaybeObject* PutEval(String* src, Context* context, Object* value); |
| 4298 | MaybeObject* PutRegExp(String* src, JSRegExp::Flags flags, FixedArray* value); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4299 | |
| 4300 | static inline CompilationCacheTable* cast(Object* obj); |
| 4301 | |
| 4302 | private: |
| 4303 | DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheTable); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 4304 | }; |
| 4305 | |
| 4306 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4307 | class CodeCache: public Struct { |
| 4308 | public: |
| 4309 | DECL_ACCESSORS(default_cache, FixedArray) |
| 4310 | DECL_ACCESSORS(normal_type_cache, Object) |
| 4311 | |
| 4312 | // Add the code object to the cache. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4313 | MUST_USE_RESULT MaybeObject* Update(String* name, Code* code); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4314 | |
| 4315 | // Lookup code object in the cache. Returns code object if found and undefined |
| 4316 | // if not. |
| 4317 | Object* Lookup(String* name, Code::Flags flags); |
| 4318 | |
| 4319 | // Get the internal index of a code object in the cache. Returns -1 if the |
| 4320 | // code object is not in that cache. This index can be used to later call |
| 4321 | // RemoveByIndex. The cache cannot be modified between a call to GetIndex and |
| 4322 | // RemoveByIndex. |
sgjesse@chromium.org | 99a37fa | 2010-03-11 09:23:46 +0000 | [diff] [blame] | 4323 | int GetIndex(Object* name, Code* code); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4324 | |
| 4325 | // Remove an object from the cache with the provided internal index. |
sgjesse@chromium.org | 99a37fa | 2010-03-11 09:23:46 +0000 | [diff] [blame] | 4326 | void RemoveByIndex(Object* name, Code* code, int index); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4327 | |
| 4328 | static inline CodeCache* cast(Object* obj); |
| 4329 | |
| 4330 | #ifdef DEBUG |
| 4331 | void CodeCachePrint(); |
| 4332 | void CodeCacheVerify(); |
| 4333 | #endif |
| 4334 | |
| 4335 | static const int kDefaultCacheOffset = HeapObject::kHeaderSize; |
| 4336 | static const int kNormalTypeCacheOffset = |
| 4337 | kDefaultCacheOffset + kPointerSize; |
| 4338 | static const int kSize = kNormalTypeCacheOffset + kPointerSize; |
| 4339 | |
| 4340 | private: |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4341 | MUST_USE_RESULT MaybeObject* UpdateDefaultCache(String* name, Code* code); |
| 4342 | MUST_USE_RESULT MaybeObject* UpdateNormalTypeCache(String* name, Code* code); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4343 | Object* LookupDefaultCache(String* name, Code::Flags flags); |
| 4344 | Object* LookupNormalTypeCache(String* name, Code::Flags flags); |
| 4345 | |
| 4346 | // Code cache layout of the default cache. Elements are alternating name and |
| 4347 | // code objects for non normal load/store/call IC's. |
| 4348 | static const int kCodeCacheEntrySize = 2; |
| 4349 | static const int kCodeCacheEntryNameOffset = 0; |
| 4350 | static const int kCodeCacheEntryCodeOffset = 1; |
| 4351 | |
| 4352 | DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCache); |
| 4353 | }; |
| 4354 | |
| 4355 | |
| 4356 | class CodeCacheHashTableShape { |
| 4357 | public: |
| 4358 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 4359 | return key->IsMatch(value); |
| 4360 | } |
| 4361 | |
| 4362 | static inline uint32_t Hash(HashTableKey* key) { |
| 4363 | return key->Hash(); |
| 4364 | } |
| 4365 | |
| 4366 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 4367 | return key->HashForObject(object); |
| 4368 | } |
| 4369 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4370 | MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4371 | return key->AsObject(); |
| 4372 | } |
| 4373 | |
| 4374 | static const int kPrefixSize = 0; |
| 4375 | static const int kEntrySize = 2; |
| 4376 | }; |
| 4377 | |
| 4378 | |
| 4379 | class CodeCacheHashTable: public HashTable<CodeCacheHashTableShape, |
| 4380 | HashTableKey*> { |
| 4381 | public: |
| 4382 | Object* Lookup(String* name, Code::Flags flags); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4383 | MUST_USE_RESULT MaybeObject* Put(String* name, Code* code); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4384 | |
| 4385 | int GetIndex(String* name, Code::Flags flags); |
| 4386 | void RemoveByIndex(int index); |
| 4387 | |
| 4388 | static inline CodeCacheHashTable* cast(Object* obj); |
| 4389 | |
| 4390 | // Initial size of the fixed array backing the hash table. |
| 4391 | static const int kInitialSize = 64; |
| 4392 | |
| 4393 | private: |
| 4394 | DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCacheHashTable); |
| 4395 | }; |
| 4396 | |
| 4397 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4398 | enum AllowNullsFlag {ALLOW_NULLS, DISALLOW_NULLS}; |
| 4399 | enum RobustnessFlag {ROBUST_STRING_TRAVERSAL, FAST_STRING_TRAVERSAL}; |
| 4400 | |
| 4401 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4402 | class StringHasher { |
| 4403 | public: |
| 4404 | inline StringHasher(int length); |
| 4405 | |
| 4406 | // Returns true if the hash of this string can be computed without |
| 4407 | // looking at the contents. |
| 4408 | inline bool has_trivial_hash(); |
| 4409 | |
| 4410 | // Add a character to the hash and update the array index calculation. |
| 4411 | inline void AddCharacter(uc32 c); |
| 4412 | |
| 4413 | // Adds a character to the hash but does not update the array index |
| 4414 | // calculation. This can only be called when it has been verified |
| 4415 | // that the input is not an array index. |
| 4416 | inline void AddCharacterNoIndex(uc32 c); |
| 4417 | |
| 4418 | // Returns the value to store in the hash field of a string with |
| 4419 | // the given length and contents. |
| 4420 | uint32_t GetHashField(); |
| 4421 | |
| 4422 | // Returns true if the characters seen so far make up a legal array |
| 4423 | // index. |
| 4424 | bool is_array_index() { return is_array_index_; } |
| 4425 | |
| 4426 | bool is_valid() { return is_valid_; } |
| 4427 | |
| 4428 | void invalidate() { is_valid_ = false; } |
| 4429 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 4430 | // Calculated hash value for a string consisting of 1 to |
| 4431 | // String::kMaxArrayIndexSize digits with no leading zeros (except "0"). |
| 4432 | // value is represented decimal value. |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 4433 | static uint32_t MakeArrayIndexHash(uint32_t value, int length); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 4434 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4435 | private: |
| 4436 | |
| 4437 | uint32_t array_index() { |
| 4438 | ASSERT(is_array_index()); |
| 4439 | return array_index_; |
| 4440 | } |
| 4441 | |
| 4442 | inline uint32_t GetHash(); |
| 4443 | |
| 4444 | int length_; |
| 4445 | uint32_t raw_running_hash_; |
| 4446 | uint32_t array_index_; |
| 4447 | bool is_array_index_; |
| 4448 | bool is_first_char_; |
| 4449 | bool is_valid_; |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4450 | friend class TwoCharHashTableKey; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4451 | }; |
| 4452 | |
| 4453 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 4454 | // The characteristics of a string are stored in its map. Retrieving these |
| 4455 | // few bits of information is moderately expensive, involving two memory |
| 4456 | // loads where the second is dependent on the first. To improve efficiency |
| 4457 | // the shape of the string is given its own class so that it can be retrieved |
| 4458 | // once and used for several string operations. A StringShape is small enough |
| 4459 | // 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] | 4460 | // string can potentially alter its shape. Also be aware that a GC caused by |
| 4461 | // 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] | 4462 | // shortcutting. Keeping these restrictions in mind has proven to be error- |
| 4463 | // prone and so we no longer put StringShapes in variables unless there is a |
| 4464 | // concrete performance benefit at that particular point in the code. |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 4465 | class StringShape BASE_EMBEDDED { |
| 4466 | public: |
| 4467 | inline explicit StringShape(String* s); |
| 4468 | inline explicit StringShape(Map* s); |
| 4469 | inline explicit StringShape(InstanceType t); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 4470 | inline bool IsSequential(); |
| 4471 | inline bool IsExternal(); |
| 4472 | inline bool IsCons(); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 4473 | inline bool IsExternalAscii(); |
| 4474 | inline bool IsExternalTwoByte(); |
| 4475 | inline bool IsSequentialAscii(); |
| 4476 | inline bool IsSequentialTwoByte(); |
| 4477 | inline bool IsSymbol(); |
| 4478 | inline StringRepresentationTag representation_tag(); |
| 4479 | inline uint32_t full_representation_tag(); |
| 4480 | inline uint32_t size_tag(); |
| 4481 | #ifdef DEBUG |
| 4482 | inline uint32_t type() { return type_; } |
| 4483 | inline void invalidate() { valid_ = false; } |
| 4484 | inline bool valid() { return valid_; } |
| 4485 | #else |
| 4486 | inline void invalidate() { } |
| 4487 | #endif |
| 4488 | private: |
| 4489 | uint32_t type_; |
| 4490 | #ifdef DEBUG |
| 4491 | inline void set_valid() { valid_ = true; } |
| 4492 | bool valid_; |
| 4493 | #else |
| 4494 | inline void set_valid() { } |
| 4495 | #endif |
| 4496 | }; |
| 4497 | |
| 4498 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4499 | // The String abstract class captures JavaScript string values: |
| 4500 | // |
| 4501 | // Ecma-262: |
| 4502 | // 4.3.16 String Value |
| 4503 | // A string value is a member of the type String and is a finite |
| 4504 | // ordered sequence of zero or more 16-bit unsigned integer values. |
| 4505 | // |
| 4506 | // All string values have a length field. |
| 4507 | class String: public HeapObject { |
| 4508 | public: |
| 4509 | // Get and set the length of the string. |
| 4510 | inline int length(); |
| 4511 | inline void set_length(int value); |
| 4512 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 4513 | // Get and set the hash field of the string. |
| 4514 | inline uint32_t hash_field(); |
| 4515 | inline void set_hash_field(uint32_t value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4516 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 4517 | inline bool IsAsciiRepresentation(); |
| 4518 | inline bool IsTwoByteRepresentation(); |
| 4519 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 4520 | // Returns whether this string has ascii chars, i.e. all of them can |
| 4521 | // be ascii encoded. This might be the case even if the string is |
| 4522 | // two-byte. Such strings may appear when the embedder prefers |
| 4523 | // two-byte external representations even for ascii data. |
ricow@chromium.org | aa1b616 | 2010-03-29 07:44:58 +0000 | [diff] [blame] | 4524 | // |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 4525 | // NOTE: this should be considered only a hint. False negatives are |
| 4526 | // possible. |
| 4527 | inline bool HasOnlyAsciiChars(); |
ricow@chromium.org | aa1b616 | 2010-03-29 07:44:58 +0000 | [diff] [blame] | 4528 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4529 | // Get and set individual two byte chars in the string. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4530 | inline void Set(int index, uint16_t value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4531 | // Get individual two byte char in the string. Repeated calls |
| 4532 | // to this method are not efficient unless the string is flat. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4533 | inline uint16_t Get(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4534 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4535 | // Try to flatten the string. Checks first inline to see if it is |
| 4536 | // necessary. Does nothing if the string is not a cons string. |
| 4537 | // Flattening allocates a sequential string with the same data as |
| 4538 | // the given string and mutates the cons string to a degenerate |
| 4539 | // form, where the first component is the new sequential string and |
| 4540 | // the second component is the empty string. If allocation fails, |
| 4541 | // this function returns a failure. If flattening succeeds, this |
| 4542 | // function returns the sequential string that is now the first |
| 4543 | // component of the cons string. |
| 4544 | // |
| 4545 | // Degenerate cons strings are handled specially by the garbage |
| 4546 | // collector (see IsShortcutCandidate). |
| 4547 | // |
| 4548 | // Use FlattenString from Handles.cc to flatten even in case an |
| 4549 | // allocation failure happens. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4550 | inline MaybeObject* TryFlatten(PretenureFlag pretenure = NOT_TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4551 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4552 | // Convenience function. Has exactly the same behavior as |
| 4553 | // TryFlatten(), except in the case of failure returns the original |
| 4554 | // string. |
| 4555 | inline String* TryFlattenGetString(PretenureFlag pretenure = NOT_TENURED); |
| 4556 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4557 | Vector<const char> ToAsciiVector(); |
| 4558 | Vector<const uc16> ToUC16Vector(); |
| 4559 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4560 | // Mark the string as an undetectable object. It only applies to |
| 4561 | // ascii and two byte string types. |
| 4562 | bool MarkAsUndetectable(); |
| 4563 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4564 | // Return a substring. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4565 | MUST_USE_RESULT MaybeObject* SubString(int from, |
| 4566 | int to, |
| 4567 | PretenureFlag pretenure = NOT_TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4568 | |
| 4569 | // String equality operations. |
| 4570 | inline bool Equals(String* other); |
| 4571 | bool IsEqualTo(Vector<const char> str); |
| 4572 | |
| 4573 | // Return a UTF8 representation of the string. The string is null |
| 4574 | // terminated but may optionally contain nulls. Length is returned |
| 4575 | // in length_output if length_output is not a null pointer The string |
| 4576 | // should be nearly flat, otherwise the performance of this method may |
| 4577 | // be very slow (quadratic in the length). Setting robustness_flag to |
| 4578 | // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
| 4579 | // handles unexpected data without causing assert failures and it does not |
| 4580 | // do any heap allocations. This is useful when printing stack traces. |
| 4581 | SmartPointer<char> ToCString(AllowNullsFlag allow_nulls, |
| 4582 | RobustnessFlag robustness_flag, |
| 4583 | int offset, |
| 4584 | int length, |
| 4585 | int* length_output = 0); |
| 4586 | SmartPointer<char> ToCString( |
| 4587 | AllowNullsFlag allow_nulls = DISALLOW_NULLS, |
| 4588 | RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL, |
| 4589 | int* length_output = 0); |
| 4590 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 4591 | int Utf8Length(); |
| 4592 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4593 | // Return a 16 bit Unicode representation of the string. |
| 4594 | // The string should be nearly flat, otherwise the performance of |
| 4595 | // of this method may be very bad. Setting robustness_flag to |
| 4596 | // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
| 4597 | // handles unexpected data without causing assert failures and it does not |
| 4598 | // do any heap allocations. This is useful when printing stack traces. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4599 | SmartPointer<uc16> ToWideCString( |
| 4600 | RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4601 | |
| 4602 | // Tells whether the hash code has been computed. |
| 4603 | inline bool HasHashCode(); |
| 4604 | |
| 4605 | // Returns a hash value used for the property table |
| 4606 | inline uint32_t Hash(); |
| 4607 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 4608 | static uint32_t ComputeHashField(unibrow::CharacterStream* buffer, |
| 4609 | int length); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4610 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4611 | static bool ComputeArrayIndex(unibrow::CharacterStream* buffer, |
| 4612 | uint32_t* index, |
| 4613 | int length); |
| 4614 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 4615 | // Externalization. |
| 4616 | bool MakeExternal(v8::String::ExternalStringResource* resource); |
| 4617 | bool MakeExternal(v8::String::ExternalAsciiStringResource* resource); |
| 4618 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4619 | // Conversion. |
| 4620 | inline bool AsArrayIndex(uint32_t* index); |
| 4621 | |
| 4622 | // Casting. |
| 4623 | static inline String* cast(Object* obj); |
| 4624 | |
| 4625 | void PrintOn(FILE* out); |
| 4626 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4627 | // For use during stack traces. Performs rudimentary sanity check. |
| 4628 | bool LooksValid(); |
| 4629 | |
| 4630 | // Dispatched behavior. |
| 4631 | void StringShortPrint(StringStream* accumulator); |
| 4632 | #ifdef DEBUG |
| 4633 | void StringPrint(); |
| 4634 | void StringVerify(); |
| 4635 | #endif |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4636 | inline bool IsFlat(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4637 | |
| 4638 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 4639 | static const int kLengthOffset = HeapObject::kHeaderSize; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 4640 | static const int kHashFieldOffset = kLengthOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4641 | static const int kSize = kHashFieldOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4642 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4643 | // Maximum number of characters to consider when trying to convert a string |
| 4644 | // value into an array index. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4645 | static const int kMaxArrayIndexSize = 10; |
| 4646 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4647 | // Max ascii char code. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4648 | static const int kMaxAsciiCharCode = unibrow::Utf8::kMaxOneByteChar; |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 4649 | static const unsigned kMaxAsciiCharCodeU = unibrow::Utf8::kMaxOneByteChar; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 4650 | static const int kMaxUC16CharCode = 0xffff; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4651 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4652 | // Minimum length for a cons string. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4653 | static const int kMinNonFlatLength = 13; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4654 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4655 | // Mask constant for checking if a string has a computed hash code |
| 4656 | // and if it is an array index. The least significant bit indicates |
| 4657 | // whether a hash code has been computed. If the hash code has been |
| 4658 | // computed the 2nd bit tells whether the string can be used as an |
| 4659 | // array index. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4660 | static const int kHashNotComputedMask = 1; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 4661 | static const int kIsNotArrayIndexMask = 1 << 1; |
| 4662 | static const int kNofHashBitFields = 2; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4663 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 4664 | // Shift constant retrieving hash code from hash field. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 4665 | static const int kHashShift = kNofHashBitFields; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 4666 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4667 | // Array index strings this short can keep their index in the hash |
| 4668 | // field. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4669 | static const int kMaxCachedArrayIndexLength = 7; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4670 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 4671 | // For strings which are array indexes the hash value has the string length |
| 4672 | // mixed into the hash, mainly to avoid a hash value of zero which would be |
| 4673 | // 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] | 4674 | static const int kArrayIndexValueBits = 24; |
| 4675 | static const int kArrayIndexLengthBits = |
| 4676 | kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields; |
| 4677 | |
| 4678 | STATIC_CHECK((kArrayIndexLengthBits > 0)); |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 4679 | STATIC_CHECK(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits)); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 4680 | |
| 4681 | static const int kArrayIndexHashLengthShift = |
| 4682 | kArrayIndexValueBits + kNofHashBitFields; |
| 4683 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 4684 | static const int kArrayIndexHashMask = (1 << kArrayIndexHashLengthShift) - 1; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 4685 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4686 | static const int kArrayIndexValueMask = |
| 4687 | ((1 << kArrayIndexValueBits) - 1) << kHashShift; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4688 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 4689 | // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we |
| 4690 | // could use a mask to test if the length of string is less than or equal to |
| 4691 | // kMaxCachedArrayIndexLength. |
| 4692 | STATIC_CHECK(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1)); |
| 4693 | |
| 4694 | static const int kContainsCachedArrayIndexMask = |
| 4695 | (~kMaxCachedArrayIndexLength << kArrayIndexHashLengthShift) | |
| 4696 | kIsNotArrayIndexMask; |
| 4697 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 4698 | // 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] | 4699 | static const int kEmptyHashField = |
| 4700 | kIsNotArrayIndexMask | kHashNotComputedMask; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4701 | |
| 4702 | // Value of hash field containing computed hash equal to zero. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 4703 | static const int kZeroHash = kIsNotArrayIndexMask; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 4704 | |
| 4705 | // Maximal string length. |
| 4706 | static const int kMaxLength = (1 << (32 - 2)) - 1; |
| 4707 | |
| 4708 | // Max length for computing hash. For strings longer than this limit the |
| 4709 | // string length is used as the hash value. |
| 4710 | static const int kMaxHashCalcLength = 16383; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4711 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4712 | // Limit for truncation in short printing. |
| 4713 | static const int kMaxShortPrintLength = 1024; |
| 4714 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4715 | // Support for regular expressions. |
| 4716 | const uc16* GetTwoByteData(); |
| 4717 | const uc16* GetTwoByteData(unsigned start); |
| 4718 | |
| 4719 | // Support for StringInputBuffer |
| 4720 | static const unibrow::byte* ReadBlock(String* input, |
| 4721 | unibrow::byte* util_buffer, |
| 4722 | unsigned capacity, |
| 4723 | unsigned* remaining, |
| 4724 | unsigned* offset); |
| 4725 | static const unibrow::byte* ReadBlock(String** input, |
| 4726 | unibrow::byte* util_buffer, |
| 4727 | unsigned capacity, |
| 4728 | unsigned* remaining, |
| 4729 | unsigned* offset); |
| 4730 | |
| 4731 | // Helper function for flattening strings. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4732 | template <typename sinkchar> |
| 4733 | static void WriteToFlat(String* source, |
| 4734 | sinkchar* sink, |
| 4735 | int from, |
| 4736 | int to); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4737 | |
| 4738 | protected: |
| 4739 | class ReadBlockBuffer { |
| 4740 | public: |
| 4741 | ReadBlockBuffer(unibrow::byte* util_buffer_, |
| 4742 | unsigned cursor_, |
| 4743 | unsigned capacity_, |
| 4744 | unsigned remaining_) : |
| 4745 | util_buffer(util_buffer_), |
| 4746 | cursor(cursor_), |
| 4747 | capacity(capacity_), |
| 4748 | remaining(remaining_) { |
| 4749 | } |
| 4750 | unibrow::byte* util_buffer; |
| 4751 | unsigned cursor; |
| 4752 | unsigned capacity; |
| 4753 | unsigned remaining; |
| 4754 | }; |
| 4755 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4756 | static inline const unibrow::byte* ReadBlock(String* input, |
| 4757 | ReadBlockBuffer* buffer, |
| 4758 | unsigned* offset, |
| 4759 | unsigned max_chars); |
| 4760 | static void ReadBlockIntoBuffer(String* input, |
| 4761 | ReadBlockBuffer* buffer, |
| 4762 | unsigned* offset_ptr, |
| 4763 | unsigned max_chars); |
| 4764 | |
| 4765 | private: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4766 | // Try to flatten the top level ConsString that is hiding behind this |
| 4767 | // string. This is a no-op unless the string is a ConsString. Flatten |
| 4768 | // mutates the ConsString and might return a failure. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4769 | MUST_USE_RESULT MaybeObject* SlowTryFlatten(PretenureFlag pretenure); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4770 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4771 | static inline bool IsHashFieldComputed(uint32_t field); |
| 4772 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4773 | // Slow case of String::Equals. This implementation works on any strings |
| 4774 | // but it is most efficient on strings that are almost flat. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4775 | bool SlowEquals(String* other); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4776 | |
| 4777 | // Slow case of AsArrayIndex. |
| 4778 | bool SlowAsArrayIndex(uint32_t* index); |
| 4779 | |
| 4780 | // Compute and set the hash code. |
| 4781 | uint32_t ComputeAndSetHash(); |
| 4782 | |
| 4783 | DISALLOW_IMPLICIT_CONSTRUCTORS(String); |
| 4784 | }; |
| 4785 | |
| 4786 | |
| 4787 | // The SeqString abstract class captures sequential string values. |
| 4788 | class SeqString: public String { |
| 4789 | public: |
| 4790 | |
| 4791 | // Casting. |
| 4792 | static inline SeqString* cast(Object* obj); |
| 4793 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4794 | private: |
| 4795 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString); |
| 4796 | }; |
| 4797 | |
| 4798 | |
| 4799 | // The AsciiString class captures sequential ascii string objects. |
| 4800 | // Each character in the AsciiString is an ascii character. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4801 | class SeqAsciiString: public SeqString { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4802 | public: |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4803 | static const bool kHasAsciiEncoding = true; |
| 4804 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4805 | // Dispatched behavior. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4806 | inline uint16_t SeqAsciiStringGet(int index); |
| 4807 | inline void SeqAsciiStringSet(int index, uint16_t value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4808 | |
| 4809 | // Get the address of the characters in this string. |
| 4810 | inline Address GetCharsAddress(); |
| 4811 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4812 | inline char* GetChars(); |
| 4813 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4814 | // Casting |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4815 | static inline SeqAsciiString* cast(Object* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4816 | |
| 4817 | // Garbage collection support. This method is called by the |
| 4818 | // garbage collector to compute the actual size of an AsciiString |
| 4819 | // instance. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4820 | inline int SeqAsciiStringSize(InstanceType instance_type); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4821 | |
| 4822 | // Computes the size for an AsciiString instance of a given length. |
| 4823 | static int SizeFor(int length) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4824 | return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4825 | } |
| 4826 | |
| 4827 | // Layout description. |
| 4828 | static const int kHeaderSize = String::kSize; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4829 | static const int kAlignedSize = POINTER_SIZE_ALIGN(kHeaderSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4830 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 4831 | // Maximal memory usage for a single sequential ASCII string. |
| 4832 | static const int kMaxSize = 512 * MB; |
| 4833 | // Maximal length of a single sequential ASCII string. |
| 4834 | // Q.v. String::kMaxLength which is the maximal size of concatenated strings. |
| 4835 | static const int kMaxLength = (kMaxSize - kHeaderSize); |
| 4836 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4837 | // Support for StringInputBuffer. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4838 | inline void SeqAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 4839 | unsigned* offset, |
| 4840 | unsigned chars); |
| 4841 | inline const unibrow::byte* SeqAsciiStringReadBlock(unsigned* remaining, |
| 4842 | unsigned* offset, |
| 4843 | unsigned chars); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4844 | |
| 4845 | private: |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4846 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqAsciiString); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4847 | }; |
| 4848 | |
| 4849 | |
| 4850 | // The TwoByteString class captures sequential unicode string objects. |
| 4851 | // Each character in the TwoByteString is a two-byte uint16_t. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4852 | class SeqTwoByteString: public SeqString { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4853 | public: |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4854 | static const bool kHasAsciiEncoding = false; |
| 4855 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4856 | // Dispatched behavior. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4857 | inline uint16_t SeqTwoByteStringGet(int index); |
| 4858 | inline void SeqTwoByteStringSet(int index, uint16_t value); |
| 4859 | |
| 4860 | // Get the address of the characters in this string. |
| 4861 | inline Address GetCharsAddress(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4862 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4863 | inline uc16* GetChars(); |
| 4864 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4865 | // For regexp code. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4866 | const uint16_t* SeqTwoByteStringGetData(unsigned start); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4867 | |
| 4868 | // Casting |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4869 | static inline SeqTwoByteString* cast(Object* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4870 | |
| 4871 | // Garbage collection support. This method is called by the |
| 4872 | // garbage collector to compute the actual size of a TwoByteString |
| 4873 | // instance. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4874 | inline int SeqTwoByteStringSize(InstanceType instance_type); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4875 | |
| 4876 | // Computes the size for a TwoByteString instance of a given length. |
| 4877 | static int SizeFor(int length) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4878 | return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4879 | } |
| 4880 | |
| 4881 | // Layout description. |
| 4882 | static const int kHeaderSize = String::kSize; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4883 | static const int kAlignedSize = POINTER_SIZE_ALIGN(kHeaderSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4884 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 4885 | // Maximal memory usage for a single sequential two-byte string. |
| 4886 | static const int kMaxSize = 512 * MB; |
| 4887 | // Maximal length of a single sequential two-byte string. |
| 4888 | // Q.v. String::kMaxLength which is the maximal size of concatenated strings. |
| 4889 | static const int kMaxLength = (kMaxSize - kHeaderSize) / sizeof(uint16_t); |
| 4890 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4891 | // Support for StringInputBuffer. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4892 | inline void SeqTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 4893 | unsigned* offset_ptr, |
| 4894 | unsigned chars); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4895 | |
| 4896 | private: |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4897 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqTwoByteString); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4898 | }; |
| 4899 | |
| 4900 | |
| 4901 | // The ConsString class describes string values built by using the |
| 4902 | // addition operator on strings. A ConsString is a pair where the |
| 4903 | // first and second components are pointers to other string values. |
| 4904 | // One or both components of a ConsString can be pointers to other |
| 4905 | // ConsStrings, creating a binary tree of ConsStrings where the leaves |
| 4906 | // are non-ConsString string values. The string value represented by |
| 4907 | // a ConsString can be obtained by concatenating the leaf string |
| 4908 | // values in a left-to-right depth-first traversal of the tree. |
| 4909 | class ConsString: public String { |
| 4910 | public: |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 4911 | // First string of the cons cell. |
| 4912 | inline String* first(); |
| 4913 | // Doesn't check that the result is a string, even in debug mode. This is |
| 4914 | // useful during GC where the mark bits confuse the checks. |
| 4915 | inline Object* unchecked_first(); |
| 4916 | inline void set_first(String* first, |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4917 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4918 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 4919 | // Second string of the cons cell. |
| 4920 | inline String* second(); |
| 4921 | // Doesn't check that the result is a string, even in debug mode. This is |
| 4922 | // useful during GC where the mark bits confuse the checks. |
| 4923 | inline Object* unchecked_second(); |
| 4924 | inline void set_second(String* second, |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4925 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4926 | |
| 4927 | // Dispatched behavior. |
| 4928 | uint16_t ConsStringGet(int index); |
| 4929 | |
| 4930 | // Casting. |
| 4931 | static inline ConsString* cast(Object* obj); |
| 4932 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4933 | // Layout description. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4934 | static const int kFirstOffset = POINTER_SIZE_ALIGN(String::kSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4935 | static const int kSecondOffset = kFirstOffset + kPointerSize; |
| 4936 | static const int kSize = kSecondOffset + kPointerSize; |
| 4937 | |
| 4938 | // Support for StringInputBuffer. |
| 4939 | inline const unibrow::byte* ConsStringReadBlock(ReadBlockBuffer* buffer, |
| 4940 | unsigned* offset_ptr, |
| 4941 | unsigned chars); |
| 4942 | inline void ConsStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 4943 | unsigned* offset_ptr, |
| 4944 | unsigned chars); |
| 4945 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4946 | // Minimum length for a cons string. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4947 | static const int kMinLength = 13; |
| 4948 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4949 | typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize> |
| 4950 | BodyDescriptor; |
| 4951 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4952 | private: |
| 4953 | DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString); |
| 4954 | }; |
| 4955 | |
| 4956 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4957 | // The ExternalString class describes string values that are backed by |
| 4958 | // a string resource that lies outside the V8 heap. ExternalStrings |
| 4959 | // consist of the length field common to all strings, a pointer to the |
| 4960 | // external resource. It is important to ensure (externally) that the |
| 4961 | // resource is not deallocated while the ExternalString is live in the |
| 4962 | // V8 heap. |
| 4963 | // |
| 4964 | // The API expects that all ExternalStrings are created through the |
| 4965 | // API. Therefore, ExternalStrings should not be used internally. |
| 4966 | class ExternalString: public String { |
| 4967 | public: |
| 4968 | // Casting |
| 4969 | static inline ExternalString* cast(Object* obj); |
| 4970 | |
| 4971 | // Layout description. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4972 | static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4973 | static const int kSize = kResourceOffset + kPointerSize; |
| 4974 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4975 | STATIC_CHECK(kResourceOffset == Internals::kStringResourceOffset); |
| 4976 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4977 | private: |
| 4978 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString); |
| 4979 | }; |
| 4980 | |
| 4981 | |
| 4982 | // The ExternalAsciiString class is an external string backed by an |
| 4983 | // ASCII string. |
| 4984 | class ExternalAsciiString: public ExternalString { |
| 4985 | public: |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4986 | static const bool kHasAsciiEncoding = true; |
| 4987 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4988 | typedef v8::String::ExternalAsciiStringResource Resource; |
| 4989 | |
| 4990 | // The underlying resource. |
| 4991 | inline Resource* resource(); |
| 4992 | inline void set_resource(Resource* buffer); |
| 4993 | |
| 4994 | // Dispatched behavior. |
| 4995 | uint16_t ExternalAsciiStringGet(int index); |
| 4996 | |
| 4997 | // Casting. |
| 4998 | static inline ExternalAsciiString* cast(Object* obj); |
| 4999 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 5000 | // Garbage collection support. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 5001 | inline void ExternalAsciiStringIterateBody(ObjectVisitor* v); |
| 5002 | |
| 5003 | template<typename StaticVisitor> |
| 5004 | inline void ExternalAsciiStringIterateBody(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 5005 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5006 | // Support for StringInputBuffer. |
| 5007 | const unibrow::byte* ExternalAsciiStringReadBlock(unsigned* remaining, |
| 5008 | unsigned* offset, |
| 5009 | unsigned chars); |
| 5010 | inline void ExternalAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 5011 | unsigned* offset, |
| 5012 | unsigned chars); |
| 5013 | |
| 5014 | private: |
| 5015 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalAsciiString); |
| 5016 | }; |
| 5017 | |
| 5018 | |
| 5019 | // The ExternalTwoByteString class is an external string backed by a UTF-16 |
| 5020 | // encoded string. |
| 5021 | class ExternalTwoByteString: public ExternalString { |
| 5022 | public: |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 5023 | static const bool kHasAsciiEncoding = false; |
| 5024 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5025 | typedef v8::String::ExternalStringResource Resource; |
| 5026 | |
| 5027 | // The underlying string resource. |
| 5028 | inline Resource* resource(); |
| 5029 | inline void set_resource(Resource* buffer); |
| 5030 | |
| 5031 | // Dispatched behavior. |
| 5032 | uint16_t ExternalTwoByteStringGet(int index); |
| 5033 | |
| 5034 | // For regexp code. |
| 5035 | const uint16_t* ExternalTwoByteStringGetData(unsigned start); |
| 5036 | |
| 5037 | // Casting. |
| 5038 | static inline ExternalTwoByteString* cast(Object* obj); |
| 5039 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 5040 | // Garbage collection support. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 5041 | inline void ExternalTwoByteStringIterateBody(ObjectVisitor* v); |
| 5042 | |
| 5043 | template<typename StaticVisitor> |
| 5044 | inline void ExternalTwoByteStringIterateBody(); |
| 5045 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 5046 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5047 | // Support for StringInputBuffer. |
| 5048 | void ExternalTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 5049 | unsigned* offset_ptr, |
| 5050 | unsigned chars); |
| 5051 | |
| 5052 | private: |
| 5053 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalTwoByteString); |
| 5054 | }; |
| 5055 | |
| 5056 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 5057 | // Utility superclass for stack-allocated objects that must be updated |
| 5058 | // on gc. It provides two ways for the gc to update instances, either |
| 5059 | // iterating or updating after gc. |
| 5060 | class Relocatable BASE_EMBEDDED { |
| 5061 | public: |
| 5062 | inline Relocatable() : prev_(top_) { top_ = this; } |
| 5063 | virtual ~Relocatable() { |
| 5064 | ASSERT_EQ(top_, this); |
| 5065 | top_ = prev_; |
| 5066 | } |
| 5067 | virtual void IterateInstance(ObjectVisitor* v) { } |
| 5068 | virtual void PostGarbageCollection() { } |
| 5069 | |
| 5070 | static void PostGarbageCollectionProcessing(); |
| 5071 | static int ArchiveSpacePerThread(); |
| 5072 | static char* ArchiveState(char* to); |
| 5073 | static char* RestoreState(char* from); |
| 5074 | static void Iterate(ObjectVisitor* v); |
| 5075 | static void Iterate(ObjectVisitor* v, Relocatable* top); |
| 5076 | static char* Iterate(ObjectVisitor* v, char* t); |
| 5077 | private: |
| 5078 | static Relocatable* top_; |
| 5079 | Relocatable* prev_; |
| 5080 | }; |
| 5081 | |
| 5082 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5083 | // A flat string reader provides random access to the contents of a |
| 5084 | // string independent of the character width of the string. The handle |
| 5085 | // must be valid as long as the reader is being used. |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 5086 | class FlatStringReader : public Relocatable { |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5087 | public: |
| 5088 | explicit FlatStringReader(Handle<String> str); |
| 5089 | explicit FlatStringReader(Vector<const char> input); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 5090 | void PostGarbageCollection(); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5091 | inline uc32 Get(int index); |
| 5092 | int length() { return length_; } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5093 | private: |
| 5094 | String** str_; |
| 5095 | bool is_ascii_; |
| 5096 | int length_; |
| 5097 | const void* start_; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5098 | }; |
| 5099 | |
| 5100 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5101 | // Note that StringInputBuffers are not valid across a GC! To fix this |
| 5102 | // it would have to store a String Handle instead of a String* and |
| 5103 | // AsciiStringReadBlock would have to be modified to use memcpy. |
| 5104 | // |
| 5105 | // StringInputBuffer is able to traverse any string regardless of how |
| 5106 | // deeply nested a sequence of ConsStrings it is made of. However, |
| 5107 | // performance will be better if deep strings are flattened before they |
| 5108 | // are traversed. Since flattening requires memory allocation this is |
| 5109 | // not always desirable, however (esp. in debugging situations). |
| 5110 | class StringInputBuffer: public unibrow::InputBuffer<String, String*, 1024> { |
| 5111 | public: |
| 5112 | virtual void Seek(unsigned pos); |
| 5113 | inline StringInputBuffer(): unibrow::InputBuffer<String, String*, 1024>() {} |
| 5114 | inline StringInputBuffer(String* backing): |
| 5115 | unibrow::InputBuffer<String, String*, 1024>(backing) {} |
| 5116 | }; |
| 5117 | |
| 5118 | |
| 5119 | class SafeStringInputBuffer |
| 5120 | : public unibrow::InputBuffer<String, String**, 256> { |
| 5121 | public: |
| 5122 | virtual void Seek(unsigned pos); |
| 5123 | inline SafeStringInputBuffer() |
| 5124 | : unibrow::InputBuffer<String, String**, 256>() {} |
| 5125 | inline SafeStringInputBuffer(String** backing) |
| 5126 | : unibrow::InputBuffer<String, String**, 256>(backing) {} |
| 5127 | }; |
| 5128 | |
| 5129 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5130 | template <typename T> |
| 5131 | class VectorIterator { |
| 5132 | public: |
| 5133 | VectorIterator(T* d, int l) : data_(Vector<const T>(d, l)), index_(0) { } |
| 5134 | explicit VectorIterator(Vector<const T> data) : data_(data), index_(0) { } |
| 5135 | T GetNext() { return data_[index_++]; } |
| 5136 | bool has_more() { return index_ < data_.length(); } |
| 5137 | private: |
| 5138 | Vector<const T> data_; |
| 5139 | int index_; |
| 5140 | }; |
| 5141 | |
| 5142 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5143 | // The Oddball describes objects null, undefined, true, and false. |
| 5144 | class Oddball: public HeapObject { |
| 5145 | public: |
| 5146 | // [to_string]: Cached to_string computed at startup. |
| 5147 | DECL_ACCESSORS(to_string, String) |
| 5148 | |
| 5149 | // [to_number]: Cached to_number computed at startup. |
| 5150 | DECL_ACCESSORS(to_number, Object) |
| 5151 | |
| 5152 | // Casting. |
| 5153 | static inline Oddball* cast(Object* obj); |
| 5154 | |
| 5155 | // Dispatched behavior. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5156 | #ifdef DEBUG |
| 5157 | void OddballVerify(); |
| 5158 | #endif |
| 5159 | |
| 5160 | // Initialize the fields. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5161 | MUST_USE_RESULT MaybeObject* Initialize(const char* to_string, |
| 5162 | Object* to_number); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5163 | |
| 5164 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5165 | static const int kToStringOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5166 | static const int kToNumberOffset = kToStringOffset + kPointerSize; |
| 5167 | static const int kSize = kToNumberOffset + kPointerSize; |
| 5168 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 5169 | typedef FixedBodyDescriptor<kToStringOffset, |
| 5170 | kToNumberOffset + kPointerSize, |
| 5171 | kSize> BodyDescriptor; |
| 5172 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5173 | private: |
| 5174 | DISALLOW_IMPLICIT_CONSTRUCTORS(Oddball); |
| 5175 | }; |
| 5176 | |
| 5177 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 5178 | class JSGlobalPropertyCell: public HeapObject { |
| 5179 | public: |
| 5180 | // [value]: value of the global property. |
| 5181 | DECL_ACCESSORS(value, Object) |
| 5182 | |
| 5183 | // Casting. |
| 5184 | static inline JSGlobalPropertyCell* cast(Object* obj); |
| 5185 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 5186 | #ifdef DEBUG |
| 5187 | void JSGlobalPropertyCellVerify(); |
| 5188 | void JSGlobalPropertyCellPrint(); |
| 5189 | #endif |
| 5190 | |
| 5191 | // Layout description. |
| 5192 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 5193 | static const int kSize = kValueOffset + kPointerSize; |
| 5194 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 5195 | typedef FixedBodyDescriptor<kValueOffset, |
| 5196 | kValueOffset + kPointerSize, |
| 5197 | kSize> BodyDescriptor; |
| 5198 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 5199 | private: |
| 5200 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalPropertyCell); |
| 5201 | }; |
| 5202 | |
| 5203 | |
| 5204 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5205 | // Proxy describes objects pointing from JavaScript to C structures. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5206 | // Since they cannot contain references to JS HeapObjects they can be |
| 5207 | // placed in old_data_space. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5208 | class Proxy: public HeapObject { |
| 5209 | public: |
| 5210 | // [proxy]: field containing the address. |
| 5211 | inline Address proxy(); |
| 5212 | inline void set_proxy(Address value); |
| 5213 | |
| 5214 | // Casting. |
| 5215 | static inline Proxy* cast(Object* obj); |
| 5216 | |
| 5217 | // Dispatched behavior. |
| 5218 | inline void ProxyIterateBody(ObjectVisitor* v); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 5219 | |
| 5220 | template<typename StaticVisitor> |
| 5221 | inline void ProxyIterateBody(); |
| 5222 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5223 | #ifdef DEBUG |
| 5224 | void ProxyPrint(); |
| 5225 | void ProxyVerify(); |
| 5226 | #endif |
| 5227 | |
| 5228 | // Layout description. |
| 5229 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5230 | static const int kProxyOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5231 | static const int kSize = kProxyOffset + kPointerSize; |
| 5232 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5233 | STATIC_CHECK(kProxyOffset == Internals::kProxyProxyOffset); |
| 5234 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5235 | private: |
| 5236 | DISALLOW_IMPLICIT_CONSTRUCTORS(Proxy); |
| 5237 | }; |
| 5238 | |
| 5239 | |
| 5240 | // The JSArray describes JavaScript Arrays |
| 5241 | // Such an array can be in one of two modes: |
| 5242 | // - fast, backing storage is a FixedArray and length <= elements.length(); |
| 5243 | // Please note: push and pop can be used to grow and shrink the array. |
| 5244 | // - slow, backing storage is a HashTable with numbers as keys. |
| 5245 | class JSArray: public JSObject { |
| 5246 | public: |
| 5247 | // [length]: The length property. |
| 5248 | DECL_ACCESSORS(length, Object) |
| 5249 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5250 | // Overload the length setter to skip write barrier when the length |
| 5251 | // is set to a smi. This matches the set function on FixedArray. |
| 5252 | inline void set_length(Smi* length); |
| 5253 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5254 | MUST_USE_RESULT MaybeObject* JSArrayUpdateLengthFromIndex(uint32_t index, |
| 5255 | Object* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5256 | |
| 5257 | // Initialize the array with the given capacity. The function may |
| 5258 | // fail due to out-of-memory situations, but only if the requested |
| 5259 | // capacity is non-zero. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5260 | MUST_USE_RESULT MaybeObject* Initialize(int capacity); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5261 | |
| 5262 | // Set the content of the array to the content of storage. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5263 | inline void SetContent(FixedArray* storage); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5264 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5265 | // Casting. |
| 5266 | static inline JSArray* cast(Object* obj); |
| 5267 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5268 | // Uses handles. Ensures that the fixed array backing the JSArray has at |
| 5269 | // least the stated size. |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 5270 | inline void EnsureSize(int minimum_size_of_backing_fixed_array); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5271 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5272 | // Dispatched behavior. |
| 5273 | #ifdef DEBUG |
| 5274 | void JSArrayPrint(); |
| 5275 | void JSArrayVerify(); |
| 5276 | #endif |
| 5277 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 5278 | // Number of element slots to pre-allocate for an empty array. |
| 5279 | static const int kPreallocatedArrayElements = 4; |
| 5280 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5281 | // Layout description. |
| 5282 | static const int kLengthOffset = JSObject::kHeaderSize; |
| 5283 | static const int kSize = kLengthOffset + kPointerSize; |
| 5284 | |
| 5285 | private: |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 5286 | // Expand the fixed array backing of a fast-case JSArray to at least |
| 5287 | // the requested size. |
| 5288 | void Expand(int minimum_size_of_backing_fixed_array); |
| 5289 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5290 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSArray); |
| 5291 | }; |
| 5292 | |
| 5293 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 5294 | // JSRegExpResult is just a JSArray with a specific initial map. |
| 5295 | // This initial map adds in-object properties for "index" and "input" |
| 5296 | // properties, as assigned by RegExp.prototype.exec, which allows |
| 5297 | // faster creation of RegExp exec results. |
| 5298 | // This class just holds constants used when creating the result. |
| 5299 | // After creation the result must be treated as a JSArray in all regards. |
| 5300 | class JSRegExpResult: public JSArray { |
| 5301 | public: |
| 5302 | // Offsets of object fields. |
| 5303 | static const int kIndexOffset = JSArray::kSize; |
| 5304 | static const int kInputOffset = kIndexOffset + kPointerSize; |
| 5305 | static const int kSize = kInputOffset + kPointerSize; |
| 5306 | // Indices of in-object properties. |
| 5307 | static const int kIndexIndex = 0; |
| 5308 | static const int kInputIndex = 1; |
| 5309 | private: |
| 5310 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSRegExpResult); |
| 5311 | }; |
| 5312 | |
| 5313 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 5314 | // An accessor must have a getter, but can have no setter. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5315 | // |
| 5316 | // When setting a property, V8 searches accessors in prototypes. |
| 5317 | // If an accessor was found and it does not have a setter, |
| 5318 | // the request is ignored. |
| 5319 | // |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 5320 | // If the accessor in the prototype has the READ_ONLY property attribute, then |
| 5321 | // a new value is added to the local object when the property is set. |
| 5322 | // This shadows the accessor in the prototype. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5323 | class AccessorInfo: public Struct { |
| 5324 | public: |
| 5325 | DECL_ACCESSORS(getter, Object) |
| 5326 | DECL_ACCESSORS(setter, Object) |
| 5327 | DECL_ACCESSORS(data, Object) |
| 5328 | DECL_ACCESSORS(name, Object) |
| 5329 | DECL_ACCESSORS(flag, Smi) |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 5330 | DECL_ACCESSORS(load_stub_cache, Object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5331 | |
| 5332 | inline bool all_can_read(); |
| 5333 | inline void set_all_can_read(bool value); |
| 5334 | |
| 5335 | inline bool all_can_write(); |
| 5336 | inline void set_all_can_write(bool value); |
| 5337 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 5338 | inline bool prohibits_overwriting(); |
| 5339 | inline void set_prohibits_overwriting(bool value); |
| 5340 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5341 | inline PropertyAttributes property_attributes(); |
| 5342 | inline void set_property_attributes(PropertyAttributes attributes); |
| 5343 | |
| 5344 | static inline AccessorInfo* cast(Object* obj); |
| 5345 | |
| 5346 | #ifdef DEBUG |
| 5347 | void AccessorInfoPrint(); |
| 5348 | void AccessorInfoVerify(); |
| 5349 | #endif |
| 5350 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5351 | static const int kGetterOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5352 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 5353 | static const int kDataOffset = kSetterOffset + kPointerSize; |
| 5354 | static const int kNameOffset = kDataOffset + kPointerSize; |
| 5355 | static const int kFlagOffset = kNameOffset + kPointerSize; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 5356 | static const int kLoadStubCacheOffset = kFlagOffset + kPointerSize; |
| 5357 | static const int kSize = kLoadStubCacheOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5358 | |
| 5359 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5360 | // Bit positions in flag. |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 5361 | static const int kAllCanReadBit = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5362 | static const int kAllCanWriteBit = 1; |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 5363 | static const int kProhibitsOverwritingBit = 2; |
| 5364 | class AttributesField: public BitField<PropertyAttributes, 3, 3> {}; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5365 | |
| 5366 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorInfo); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5367 | }; |
| 5368 | |
| 5369 | |
| 5370 | class AccessCheckInfo: public Struct { |
| 5371 | public: |
| 5372 | DECL_ACCESSORS(named_callback, Object) |
| 5373 | DECL_ACCESSORS(indexed_callback, Object) |
| 5374 | DECL_ACCESSORS(data, Object) |
| 5375 | |
| 5376 | static inline AccessCheckInfo* cast(Object* obj); |
| 5377 | |
| 5378 | #ifdef DEBUG |
| 5379 | void AccessCheckInfoPrint(); |
| 5380 | void AccessCheckInfoVerify(); |
| 5381 | #endif |
| 5382 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5383 | static const int kNamedCallbackOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5384 | static const int kIndexedCallbackOffset = kNamedCallbackOffset + kPointerSize; |
| 5385 | static const int kDataOffset = kIndexedCallbackOffset + kPointerSize; |
| 5386 | static const int kSize = kDataOffset + kPointerSize; |
| 5387 | |
| 5388 | private: |
| 5389 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessCheckInfo); |
| 5390 | }; |
| 5391 | |
| 5392 | |
| 5393 | class InterceptorInfo: public Struct { |
| 5394 | public: |
| 5395 | DECL_ACCESSORS(getter, Object) |
| 5396 | DECL_ACCESSORS(setter, Object) |
| 5397 | DECL_ACCESSORS(query, Object) |
| 5398 | DECL_ACCESSORS(deleter, Object) |
| 5399 | DECL_ACCESSORS(enumerator, Object) |
| 5400 | DECL_ACCESSORS(data, Object) |
| 5401 | |
| 5402 | static inline InterceptorInfo* cast(Object* obj); |
| 5403 | |
| 5404 | #ifdef DEBUG |
| 5405 | void InterceptorInfoPrint(); |
| 5406 | void InterceptorInfoVerify(); |
| 5407 | #endif |
| 5408 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5409 | static const int kGetterOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5410 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 5411 | static const int kQueryOffset = kSetterOffset + kPointerSize; |
| 5412 | static const int kDeleterOffset = kQueryOffset + kPointerSize; |
| 5413 | static const int kEnumeratorOffset = kDeleterOffset + kPointerSize; |
| 5414 | static const int kDataOffset = kEnumeratorOffset + kPointerSize; |
| 5415 | static const int kSize = kDataOffset + kPointerSize; |
| 5416 | |
| 5417 | private: |
| 5418 | DISALLOW_IMPLICIT_CONSTRUCTORS(InterceptorInfo); |
| 5419 | }; |
| 5420 | |
| 5421 | |
| 5422 | class CallHandlerInfo: public Struct { |
| 5423 | public: |
| 5424 | DECL_ACCESSORS(callback, Object) |
| 5425 | DECL_ACCESSORS(data, Object) |
| 5426 | |
| 5427 | static inline CallHandlerInfo* cast(Object* obj); |
| 5428 | |
| 5429 | #ifdef DEBUG |
| 5430 | void CallHandlerInfoPrint(); |
| 5431 | void CallHandlerInfoVerify(); |
| 5432 | #endif |
| 5433 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5434 | static const int kCallbackOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5435 | static const int kDataOffset = kCallbackOffset + kPointerSize; |
| 5436 | static const int kSize = kDataOffset + kPointerSize; |
| 5437 | |
| 5438 | private: |
| 5439 | DISALLOW_IMPLICIT_CONSTRUCTORS(CallHandlerInfo); |
| 5440 | }; |
| 5441 | |
| 5442 | |
| 5443 | class TemplateInfo: public Struct { |
| 5444 | public: |
| 5445 | DECL_ACCESSORS(tag, Object) |
| 5446 | DECL_ACCESSORS(property_list, Object) |
| 5447 | |
| 5448 | #ifdef DEBUG |
| 5449 | void TemplateInfoVerify(); |
| 5450 | #endif |
| 5451 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5452 | static const int kTagOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5453 | static const int kPropertyListOffset = kTagOffset + kPointerSize; |
| 5454 | static const int kHeaderSize = kPropertyListOffset + kPointerSize; |
| 5455 | protected: |
| 5456 | friend class AGCCVersionRequiresThisClassToHaveAFriendSoHereItIs; |
| 5457 | DISALLOW_IMPLICIT_CONSTRUCTORS(TemplateInfo); |
| 5458 | }; |
| 5459 | |
| 5460 | |
| 5461 | class FunctionTemplateInfo: public TemplateInfo { |
| 5462 | public: |
| 5463 | DECL_ACCESSORS(serial_number, Object) |
| 5464 | DECL_ACCESSORS(call_code, Object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5465 | DECL_ACCESSORS(property_accessors, Object) |
| 5466 | DECL_ACCESSORS(prototype_template, Object) |
| 5467 | DECL_ACCESSORS(parent_template, Object) |
| 5468 | DECL_ACCESSORS(named_property_handler, Object) |
| 5469 | DECL_ACCESSORS(indexed_property_handler, Object) |
| 5470 | DECL_ACCESSORS(instance_template, Object) |
| 5471 | DECL_ACCESSORS(class_name, Object) |
| 5472 | DECL_ACCESSORS(signature, Object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5473 | DECL_ACCESSORS(instance_call_handler, Object) |
| 5474 | DECL_ACCESSORS(access_check_info, Object) |
| 5475 | DECL_ACCESSORS(flag, Smi) |
| 5476 | |
| 5477 | // Following properties use flag bits. |
| 5478 | DECL_BOOLEAN_ACCESSORS(hidden_prototype) |
| 5479 | DECL_BOOLEAN_ACCESSORS(undetectable) |
| 5480 | // If the bit is set, object instances created by this function |
| 5481 | // requires access check. |
| 5482 | DECL_BOOLEAN_ACCESSORS(needs_access_check) |
| 5483 | |
| 5484 | static inline FunctionTemplateInfo* cast(Object* obj); |
| 5485 | |
| 5486 | #ifdef DEBUG |
| 5487 | void FunctionTemplateInfoPrint(); |
| 5488 | void FunctionTemplateInfoVerify(); |
| 5489 | #endif |
| 5490 | |
| 5491 | static const int kSerialNumberOffset = TemplateInfo::kHeaderSize; |
| 5492 | static const int kCallCodeOffset = kSerialNumberOffset + kPointerSize; |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 5493 | static const int kPropertyAccessorsOffset = kCallCodeOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5494 | static const int kPrototypeTemplateOffset = |
| 5495 | kPropertyAccessorsOffset + kPointerSize; |
| 5496 | static const int kParentTemplateOffset = |
| 5497 | kPrototypeTemplateOffset + kPointerSize; |
| 5498 | static const int kNamedPropertyHandlerOffset = |
| 5499 | kParentTemplateOffset + kPointerSize; |
| 5500 | static const int kIndexedPropertyHandlerOffset = |
| 5501 | kNamedPropertyHandlerOffset + kPointerSize; |
| 5502 | static const int kInstanceTemplateOffset = |
| 5503 | kIndexedPropertyHandlerOffset + kPointerSize; |
| 5504 | static const int kClassNameOffset = kInstanceTemplateOffset + kPointerSize; |
| 5505 | static const int kSignatureOffset = kClassNameOffset + kPointerSize; |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 5506 | static const int kInstanceCallHandlerOffset = kSignatureOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5507 | static const int kAccessCheckInfoOffset = |
| 5508 | kInstanceCallHandlerOffset + kPointerSize; |
| 5509 | static const int kFlagOffset = kAccessCheckInfoOffset + kPointerSize; |
| 5510 | static const int kSize = kFlagOffset + kPointerSize; |
| 5511 | |
| 5512 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5513 | // Bit position in the flag, from least significant bit position. |
| 5514 | static const int kHiddenPrototypeBit = 0; |
| 5515 | static const int kUndetectableBit = 1; |
| 5516 | static const int kNeedsAccessCheckBit = 2; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5517 | |
| 5518 | DISALLOW_IMPLICIT_CONSTRUCTORS(FunctionTemplateInfo); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5519 | }; |
| 5520 | |
| 5521 | |
| 5522 | class ObjectTemplateInfo: public TemplateInfo { |
| 5523 | public: |
| 5524 | DECL_ACCESSORS(constructor, Object) |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 5525 | DECL_ACCESSORS(internal_field_count, Object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5526 | |
| 5527 | static inline ObjectTemplateInfo* cast(Object* obj); |
| 5528 | |
| 5529 | #ifdef DEBUG |
| 5530 | void ObjectTemplateInfoPrint(); |
| 5531 | void ObjectTemplateInfoVerify(); |
| 5532 | #endif |
| 5533 | |
| 5534 | static const int kConstructorOffset = TemplateInfo::kHeaderSize; |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 5535 | static const int kInternalFieldCountOffset = |
| 5536 | kConstructorOffset + kPointerSize; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5537 | static const int kSize = kInternalFieldCountOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5538 | }; |
| 5539 | |
| 5540 | |
| 5541 | class SignatureInfo: public Struct { |
| 5542 | public: |
| 5543 | DECL_ACCESSORS(receiver, Object) |
| 5544 | DECL_ACCESSORS(args, Object) |
| 5545 | |
| 5546 | static inline SignatureInfo* cast(Object* obj); |
| 5547 | |
| 5548 | #ifdef DEBUG |
| 5549 | void SignatureInfoPrint(); |
| 5550 | void SignatureInfoVerify(); |
| 5551 | #endif |
| 5552 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5553 | static const int kReceiverOffset = Struct::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5554 | static const int kArgsOffset = kReceiverOffset + kPointerSize; |
| 5555 | static const int kSize = kArgsOffset + kPointerSize; |
| 5556 | |
| 5557 | private: |
| 5558 | DISALLOW_IMPLICIT_CONSTRUCTORS(SignatureInfo); |
| 5559 | }; |
| 5560 | |
| 5561 | |
| 5562 | class TypeSwitchInfo: public Struct { |
| 5563 | public: |
| 5564 | DECL_ACCESSORS(types, Object) |
| 5565 | |
| 5566 | static inline TypeSwitchInfo* cast(Object* obj); |
| 5567 | |
| 5568 | #ifdef DEBUG |
| 5569 | void TypeSwitchInfoPrint(); |
| 5570 | void TypeSwitchInfoVerify(); |
| 5571 | #endif |
| 5572 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5573 | static const int kTypesOffset = Struct::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5574 | static const int kSize = kTypesOffset + kPointerSize; |
| 5575 | }; |
| 5576 | |
| 5577 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5578 | #ifdef ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 5579 | // The DebugInfo class holds additional information for a function being |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5580 | // debugged. |
| 5581 | class DebugInfo: public Struct { |
| 5582 | public: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 5583 | // The shared function info for the source being debugged. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5584 | DECL_ACCESSORS(shared, SharedFunctionInfo) |
| 5585 | // Code object for the original code. |
| 5586 | DECL_ACCESSORS(original_code, Code) |
| 5587 | // Code object for the patched code. This code object is the code object |
| 5588 | // currently active for the function. |
| 5589 | DECL_ACCESSORS(code, Code) |
| 5590 | // Fixed array holding status information for each active break point. |
| 5591 | DECL_ACCESSORS(break_points, FixedArray) |
| 5592 | |
| 5593 | // Check if there is a break point at a code position. |
| 5594 | bool HasBreakPoint(int code_position); |
| 5595 | // Get the break point info object for a code position. |
| 5596 | Object* GetBreakPointInfo(int code_position); |
| 5597 | // Clear a break point. |
| 5598 | static void ClearBreakPoint(Handle<DebugInfo> debug_info, |
| 5599 | int code_position, |
| 5600 | Handle<Object> break_point_object); |
| 5601 | // Set a break point. |
| 5602 | static void SetBreakPoint(Handle<DebugInfo> debug_info, int code_position, |
| 5603 | int source_position, int statement_position, |
| 5604 | Handle<Object> break_point_object); |
| 5605 | // Get the break point objects for a code position. |
| 5606 | Object* GetBreakPointObjects(int code_position); |
| 5607 | // Find the break point info holding this break point object. |
| 5608 | static Object* FindBreakPointInfo(Handle<DebugInfo> debug_info, |
| 5609 | Handle<Object> break_point_object); |
| 5610 | // Get the number of break points for this function. |
| 5611 | int GetBreakPointCount(); |
| 5612 | |
| 5613 | static inline DebugInfo* cast(Object* obj); |
| 5614 | |
| 5615 | #ifdef DEBUG |
| 5616 | void DebugInfoPrint(); |
| 5617 | void DebugInfoVerify(); |
| 5618 | #endif |
| 5619 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5620 | static const int kSharedFunctionInfoIndex = Struct::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5621 | static const int kOriginalCodeIndex = kSharedFunctionInfoIndex + kPointerSize; |
| 5622 | static const int kPatchedCodeIndex = kOriginalCodeIndex + kPointerSize; |
| 5623 | static const int kActiveBreakPointsCountIndex = |
| 5624 | kPatchedCodeIndex + kPointerSize; |
| 5625 | static const int kBreakPointsStateIndex = |
| 5626 | kActiveBreakPointsCountIndex + kPointerSize; |
| 5627 | static const int kSize = kBreakPointsStateIndex + kPointerSize; |
| 5628 | |
| 5629 | private: |
| 5630 | static const int kNoBreakPointInfo = -1; |
| 5631 | |
| 5632 | // Lookup the index in the break_points array for a code position. |
| 5633 | int GetBreakPointInfoIndex(int code_position); |
| 5634 | |
| 5635 | DISALLOW_IMPLICIT_CONSTRUCTORS(DebugInfo); |
| 5636 | }; |
| 5637 | |
| 5638 | |
| 5639 | // The BreakPointInfo class holds information for break points set in a |
| 5640 | // function. The DebugInfo object holds a BreakPointInfo object for each code |
| 5641 | // position with one or more break points. |
| 5642 | class BreakPointInfo: public Struct { |
| 5643 | public: |
| 5644 | // The position in the code for the break point. |
| 5645 | DECL_ACCESSORS(code_position, Smi) |
| 5646 | // The position in the source for the break position. |
| 5647 | DECL_ACCESSORS(source_position, Smi) |
| 5648 | // The position in the source for the last statement before this break |
| 5649 | // position. |
| 5650 | DECL_ACCESSORS(statement_position, Smi) |
| 5651 | // List of related JavaScript break points. |
| 5652 | DECL_ACCESSORS(break_point_objects, Object) |
| 5653 | |
| 5654 | // Removes a break point. |
| 5655 | static void ClearBreakPoint(Handle<BreakPointInfo> info, |
| 5656 | Handle<Object> break_point_object); |
| 5657 | // Set a break point. |
| 5658 | static void SetBreakPoint(Handle<BreakPointInfo> info, |
| 5659 | Handle<Object> break_point_object); |
| 5660 | // Check if break point info has this break point object. |
| 5661 | static bool HasBreakPointObject(Handle<BreakPointInfo> info, |
| 5662 | Handle<Object> break_point_object); |
| 5663 | // Get the number of break points for this code position. |
| 5664 | int GetBreakPointCount(); |
| 5665 | |
| 5666 | static inline BreakPointInfo* cast(Object* obj); |
| 5667 | |
| 5668 | #ifdef DEBUG |
| 5669 | void BreakPointInfoPrint(); |
| 5670 | void BreakPointInfoVerify(); |
| 5671 | #endif |
| 5672 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5673 | static const int kCodePositionIndex = Struct::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5674 | static const int kSourcePositionIndex = kCodePositionIndex + kPointerSize; |
| 5675 | static const int kStatementPositionIndex = |
| 5676 | kSourcePositionIndex + kPointerSize; |
| 5677 | static const int kBreakPointObjectsIndex = |
| 5678 | kStatementPositionIndex + kPointerSize; |
| 5679 | static const int kSize = kBreakPointObjectsIndex + kPointerSize; |
| 5680 | |
| 5681 | private: |
| 5682 | DISALLOW_IMPLICIT_CONSTRUCTORS(BreakPointInfo); |
| 5683 | }; |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5684 | #endif // ENABLE_DEBUGGER_SUPPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5685 | |
| 5686 | |
| 5687 | #undef DECL_BOOLEAN_ACCESSORS |
| 5688 | #undef DECL_ACCESSORS |
| 5689 | |
| 5690 | |
| 5691 | // Abstract base class for visiting, and optionally modifying, the |
| 5692 | // pointers contained in Objects. Used in GC and serialization/deserialization. |
| 5693 | class ObjectVisitor BASE_EMBEDDED { |
| 5694 | public: |
| 5695 | virtual ~ObjectVisitor() {} |
| 5696 | |
| 5697 | // Visits a contiguous arrays of pointers in the half-open range |
| 5698 | // [start, end). Any or all of the values may be modified on return. |
| 5699 | virtual void VisitPointers(Object** start, Object** end) = 0; |
| 5700 | |
| 5701 | // To allow lazy clearing of inline caches the visitor has |
| 5702 | // a rich interface for iterating over Code objects.. |
| 5703 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5704 | // Visits a code target in the instruction stream. |
| 5705 | virtual void VisitCodeTarget(RelocInfo* rinfo); |
| 5706 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 5707 | // Visits a code entry in a JS function. |
| 5708 | virtual void VisitCodeEntry(Address entry_address); |
| 5709 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5710 | // Visits a runtime entry in the instruction stream. |
| 5711 | virtual void VisitRuntimeEntry(RelocInfo* rinfo) {} |
| 5712 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 5713 | // Visits the resource of an ASCII or two-byte string. |
| 5714 | virtual void VisitExternalAsciiString( |
| 5715 | v8::String::ExternalAsciiStringResource** resource) {} |
| 5716 | virtual void VisitExternalTwoByteString( |
| 5717 | v8::String::ExternalStringResource** resource) {} |
| 5718 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5719 | // Visits a debug call target in the instruction stream. |
| 5720 | virtual void VisitDebugTarget(RelocInfo* rinfo); |
| 5721 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5722 | // Handy shorthand for visiting a single pointer. |
| 5723 | virtual void VisitPointer(Object** p) { VisitPointers(p, p + 1); } |
| 5724 | |
| 5725 | // Visits a contiguous arrays of external references (references to the C++ |
| 5726 | // heap) in the half-open range [start, end). Any or all of the values |
| 5727 | // may be modified on return. |
| 5728 | virtual void VisitExternalReferences(Address* start, Address* end) {} |
| 5729 | |
| 5730 | inline void VisitExternalReference(Address* p) { |
| 5731 | VisitExternalReferences(p, p + 1); |
| 5732 | } |
| 5733 | |
| 5734 | #ifdef DEBUG |
| 5735 | // Intended for serialization/deserialization checking: insert, or |
| 5736 | // check for the presence of, a tag at this position in the stream. |
| 5737 | virtual void Synchronize(const char* tag) {} |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 5738 | #else |
| 5739 | inline void Synchronize(const char* tag) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5740 | #endif |
| 5741 | }; |
| 5742 | |
| 5743 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 5744 | class StructBodyDescriptor : public |
| 5745 | FlexibleBodyDescriptor<HeapObject::kHeaderSize> { |
| 5746 | public: |
| 5747 | static inline int SizeOf(Map* map, HeapObject* object) { |
| 5748 | return map->instance_size(); |
| 5749 | } |
| 5750 | }; |
| 5751 | |
| 5752 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5753 | // BooleanBit is a helper class for setting and getting a bit in an |
| 5754 | // integer or Smi. |
| 5755 | class BooleanBit : public AllStatic { |
| 5756 | public: |
| 5757 | static inline bool get(Smi* smi, int bit_position) { |
| 5758 | return get(smi->value(), bit_position); |
| 5759 | } |
| 5760 | |
| 5761 | static inline bool get(int value, int bit_position) { |
| 5762 | return (value & (1 << bit_position)) != 0; |
| 5763 | } |
| 5764 | |
| 5765 | static inline Smi* set(Smi* smi, int bit_position, bool v) { |
| 5766 | return Smi::FromInt(set(smi->value(), bit_position, v)); |
| 5767 | } |
| 5768 | |
| 5769 | static inline int set(int value, int bit_position, bool v) { |
| 5770 | if (v) { |
| 5771 | value |= (1 << bit_position); |
| 5772 | } else { |
| 5773 | value &= ~(1 << bit_position); |
| 5774 | } |
| 5775 | return value; |
| 5776 | } |
| 5777 | }; |
| 5778 | |
| 5779 | } } // namespace v8::internal |
| 5780 | |
| 5781 | #endif // V8_OBJECTS_H_ |