ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1 | // Copyright 2006-2008 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" |
| 32 | #include "code-stubs.h" |
| 33 | #include "smart-pointer.h" |
| 34 | #include "unicode-inl.h" |
| 35 | |
| 36 | // |
| 37 | // All object types in the V8 JavaScript are described in this file. |
| 38 | // |
| 39 | // Inheritance hierarchy: |
| 40 | // - Object |
| 41 | // - Smi (immediate small integer) |
| 42 | // - Failure (immediate for marking failed operation) |
| 43 | // - HeapObject (superclass for everything allocated in the heap) |
| 44 | // - JSObject |
| 45 | // - JSArray |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 46 | // - JSRegExp |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 47 | // - JSFunction |
| 48 | // - GlobalObject |
| 49 | // - JSGlobalObject |
| 50 | // - JSBuiltinsObject |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 51 | // - JSGlobalProxy |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 52 | // - JSValue |
| 53 | // - Script |
| 54 | // - Array |
| 55 | // - ByteArray |
| 56 | // - FixedArray |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 57 | // - DescriptorArray |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 58 | // - HashTable |
| 59 | // - Dictionary |
| 60 | // - SymbolTable |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 61 | // - CompilationCacheTable |
| 62 | // - MapCache |
| 63 | // - LookupCache |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 64 | // - Context |
| 65 | // - GlobalContext |
| 66 | // - String |
| 67 | // - SeqString |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 68 | // - SeqAsciiString |
| 69 | // - SeqTwoByteString |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 70 | // - ConsString |
| 71 | // - SlicedString |
| 72 | // - ExternalString |
| 73 | // - ExternalAsciiString |
| 74 | // - ExternalTwoByteString |
| 75 | // - HeapNumber |
| 76 | // - Code |
| 77 | // - Map |
| 78 | // - Oddball |
| 79 | // - Proxy |
| 80 | // - SharedFunctionInfo |
| 81 | // - Struct |
| 82 | // - AccessorInfo |
| 83 | // - AccessCheckInfo |
| 84 | // - InterceptorInfo |
| 85 | // - CallHandlerInfo |
| 86 | // - FunctionTemplateInfo |
| 87 | // - ObjectTemplateInfo |
| 88 | // - SignatureInfo |
| 89 | // - TypeSwitchInfo |
| 90 | // - DebugInfo |
| 91 | // - BreakPointInfo |
| 92 | // |
| 93 | // Formats of Object*: |
| 94 | // Smi: [31 bit signed int] 0 |
| 95 | // HeapObject: [32 bit direct pointer] (4 byte aligned) | 01 |
| 96 | // Failure: [30 bit signed int] 11 |
| 97 | |
| 98 | |
| 99 | // Ecma-262 3rd 8.6.1 |
| 100 | enum PropertyAttributes { |
| 101 | NONE = v8::None, |
| 102 | READ_ONLY = v8::ReadOnly, |
| 103 | DONT_ENUM = v8::DontEnum, |
| 104 | DONT_DELETE = v8::DontDelete, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 105 | 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] | 106 | // ABSENT can never be stored in or returned from a descriptor's attributes |
| 107 | // bitfield. It is only used as a return value meaning the attributes of |
| 108 | // a non-existent property. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | namespace v8 { namespace internal { |
| 112 | |
| 113 | |
| 114 | // PropertyDetails captures type and attributes for a property. |
| 115 | // They are used both in property dictionaries and instance descriptors. |
| 116 | class PropertyDetails BASE_EMBEDDED { |
| 117 | public: |
| 118 | |
| 119 | PropertyDetails(PropertyAttributes attributes, |
| 120 | PropertyType type, |
| 121 | int index = 0) { |
| 122 | ASSERT(TypeField::is_valid(type)); |
| 123 | ASSERT(AttributesField::is_valid(attributes)); |
| 124 | ASSERT(IndexField::is_valid(index)); |
| 125 | |
| 126 | value_ = TypeField::encode(type) |
| 127 | | AttributesField::encode(attributes) |
| 128 | | IndexField::encode(index); |
| 129 | |
| 130 | ASSERT(type == this->type()); |
| 131 | ASSERT(attributes == this->attributes()); |
| 132 | ASSERT(index == this->index()); |
| 133 | } |
| 134 | |
| 135 | // Conversion for storing details as Object*. |
| 136 | inline PropertyDetails(Smi* smi); |
| 137 | inline Smi* AsSmi(); |
| 138 | |
| 139 | PropertyType type() { return TypeField::decode(value_); } |
| 140 | |
| 141 | bool IsTransition() { |
| 142 | PropertyType t = type(); |
| 143 | ASSERT(t != INTERCEPTOR); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 144 | return t == MAP_TRANSITION || t == CONSTANT_TRANSITION; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | PropertyAttributes attributes() { return AttributesField::decode(value_); } |
| 148 | |
| 149 | int index() { return IndexField::decode(value_); } |
| 150 | |
| 151 | static bool IsValidIndex(int index) { return IndexField::is_valid(index); } |
| 152 | |
| 153 | bool IsReadOnly() { return (attributes() & READ_ONLY) != 0; } |
| 154 | bool IsDontDelete() { return (attributes() & DONT_DELETE) != 0; } |
| 155 | bool IsDontEnum() { return (attributes() & DONT_ENUM) != 0; } |
| 156 | |
| 157 | // Bit fields in value_ (type, shift, size). Must be public so the |
| 158 | // constants can be embedded in generated code. |
| 159 | class TypeField: public BitField<PropertyType, 0, 3> {}; |
| 160 | class AttributesField: public BitField<PropertyAttributes, 3, 3> {}; |
| 161 | class IndexField: public BitField<uint32_t, 6, 32-6> {}; |
| 162 | |
| 163 | static const int kInitialIndex = 1; |
| 164 | |
| 165 | private: |
| 166 | uint32_t value_; |
| 167 | }; |
| 168 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 169 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 170 | // Setter that skips the write barrier if mode is SKIP_WRITE_BARRIER. |
| 171 | enum WriteBarrierMode { SKIP_WRITE_BARRIER, UPDATE_WRITE_BARRIER }; |
| 172 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 173 | |
| 174 | // PropertyNormalizationMode is used to specify whether to keep |
| 175 | // inobject properties when normalizing properties of a JSObject. |
| 176 | enum PropertyNormalizationMode { |
| 177 | CLEAR_INOBJECT_PROPERTIES, |
| 178 | KEEP_INOBJECT_PROPERTIES |
| 179 | }; |
| 180 | |
| 181 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 182 | // All Maps have a field instance_type containing a InstanceType. |
| 183 | // It describes the type of the instances. |
| 184 | // |
| 185 | // As an example, a JavaScript object is a heap object and its map |
| 186 | // instance_type is JS_OBJECT_TYPE. |
| 187 | // |
| 188 | // The names of the string instance types are intended to systematically |
| 189 | // mirror their encoding in the instance_type field of the map. The length |
| 190 | // (SHORT, MEDIUM, or LONG) is always mentioned. The default encoding is |
| 191 | // considered TWO_BYTE. It is not mentioned in the name. ASCII encoding is |
| 192 | // mentioned explicitly in the name. Likewise, the default representation is |
| 193 | // considered sequential. It is not mentioned in the name. The other |
| 194 | // representations (eg, CONS, SLICED, EXTERNAL) are explicitly mentioned. |
| 195 | // Finally, the string is either a SYMBOL_TYPE (if it is a symbol) or a |
| 196 | // STRING_TYPE (if it is not a symbol). |
| 197 | // |
| 198 | // NOTE: The following things are some that depend on the string types having |
| 199 | // instance_types that are less than those of all other types: |
| 200 | // HeapObject::Size, HeapObject::IterateBody, the typeof operator, and |
| 201 | // Object::IsString. |
| 202 | // |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 203 | // NOTE: Everything following JS_VALUE_TYPE is considered a |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 204 | // JSObject for GC purposes. The first four entries here have typeof |
| 205 | // 'object', whereas JS_FUNCTION_TYPE has typeof 'function'. |
| 206 | #define INSTANCE_TYPE_LIST(V) \ |
| 207 | V(SHORT_SYMBOL_TYPE) \ |
| 208 | V(MEDIUM_SYMBOL_TYPE) \ |
| 209 | V(LONG_SYMBOL_TYPE) \ |
| 210 | V(SHORT_ASCII_SYMBOL_TYPE) \ |
| 211 | V(MEDIUM_ASCII_SYMBOL_TYPE) \ |
| 212 | V(LONG_ASCII_SYMBOL_TYPE) \ |
| 213 | V(SHORT_CONS_SYMBOL_TYPE) \ |
| 214 | V(MEDIUM_CONS_SYMBOL_TYPE) \ |
| 215 | V(LONG_CONS_SYMBOL_TYPE) \ |
| 216 | V(SHORT_CONS_ASCII_SYMBOL_TYPE) \ |
| 217 | V(MEDIUM_CONS_ASCII_SYMBOL_TYPE) \ |
| 218 | V(LONG_CONS_ASCII_SYMBOL_TYPE) \ |
| 219 | V(SHORT_SLICED_SYMBOL_TYPE) \ |
| 220 | V(MEDIUM_SLICED_SYMBOL_TYPE) \ |
| 221 | V(LONG_SLICED_SYMBOL_TYPE) \ |
| 222 | V(SHORT_SLICED_ASCII_SYMBOL_TYPE) \ |
| 223 | V(MEDIUM_SLICED_ASCII_SYMBOL_TYPE) \ |
| 224 | V(LONG_SLICED_ASCII_SYMBOL_TYPE) \ |
| 225 | V(SHORT_EXTERNAL_SYMBOL_TYPE) \ |
| 226 | V(MEDIUM_EXTERNAL_SYMBOL_TYPE) \ |
| 227 | V(LONG_EXTERNAL_SYMBOL_TYPE) \ |
| 228 | V(SHORT_EXTERNAL_ASCII_SYMBOL_TYPE) \ |
| 229 | V(MEDIUM_EXTERNAL_ASCII_SYMBOL_TYPE) \ |
| 230 | V(LONG_EXTERNAL_ASCII_SYMBOL_TYPE) \ |
| 231 | V(SHORT_STRING_TYPE) \ |
| 232 | V(MEDIUM_STRING_TYPE) \ |
| 233 | V(LONG_STRING_TYPE) \ |
| 234 | V(SHORT_ASCII_STRING_TYPE) \ |
| 235 | V(MEDIUM_ASCII_STRING_TYPE) \ |
| 236 | V(LONG_ASCII_STRING_TYPE) \ |
| 237 | V(SHORT_CONS_STRING_TYPE) \ |
| 238 | V(MEDIUM_CONS_STRING_TYPE) \ |
| 239 | V(LONG_CONS_STRING_TYPE) \ |
| 240 | V(SHORT_CONS_ASCII_STRING_TYPE) \ |
| 241 | V(MEDIUM_CONS_ASCII_STRING_TYPE) \ |
| 242 | V(LONG_CONS_ASCII_STRING_TYPE) \ |
| 243 | V(SHORT_SLICED_STRING_TYPE) \ |
| 244 | V(MEDIUM_SLICED_STRING_TYPE) \ |
| 245 | V(LONG_SLICED_STRING_TYPE) \ |
| 246 | V(SHORT_SLICED_ASCII_STRING_TYPE) \ |
| 247 | V(MEDIUM_SLICED_ASCII_STRING_TYPE) \ |
| 248 | V(LONG_SLICED_ASCII_STRING_TYPE) \ |
| 249 | V(SHORT_EXTERNAL_STRING_TYPE) \ |
| 250 | V(MEDIUM_EXTERNAL_STRING_TYPE) \ |
| 251 | V(LONG_EXTERNAL_STRING_TYPE) \ |
| 252 | V(SHORT_EXTERNAL_ASCII_STRING_TYPE) \ |
| 253 | V(MEDIUM_EXTERNAL_ASCII_STRING_TYPE) \ |
| 254 | V(LONG_EXTERNAL_ASCII_STRING_TYPE) \ |
| 255 | V(LONG_PRIVATE_EXTERNAL_ASCII_STRING_TYPE) \ |
| 256 | \ |
| 257 | V(MAP_TYPE) \ |
| 258 | V(HEAP_NUMBER_TYPE) \ |
| 259 | V(FIXED_ARRAY_TYPE) \ |
| 260 | V(CODE_TYPE) \ |
| 261 | V(ODDBALL_TYPE) \ |
| 262 | V(PROXY_TYPE) \ |
| 263 | V(BYTE_ARRAY_TYPE) \ |
| 264 | V(FILLER_TYPE) \ |
| 265 | \ |
| 266 | V(ACCESSOR_INFO_TYPE) \ |
| 267 | V(ACCESS_CHECK_INFO_TYPE) \ |
| 268 | V(INTERCEPTOR_INFO_TYPE) \ |
| 269 | V(SHARED_FUNCTION_INFO_TYPE) \ |
| 270 | V(CALL_HANDLER_INFO_TYPE) \ |
| 271 | V(FUNCTION_TEMPLATE_INFO_TYPE) \ |
| 272 | V(OBJECT_TEMPLATE_INFO_TYPE) \ |
| 273 | V(SIGNATURE_INFO_TYPE) \ |
| 274 | V(TYPE_SWITCH_INFO_TYPE) \ |
| 275 | V(DEBUG_INFO_TYPE) \ |
| 276 | V(BREAK_POINT_INFO_TYPE) \ |
| 277 | V(SCRIPT_TYPE) \ |
| 278 | \ |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 279 | V(JS_VALUE_TYPE) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 280 | V(JS_OBJECT_TYPE) \ |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 281 | V(JS_CONTEXT_EXTENSION_OBJECT_TYPE) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 282 | V(JS_GLOBAL_OBJECT_TYPE) \ |
| 283 | V(JS_BUILTINS_OBJECT_TYPE) \ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 284 | V(JS_GLOBAL_PROXY_TYPE) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 285 | V(JS_ARRAY_TYPE) \ |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 286 | V(JS_REGEXP_TYPE) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 287 | \ |
| 288 | V(JS_FUNCTION_TYPE) \ |
| 289 | |
| 290 | |
| 291 | // Since string types are not consecutive, this macro is used to |
| 292 | // iterate over them. |
| 293 | #define STRING_TYPE_LIST(V) \ |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 294 | V(SHORT_SYMBOL_TYPE, SeqTwoByteString::kHeaderSize, short_symbol) \ |
| 295 | V(MEDIUM_SYMBOL_TYPE, SeqTwoByteString::kHeaderSize, medium_symbol) \ |
| 296 | V(LONG_SYMBOL_TYPE, SeqTwoByteString::kHeaderSize, long_symbol) \ |
| 297 | V(SHORT_ASCII_SYMBOL_TYPE, SeqAsciiString::kHeaderSize, short_ascii_symbol) \ |
| 298 | V(MEDIUM_ASCII_SYMBOL_TYPE, SeqAsciiString::kHeaderSize, medium_ascii_symbol)\ |
| 299 | V(LONG_ASCII_SYMBOL_TYPE, SeqAsciiString::kHeaderSize, long_ascii_symbol) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 300 | V(SHORT_CONS_SYMBOL_TYPE, ConsString::kSize, short_cons_symbol) \ |
| 301 | V(MEDIUM_CONS_SYMBOL_TYPE, ConsString::kSize, medium_cons_symbol) \ |
| 302 | V(LONG_CONS_SYMBOL_TYPE, ConsString::kSize, long_cons_symbol) \ |
| 303 | V(SHORT_CONS_ASCII_SYMBOL_TYPE, ConsString::kSize, short_cons_ascii_symbol) \ |
| 304 | V(MEDIUM_CONS_ASCII_SYMBOL_TYPE, ConsString::kSize, medium_cons_ascii_symbol)\ |
| 305 | V(LONG_CONS_ASCII_SYMBOL_TYPE, ConsString::kSize, long_cons_ascii_symbol) \ |
| 306 | V(SHORT_SLICED_SYMBOL_TYPE, SlicedString::kSize, short_sliced_symbol) \ |
| 307 | V(MEDIUM_SLICED_SYMBOL_TYPE, SlicedString::kSize, medium_sliced_symbol) \ |
| 308 | V(LONG_SLICED_SYMBOL_TYPE, SlicedString::kSize, long_sliced_symbol) \ |
| 309 | V(SHORT_SLICED_ASCII_SYMBOL_TYPE, \ |
| 310 | SlicedString::kSize, \ |
| 311 | short_sliced_ascii_symbol) \ |
| 312 | V(MEDIUM_SLICED_ASCII_SYMBOL_TYPE, \ |
| 313 | SlicedString::kSize, \ |
| 314 | medium_sliced_ascii_symbol) \ |
| 315 | V(LONG_SLICED_ASCII_SYMBOL_TYPE, \ |
| 316 | SlicedString::kSize, \ |
| 317 | long_sliced_ascii_symbol) \ |
| 318 | V(SHORT_EXTERNAL_SYMBOL_TYPE, \ |
| 319 | ExternalTwoByteString::kSize, \ |
| 320 | short_external_symbol) \ |
| 321 | V(MEDIUM_EXTERNAL_SYMBOL_TYPE, \ |
| 322 | ExternalTwoByteString::kSize, \ |
| 323 | medium_external_symbol) \ |
| 324 | V(LONG_EXTERNAL_SYMBOL_TYPE, \ |
| 325 | ExternalTwoByteString::kSize, \ |
| 326 | long_external_symbol) \ |
| 327 | V(SHORT_EXTERNAL_ASCII_SYMBOL_TYPE, \ |
| 328 | ExternalAsciiString::kSize, \ |
| 329 | short_external_ascii_symbol) \ |
| 330 | V(MEDIUM_EXTERNAL_ASCII_SYMBOL_TYPE, \ |
| 331 | ExternalAsciiString::kSize, \ |
| 332 | medium_external_ascii_symbol) \ |
| 333 | V(LONG_EXTERNAL_ASCII_SYMBOL_TYPE, \ |
| 334 | ExternalAsciiString::kSize, \ |
| 335 | long_external_ascii_symbol) \ |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 336 | V(SHORT_STRING_TYPE, SeqTwoByteString::kHeaderSize, short_string) \ |
| 337 | V(MEDIUM_STRING_TYPE, SeqTwoByteString::kHeaderSize, medium_string) \ |
| 338 | V(LONG_STRING_TYPE, SeqTwoByteString::kHeaderSize, long_string) \ |
| 339 | V(SHORT_ASCII_STRING_TYPE, SeqAsciiString::kHeaderSize, short_ascii_string) \ |
| 340 | V(MEDIUM_ASCII_STRING_TYPE, SeqAsciiString::kHeaderSize, medium_ascii_string)\ |
| 341 | V(LONG_ASCII_STRING_TYPE, SeqAsciiString::kHeaderSize, long_ascii_string) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 342 | V(SHORT_CONS_STRING_TYPE, ConsString::kSize, short_cons_string) \ |
| 343 | V(MEDIUM_CONS_STRING_TYPE, ConsString::kSize, medium_cons_string) \ |
| 344 | V(LONG_CONS_STRING_TYPE, ConsString::kSize, long_cons_string) \ |
| 345 | V(SHORT_CONS_ASCII_STRING_TYPE, ConsString::kSize, short_cons_ascii_string) \ |
| 346 | V(MEDIUM_CONS_ASCII_STRING_TYPE, ConsString::kSize, medium_cons_ascii_string)\ |
| 347 | V(LONG_CONS_ASCII_STRING_TYPE, ConsString::kSize, long_cons_ascii_string) \ |
| 348 | V(SHORT_SLICED_STRING_TYPE, SlicedString::kSize, short_sliced_string) \ |
| 349 | V(MEDIUM_SLICED_STRING_TYPE, SlicedString::kSize, medium_sliced_string) \ |
| 350 | V(LONG_SLICED_STRING_TYPE, SlicedString::kSize, long_sliced_string) \ |
| 351 | V(SHORT_SLICED_ASCII_STRING_TYPE, \ |
| 352 | SlicedString::kSize, \ |
| 353 | short_sliced_ascii_string) \ |
| 354 | V(MEDIUM_SLICED_ASCII_STRING_TYPE, \ |
| 355 | SlicedString::kSize, \ |
| 356 | medium_sliced_ascii_string) \ |
| 357 | V(LONG_SLICED_ASCII_STRING_TYPE, \ |
| 358 | SlicedString::kSize, \ |
| 359 | long_sliced_ascii_string) \ |
| 360 | V(SHORT_EXTERNAL_STRING_TYPE, \ |
| 361 | ExternalTwoByteString::kSize, \ |
| 362 | short_external_string) \ |
| 363 | V(MEDIUM_EXTERNAL_STRING_TYPE, \ |
| 364 | ExternalTwoByteString::kSize, \ |
| 365 | medium_external_string) \ |
| 366 | V(LONG_EXTERNAL_STRING_TYPE, \ |
| 367 | ExternalTwoByteString::kSize, \ |
| 368 | long_external_string) \ |
| 369 | V(SHORT_EXTERNAL_ASCII_STRING_TYPE, \ |
| 370 | ExternalAsciiString::kSize, \ |
| 371 | short_external_ascii_string) \ |
| 372 | V(MEDIUM_EXTERNAL_ASCII_STRING_TYPE, \ |
| 373 | ExternalAsciiString::kSize, \ |
| 374 | medium_external_ascii_string) \ |
| 375 | V(LONG_EXTERNAL_ASCII_STRING_TYPE, \ |
| 376 | ExternalAsciiString::kSize, \ |
| 377 | long_external_ascii_string) |
| 378 | |
| 379 | // A struct is a simple object a set of object-valued fields. Including an |
| 380 | // object type in this causes the compiler to generate most of the boilerplate |
| 381 | // code for the class including allocation and garbage collection routines, |
| 382 | // casts and predicates. All you need to define is the class, methods and |
| 383 | // object verification routines. Easy, no? |
| 384 | // |
| 385 | // Note that for subtle reasons related to the ordering or numerical values of |
| 386 | // type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST |
| 387 | // manually. |
| 388 | #define STRUCT_LIST(V) \ |
| 389 | V(ACCESSOR_INFO, AccessorInfo, accessor_info) \ |
| 390 | V(ACCESS_CHECK_INFO, AccessCheckInfo, access_check_info) \ |
| 391 | V(INTERCEPTOR_INFO, InterceptorInfo, interceptor_info) \ |
| 392 | V(CALL_HANDLER_INFO, CallHandlerInfo, call_handler_info) \ |
| 393 | V(FUNCTION_TEMPLATE_INFO, FunctionTemplateInfo, function_template_info) \ |
| 394 | V(OBJECT_TEMPLATE_INFO, ObjectTemplateInfo, object_template_info) \ |
| 395 | V(SIGNATURE_INFO, SignatureInfo, signature_info) \ |
| 396 | V(TYPE_SWITCH_INFO, TypeSwitchInfo, type_switch_info) \ |
| 397 | V(DEBUG_INFO, DebugInfo, debug_info) \ |
| 398 | V(BREAK_POINT_INFO, BreakPointInfo, break_point_info) \ |
| 399 | V(SCRIPT, Script, script) |
| 400 | |
| 401 | |
| 402 | // We use the full 8 bits of the instance_type field to encode heap object |
| 403 | // instance types. The high-order bit (bit 7) is set if the object is not a |
| 404 | // string, and cleared if it is a string. |
| 405 | const uint32_t kIsNotStringMask = 0x80; |
| 406 | const uint32_t kStringTag = 0x0; |
| 407 | const uint32_t kNotStringTag = 0x80; |
| 408 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 409 | // If bit 7 is clear, bit 5 indicates that the string is a symbol (if set) or |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 410 | // not (if cleared). |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 411 | const uint32_t kIsSymbolMask = 0x20; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 412 | const uint32_t kNotSymbolTag = 0x0; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 413 | const uint32_t kSymbolTag = 0x20; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 414 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 415 | // If bit 7 is clear, bits 3 and 4 are the string's size (short, medium or |
| 416 | // long). These values are very special in that they are also used to shift |
| 417 | // the length field to get the length, removing the hash value. This avoids |
| 418 | // using if or switch when getting the length of a string. |
| 419 | const uint32_t kStringSizeMask = 0x18; |
| 420 | const uint32_t kShortStringTag = 0x18; |
| 421 | const uint32_t kMediumStringTag = 0x10; |
| 422 | const uint32_t kLongStringTag = 0x00; |
| 423 | |
| 424 | // If bit 7 is clear then bit 2 indicates whether the string consists of |
| 425 | // two-byte characters or one-byte characters. |
| 426 | const uint32_t kStringEncodingMask = 0x4; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 427 | const uint32_t kTwoByteStringTag = 0x0; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 428 | const uint32_t kAsciiStringTag = 0x4; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 429 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 430 | // 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] | 431 | // of the string. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 432 | const uint32_t kStringRepresentationMask = 0x03; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 433 | enum StringRepresentationTag { |
| 434 | kSeqStringTag = 0x0, |
| 435 | kConsStringTag = 0x1, |
| 436 | kSlicedStringTag = 0x2, |
| 437 | kExternalStringTag = 0x3 |
| 438 | }; |
| 439 | |
| 440 | enum InstanceType { |
| 441 | SHORT_SYMBOL_TYPE = kShortStringTag | kSymbolTag | kSeqStringTag, |
| 442 | MEDIUM_SYMBOL_TYPE = kMediumStringTag | kSymbolTag | kSeqStringTag, |
| 443 | LONG_SYMBOL_TYPE = kLongStringTag | kSymbolTag | kSeqStringTag, |
| 444 | SHORT_ASCII_SYMBOL_TYPE = |
| 445 | kShortStringTag | kAsciiStringTag | kSymbolTag | kSeqStringTag, |
| 446 | MEDIUM_ASCII_SYMBOL_TYPE = |
| 447 | kMediumStringTag | kAsciiStringTag | kSymbolTag | kSeqStringTag, |
| 448 | LONG_ASCII_SYMBOL_TYPE = |
| 449 | kLongStringTag | kAsciiStringTag | kSymbolTag | kSeqStringTag, |
| 450 | SHORT_CONS_SYMBOL_TYPE = kShortStringTag | kSymbolTag | kConsStringTag, |
| 451 | MEDIUM_CONS_SYMBOL_TYPE = kMediumStringTag | kSymbolTag | kConsStringTag, |
| 452 | LONG_CONS_SYMBOL_TYPE = kLongStringTag | kSymbolTag | kConsStringTag, |
| 453 | SHORT_CONS_ASCII_SYMBOL_TYPE = |
| 454 | kShortStringTag | kAsciiStringTag | kSymbolTag | kConsStringTag, |
| 455 | MEDIUM_CONS_ASCII_SYMBOL_TYPE = |
| 456 | kMediumStringTag | kAsciiStringTag | kSymbolTag | kConsStringTag, |
| 457 | LONG_CONS_ASCII_SYMBOL_TYPE = |
| 458 | kLongStringTag | kAsciiStringTag | kSymbolTag | kConsStringTag, |
| 459 | SHORT_SLICED_SYMBOL_TYPE = kShortStringTag | kSymbolTag | kSlicedStringTag, |
| 460 | MEDIUM_SLICED_SYMBOL_TYPE = kMediumStringTag | kSymbolTag | kSlicedStringTag, |
| 461 | LONG_SLICED_SYMBOL_TYPE = kLongStringTag | kSymbolTag | kSlicedStringTag, |
| 462 | SHORT_SLICED_ASCII_SYMBOL_TYPE = |
| 463 | kShortStringTag | kAsciiStringTag | kSymbolTag | kSlicedStringTag, |
| 464 | MEDIUM_SLICED_ASCII_SYMBOL_TYPE = |
| 465 | kMediumStringTag | kAsciiStringTag | kSymbolTag | kSlicedStringTag, |
| 466 | LONG_SLICED_ASCII_SYMBOL_TYPE = |
| 467 | kLongStringTag | kAsciiStringTag | kSymbolTag | kSlicedStringTag, |
| 468 | SHORT_EXTERNAL_SYMBOL_TYPE = |
| 469 | kShortStringTag | kSymbolTag | kExternalStringTag, |
| 470 | MEDIUM_EXTERNAL_SYMBOL_TYPE = |
| 471 | kMediumStringTag | kSymbolTag | kExternalStringTag, |
| 472 | LONG_EXTERNAL_SYMBOL_TYPE = kLongStringTag | kSymbolTag | kExternalStringTag, |
| 473 | SHORT_EXTERNAL_ASCII_SYMBOL_TYPE = |
| 474 | kShortStringTag | kAsciiStringTag | kSymbolTag | kExternalStringTag, |
| 475 | MEDIUM_EXTERNAL_ASCII_SYMBOL_TYPE = |
| 476 | kMediumStringTag | kAsciiStringTag | kSymbolTag | kExternalStringTag, |
| 477 | LONG_EXTERNAL_ASCII_SYMBOL_TYPE = |
| 478 | kLongStringTag | kAsciiStringTag | kSymbolTag | kExternalStringTag, |
| 479 | SHORT_STRING_TYPE = kShortStringTag | kSeqStringTag, |
| 480 | MEDIUM_STRING_TYPE = kMediumStringTag | kSeqStringTag, |
| 481 | LONG_STRING_TYPE = kLongStringTag | kSeqStringTag, |
| 482 | SHORT_ASCII_STRING_TYPE = kShortStringTag | kAsciiStringTag | kSeqStringTag, |
| 483 | MEDIUM_ASCII_STRING_TYPE = kMediumStringTag | kAsciiStringTag | kSeqStringTag, |
| 484 | LONG_ASCII_STRING_TYPE = kLongStringTag | kAsciiStringTag | kSeqStringTag, |
| 485 | SHORT_CONS_STRING_TYPE = kShortStringTag | kConsStringTag, |
| 486 | MEDIUM_CONS_STRING_TYPE = kMediumStringTag | kConsStringTag, |
| 487 | LONG_CONS_STRING_TYPE = kLongStringTag | kConsStringTag, |
| 488 | SHORT_CONS_ASCII_STRING_TYPE = |
| 489 | kShortStringTag | kAsciiStringTag | kConsStringTag, |
| 490 | MEDIUM_CONS_ASCII_STRING_TYPE = |
| 491 | kMediumStringTag | kAsciiStringTag | kConsStringTag, |
| 492 | LONG_CONS_ASCII_STRING_TYPE = |
| 493 | kLongStringTag | kAsciiStringTag | kConsStringTag, |
| 494 | SHORT_SLICED_STRING_TYPE = kShortStringTag | kSlicedStringTag, |
| 495 | MEDIUM_SLICED_STRING_TYPE = kMediumStringTag | kSlicedStringTag, |
| 496 | LONG_SLICED_STRING_TYPE = kLongStringTag | kSlicedStringTag, |
| 497 | SHORT_SLICED_ASCII_STRING_TYPE = |
| 498 | kShortStringTag | kAsciiStringTag | kSlicedStringTag, |
| 499 | MEDIUM_SLICED_ASCII_STRING_TYPE = |
| 500 | kMediumStringTag | kAsciiStringTag | kSlicedStringTag, |
| 501 | LONG_SLICED_ASCII_STRING_TYPE = |
| 502 | kLongStringTag | kAsciiStringTag | kSlicedStringTag, |
| 503 | SHORT_EXTERNAL_STRING_TYPE = kShortStringTag | kExternalStringTag, |
| 504 | MEDIUM_EXTERNAL_STRING_TYPE = kMediumStringTag | kExternalStringTag, |
| 505 | LONG_EXTERNAL_STRING_TYPE = kLongStringTag | kExternalStringTag, |
| 506 | SHORT_EXTERNAL_ASCII_STRING_TYPE = |
| 507 | kShortStringTag | kAsciiStringTag | kExternalStringTag, |
| 508 | MEDIUM_EXTERNAL_ASCII_STRING_TYPE = |
| 509 | kMediumStringTag | kAsciiStringTag | kExternalStringTag, |
| 510 | LONG_EXTERNAL_ASCII_STRING_TYPE = |
| 511 | kLongStringTag | kAsciiStringTag | kExternalStringTag, |
| 512 | LONG_PRIVATE_EXTERNAL_ASCII_STRING_TYPE = LONG_EXTERNAL_ASCII_STRING_TYPE, |
| 513 | |
| 514 | MAP_TYPE = kNotStringTag, |
| 515 | HEAP_NUMBER_TYPE, |
| 516 | FIXED_ARRAY_TYPE, |
| 517 | CODE_TYPE, |
| 518 | ODDBALL_TYPE, |
| 519 | PROXY_TYPE, |
| 520 | BYTE_ARRAY_TYPE, |
| 521 | FILLER_TYPE, |
| 522 | SMI_TYPE, |
| 523 | |
| 524 | ACCESSOR_INFO_TYPE, |
| 525 | ACCESS_CHECK_INFO_TYPE, |
| 526 | INTERCEPTOR_INFO_TYPE, |
| 527 | SHARED_FUNCTION_INFO_TYPE, |
| 528 | CALL_HANDLER_INFO_TYPE, |
| 529 | FUNCTION_TEMPLATE_INFO_TYPE, |
| 530 | OBJECT_TEMPLATE_INFO_TYPE, |
| 531 | SIGNATURE_INFO_TYPE, |
| 532 | TYPE_SWITCH_INFO_TYPE, |
| 533 | DEBUG_INFO_TYPE, |
| 534 | BREAK_POINT_INFO_TYPE, |
| 535 | SCRIPT_TYPE, |
| 536 | |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 537 | JS_VALUE_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 538 | JS_OBJECT_TYPE, |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 539 | JS_CONTEXT_EXTENSION_OBJECT_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 540 | JS_GLOBAL_OBJECT_TYPE, |
| 541 | JS_BUILTINS_OBJECT_TYPE, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 542 | JS_GLOBAL_PROXY_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 543 | JS_ARRAY_TYPE, |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 544 | JS_REGEXP_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 545 | |
| 546 | JS_FUNCTION_TYPE, |
| 547 | |
| 548 | // Pseudo-types |
| 549 | FIRST_NONSTRING_TYPE = MAP_TYPE, |
| 550 | FIRST_TYPE = 0x0, |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 551 | INVALID_TYPE = FIRST_TYPE - 1, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 552 | LAST_TYPE = JS_FUNCTION_TYPE, |
| 553 | // Boundaries for testing the type is a JavaScript "object". Note that |
| 554 | // function objects are not counted as objects, even though they are |
| 555 | // implemented as such; only values whose typeof is "object" are included. |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 556 | FIRST_JS_OBJECT_TYPE = JS_VALUE_TYPE, |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 557 | LAST_JS_OBJECT_TYPE = JS_REGEXP_TYPE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 558 | }; |
| 559 | |
| 560 | |
| 561 | enum CompareResult { |
| 562 | LESS = -1, |
| 563 | EQUAL = 0, |
| 564 | GREATER = 1, |
| 565 | |
| 566 | NOT_EQUAL = GREATER |
| 567 | }; |
| 568 | |
| 569 | |
| 570 | #define DECL_BOOLEAN_ACCESSORS(name) \ |
| 571 | inline bool name(); \ |
| 572 | inline void set_##name(bool value); \ |
| 573 | |
| 574 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 575 | #define DECL_ACCESSORS(name, type) \ |
| 576 | inline type* name(); \ |
| 577 | inline void set_##name(type* value, \ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 578 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 579 | |
| 580 | |
| 581 | class StringStream; |
| 582 | class ObjectVisitor; |
| 583 | |
| 584 | struct ValueInfo : public Malloced { |
| 585 | ValueInfo() : type(FIRST_TYPE), ptr(NULL), str(NULL), number(0) { } |
| 586 | InstanceType type; |
| 587 | Object* ptr; |
| 588 | const char* str; |
| 589 | double number; |
| 590 | }; |
| 591 | |
| 592 | |
| 593 | // A template-ized version of the IsXXX functions. |
| 594 | template <class C> static inline bool Is(Object* obj); |
| 595 | |
| 596 | |
| 597 | // Object is the abstract superclass for all classes in the |
| 598 | // object hierarchy. |
| 599 | // Object does not use any virtual functions to avoid the |
| 600 | // allocation of the C++ vtable. |
| 601 | // Since Smi and Failure are subclasses of Object no |
| 602 | // data members can be present in Object. |
| 603 | class Object BASE_EMBEDDED { |
| 604 | public: |
| 605 | // Type testing. |
| 606 | inline bool IsSmi(); |
| 607 | inline bool IsHeapObject(); |
| 608 | inline bool IsHeapNumber(); |
| 609 | inline bool IsString(); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 610 | inline bool IsSymbol(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 611 | inline bool IsSeqString(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 612 | inline bool IsSlicedString(); |
| 613 | inline bool IsExternalString(); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 614 | inline bool IsConsString(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 615 | inline bool IsExternalTwoByteString(); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 616 | inline bool IsExternalAsciiString(); |
| 617 | inline bool IsSeqTwoByteString(); |
| 618 | inline bool IsSeqAsciiString(); |
| 619 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 620 | inline bool IsNumber(); |
| 621 | inline bool IsByteArray(); |
| 622 | inline bool IsFailure(); |
| 623 | inline bool IsRetryAfterGC(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 624 | inline bool IsOutOfMemoryFailure(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 625 | inline bool IsException(); |
| 626 | inline bool IsJSObject(); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 627 | inline bool IsJSContextExtensionObject(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 628 | inline bool IsMap(); |
| 629 | inline bool IsFixedArray(); |
| 630 | inline bool IsDescriptorArray(); |
| 631 | inline bool IsContext(); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 632 | inline bool IsCatchContext(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 633 | inline bool IsGlobalContext(); |
| 634 | inline bool IsJSFunction(); |
| 635 | inline bool IsCode(); |
| 636 | inline bool IsOddball(); |
| 637 | inline bool IsSharedFunctionInfo(); |
| 638 | inline bool IsJSValue(); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 639 | inline bool IsStringWrapper(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 640 | inline bool IsProxy(); |
| 641 | inline bool IsBoolean(); |
| 642 | inline bool IsJSArray(); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 643 | inline bool IsJSRegExp(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 644 | inline bool IsHashTable(); |
| 645 | inline bool IsDictionary(); |
| 646 | inline bool IsSymbolTable(); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 647 | inline bool IsCompilationCacheTable(); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 648 | inline bool IsMapCache(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 649 | inline bool IsLookupCache(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 650 | inline bool IsPrimitive(); |
| 651 | inline bool IsGlobalObject(); |
| 652 | inline bool IsJSGlobalObject(); |
| 653 | inline bool IsJSBuiltinsObject(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 654 | inline bool IsJSGlobalProxy(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 655 | inline bool IsUndetectableObject(); |
| 656 | inline bool IsAccessCheckNeeded(); |
| 657 | |
| 658 | // Returns true if this object is an instance of the specified |
| 659 | // function template. |
| 660 | bool IsInstanceOf(FunctionTemplateInfo* type); |
| 661 | |
| 662 | inline bool IsStruct(); |
| 663 | #define DECLARE_STRUCT_PREDICATE(NAME, Name, name) inline bool Is##Name(); |
| 664 | STRUCT_LIST(DECLARE_STRUCT_PREDICATE) |
| 665 | #undef DECLARE_STRUCT_PREDICATE |
| 666 | |
| 667 | // Oddball testing. |
| 668 | INLINE(bool IsUndefined()); |
| 669 | INLINE(bool IsTheHole()); |
| 670 | INLINE(bool IsNull()); |
| 671 | INLINE(bool IsTrue()); |
| 672 | INLINE(bool IsFalse()); |
| 673 | |
| 674 | // Extract the number. |
| 675 | inline double Number(); |
| 676 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 677 | inline bool HasSpecificClassOf(String* name); |
| 678 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 679 | Object* ToObject(); // ECMA-262 9.9. |
| 680 | Object* ToBoolean(); // ECMA-262 9.2. |
| 681 | |
| 682 | // Convert to a JSObject if needed. |
| 683 | // global_context is used when creating wrapper object. |
| 684 | Object* ToObject(Context* global_context); |
| 685 | |
| 686 | // Converts this to a Smi if possible. |
| 687 | // Failure is returned otherwise. |
| 688 | inline Object* ToSmi(); |
| 689 | |
| 690 | void Lookup(String* name, LookupResult* result); |
| 691 | |
| 692 | // Property access. |
| 693 | inline Object* GetProperty(String* key); |
| 694 | inline Object* GetProperty(String* key, PropertyAttributes* attributes); |
| 695 | Object* GetPropertyWithReceiver(Object* receiver, |
| 696 | String* key, |
| 697 | PropertyAttributes* attributes); |
| 698 | Object* GetProperty(Object* receiver, |
| 699 | LookupResult* result, |
| 700 | String* key, |
| 701 | PropertyAttributes* attributes); |
| 702 | Object* GetPropertyWithCallback(Object* receiver, |
| 703 | Object* structure, |
| 704 | String* name, |
| 705 | Object* holder); |
| 706 | |
| 707 | inline Object* GetElement(uint32_t index); |
| 708 | Object* GetElementWithReceiver(Object* receiver, uint32_t index); |
| 709 | |
| 710 | // Return the object's prototype (might be Heap::null_value()). |
| 711 | Object* GetPrototype(); |
| 712 | |
| 713 | // Returns true if this is a JSValue containing a string and the index is |
| 714 | // < the length of the string. Used to implement [] on strings. |
| 715 | inline bool IsStringObjectWithCharacterAt(uint32_t index); |
| 716 | |
| 717 | #ifdef DEBUG |
| 718 | // Prints this object with details. |
| 719 | void Print(); |
| 720 | void PrintLn(); |
| 721 | // Verifies the object. |
| 722 | void Verify(); |
| 723 | |
| 724 | // Verify a pointer is a valid object pointer. |
| 725 | static void VerifyPointer(Object* p); |
| 726 | #endif |
| 727 | |
| 728 | // Prints this object without details. |
| 729 | void ShortPrint(); |
| 730 | |
| 731 | // Prints this object without details to a message accumulator. |
| 732 | void ShortPrint(StringStream* accumulator); |
| 733 | |
| 734 | // Casting: This cast is only needed to satisfy macros in objects-inl.h. |
| 735 | static Object* cast(Object* value) { return value; } |
| 736 | |
| 737 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 738 | 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] | 739 | |
| 740 | private: |
| 741 | DISALLOW_IMPLICIT_CONSTRUCTORS(Object); |
| 742 | }; |
| 743 | |
| 744 | |
| 745 | // Smi represents integer Numbers that can be stored in 31 bits. |
| 746 | // Smis are immediate which means they are NOT allocated in the heap. |
| 747 | // The this pointer has the following format: [31 bit signed int] 0 |
| 748 | // Smi stands for small integer. |
| 749 | class Smi: public Object { |
| 750 | public: |
| 751 | // Returns the integer value. |
| 752 | inline int value(); |
| 753 | |
| 754 | // Convert a value to a Smi object. |
| 755 | static inline Smi* FromInt(int value); |
| 756 | |
| 757 | // Returns whether value can be represented in a Smi. |
| 758 | static inline bool IsValid(int value); |
| 759 | |
| 760 | // Casting. |
| 761 | static inline Smi* cast(Object* object); |
| 762 | |
| 763 | // Dispatched behavior. |
| 764 | void SmiPrint(); |
| 765 | void SmiPrint(StringStream* accumulator); |
| 766 | #ifdef DEBUG |
| 767 | void SmiVerify(); |
| 768 | #endif |
| 769 | |
| 770 | // Min and max limits for Smi values. |
| 771 | static const int kMinValue = -(1 << (kBitsPerPointer - (kSmiTagSize + 1))); |
| 772 | static const int kMaxValue = (1 << (kBitsPerPointer - (kSmiTagSize + 1))) - 1; |
| 773 | |
| 774 | private: |
| 775 | DISALLOW_IMPLICIT_CONSTRUCTORS(Smi); |
| 776 | }; |
| 777 | |
| 778 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 779 | // Failure is used for reporting out of memory situations and |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 780 | // propagating exceptions through the runtime system. Failure objects |
| 781 | // are transient and cannot occur as part of the objects graph. |
| 782 | // |
| 783 | // Failures are a single word, encoded as follows: |
| 784 | // +-------------------------+---+--+--+ |
| 785 | // |rrrrrrrrrrrrrrrrrrrrrrrrr|sss|tt|11| |
| 786 | // +-------------------------+---+--+--+ |
| 787 | // |
| 788 | // The low two bits, 0-1, are the failure tag, 11. The next two bits, |
| 789 | // 2-3, are a failure type tag 'tt' with possible values: |
| 790 | // 00 RETRY_AFTER_GC |
| 791 | // 01 EXCEPTION |
| 792 | // 10 INTERNAL_ERROR |
| 793 | // 11 OUT_OF_MEMORY_EXCEPTION |
| 794 | // |
| 795 | // The next three bits, 4-6, are an allocation space tag 'sss'. The |
| 796 | // allocation space tag is 000 for all failure types except |
| 797 | // RETRY_AFTER_GC. For RETRY_AFTER_GC, the possible values are |
| 798 | // (the encoding is found in globals.h): |
| 799 | // 000 NEW_SPACE |
| 800 | // 001 OLD_SPACE |
| 801 | // 010 CODE_SPACE |
| 802 | // 011 MAP_SPACE |
| 803 | // 100 LO_SPACE |
| 804 | // |
| 805 | // The remaining bits is the number of words requested by the |
| 806 | // allocation request that failed, and is zeroed except for |
| 807 | // RETRY_AFTER_GC failures. The 25 bits (on a 32 bit platform) gives |
| 808 | // a representable range of 2^27 bytes (128MB). |
| 809 | |
| 810 | // Failure type tag info. |
| 811 | const int kFailureTypeTagSize = 2; |
| 812 | const int kFailureTypeTagMask = (1 << kFailureTypeTagSize) - 1; |
| 813 | |
| 814 | class Failure: public Object { |
| 815 | public: |
| 816 | // RuntimeStubs assumes EXCEPTION = 1 in the compiler-generated code. |
| 817 | enum Type { |
| 818 | RETRY_AFTER_GC = 0, |
| 819 | EXCEPTION = 1, // Returning this marker tells the real exception |
| 820 | // is in Top::pending_exception. |
| 821 | INTERNAL_ERROR = 2, |
| 822 | OUT_OF_MEMORY_EXCEPTION = 3 |
| 823 | }; |
| 824 | |
| 825 | inline Type type() const; |
| 826 | |
| 827 | // Returns the space that needs to be collected for RetryAfterGC failures. |
| 828 | inline AllocationSpace allocation_space() const; |
| 829 | |
| 830 | // Returns the number of bytes requested (up to the representable maximum) |
| 831 | // for RetryAfterGC failures. |
| 832 | inline int requested() const; |
| 833 | |
| 834 | inline bool IsInternalError() const; |
| 835 | inline bool IsOutOfMemoryException() const; |
| 836 | |
| 837 | static Failure* RetryAfterGC(int requested_bytes, AllocationSpace space); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 838 | static inline Failure* RetryAfterGC(int requested_bytes); // NEW_SPACE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 839 | static inline Failure* Exception(); |
| 840 | static inline Failure* InternalError(); |
| 841 | static inline Failure* OutOfMemoryException(); |
| 842 | // Casting. |
| 843 | static inline Failure* cast(Object* object); |
| 844 | |
| 845 | // Dispatched behavior. |
| 846 | void FailurePrint(); |
| 847 | void FailurePrint(StringStream* accumulator); |
| 848 | #ifdef DEBUG |
| 849 | void FailureVerify(); |
| 850 | #endif |
| 851 | |
| 852 | private: |
| 853 | inline int value() const; |
| 854 | static inline Failure* Construct(Type type, int value = 0); |
| 855 | |
| 856 | DISALLOW_IMPLICIT_CONSTRUCTORS(Failure); |
| 857 | }; |
| 858 | |
| 859 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 860 | // Heap objects typically have a map pointer in their first word. However, |
| 861 | // during GC other data (eg, mark bits, forwarding addresses) is sometimes |
| 862 | // encoded in the first word. The class MapWord is an abstraction of the |
| 863 | // value in a heap object's first word. |
| 864 | class MapWord BASE_EMBEDDED { |
| 865 | public: |
| 866 | // Normal state: the map word contains a map pointer. |
| 867 | |
| 868 | // Create a map word from a map pointer. |
| 869 | static inline MapWord FromMap(Map* map); |
| 870 | |
| 871 | // View this map word as a map pointer. |
| 872 | inline Map* ToMap(); |
| 873 | |
| 874 | |
| 875 | // Scavenge collection: the map word of live objects in the from space |
| 876 | // contains a forwarding address (a heap object pointer in the to space). |
| 877 | |
| 878 | // True if this map word is a forwarding address for a scavenge |
| 879 | // collection. Only valid during a scavenge collection (specifically, |
| 880 | // when all map words are heap object pointers, ie. not during a full GC). |
| 881 | inline bool IsForwardingAddress(); |
| 882 | |
| 883 | // Create a map word from a forwarding address. |
| 884 | static inline MapWord FromForwardingAddress(HeapObject* object); |
| 885 | |
| 886 | // View this map word as a forwarding address. |
| 887 | inline HeapObject* ToForwardingAddress(); |
| 888 | |
| 889 | |
| 890 | // Marking phase of full collection: the map word of live objects is |
| 891 | // marked, and may be marked as overflowed (eg, the object is live, its |
| 892 | // children have not been visited, and it does not fit in the marking |
| 893 | // stack). |
| 894 | |
| 895 | // True if this map word's mark bit is set. |
| 896 | inline bool IsMarked(); |
| 897 | |
| 898 | // Return this map word but with its mark bit set. |
| 899 | inline void SetMark(); |
| 900 | |
| 901 | // Return this map word but with its mark bit cleared. |
| 902 | inline void ClearMark(); |
| 903 | |
| 904 | // True if this map word's overflow bit is set. |
| 905 | inline bool IsOverflowed(); |
| 906 | |
| 907 | // Return this map word but with its overflow bit set. |
| 908 | inline void SetOverflow(); |
| 909 | |
| 910 | // Return this map word but with its overflow bit cleared. |
| 911 | inline void ClearOverflow(); |
| 912 | |
| 913 | |
| 914 | // Compacting phase of a full compacting collection: the map word of live |
| 915 | // objects contains an encoding of the original map address along with the |
| 916 | // forwarding address (represented as an offset from the first live object |
| 917 | // in the same page as the (old) object address). |
| 918 | |
| 919 | // Create a map word from a map address and a forwarding address offset. |
| 920 | static inline MapWord EncodeAddress(Address map_address, int offset); |
| 921 | |
| 922 | // Return the map address encoded in this map word. |
| 923 | inline Address DecodeMapAddress(MapSpace* map_space); |
| 924 | |
| 925 | // Return the forwarding offset encoded in this map word. |
| 926 | inline int DecodeOffset(); |
| 927 | |
| 928 | |
| 929 | // During serialization: the map word is used to hold an encoded |
| 930 | // address, and possibly a mark bit (set and cleared with SetMark |
| 931 | // and ClearMark). |
| 932 | |
| 933 | // Create a map word from an encoded address. |
| 934 | static inline MapWord FromEncodedAddress(Address address); |
| 935 | |
| 936 | inline Address ToEncodedAddress(); |
| 937 | |
| 938 | private: |
| 939 | // HeapObject calls the private constructor and directly reads the value. |
| 940 | friend class HeapObject; |
| 941 | |
| 942 | explicit MapWord(uintptr_t value) : value_(value) {} |
| 943 | |
| 944 | uintptr_t value_; |
| 945 | |
| 946 | // Bits used by the marking phase of the garbage collector. |
| 947 | // |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 948 | // 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] | 949 | // bits are tagged as '01' (kHeapObjectTag). We reuse the last two bits to |
| 950 | // mark an object as live and/or overflowed: |
| 951 | // last bit = 0, marked as alive |
| 952 | // second bit = 1, overflowed |
| 953 | // An object is only marked as overflowed when it is marked as live while |
| 954 | // the marking stack is overflowed. |
| 955 | static const int kMarkingBit = 0; // marking bit |
| 956 | static const int kMarkingMask = (1 << kMarkingBit); // marking mask |
| 957 | static const int kOverflowBit = 1; // overflow bit |
| 958 | static const int kOverflowMask = (1 << kOverflowBit); // overflow mask |
| 959 | |
| 960 | // Forwarding pointers and map pointer encoding |
| 961 | // 31 21 20 10 9 0 |
| 962 | // +-----------------+------------------+-----------------+ |
| 963 | // |forwarding offset|page offset of map|page index of map| |
| 964 | // +-----------------+------------------+-----------------+ |
| 965 | // 11 bits 11 bits 10 bits |
| 966 | static const int kMapPageIndexBits = 10; |
| 967 | static const int kMapPageOffsetBits = 11; |
| 968 | static const int kForwardingOffsetBits = 11; |
| 969 | |
| 970 | static const int kMapPageIndexShift = 0; |
| 971 | static const int kMapPageOffsetShift = |
| 972 | kMapPageIndexShift + kMapPageIndexBits; |
| 973 | static const int kForwardingOffsetShift = |
| 974 | kMapPageOffsetShift + kMapPageOffsetBits; |
| 975 | |
| 976 | // 0x000003FF |
| 977 | static const uint32_t kMapPageIndexMask = |
| 978 | (1 << kMapPageOffsetShift) - 1; |
| 979 | |
| 980 | // 0x001FFC00 |
| 981 | static const uint32_t kMapPageOffsetMask = |
| 982 | ((1 << kForwardingOffsetShift) - 1) & ~kMapPageIndexMask; |
| 983 | |
| 984 | // 0xFFE00000 |
| 985 | static const uint32_t kForwardingOffsetMask = |
| 986 | ~(kMapPageIndexMask | kMapPageOffsetMask); |
| 987 | }; |
| 988 | |
| 989 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 990 | // HeapObject is the superclass for all classes describing heap allocated |
| 991 | // objects. |
| 992 | class HeapObject: public Object { |
| 993 | public: |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 994 | // [map]: Contains a map which contains the object's reflective |
| 995 | // information. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 996 | inline Map* map(); |
| 997 | inline void set_map(Map* value); |
| 998 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 999 | // During garbage collection, the map word of a heap object does not |
| 1000 | // necessarily contain a map pointer. |
| 1001 | inline MapWord map_word(); |
| 1002 | inline void set_map_word(MapWord map_word); |
| 1003 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1004 | // Converts an address to a HeapObject pointer. |
| 1005 | static inline HeapObject* FromAddress(Address address); |
| 1006 | |
| 1007 | // Returns the address of this HeapObject. |
| 1008 | inline Address address(); |
| 1009 | |
| 1010 | // Iterates over pointers contained in the object (including the Map) |
| 1011 | void Iterate(ObjectVisitor* v); |
| 1012 | |
| 1013 | // Iterates over all pointers contained in the object except the |
| 1014 | // first map pointer. The object type is given in the first |
| 1015 | // parameter. This function does not access the map pointer in the |
| 1016 | // object, and so is safe to call while the map pointer is modified. |
| 1017 | void IterateBody(InstanceType type, int object_size, ObjectVisitor* v); |
| 1018 | |
| 1019 | // This method only applies to struct objects. Iterates over all the fields |
| 1020 | // of this struct. |
| 1021 | void IterateStructBody(int object_size, ObjectVisitor* v); |
| 1022 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1023 | // Returns the heap object's size in bytes |
| 1024 | inline int Size(); |
| 1025 | |
| 1026 | // Given a heap object's map pointer, returns the heap size in bytes |
| 1027 | // Useful when the map pointer field is used for other purposes. |
| 1028 | // GC internal. |
| 1029 | inline int SizeFromMap(Map* map); |
| 1030 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1031 | // Support for the marking heap objects during the marking phase of GC. |
| 1032 | // True if the object is marked live. |
| 1033 | inline bool IsMarked(); |
| 1034 | |
| 1035 | // Mutate this object's map pointer to indicate that the object is live. |
| 1036 | inline void SetMark(); |
| 1037 | |
| 1038 | // Mutate this object's map pointer to remove the indication that the |
| 1039 | // object is live (ie, partially restore the map pointer). |
| 1040 | inline void ClearMark(); |
| 1041 | |
| 1042 | // True if this object is marked as overflowed. Overflowed objects have |
| 1043 | // been reached and marked during marking of the heap, but their children |
| 1044 | // have not necessarily been marked and they have not been pushed on the |
| 1045 | // marking stack. |
| 1046 | inline bool IsOverflowed(); |
| 1047 | |
| 1048 | // Mutate this object's map pointer to indicate that the object is |
| 1049 | // overflowed. |
| 1050 | inline void SetOverflow(); |
| 1051 | |
| 1052 | // Mutate this object's map pointer to remove the indication that the |
| 1053 | // object is overflowed (ie, partially restore the map pointer). |
| 1054 | inline void ClearOverflow(); |
| 1055 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 1056 | // Returns the field at offset in obj, as a read/write Object* reference. |
| 1057 | // Does no checking, and is safe to use during GC, while maps are invalid. |
| 1058 | // Does not update remembered sets, so should only be assigned to |
| 1059 | // during marking GC. |
| 1060 | static inline Object** RawField(HeapObject* obj, int offset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1061 | |
| 1062 | // Casting. |
| 1063 | static inline HeapObject* cast(Object* obj); |
| 1064 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1065 | // Return the write barrier mode for this. |
| 1066 | inline WriteBarrierMode GetWriteBarrierMode(); |
| 1067 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1068 | // Dispatched behavior. |
| 1069 | void HeapObjectShortPrint(StringStream* accumulator); |
| 1070 | #ifdef DEBUG |
| 1071 | void HeapObjectPrint(); |
| 1072 | void HeapObjectVerify(); |
| 1073 | inline void VerifyObjectField(int offset); |
| 1074 | |
| 1075 | void PrintHeader(const char* id); |
| 1076 | |
| 1077 | // Verify a pointer is a valid HeapObject pointer that points to object |
| 1078 | // areas in the heap. |
| 1079 | static void VerifyHeapPointer(Object* p); |
| 1080 | #endif |
| 1081 | |
| 1082 | // Layout description. |
| 1083 | // First field in a heap object is map. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1084 | static const int kMapOffset = Object::kHeaderSize; |
| 1085 | static const int kHeaderSize = kMapOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1086 | |
| 1087 | protected: |
| 1088 | // helpers for calling an ObjectVisitor to iterate over pointers in the |
| 1089 | // half-open range [start, end) specified as integer offsets |
| 1090 | inline void IteratePointers(ObjectVisitor* v, int start, int end); |
| 1091 | // as above, for the single element at "offset" |
| 1092 | inline void IteratePointer(ObjectVisitor* v, int offset); |
| 1093 | |
| 1094 | // Computes the object size from the map. |
| 1095 | // Should only be used from SizeFromMap. |
| 1096 | int SlowSizeFromMap(Map* map); |
| 1097 | |
| 1098 | private: |
| 1099 | DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject); |
| 1100 | }; |
| 1101 | |
| 1102 | |
| 1103 | // The HeapNumber class describes heap allocated numbers that cannot be |
| 1104 | // represented in a Smi (small integer) |
| 1105 | class HeapNumber: public HeapObject { |
| 1106 | public: |
| 1107 | // [value]: number value. |
| 1108 | inline double value(); |
| 1109 | inline void set_value(double value); |
| 1110 | |
| 1111 | // Casting. |
| 1112 | static inline HeapNumber* cast(Object* obj); |
| 1113 | |
| 1114 | // Dispatched behavior. |
| 1115 | Object* HeapNumberToBoolean(); |
| 1116 | void HeapNumberPrint(); |
| 1117 | void HeapNumberPrint(StringStream* accumulator); |
| 1118 | #ifdef DEBUG |
| 1119 | void HeapNumberVerify(); |
| 1120 | #endif |
| 1121 | |
| 1122 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1123 | static const int kValueOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1124 | static const int kSize = kValueOffset + kDoubleSize; |
| 1125 | |
| 1126 | private: |
| 1127 | DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumber); |
| 1128 | }; |
| 1129 | |
| 1130 | |
| 1131 | // The JSObject describes real heap allocated JavaScript objects with |
| 1132 | // properties. |
| 1133 | // Note that the map of JSObject changes during execution to enable inline |
| 1134 | // caching. |
| 1135 | class JSObject: public HeapObject { |
| 1136 | public: |
| 1137 | // [properties]: Backing storage for properties. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1138 | // properties is a FixedArray in the fast case, and a Dictionary in the |
| 1139 | // slow case. |
| 1140 | DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1141 | inline void initialize_properties(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1142 | inline bool HasFastProperties(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1143 | inline Dictionary* property_dictionary(); // Gets slow properties. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1144 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1145 | // [elements]: The elements (properties with names that are integers). |
| 1146 | // elements is a FixedArray in the fast case, and a Dictionary in the slow |
| 1147 | // case. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1148 | DECL_ACCESSORS(elements, FixedArray) // Get and set fast elements. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1149 | inline void initialize_elements(); |
| 1150 | inline bool HasFastElements(); |
| 1151 | inline Dictionary* element_dictionary(); // Gets slow elements. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1152 | |
| 1153 | Object* SetProperty(String* key, |
| 1154 | Object* value, |
| 1155 | PropertyAttributes attributes); |
| 1156 | Object* SetProperty(LookupResult* result, |
| 1157 | String* key, |
| 1158 | Object* value, |
| 1159 | PropertyAttributes attributes); |
| 1160 | Object* SetPropertyWithFailedAccessCheck(LookupResult* result, |
| 1161 | String* name, |
| 1162 | Object* value); |
| 1163 | Object* SetPropertyWithCallback(Object* structure, |
| 1164 | String* name, |
| 1165 | Object* value, |
| 1166 | JSObject* holder); |
| 1167 | Object* SetPropertyWithInterceptor(String* name, |
| 1168 | Object* value, |
| 1169 | PropertyAttributes attributes); |
| 1170 | Object* SetPropertyPostInterceptor(String* name, |
| 1171 | Object* value, |
| 1172 | PropertyAttributes attributes); |
| 1173 | Object* IgnoreAttributesAndSetLocalProperty(String* key, |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1174 | Object* value, |
| 1175 | PropertyAttributes attributes); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1176 | |
| 1177 | // Sets a property that currently has lazy loading. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1178 | Object* SetLazyProperty(LookupResult* result, |
| 1179 | String* name, |
| 1180 | Object* value, |
| 1181 | PropertyAttributes attributes); |
| 1182 | |
| 1183 | // Returns the class name ([[Class]] property in the specification). |
| 1184 | String* class_name(); |
| 1185 | |
| 1186 | // Retrieve interceptors. |
| 1187 | InterceptorInfo* GetNamedInterceptor(); |
| 1188 | InterceptorInfo* GetIndexedInterceptor(); |
| 1189 | |
| 1190 | inline PropertyAttributes GetPropertyAttribute(String* name); |
| 1191 | PropertyAttributes GetPropertyAttributeWithReceiver(JSObject* receiver, |
| 1192 | String* name); |
| 1193 | PropertyAttributes GetLocalPropertyAttribute(String* name); |
| 1194 | |
| 1195 | Object* DefineAccessor(String* name, bool is_getter, JSFunction* fun, |
| 1196 | PropertyAttributes attributes); |
| 1197 | Object* LookupAccessor(String* name, bool is_getter); |
| 1198 | |
| 1199 | // Used from Object::GetProperty(). |
| 1200 | Object* GetPropertyWithFailedAccessCheck(Object* receiver, |
| 1201 | LookupResult* result, |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 1202 | String* name, |
| 1203 | PropertyAttributes* attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1204 | Object* GetPropertyWithInterceptor(JSObject* receiver, |
| 1205 | String* name, |
| 1206 | PropertyAttributes* attributes); |
| 1207 | Object* GetPropertyPostInterceptor(JSObject* receiver, |
| 1208 | String* name, |
| 1209 | PropertyAttributes* attributes); |
| 1210 | Object* GetLazyProperty(Object* receiver, |
| 1211 | LookupResult* result, |
| 1212 | String* name, |
| 1213 | PropertyAttributes* attributes); |
| 1214 | |
| 1215 | bool HasProperty(String* name) { |
| 1216 | return GetPropertyAttribute(name) != ABSENT; |
| 1217 | } |
| 1218 | |
| 1219 | bool HasLocalProperty(String* name) { |
| 1220 | return GetLocalPropertyAttribute(name) != ABSENT; |
| 1221 | } |
| 1222 | |
| 1223 | Object* DeleteProperty(String* name); |
| 1224 | Object* DeleteElement(uint32_t index); |
| 1225 | Object* DeleteLazyProperty(LookupResult* result, String* name); |
| 1226 | |
| 1227 | // Tests for the fast common case for property enumeration. |
| 1228 | bool IsSimpleEnum(); |
| 1229 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1230 | // Do we want to keep the elements in fast case when increasing the |
| 1231 | // capacity? |
| 1232 | bool ShouldConvertToSlowElements(int new_capacity); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1233 | // Returns true if the backing storage for the slow-case elements of |
| 1234 | // this object takes up nearly as much space as a fast-case backing |
| 1235 | // storage would. In that case the JSObject should have fast |
| 1236 | // elements. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1237 | bool ShouldConvertToFastElements(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1238 | |
| 1239 | // Return the object's prototype (might be Heap::null_value()). |
| 1240 | inline Object* GetPrototype(); |
| 1241 | |
| 1242 | // Tells whether the index'th element is present. |
| 1243 | inline bool HasElement(uint32_t index); |
| 1244 | bool HasElementWithReceiver(JSObject* receiver, uint32_t index); |
| 1245 | bool HasLocalElement(uint32_t index); |
| 1246 | |
| 1247 | bool HasElementWithInterceptor(JSObject* receiver, uint32_t index); |
| 1248 | bool HasElementPostInterceptor(JSObject* receiver, uint32_t index); |
| 1249 | |
| 1250 | Object* SetFastElement(uint32_t index, Object* value); |
| 1251 | |
| 1252 | // Set the index'th array element. |
| 1253 | // A Failure object is returned if GC is needed. |
| 1254 | Object* SetElement(uint32_t index, Object* value); |
| 1255 | |
| 1256 | // Returns the index'th element. |
| 1257 | // The undefined object if index is out of bounds. |
| 1258 | Object* GetElementWithReceiver(JSObject* receiver, uint32_t index); |
| 1259 | |
| 1260 | void SetFastElements(FixedArray* elements); |
| 1261 | Object* SetSlowElements(Object* length); |
| 1262 | |
| 1263 | // Lookup interceptors are used for handling properties controlled by host |
| 1264 | // objects. |
| 1265 | inline bool HasNamedInterceptor(); |
| 1266 | inline bool HasIndexedInterceptor(); |
| 1267 | |
| 1268 | // Support functions for v8 api (needed for correct interceptor behavior). |
| 1269 | bool HasRealNamedProperty(String* key); |
| 1270 | bool HasRealElementProperty(uint32_t index); |
| 1271 | bool HasRealNamedCallbackProperty(String* key); |
| 1272 | |
| 1273 | // Initializes the array to a certain length |
| 1274 | Object* SetElementsLength(Object* length); |
| 1275 | |
| 1276 | // Get the header size for a JSObject. Used to compute the index of |
| 1277 | // internal fields as well as the number of internal fields. |
| 1278 | inline int GetHeaderSize(); |
| 1279 | |
| 1280 | inline int GetInternalFieldCount(); |
| 1281 | inline Object* GetInternalField(int index); |
| 1282 | inline void SetInternalField(int index, Object* value); |
| 1283 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1284 | // Lookup a property. If found, the result is valid and has |
| 1285 | // detailed information. |
| 1286 | void LocalLookup(String* name, LookupResult* result); |
| 1287 | void Lookup(String* name, LookupResult* result); |
| 1288 | |
| 1289 | // The following lookup functions skip interceptors. |
| 1290 | void LocalLookupRealNamedProperty(String* name, LookupResult* result); |
| 1291 | void LookupRealNamedProperty(String* name, LookupResult* result); |
| 1292 | void LookupRealNamedPropertyInPrototypes(String* name, LookupResult* result); |
| 1293 | void LookupCallbackSetterInPrototypes(String* name, LookupResult* result); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 1294 | void LookupCallback(String* name, LookupResult* result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1295 | |
| 1296 | // Returns the number of properties on this object filtering out properties |
| 1297 | // with the specified attributes (ignoring interceptors). |
| 1298 | int NumberOfLocalProperties(PropertyAttributes filter); |
| 1299 | // Returns the number of enumerable properties (ignoring interceptors). |
| 1300 | int NumberOfEnumProperties(); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 1301 | // Fill in details for properties into storage starting at the specified |
| 1302 | // index. |
| 1303 | void GetLocalPropertyNames(FixedArray* storage, int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1304 | |
| 1305 | // Returns the number of properties on this object filtering out properties |
| 1306 | // with the specified attributes (ignoring interceptors). |
| 1307 | int NumberOfLocalElements(PropertyAttributes filter); |
| 1308 | // Returns the number of enumerable elements (ignoring interceptors). |
| 1309 | int NumberOfEnumElements(); |
| 1310 | // Returns the number of elements on this object filtering out elements |
| 1311 | // with the specified attributes (ignoring interceptors). |
| 1312 | int GetLocalElementKeys(FixedArray* storage, PropertyAttributes filter); |
| 1313 | // Count and fill in the enumerable elements into storage. |
| 1314 | // (storage->length() == NumberOfEnumElements()). |
| 1315 | // If storage is NULL, will count the elements without adding |
| 1316 | // them to any storage. |
| 1317 | // Returns the number of enumerable elements. |
| 1318 | int GetEnumElementKeys(FixedArray* storage); |
| 1319 | |
| 1320 | // Add a property to a fast-case object using a map transition to |
| 1321 | // new_map. |
| 1322 | Object* AddFastPropertyUsingMap(Map* new_map, |
| 1323 | String* name, |
| 1324 | Object* value); |
| 1325 | |
| 1326 | // 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] | 1327 | // This leaves a CONSTANT_TRANSITION in the old map, and |
| 1328 | // if it is called on a second object with this map, a |
| 1329 | // normal property is added instead, with a map transition. |
| 1330 | // This avoids the creation of many maps with the same constant |
| 1331 | // function, all orphaned. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1332 | Object* AddConstantFunctionProperty(String* name, |
| 1333 | JSFunction* function, |
| 1334 | PropertyAttributes attributes); |
| 1335 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1336 | Object* ReplaceSlowProperty(String* name, |
| 1337 | Object* value, |
| 1338 | PropertyAttributes attributes); |
| 1339 | |
| 1340 | // Converts a descriptor of any other type to a real field, |
| 1341 | // backed by the properties array. Descriptors of visible |
| 1342 | // types, such as CONSTANT_FUNCTION, keep their enumeration order. |
| 1343 | // Converts the descriptor on the original object's map to a |
| 1344 | // map transition, and the the new field is on the object's new map. |
| 1345 | Object* ConvertDescriptorToFieldAndMapTransition( |
| 1346 | String* name, |
| 1347 | Object* new_value, |
| 1348 | PropertyAttributes attributes); |
| 1349 | |
| 1350 | // Converts a descriptor of any other type to a real field, |
| 1351 | // backed by the properties array. Descriptors of visible |
| 1352 | // types, such as CONSTANT_FUNCTION, keep their enumeration order. |
| 1353 | Object* ConvertDescriptorToField(String* name, |
| 1354 | Object* new_value, |
| 1355 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1356 | |
| 1357 | // Add a property to a fast-case object. |
| 1358 | Object* AddFastProperty(String* name, |
| 1359 | Object* value, |
| 1360 | PropertyAttributes attributes); |
| 1361 | |
| 1362 | // Add a property to a slow-case object. |
| 1363 | Object* AddSlowProperty(String* name, |
| 1364 | Object* value, |
| 1365 | PropertyAttributes attributes); |
| 1366 | |
| 1367 | // Add a property to an object. |
| 1368 | Object* AddProperty(String* name, |
| 1369 | Object* value, |
| 1370 | PropertyAttributes attributes); |
| 1371 | |
| 1372 | // Convert the object to use the canonical dictionary |
| 1373 | // representation. |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1374 | Object* NormalizeProperties(PropertyNormalizationMode mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1375 | Object* NormalizeElements(); |
| 1376 | |
| 1377 | // Transform slow named properties to fast variants. |
| 1378 | // Returns failure if allocation failed. |
| 1379 | Object* TransformToFastProperties(int unused_property_fields); |
| 1380 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1381 | // Access fast-case object properties at index. |
| 1382 | inline Object* FastPropertyAt(int index); |
| 1383 | inline Object* FastPropertyAtPut(int index, Object* value); |
| 1384 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1385 | // Access to set in object properties. |
| 1386 | inline Object* InObjectPropertyAtPut(int index, |
| 1387 | Object* value, |
| 1388 | WriteBarrierMode mode |
| 1389 | = UPDATE_WRITE_BARRIER); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1390 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1391 | // initializes the body after properties slot, properties slot is |
| 1392 | // initialized by set_properties |
| 1393 | // Note: this call does not update write barrier, it is caller's |
| 1394 | // reponsibility to ensure that *v* can be collected without WB here. |
| 1395 | inline void InitializeBody(int object_size); |
| 1396 | |
| 1397 | // Check whether this object references another object |
| 1398 | bool ReferencesObject(Object* obj); |
| 1399 | |
| 1400 | // Casting. |
| 1401 | static inline JSObject* cast(Object* obj); |
| 1402 | |
| 1403 | // Dispatched behavior. |
| 1404 | void JSObjectIterateBody(int object_size, ObjectVisitor* v); |
| 1405 | void JSObjectShortPrint(StringStream* accumulator); |
| 1406 | #ifdef DEBUG |
| 1407 | void JSObjectPrint(); |
| 1408 | void JSObjectVerify(); |
| 1409 | void PrintProperties(); |
| 1410 | void PrintElements(); |
| 1411 | |
| 1412 | // Structure for collecting spill information about JSObjects. |
| 1413 | class SpillInformation { |
| 1414 | public: |
| 1415 | void Clear(); |
| 1416 | void Print(); |
| 1417 | int number_of_objects_; |
| 1418 | int number_of_objects_with_fast_properties_; |
| 1419 | int number_of_objects_with_fast_elements_; |
| 1420 | int number_of_fast_used_fields_; |
| 1421 | int number_of_fast_unused_fields_; |
| 1422 | int number_of_slow_used_properties_; |
| 1423 | int number_of_slow_unused_properties_; |
| 1424 | int number_of_fast_used_elements_; |
| 1425 | int number_of_fast_unused_elements_; |
| 1426 | int number_of_slow_used_elements_; |
| 1427 | int number_of_slow_unused_elements_; |
| 1428 | }; |
| 1429 | |
| 1430 | void IncrementSpillStatistics(SpillInformation* info); |
| 1431 | #endif |
| 1432 | Object* SlowReverseLookup(Object* value); |
| 1433 | |
| 1434 | static const uint32_t kMaxGap = 1024; |
| 1435 | static const int kMaxFastElementsLength = 5000; |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1436 | static const int kMaxFastProperties = 8; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1437 | static const int kMaxInstanceSize = 255 * kPointerSize; |
| 1438 | // When extending the backing storage for property values, we increase |
| 1439 | // its size by more than the 1 entry necessary, so sequentially adding fields |
| 1440 | // to the same object requires fewer allocations and copies. |
| 1441 | static const int kFieldsAdded = 3; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1442 | |
| 1443 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1444 | static const int kPropertiesOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1445 | static const int kElementsOffset = kPropertiesOffset + kPointerSize; |
| 1446 | static const int kHeaderSize = kElementsOffset + kPointerSize; |
| 1447 | |
| 1448 | Object* GetElementWithInterceptor(JSObject* receiver, uint32_t index); |
| 1449 | |
| 1450 | private: |
| 1451 | Object* SetElementWithInterceptor(uint32_t index, Object* value); |
| 1452 | Object* SetElementPostInterceptor(uint32_t index, Object* value); |
| 1453 | |
| 1454 | Object* GetElementPostInterceptor(JSObject* receiver, uint32_t index); |
| 1455 | |
| 1456 | Object* DeletePropertyPostInterceptor(String* name); |
| 1457 | Object* DeletePropertyWithInterceptor(String* name); |
| 1458 | |
| 1459 | Object* DeleteElementPostInterceptor(uint32_t index); |
| 1460 | Object* DeleteElementWithInterceptor(uint32_t index); |
| 1461 | |
| 1462 | PropertyAttributes GetPropertyAttributePostInterceptor(JSObject* receiver, |
| 1463 | String* name, |
| 1464 | bool continue_search); |
| 1465 | PropertyAttributes GetPropertyAttributeWithInterceptor(JSObject* receiver, |
| 1466 | String* name, |
| 1467 | bool continue_search); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 1468 | PropertyAttributes GetPropertyAttributeWithFailedAccessCheck( |
| 1469 | Object* receiver, |
| 1470 | LookupResult* result, |
| 1471 | String* name, |
| 1472 | bool continue_search); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1473 | PropertyAttributes GetPropertyAttribute(JSObject* receiver, |
| 1474 | LookupResult* result, |
| 1475 | String* name, |
| 1476 | bool continue_search); |
| 1477 | |
| 1478 | // Returns true if most of the elements backing storage is used. |
| 1479 | bool HasDenseElements(); |
| 1480 | |
| 1481 | Object* DefineGetterSetter(String* name, PropertyAttributes attributes); |
| 1482 | |
| 1483 | void LookupInDescriptor(String* name, LookupResult* result); |
| 1484 | |
| 1485 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject); |
| 1486 | }; |
| 1487 | |
| 1488 | |
| 1489 | // Abstract super class arrays. It provides length behavior. |
| 1490 | class Array: public HeapObject { |
| 1491 | public: |
| 1492 | // [length]: length of the array. |
| 1493 | inline int length(); |
| 1494 | inline void set_length(int value); |
| 1495 | |
| 1496 | // Convert an object to an array index. |
| 1497 | // Returns true if the conversion succeeded. |
| 1498 | static inline bool IndexFromObject(Object* object, uint32_t* index); |
| 1499 | |
| 1500 | // Layout descriptor. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1501 | static const int kLengthOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1502 | static const int kHeaderSize = kLengthOffset + kIntSize; |
| 1503 | |
| 1504 | private: |
| 1505 | DISALLOW_IMPLICIT_CONSTRUCTORS(Array); |
| 1506 | }; |
| 1507 | |
| 1508 | |
| 1509 | // FixedArray describes fixed sized arrays where element |
| 1510 | // type is Object*. |
| 1511 | |
| 1512 | class FixedArray: public Array { |
| 1513 | public: |
| 1514 | |
| 1515 | // Setter and getter for elements. |
| 1516 | inline Object* get(int index); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1517 | // Setter that uses write barrier. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1518 | inline void set(int index, Object* value); |
| 1519 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1520 | // Setter that doesn't need write barrier). |
| 1521 | inline void set(int index, Smi* value); |
| 1522 | // Setter with explicit barrier mode. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1523 | inline void set(int index, Object* value, WriteBarrierMode mode); |
| 1524 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1525 | // Setters for frequently used oddballs located in old space. |
| 1526 | inline void set_undefined(int index); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1527 | inline void set_null(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1528 | inline void set_the_hole(int index); |
| 1529 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1530 | // Copy operations. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1531 | inline Object* Copy(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1532 | Object* CopySize(int new_length); |
| 1533 | |
| 1534 | // Add the elements of a JSArray to this FixedArray. |
| 1535 | Object* AddKeysFromJSArray(JSArray* array); |
| 1536 | |
| 1537 | // Compute the union of this and other. |
| 1538 | Object* UnionOfKeys(FixedArray* other); |
| 1539 | |
| 1540 | // Copy a sub array from the receiver to dest. |
| 1541 | void CopyTo(int pos, FixedArray* dest, int dest_pos, int len); |
| 1542 | |
| 1543 | // Garbage collection support. |
| 1544 | static int SizeFor(int length) { return kHeaderSize + length * kPointerSize; } |
| 1545 | |
| 1546 | // Casting. |
| 1547 | static inline FixedArray* cast(Object* obj); |
| 1548 | |
| 1549 | // Dispatched behavior. |
| 1550 | int FixedArraySize() { return SizeFor(length()); } |
| 1551 | void FixedArrayIterateBody(ObjectVisitor* v); |
| 1552 | #ifdef DEBUG |
| 1553 | void FixedArrayPrint(); |
| 1554 | void FixedArrayVerify(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1555 | // Checks if two FixedArrays have identical contents. |
| 1556 | bool IsEqualTo(FixedArray* other); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1557 | #endif |
| 1558 | |
| 1559 | // Swap two elements. |
| 1560 | void Swap(int i, int j); |
| 1561 | |
| 1562 | // Sort this array and the smis as pairs wrt. the smis. |
| 1563 | void SortPairs(FixedArray* smis); |
| 1564 | |
| 1565 | protected: |
| 1566 | // Set operation on FixedArray without using write barriers. |
| 1567 | static inline void fast_set(FixedArray* array, int index, Object* value); |
| 1568 | |
| 1569 | private: |
| 1570 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedArray); |
| 1571 | }; |
| 1572 | |
| 1573 | |
| 1574 | // DescriptorArrays are fixed arrays used to hold instance descriptors. |
| 1575 | // The format of the these objects is: |
| 1576 | // [0]: point to a fixed array with (value, detail) pairs. |
| 1577 | // [1]: next enumeration index (Smi), or pointer to small fixed array: |
| 1578 | // [0]: next enumeration index (Smi) |
| 1579 | // [1]: pointer to fixed array with enum cache |
| 1580 | // [2]: first key |
| 1581 | // [length() - 1]: last key |
| 1582 | // |
| 1583 | class DescriptorArray: public FixedArray { |
| 1584 | public: |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1585 | // Is this the singleton empty_descriptor_array? |
| 1586 | inline bool IsEmpty(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1587 | // Returns the number of descriptors in the array. |
| 1588 | int number_of_descriptors() { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1589 | return IsEmpty() ? 0 : length() - kFirstIndex; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1590 | } |
| 1591 | |
| 1592 | int NextEnumerationIndex() { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1593 | if (IsEmpty()) return PropertyDetails::kInitialIndex; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1594 | Object* obj = get(kEnumerationIndexIndex); |
| 1595 | if (obj->IsSmi()) { |
| 1596 | return Smi::cast(obj)->value(); |
| 1597 | } else { |
| 1598 | Object* index = FixedArray::cast(obj)->get(kEnumCacheBridgeEnumIndex); |
| 1599 | return Smi::cast(index)->value(); |
| 1600 | } |
| 1601 | } |
| 1602 | |
| 1603 | // Set next enumeration index and flush any enum cache. |
| 1604 | void SetNextEnumerationIndex(int value) { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1605 | if (!IsEmpty()) { |
| 1606 | fast_set(this, kEnumerationIndexIndex, Smi::FromInt(value)); |
| 1607 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1608 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1609 | bool HasEnumCache() { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1610 | return !IsEmpty() && !get(kEnumerationIndexIndex)->IsSmi(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1611 | } |
| 1612 | |
| 1613 | Object* GetEnumCache() { |
| 1614 | ASSERT(HasEnumCache()); |
| 1615 | FixedArray* bridge = FixedArray::cast(get(kEnumerationIndexIndex)); |
| 1616 | return bridge->get(kEnumCacheBridgeCacheIndex); |
| 1617 | } |
| 1618 | |
| 1619 | // Initialize or change the enum cache, |
| 1620 | // using the supplied storage for the small "bridge". |
| 1621 | void SetEnumCache(FixedArray* bridge_storage, FixedArray* new_cache); |
| 1622 | |
| 1623 | // Accessors for fetching instance descriptor at descriptor number.. |
| 1624 | inline String* GetKey(int descriptor_number); |
| 1625 | inline Object* GetValue(int descriptor_number); |
| 1626 | inline Smi* GetDetails(int descriptor_number); |
| 1627 | |
| 1628 | // Accessor for complete descriptor. |
| 1629 | inline void Get(int descriptor_number, Descriptor* desc); |
| 1630 | inline void Set(int descriptor_number, Descriptor* desc); |
| 1631 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1632 | // 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] | 1633 | // remove map transitions. If the descriptor is already present, it is |
| 1634 | // replaced. If a replaced descriptor is a real property (not a transition |
| 1635 | // or null), its enumeration index is kept as is. |
| 1636 | // If adding a real property, map transitions must be removed. If adding |
| 1637 | // a transition, they must not be removed. All null descriptors are removed. |
| 1638 | Object* CopyInsert(Descriptor* descriptor, TransitionFlag transition_flag); |
| 1639 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1640 | // Remove all transitions. Return a copy of the array with all transitions |
| 1641 | // removed, or a Failure object if the new array could not be allocated. |
| 1642 | Object* RemoveTransitions(); |
| 1643 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1644 | // Sort the instance descriptors by the hash codes of their keys. |
| 1645 | void Sort(); |
| 1646 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1647 | // Search the instance descriptors for given name. |
| 1648 | inline int Search(String* name); |
| 1649 | |
| 1650 | // Tells whether the name is present int the array. |
| 1651 | bool Contains(String* name) { return kNotFound != Search(name); } |
| 1652 | |
| 1653 | // Perform a binary search in the instance descriptors represented |
| 1654 | // by this fixed array. low and high are descriptor indices. If there |
| 1655 | // are three instance descriptors in this array it should be called |
| 1656 | // with low=0 and high=2. |
| 1657 | int BinarySearch(String* name, int low, int high); |
| 1658 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1659 | // Perform a linear search in the instance descriptors represented |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1660 | // 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] | 1661 | // valid. Does not require the descriptors to be sorted. |
| 1662 | int LinearSearch(String* name, int len); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1663 | |
| 1664 | // Allocates a DescriptorArray, but returns the singleton |
| 1665 | // empty descriptor array object if number_of_descriptors is 0. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1666 | static Object* Allocate(int number_of_descriptors); |
| 1667 | |
| 1668 | // Casting. |
| 1669 | static inline DescriptorArray* cast(Object* obj); |
| 1670 | |
| 1671 | // Constant for denoting key was not found. |
| 1672 | static const int kNotFound = -1; |
| 1673 | |
| 1674 | static const int kContentArrayIndex = 0; |
| 1675 | static const int kEnumerationIndexIndex = 1; |
| 1676 | static const int kFirstIndex = 2; |
| 1677 | |
| 1678 | // The length of the "bridge" to the enum cache. |
| 1679 | static const int kEnumCacheBridgeLength = 2; |
| 1680 | static const int kEnumCacheBridgeEnumIndex = 0; |
| 1681 | static const int kEnumCacheBridgeCacheIndex = 1; |
| 1682 | |
| 1683 | // Layout description. |
| 1684 | static const int kContentArrayOffset = FixedArray::kHeaderSize; |
| 1685 | static const int kEnumerationIndexOffset = kContentArrayOffset + kPointerSize; |
| 1686 | static const int kFirstOffset = kEnumerationIndexOffset + kPointerSize; |
| 1687 | |
| 1688 | // Layout description for the bridge array. |
| 1689 | static const int kEnumCacheBridgeEnumOffset = FixedArray::kHeaderSize; |
| 1690 | static const int kEnumCacheBridgeCacheOffset = |
| 1691 | kEnumCacheBridgeEnumOffset + kPointerSize; |
| 1692 | |
| 1693 | #ifdef DEBUG |
| 1694 | // Print all the descriptors. |
| 1695 | void PrintDescriptors(); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1696 | |
| 1697 | // Is the descriptor array sorted and without duplicates? |
| 1698 | bool IsSortedNoDuplicates(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1699 | |
| 1700 | // Are two DescriptorArrays equal? |
| 1701 | bool IsEqualTo(DescriptorArray* other); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1702 | #endif |
| 1703 | |
| 1704 | // The maximum number of descriptors we want in a descriptor array (should |
| 1705 | // fit in a page). |
| 1706 | static const int kMaxNumberOfDescriptors = 1024 + 512; |
| 1707 | |
| 1708 | private: |
| 1709 | // Conversion from descriptor number to array indices. |
| 1710 | static int ToKeyIndex(int descriptor_number) { |
| 1711 | return descriptor_number+kFirstIndex; |
| 1712 | } |
| 1713 | static int ToValueIndex(int descriptor_number) { |
| 1714 | return descriptor_number << 1; |
| 1715 | } |
| 1716 | static int ToDetailsIndex(int descriptor_number) { |
| 1717 | return( descriptor_number << 1) + 1; |
| 1718 | } |
| 1719 | |
| 1720 | // Swap operation on FixedArray without using write barriers. |
| 1721 | static inline void fast_swap(FixedArray* array, int first, int second); |
| 1722 | |
| 1723 | // Swap descriptor first and second. |
| 1724 | inline void Swap(int first, int second); |
| 1725 | |
| 1726 | FixedArray* GetContentArray() { |
| 1727 | return FixedArray::cast(get(kContentArrayIndex)); |
| 1728 | } |
| 1729 | DISALLOW_IMPLICIT_CONSTRUCTORS(DescriptorArray); |
| 1730 | }; |
| 1731 | |
| 1732 | |
| 1733 | // HashTable is a subclass of FixedArray that implements a hash table |
| 1734 | // that uses open addressing and quadratic probing. |
| 1735 | // |
| 1736 | // In order for the quadratic probing to work, elements that have not |
| 1737 | // yet been used and elements that have been deleted are |
| 1738 | // distinguished. Probing continues when deleted elements are |
| 1739 | // encountered and stops when unused elements are encountered. |
| 1740 | // |
| 1741 | // - Elements with key == undefined have not been used yet. |
| 1742 | // - Elements with key == null have been deleted. |
| 1743 | // |
| 1744 | // The hash table class is parameterized with a prefix size and with |
| 1745 | // the size, including the key size, of the elements held in the hash |
| 1746 | // table. The prefix size indicates an amount of memory in the |
| 1747 | // beginning of the backing storage that can be used for non-element |
| 1748 | // information by subclasses. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1749 | |
| 1750 | // HashTableKey is an abstract superclass keys. |
| 1751 | class HashTableKey { |
| 1752 | public: |
| 1753 | // Returns whether the other object matches this key. |
| 1754 | virtual bool IsMatch(Object* other) = 0; |
| 1755 | typedef uint32_t (*HashFunction)(Object* obj); |
| 1756 | // Returns the hash function used for this key. |
| 1757 | virtual HashFunction GetHashFunction() = 0; |
| 1758 | // Returns the hash value for this key. |
| 1759 | virtual uint32_t Hash() = 0; |
| 1760 | // Returns the key object for storing into the dictionary. |
| 1761 | // If allocations fails a failure object is returned. |
| 1762 | virtual Object* GetObject() = 0; |
| 1763 | virtual bool IsStringKey() = 0; |
| 1764 | // Required. |
| 1765 | virtual ~HashTableKey() {} |
| 1766 | }; |
| 1767 | |
| 1768 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1769 | template<int prefix_size, int element_size> |
| 1770 | class HashTable: public FixedArray { |
| 1771 | public: |
| 1772 | // Returns the number of elements in the dictionary. |
| 1773 | int NumberOfElements() { |
| 1774 | return Smi::cast(get(kNumberOfElementsIndex))->value(); |
| 1775 | } |
| 1776 | |
| 1777 | // Returns the capacity of the dictionary. |
| 1778 | int Capacity() { |
| 1779 | return Smi::cast(get(kCapacityIndex))->value(); |
| 1780 | } |
| 1781 | |
| 1782 | // ElementAdded should be called whenever an element is added to a |
| 1783 | // dictionary. |
| 1784 | void ElementAdded() { SetNumberOfElements(NumberOfElements() + 1); } |
| 1785 | |
| 1786 | // ElementRemoved should be called whenever an element is removed from |
| 1787 | // a dictionary. |
| 1788 | void ElementRemoved() { SetNumberOfElements(NumberOfElements() - 1); } |
| 1789 | void ElementsRemoved(int n) { SetNumberOfElements(NumberOfElements() - n); } |
| 1790 | |
| 1791 | // Returns a new array for dictionary usage. Might return Failure. |
| 1792 | static Object* Allocate(int at_least_space_for); |
| 1793 | |
| 1794 | // Returns the key at entry. |
| 1795 | Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } |
| 1796 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1797 | // 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] | 1798 | // as keys and can be used to indicate missing or deleted elements. |
| 1799 | bool IsKey(Object* k) { |
| 1800 | return !k->IsNull() && !k->IsUndefined(); |
| 1801 | } |
| 1802 | |
| 1803 | // Garbage collection support. |
| 1804 | void IteratePrefix(ObjectVisitor* visitor); |
| 1805 | void IterateElements(ObjectVisitor* visitor); |
| 1806 | |
| 1807 | // Casting. |
| 1808 | static inline HashTable* cast(Object* obj); |
| 1809 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1810 | // Compute the probe offset (quadratic probing). |
| 1811 | INLINE(static uint32_t GetProbeOffset(uint32_t n)) { |
| 1812 | return (n + n * n) >> 1; |
| 1813 | } |
| 1814 | |
| 1815 | static const int kNumberOfElementsIndex = 0; |
| 1816 | static const int kCapacityIndex = 1; |
| 1817 | static const int kPrefixStartIndex = 2; |
| 1818 | static const int kElementsStartIndex = kPrefixStartIndex + prefix_size; |
| 1819 | static const int kElementSize = element_size; |
| 1820 | static const int kElementsStartOffset = |
| 1821 | kHeaderSize + kElementsStartIndex * kPointerSize; |
| 1822 | |
| 1823 | protected: |
| 1824 | // Find entry for key otherwise return -1. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1825 | int FindEntry(HashTableKey* key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1826 | |
| 1827 | // Find the entry at which to insert element with the given key that |
| 1828 | // has the given hash value. |
| 1829 | uint32_t FindInsertionEntry(Object* key, uint32_t hash); |
| 1830 | |
| 1831 | // Returns the index for an entry (of the key) |
| 1832 | static inline int EntryToIndex(int entry) { |
| 1833 | return (entry * kElementSize) + kElementsStartIndex; |
| 1834 | } |
| 1835 | |
| 1836 | // Update the number of elements in the dictionary. |
| 1837 | void SetNumberOfElements(int nof) { |
| 1838 | fast_set(this, kNumberOfElementsIndex, Smi::FromInt(nof)); |
| 1839 | } |
| 1840 | |
| 1841 | // Sets the capacity of the hash table. |
| 1842 | void SetCapacity(int capacity) { |
| 1843 | // To scale a computed hash code to fit within the hash table, we |
| 1844 | // use bit-wise AND with a mask, so the capacity must be positive |
| 1845 | // and non-zero. |
| 1846 | ASSERT(capacity > 0); |
| 1847 | fast_set(this, kCapacityIndex, Smi::FromInt(capacity)); |
| 1848 | } |
| 1849 | |
| 1850 | |
| 1851 | // Returns probe entry. |
| 1852 | static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size) { |
| 1853 | ASSERT(IsPowerOf2(size)); |
| 1854 | return (hash + GetProbeOffset(number)) & (size - 1); |
| 1855 | } |
| 1856 | |
| 1857 | // Ensure enough space for n additional elements. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1858 | Object* EnsureCapacity(int n, HashTableKey* key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1859 | }; |
| 1860 | |
| 1861 | |
| 1862 | // SymbolTable. |
| 1863 | // |
| 1864 | // No special elements in the prefix and the element size is 1 |
| 1865 | // because only the symbol itself (the key) needs to be stored. |
| 1866 | class SymbolTable: public HashTable<0, 1> { |
| 1867 | public: |
| 1868 | // Find symbol in the symbol table. If it is not there yet, it is |
| 1869 | // added. The return value is the symbol table which might have |
| 1870 | // been enlarged. If the return value is not a failure, the symbol |
| 1871 | // pointer *s is set to the symbol found. |
| 1872 | Object* LookupSymbol(Vector<const char> str, Object** s); |
| 1873 | Object* LookupString(String* key, Object** s); |
| 1874 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1875 | // Looks up a symbol that is equal to the given string and returns |
| 1876 | // true if it is found, assigning the symbol to the given output |
| 1877 | // parameter. |
| 1878 | bool LookupSymbolIfExists(String* str, String** symbol); |
| 1879 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1880 | // Casting. |
| 1881 | static inline SymbolTable* cast(Object* obj); |
| 1882 | |
| 1883 | private: |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1884 | Object* LookupKey(HashTableKey* key, Object** s); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1885 | |
| 1886 | DISALLOW_IMPLICIT_CONSTRUCTORS(SymbolTable); |
| 1887 | }; |
| 1888 | |
| 1889 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1890 | // MapCache. |
| 1891 | // |
| 1892 | // Maps keys that are a fixed array of symbols to a map. |
| 1893 | // Used for canonicalize maps for object literals. |
| 1894 | class MapCache: public HashTable<0, 2> { |
| 1895 | public: |
| 1896 | // Find cached value for a string key, otherwise return null. |
| 1897 | Object* Lookup(FixedArray* key); |
| 1898 | Object* Put(FixedArray* key, Map* value); |
| 1899 | static inline MapCache* cast(Object* obj); |
| 1900 | |
| 1901 | private: |
| 1902 | DISALLOW_IMPLICIT_CONSTRUCTORS(MapCache); |
| 1903 | }; |
| 1904 | |
| 1905 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1906 | // LookupCache. |
| 1907 | // |
| 1908 | // Maps a key consisting of a map and a name to an index within a |
| 1909 | // fast-case properties array. |
| 1910 | // |
| 1911 | // LookupCaches are used to avoid repeatedly searching instance |
| 1912 | // descriptors. |
| 1913 | class LookupCache: public HashTable<0, 2> { |
| 1914 | public: |
| 1915 | int Lookup(Map* map, String* name); |
| 1916 | Object* Put(Map* map, String* name, int offset); |
| 1917 | static inline LookupCache* cast(Object* obj); |
| 1918 | |
| 1919 | // Constant returned by Lookup when the key was not found. |
| 1920 | static const int kNotFound = -1; |
| 1921 | |
| 1922 | private: |
| 1923 | DISALLOW_IMPLICIT_CONSTRUCTORS(LookupCache); |
| 1924 | }; |
| 1925 | |
| 1926 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1927 | // Dictionary for keeping properties and elements in slow case. |
| 1928 | // |
| 1929 | // One element in the prefix is used for storing non-element |
| 1930 | // information about the dictionary. |
| 1931 | // |
| 1932 | // The rest of the array embeds triples of (key, value, details). |
| 1933 | // if key == undefined the triple is empty. |
| 1934 | // if key == null the triple has been deleted. |
| 1935 | // otherwise key contains the name of a property. |
| 1936 | class DictionaryBase: public HashTable<2, 3> {}; |
| 1937 | |
| 1938 | class Dictionary: public DictionaryBase { |
| 1939 | public: |
| 1940 | // Returns the value at entry. |
| 1941 | Object* ValueAt(int entry) { return get(EntryToIndex(entry)+1); } |
| 1942 | |
| 1943 | // Set the value for entry. |
| 1944 | void ValueAtPut(int entry, Object* value) { |
| 1945 | set(EntryToIndex(entry)+1, value); |
| 1946 | } |
| 1947 | |
| 1948 | // Returns the property details for the property at entry. |
| 1949 | PropertyDetails DetailsAt(int entry) { |
| 1950 | return PropertyDetails(Smi::cast(get(EntryToIndex(entry) + 2))); |
| 1951 | } |
| 1952 | |
| 1953 | // Set the details for entry. |
| 1954 | void DetailsAtPut(int entry, PropertyDetails value) { |
| 1955 | set(EntryToIndex(entry) + 2, value.AsSmi()); |
| 1956 | } |
| 1957 | |
| 1958 | // Remove all entries were key is a number and (from <= key && key < to). |
| 1959 | void RemoveNumberEntries(uint32_t from, uint32_t to); |
| 1960 | |
| 1961 | // Sorting support |
| 1962 | Object* RemoveHoles(); |
| 1963 | void CopyValuesTo(FixedArray* elements); |
| 1964 | |
| 1965 | // Casting. |
| 1966 | static inline Dictionary* cast(Object* obj); |
| 1967 | |
| 1968 | // Find entry for string key otherwise return -1. |
| 1969 | int FindStringEntry(String* key); |
| 1970 | |
| 1971 | // Find entry for number key otherwise return -1. |
| 1972 | int FindNumberEntry(uint32_t index); |
| 1973 | |
| 1974 | // Delete a property from the dictionary. |
| 1975 | Object* DeleteProperty(int entry); |
| 1976 | |
| 1977 | // Type specific at put (default NONE attributes is used when adding). |
| 1978 | Object* AtStringPut(String* key, Object* value); |
| 1979 | Object* AtNumberPut(uint32_t key, Object* value); |
| 1980 | |
| 1981 | Object* AddStringEntry(String* key, Object* value, PropertyDetails details); |
| 1982 | Object* AddNumberEntry(uint32_t key, Object* value, PropertyDetails details); |
| 1983 | |
| 1984 | // Set and existing string entry or add a new one if needed. |
| 1985 | Object* SetOrAddStringEntry(String* key, |
| 1986 | Object* value, |
| 1987 | PropertyDetails details); |
| 1988 | |
| 1989 | // Returns the number of elements in the dictionary filtering out properties |
| 1990 | // with the specified attributes. |
| 1991 | int NumberOfElementsFilterAttributes(PropertyAttributes filter); |
| 1992 | |
| 1993 | // Returns the number of enumerable elements in the dictionary. |
| 1994 | int NumberOfEnumElements(); |
| 1995 | |
| 1996 | // Copies keys to preallocated fixed array. |
| 1997 | void CopyKeysTo(FixedArray* storage, PropertyAttributes filter); |
| 1998 | // Copies enumerable keys to preallocated fixed array. |
| 1999 | void CopyEnumKeysTo(FixedArray* storage, FixedArray* sort_array); |
| 2000 | // Fill in details for properties into storage. |
| 2001 | void CopyKeysTo(FixedArray* storage); |
| 2002 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2003 | // For transforming properties of a JSObject. |
| 2004 | Object* TransformPropertiesToFastFor(JSObject* obj, |
| 2005 | int unused_property_fields); |
| 2006 | |
| 2007 | // If slow elements are required we will never go back to fast-case |
| 2008 | // for the elements kept in this dictionary. We require slow |
| 2009 | // elements if an element has been added at an index larger than |
| 2010 | // kRequiresSlowElementsLimit. |
| 2011 | inline bool requires_slow_elements(); |
| 2012 | |
| 2013 | // Get the value of the max number key that has been added to this |
| 2014 | // dictionary. max_number_key can only be called if |
| 2015 | // requires_slow_elements returns false. |
| 2016 | inline uint32_t max_number_key(); |
| 2017 | |
| 2018 | // Accessors for next enumeration index. |
| 2019 | void SetNextEnumerationIndex(int index) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2020 | fast_set(this, kNextEnumerationIndexIndex, Smi::FromInt(index)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2021 | } |
| 2022 | |
| 2023 | int NextEnumerationIndex() { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2024 | return Smi::cast(get(kNextEnumerationIndexIndex))->value(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2025 | } |
| 2026 | |
| 2027 | // Returns a new array for dictionary usage. Might return Failure. |
| 2028 | static Object* Allocate(int at_least_space_for); |
| 2029 | |
| 2030 | // Ensure enough space for n additional elements. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2031 | Object* EnsureCapacity(int n, HashTableKey* key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2032 | |
| 2033 | #ifdef DEBUG |
| 2034 | void Print(); |
| 2035 | #endif |
| 2036 | // Returns the key (slow). |
| 2037 | Object* SlowReverseLookup(Object* value); |
| 2038 | |
| 2039 | // Bit masks. |
| 2040 | static const int kRequiresSlowElementsMask = 1; |
| 2041 | static const int kRequiresSlowElementsTagSize = 1; |
| 2042 | static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1; |
| 2043 | |
| 2044 | private: |
| 2045 | // Generic at put operation. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2046 | Object* AtPut(HashTableKey* key, Object* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2047 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2048 | Object* Add(HashTableKey* key, Object* value, PropertyDetails details); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2049 | |
| 2050 | // Add entry to dictionary. |
| 2051 | void AddEntry(Object* key, |
| 2052 | Object* value, |
| 2053 | PropertyDetails details, |
| 2054 | uint32_t hash); |
| 2055 | |
| 2056 | // Sets the entry to (key, value) pair. |
| 2057 | inline void SetEntry(int entry, |
| 2058 | Object* key, |
| 2059 | Object* value, |
| 2060 | PropertyDetails details); |
| 2061 | |
| 2062 | void UpdateMaxNumberKey(uint32_t key); |
| 2063 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2064 | // Generate new enumeration indices to avoid enumeration index overflow. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2065 | Object* GenerateNewEnumerationIndices(); |
| 2066 | |
| 2067 | static const int kMaxNumberKeyIndex = kPrefixStartIndex; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2068 | static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2069 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2070 | DISALLOW_IMPLICIT_CONSTRUCTORS(Dictionary); |
| 2071 | }; |
| 2072 | |
| 2073 | |
| 2074 | // ByteArray represents fixed sized byte arrays. Used by the outside world, |
| 2075 | // such as PCRE, and also by the memory allocator and garbage collector to |
| 2076 | // fill in free blocks in the heap. |
| 2077 | class ByteArray: public Array { |
| 2078 | public: |
| 2079 | // Setter and getter. |
| 2080 | inline byte get(int index); |
| 2081 | inline void set(int index, byte value); |
| 2082 | |
| 2083 | // Treat contents as an int array. |
| 2084 | inline int get_int(int index); |
| 2085 | |
| 2086 | static int SizeFor(int length) { |
| 2087 | return kHeaderSize + OBJECT_SIZE_ALIGN(length); |
| 2088 | } |
| 2089 | // We use byte arrays for free blocks in the heap. Given a desired size in |
| 2090 | // bytes that is a multiple of the word size and big enough to hold a byte |
| 2091 | // array, this function returns the number of elements a byte array should |
| 2092 | // have. |
| 2093 | static int LengthFor(int size_in_bytes) { |
| 2094 | ASSERT(IsAligned(size_in_bytes, kPointerSize)); |
| 2095 | ASSERT(size_in_bytes >= kHeaderSize); |
| 2096 | return size_in_bytes - kHeaderSize; |
| 2097 | } |
| 2098 | |
| 2099 | // Returns data start address. |
| 2100 | inline Address GetDataStartAddress(); |
| 2101 | |
| 2102 | // Returns a pointer to the ByteArray object for a given data start address. |
| 2103 | static inline ByteArray* FromDataStartAddress(Address address); |
| 2104 | |
| 2105 | // Casting. |
| 2106 | static inline ByteArray* cast(Object* obj); |
| 2107 | |
| 2108 | // Dispatched behavior. |
| 2109 | int ByteArraySize() { return SizeFor(length()); } |
| 2110 | #ifdef DEBUG |
| 2111 | void ByteArrayPrint(); |
| 2112 | void ByteArrayVerify(); |
| 2113 | #endif |
| 2114 | |
| 2115 | private: |
| 2116 | DISALLOW_IMPLICIT_CONSTRUCTORS(ByteArray); |
| 2117 | }; |
| 2118 | |
| 2119 | |
| 2120 | // Code describes objects with on-the-fly generated machine code. |
| 2121 | class Code: public HeapObject { |
| 2122 | public: |
| 2123 | // Opaque data type for encapsulating code flags like kind, inline |
| 2124 | // cache state, and arguments count. |
| 2125 | enum Flags { }; |
| 2126 | |
| 2127 | enum Kind { |
| 2128 | FUNCTION, |
| 2129 | STUB, |
| 2130 | BUILTIN, |
| 2131 | LOAD_IC, |
| 2132 | KEYED_LOAD_IC, |
| 2133 | CALL_IC, |
| 2134 | STORE_IC, |
| 2135 | KEYED_STORE_IC, |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2136 | // No more than eight kinds. The value currently encoded in three bits in |
| 2137 | // Flags. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2138 | |
| 2139 | // Pseudo-kinds. |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2140 | REGEXP = BUILTIN, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2141 | FIRST_IC_KIND = LOAD_IC, |
| 2142 | LAST_IC_KIND = KEYED_STORE_IC |
| 2143 | }; |
| 2144 | |
| 2145 | enum { |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2146 | NUMBER_OF_KINDS = KEYED_STORE_IC + 1 |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2147 | }; |
| 2148 | |
| 2149 | // A state indicates that inline cache in this Code object contains |
| 2150 | // objects or relative instruction addresses. |
| 2151 | enum ICTargetState { |
| 2152 | IC_TARGET_IS_ADDRESS, |
| 2153 | IC_TARGET_IS_OBJECT |
| 2154 | }; |
| 2155 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 2156 | #ifdef ENABLE_DISASSEMBLER |
| 2157 | // Printing |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2158 | static const char* Kind2String(Kind kind); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2159 | static const char* ICState2String(InlineCacheState state); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2160 | void Disassemble(); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 2161 | #endif // ENABLE_DISASSEMBLER |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2162 | |
| 2163 | // [instruction_size]: Size of the native instructions |
| 2164 | inline int instruction_size(); |
| 2165 | inline void set_instruction_size(int value); |
| 2166 | |
| 2167 | // [relocation_size]: Size of relocation information. |
| 2168 | inline int relocation_size(); |
| 2169 | inline void set_relocation_size(int value); |
| 2170 | |
| 2171 | // [sinfo_size]: Size of scope information. |
| 2172 | inline int sinfo_size(); |
| 2173 | inline void set_sinfo_size(int value); |
| 2174 | |
| 2175 | // [flags]: Various code flags. |
| 2176 | inline Flags flags(); |
| 2177 | inline void set_flags(Flags flags); |
| 2178 | |
| 2179 | // [flags]: Access to specific code flags. |
| 2180 | inline Kind kind(); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2181 | inline InlineCacheState ic_state(); // only valid for IC stubs |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2182 | inline PropertyType type(); // only valid for monomorphic IC stubs |
| 2183 | inline int arguments_count(); // only valid for call IC stubs |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2184 | |
| 2185 | // Testers for IC stub kinds. |
| 2186 | inline bool is_inline_cache_stub(); |
| 2187 | inline bool is_load_stub() { return kind() == LOAD_IC; } |
| 2188 | inline bool is_keyed_load_stub() { return kind() == KEYED_LOAD_IC; } |
| 2189 | inline bool is_store_stub() { return kind() == STORE_IC; } |
| 2190 | inline bool is_keyed_store_stub() { return kind() == KEYED_STORE_IC; } |
| 2191 | inline bool is_call_stub() { return kind() == CALL_IC; } |
| 2192 | |
| 2193 | // [ic_flag]: State of inline cache targets. The flag is set to the |
| 2194 | // object variant in ConvertICTargetsFromAddressToObject, and set to |
| 2195 | // the address variant in ConvertICTargetsFromObjectToAddress. |
| 2196 | inline ICTargetState ic_flag(); |
| 2197 | inline void set_ic_flag(ICTargetState value); |
| 2198 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2199 | // [major_key]: For kind STUB, the major key. |
| 2200 | inline CodeStub::Major major_key(); |
| 2201 | inline void set_major_key(CodeStub::Major major); |
| 2202 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2203 | // Flags operations. |
| 2204 | static inline Flags ComputeFlags(Kind kind, |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2205 | InlineCacheState ic_state = UNINITIALIZED, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2206 | PropertyType type = NORMAL, |
| 2207 | int argc = -1); |
| 2208 | |
| 2209 | static inline Flags ComputeMonomorphicFlags(Kind kind, |
| 2210 | PropertyType type, |
| 2211 | int argc = -1); |
| 2212 | |
| 2213 | static inline Kind ExtractKindFromFlags(Flags flags); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2214 | static inline InlineCacheState ExtractICStateFromFlags(Flags flags); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2215 | static inline PropertyType ExtractTypeFromFlags(Flags flags); |
| 2216 | static inline int ExtractArgumentsCountFromFlags(Flags flags); |
| 2217 | static inline Flags RemoveTypeFromFlags(Flags flags); |
| 2218 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 2219 | // Convert a target address into a code object. |
| 2220 | static inline Code* GetCodeFromTargetAddress(Address address); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2221 | |
| 2222 | // Returns the address of the first instruction. |
| 2223 | inline byte* instruction_start(); |
| 2224 | |
| 2225 | // Returns the size of the instructions, padding, and relocation information. |
| 2226 | inline int body_size(); |
| 2227 | |
| 2228 | // Returns the address of the first relocation info (read backwards!). |
| 2229 | inline byte* relocation_start(); |
| 2230 | |
| 2231 | // Code entry point. |
| 2232 | inline byte* entry(); |
| 2233 | |
| 2234 | // Returns true if pc is inside this object's instructions. |
| 2235 | inline bool contains(byte* pc); |
| 2236 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2237 | // Returns the address of the scope information. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2238 | inline byte* sinfo_start(); |
| 2239 | |
| 2240 | // Convert inline cache target from address to code object before GC. |
| 2241 | void ConvertICTargetsFromAddressToObject(); |
| 2242 | |
| 2243 | // Convert inline cache target from code object to address after GC |
| 2244 | void ConvertICTargetsFromObjectToAddress(); |
| 2245 | |
| 2246 | // Relocate the code by delta bytes. Called to signal that this code |
| 2247 | // object has been moved by delta bytes. |
| 2248 | void Relocate(int delta); |
| 2249 | |
| 2250 | // Migrate code described by desc. |
| 2251 | void CopyFrom(const CodeDesc& desc); |
| 2252 | |
| 2253 | // Returns the object size for a given body and sinfo size (Used for |
| 2254 | // allocation). |
| 2255 | static int SizeFor(int body_size, int sinfo_size) { |
| 2256 | ASSERT_SIZE_TAG_ALIGNED(body_size); |
| 2257 | ASSERT_SIZE_TAG_ALIGNED(sinfo_size); |
| 2258 | return kHeaderSize + body_size + sinfo_size; |
| 2259 | } |
| 2260 | |
| 2261 | // Locating source position. |
| 2262 | int SourcePosition(Address pc); |
| 2263 | int SourceStatementPosition(Address pc); |
| 2264 | |
| 2265 | // Casting. |
| 2266 | static inline Code* cast(Object* obj); |
| 2267 | |
| 2268 | // Dispatched behavior. |
| 2269 | int CodeSize() { return SizeFor(body_size(), sinfo_size()); } |
| 2270 | void CodeIterateBody(ObjectVisitor* v); |
| 2271 | #ifdef DEBUG |
| 2272 | void CodePrint(); |
| 2273 | void CodeVerify(); |
| 2274 | #endif |
| 2275 | |
| 2276 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2277 | static const int kInstructionSizeOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2278 | static const int kRelocationSizeOffset = kInstructionSizeOffset + kIntSize; |
| 2279 | static const int kSInfoSizeOffset = kRelocationSizeOffset + kIntSize; |
| 2280 | static const int kFlagsOffset = kSInfoSizeOffset + kIntSize; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2281 | static const int kKindSpecificFlagsOffset = kFlagsOffset + kIntSize; |
| 2282 | static const int kHeaderSize = kKindSpecificFlagsOffset + kIntSize; |
| 2283 | |
| 2284 | // Byte offsets within kKindSpecificFlagsOffset. |
| 2285 | static const int kICFlagOffset = kKindSpecificFlagsOffset + 0; |
| 2286 | static const int kStubMajorKeyOffset = kKindSpecificFlagsOffset + 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2287 | |
| 2288 | // Flags layout. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2289 | static const int kFlagsICStateShift = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2290 | static const int kFlagsKindShift = 3; |
| 2291 | static const int kFlagsTypeShift = 6; |
| 2292 | static const int kFlagsArgumentsCountShift = 9; |
| 2293 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2294 | static const int kFlagsICStateMask = 0x00000007; // 000000111 |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2295 | static const int kFlagsKindMask = 0x00000038; // 000111000 |
| 2296 | static const int kFlagsTypeMask = 0x000001C0; // 111000000 |
| 2297 | static const int kFlagsArgumentsCountMask = 0xFFFFFE00; |
| 2298 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2299 | private: |
| 2300 | DISALLOW_IMPLICIT_CONSTRUCTORS(Code); |
| 2301 | }; |
| 2302 | |
| 2303 | |
| 2304 | // All heap objects have a Map that describes their structure. |
| 2305 | // A Map contains information about: |
| 2306 | // - Size information about the object |
| 2307 | // - How to iterate over an object (for garbage collection) |
| 2308 | class Map: public HeapObject { |
| 2309 | public: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2310 | // Instance size. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2311 | inline int instance_size(); |
| 2312 | inline void set_instance_size(int value); |
| 2313 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2314 | // Count of properties allocated in the object. |
| 2315 | inline int inobject_properties(); |
| 2316 | inline void set_inobject_properties(int value); |
| 2317 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2318 | // Instance type. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2319 | inline InstanceType instance_type(); |
| 2320 | inline void set_instance_type(InstanceType value); |
| 2321 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2322 | // Tells how many unused property fields are available in the |
| 2323 | // instance (only used for JSObject in fast mode). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2324 | inline int unused_property_fields(); |
| 2325 | inline void set_unused_property_fields(int value); |
| 2326 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2327 | // Bit field. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2328 | inline byte bit_field(); |
| 2329 | inline void set_bit_field(byte value); |
| 2330 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2331 | // Tells whether the object in the prototype property will be used |
| 2332 | // for instances created from this function. If the prototype |
| 2333 | // property is set to a value that is not a JSObject, the prototype |
| 2334 | // property will not be used to create instances of the function. |
| 2335 | // See ECMA-262, 13.2.2. |
| 2336 | inline void set_non_instance_prototype(bool value); |
| 2337 | inline bool has_non_instance_prototype(); |
| 2338 | |
| 2339 | // Tells whether the instance with this map should be ignored by the |
| 2340 | // __proto__ accessor. |
| 2341 | inline void set_is_hidden_prototype() { |
| 2342 | set_bit_field(bit_field() | (1 << kIsHiddenPrototype)); |
| 2343 | } |
| 2344 | |
| 2345 | inline bool is_hidden_prototype() { |
| 2346 | return ((1 << kIsHiddenPrototype) & bit_field()) != 0; |
| 2347 | } |
| 2348 | |
| 2349 | // Tells whether the instance has a named interceptor. |
| 2350 | inline void set_has_named_interceptor() { |
| 2351 | set_bit_field(bit_field() | (1 << kHasNamedInterceptor)); |
| 2352 | } |
| 2353 | |
| 2354 | inline bool has_named_interceptor() { |
| 2355 | return ((1 << kHasNamedInterceptor) & bit_field()) != 0; |
| 2356 | } |
| 2357 | |
| 2358 | // Tells whether the instance has a named interceptor. |
| 2359 | inline void set_has_indexed_interceptor() { |
| 2360 | set_bit_field(bit_field() | (1 << kHasIndexedInterceptor)); |
| 2361 | } |
| 2362 | |
| 2363 | inline bool has_indexed_interceptor() { |
| 2364 | return ((1 << kHasIndexedInterceptor) & bit_field()) != 0; |
| 2365 | } |
| 2366 | |
| 2367 | // Tells whether the instance is undetectable. |
| 2368 | // An undetectable object is a special class of JSObject: 'typeof' operator |
| 2369 | // returns undefined, ToBoolean returns false. Otherwise it behaves like |
| 2370 | // a normal JS object. It is useful for implementing undetectable |
| 2371 | // document.all in Firefox & Safari. |
| 2372 | // See https://bugzilla.mozilla.org/show_bug.cgi?id=248549. |
| 2373 | inline void set_is_undetectable() { |
| 2374 | set_bit_field(bit_field() | (1 << kIsUndetectable)); |
| 2375 | } |
| 2376 | |
| 2377 | inline bool is_undetectable() { |
| 2378 | return ((1 << kIsUndetectable) & bit_field()) != 0; |
| 2379 | } |
| 2380 | |
| 2381 | // Tells whether the instance has a call-as-function handler. |
| 2382 | inline void set_has_instance_call_handler() { |
| 2383 | set_bit_field(bit_field() | (1 << kHasInstanceCallHandler)); |
| 2384 | } |
| 2385 | |
| 2386 | inline bool has_instance_call_handler() { |
| 2387 | return ((1 << kHasInstanceCallHandler) & bit_field()) != 0; |
| 2388 | } |
| 2389 | |
| 2390 | // Tells whether the instance needs security checks when accessing its |
| 2391 | // properties. |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 2392 | inline void set_is_access_check_needed(bool access_check_needed); |
| 2393 | inline bool is_access_check_needed(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2394 | |
| 2395 | // [prototype]: implicit prototype object. |
| 2396 | DECL_ACCESSORS(prototype, Object) |
| 2397 | |
| 2398 | // [constructor]: points back to the function responsible for this map. |
| 2399 | DECL_ACCESSORS(constructor, Object) |
| 2400 | |
| 2401 | // [instance descriptors]: describes the object. |
| 2402 | DECL_ACCESSORS(instance_descriptors, DescriptorArray) |
| 2403 | |
| 2404 | // [stub cache]: contains stubs compiled for this map. |
| 2405 | DECL_ACCESSORS(code_cache, FixedArray) |
| 2406 | |
| 2407 | // Returns a copy of the map. |
| 2408 | Object* Copy(); |
| 2409 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2410 | // Returns a copy of the map, with all transitions dropped from the |
| 2411 | // instance descriptors. |
| 2412 | Object* CopyDropTransitions(); |
| 2413 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2414 | // Returns the property index for name (only valid for FAST MODE). |
| 2415 | int PropertyIndexFor(String* name); |
| 2416 | |
| 2417 | // Returns the next free property index (only valid for FAST MODE). |
| 2418 | int NextFreePropertyIndex(); |
| 2419 | |
| 2420 | // Returns the number of properties described in instance_descriptors. |
| 2421 | int NumberOfDescribedProperties(); |
| 2422 | |
| 2423 | // Casting. |
| 2424 | static inline Map* cast(Object* obj); |
| 2425 | |
| 2426 | // Locate an accessor in the instance descriptor. |
| 2427 | AccessorDescriptor* FindAccessor(String* name); |
| 2428 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2429 | // Code cache operations. |
| 2430 | |
| 2431 | // Clears the code cache. |
| 2432 | inline void ClearCodeCache(); |
| 2433 | |
| 2434 | // Update code cache. |
| 2435 | Object* UpdateCodeCache(String* name, Code* code); |
| 2436 | |
| 2437 | // Returns the found code or undefined if absent. |
| 2438 | Object* FindInCodeCache(String* name, Code::Flags flags); |
| 2439 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2440 | // Returns the non-negative index of the code object if it is in the |
| 2441 | // cache and -1 otherwise. |
| 2442 | int IndexInCodeCache(Code* code); |
| 2443 | |
| 2444 | // Removes a code object from the code cache at the given index. |
| 2445 | void RemoveFromCodeCache(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2446 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 2447 | // For every transition in this map, makes the transition's |
| 2448 | // target's prototype pointer point back to this map. |
| 2449 | // This is undone in MarkCompactCollector::ClearNonLiveTransitions(). |
| 2450 | void CreateBackPointers(); |
| 2451 | |
| 2452 | // Set all map transitions from this map to dead maps to null. |
| 2453 | // Also, restore the original prototype on the targets of these |
| 2454 | // transitions, so that we do not process this map again while |
| 2455 | // following back pointers. |
| 2456 | void ClearNonLiveTransitions(Object* real_prototype); |
| 2457 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2458 | // Dispatched behavior. |
| 2459 | void MapIterateBody(ObjectVisitor* v); |
| 2460 | #ifdef DEBUG |
| 2461 | void MapPrint(); |
| 2462 | void MapVerify(); |
| 2463 | #endif |
| 2464 | |
| 2465 | // Layout description. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2466 | static const int kInstanceSizesOffset = HeapObject::kHeaderSize; |
| 2467 | static const int kInstanceAttributesOffset = kInstanceSizesOffset + kIntSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2468 | static const int kPrototypeOffset = kInstanceAttributesOffset + kIntSize; |
| 2469 | static const int kConstructorOffset = kPrototypeOffset + kPointerSize; |
| 2470 | static const int kInstanceDescriptorsOffset = |
| 2471 | kConstructorOffset + kPointerSize; |
| 2472 | static const int kCodeCacheOffset = kInstanceDescriptorsOffset + kPointerSize; |
| 2473 | static const int kSize = kCodeCacheOffset + kIntSize; |
| 2474 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2475 | // Byte offsets within kInstanceSizesOffset. |
| 2476 | static const int kInstanceSizeOffset = kInstanceSizesOffset + 0; |
| 2477 | static const int kInObjectPropertiesOffset = kInstanceSizesOffset + 1; |
| 2478 | // The bytes at positions 2 and 3 are not in use at the moment. |
| 2479 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2480 | // Byte offsets within kInstanceAttributesOffset attributes. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2481 | static const int kInstanceTypeOffset = kInstanceAttributesOffset + 0; |
| 2482 | static const int kUnusedPropertyFieldsOffset = kInstanceAttributesOffset + 1; |
| 2483 | static const int kBitFieldOffset = kInstanceAttributesOffset + 2; |
| 2484 | // The byte at position 3 is not in use at the moment. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2485 | |
| 2486 | // Bit positions for bit field. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2487 | 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] | 2488 | static const int kHasNonInstancePrototype = 1; |
| 2489 | static const int kIsHiddenPrototype = 2; |
| 2490 | static const int kHasNamedInterceptor = 3; |
| 2491 | static const int kHasIndexedInterceptor = 4; |
| 2492 | static const int kIsUndetectable = 5; |
| 2493 | static const int kHasInstanceCallHandler = 6; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2494 | static const int kIsAccessCheckNeeded = 7; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2495 | private: |
| 2496 | DISALLOW_IMPLICIT_CONSTRUCTORS(Map); |
| 2497 | }; |
| 2498 | |
| 2499 | |
| 2500 | // An abstract superclass, a marker class really, for simple structure classes. |
| 2501 | // It doesn't carry much functionality but allows struct classes to me |
| 2502 | // identified in the type system. |
| 2503 | class Struct: public HeapObject { |
| 2504 | public: |
| 2505 | inline void InitializeBody(int object_size); |
| 2506 | static inline Struct* cast(Object* that); |
| 2507 | }; |
| 2508 | |
| 2509 | |
| 2510 | // Script types. |
| 2511 | enum ScriptType { |
| 2512 | SCRIPT_TYPE_NATIVE, |
| 2513 | SCRIPT_TYPE_EXTENSION, |
| 2514 | SCRIPT_TYPE_NORMAL |
| 2515 | }; |
| 2516 | |
| 2517 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2518 | // Script describes a script which has been added to the VM. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2519 | class Script: public Struct { |
| 2520 | public: |
| 2521 | // [source]: the script source. |
| 2522 | DECL_ACCESSORS(source, Object) |
| 2523 | |
| 2524 | // [name]: the script name. |
| 2525 | DECL_ACCESSORS(name, Object) |
| 2526 | |
| 2527 | // [line_offset]: script line offset in resource from where it was extracted. |
| 2528 | DECL_ACCESSORS(line_offset, Smi) |
| 2529 | |
| 2530 | // [column_offset]: script column offset in resource from where it was |
| 2531 | // extracted. |
| 2532 | DECL_ACCESSORS(column_offset, Smi) |
| 2533 | |
| 2534 | // [wrapper]: the wrapper cache. |
| 2535 | DECL_ACCESSORS(wrapper, Proxy) |
| 2536 | |
| 2537 | // [type]: the script type. |
| 2538 | DECL_ACCESSORS(type, Smi) |
| 2539 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 2540 | // [line_ends]: array of line ends positions |
| 2541 | DECL_ACCESSORS(line_ends, Object) |
| 2542 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2543 | static inline Script* cast(Object* obj); |
| 2544 | |
| 2545 | #ifdef DEBUG |
| 2546 | void ScriptPrint(); |
| 2547 | void ScriptVerify(); |
| 2548 | #endif |
| 2549 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 2550 | void InitLineEnds(); |
| 2551 | int GetLineNumber(int code_position); |
| 2552 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2553 | static const int kSourceOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2554 | static const int kNameOffset = kSourceOffset + kPointerSize; |
| 2555 | static const int kLineOffsetOffset = kNameOffset + kPointerSize; |
| 2556 | static const int kColumnOffsetOffset = kLineOffsetOffset + kPointerSize; |
| 2557 | static const int kWrapperOffset = kColumnOffsetOffset + kPointerSize; |
| 2558 | static const int kTypeOffset = kWrapperOffset + kPointerSize; |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 2559 | static const int kLineEndsOffset = kTypeOffset + kPointerSize; |
| 2560 | static const int kSize = kLineEndsOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2561 | |
| 2562 | private: |
| 2563 | DISALLOW_IMPLICIT_CONSTRUCTORS(Script); |
| 2564 | }; |
| 2565 | |
| 2566 | |
| 2567 | // SharedFunctionInfo describes the JSFunction information that can be |
| 2568 | // shared by multiple instances of the function. |
| 2569 | class SharedFunctionInfo: public HeapObject { |
| 2570 | public: |
| 2571 | // [name]: Function name. |
| 2572 | DECL_ACCESSORS(name, Object) |
| 2573 | |
| 2574 | // [code]: Function code. |
| 2575 | DECL_ACCESSORS(code, Code) |
| 2576 | |
| 2577 | // Returns if this function has been compiled to native code yet. |
| 2578 | inline bool is_compiled(); |
| 2579 | |
| 2580 | // [length]: The function length - usually the number of declared parameters. |
| 2581 | // Use up to 2^30 parameters. |
| 2582 | inline int length(); |
| 2583 | inline void set_length(int value); |
| 2584 | |
| 2585 | // [formal parameter count]: The declared number of parameters. |
| 2586 | inline int formal_parameter_count(); |
| 2587 | inline void set_formal_parameter_count(int value); |
| 2588 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2589 | // Set the formal parameter count so the function code will be |
| 2590 | // called without using argument adaptor frames. |
| 2591 | inline void DontAdaptArguments(); |
| 2592 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2593 | // [expected_nof_properties]: Expected number of properties for the function. |
| 2594 | inline int expected_nof_properties(); |
| 2595 | inline void set_expected_nof_properties(int value); |
| 2596 | |
| 2597 | // [instance class name]: class name for instances. |
| 2598 | DECL_ACCESSORS(instance_class_name, Object) |
| 2599 | |
| 2600 | // [function data]: This field has been added for make benefit the API. |
| 2601 | // In the long run we don't want all functions to have this field but |
| 2602 | // we can fix that when we have a better model for storing hidden data |
| 2603 | // on objects. |
| 2604 | DECL_ACCESSORS(function_data, Object) |
| 2605 | |
| 2606 | // [lazy load data]: If the function has lazy loading, this field |
| 2607 | // contains contexts and other data needed to load it. |
| 2608 | DECL_ACCESSORS(lazy_load_data, Object) |
| 2609 | |
| 2610 | // [script info]: Script from which the function originates. |
| 2611 | DECL_ACCESSORS(script, Object) |
| 2612 | |
| 2613 | // [start_position_and_type]: Field used to store both the source code |
| 2614 | // position, whether or not the function is a function expression, |
| 2615 | // and whether or not the function is a toplevel function. The two |
| 2616 | // least significants bit indicates whether the function is an |
| 2617 | // expression and the rest contains the source code position. |
| 2618 | inline int start_position_and_type(); |
| 2619 | inline void set_start_position_and_type(int value); |
| 2620 | |
| 2621 | // [debug info]: Debug information. |
| 2622 | DECL_ACCESSORS(debug_info, Object) |
| 2623 | |
| 2624 | // Position of the 'function' token in the script source. |
| 2625 | inline int function_token_position(); |
| 2626 | inline void set_function_token_position(int function_token_position); |
| 2627 | |
| 2628 | // Position of this function in the script source. |
| 2629 | inline int start_position(); |
| 2630 | inline void set_start_position(int start_position); |
| 2631 | |
| 2632 | // End position of this function in the script source. |
| 2633 | inline int end_position(); |
| 2634 | inline void set_end_position(int end_position); |
| 2635 | |
| 2636 | // Is this function a function expression in the source code. |
| 2637 | inline bool is_expression(); |
| 2638 | inline void set_is_expression(bool value); |
| 2639 | |
| 2640 | // Is this function a top-level function. Used for accessing the |
| 2641 | // caller of functions. Top-level functions (scripts, evals) are |
| 2642 | // returned as null; see JSFunction::GetCallerAccessor(...). |
| 2643 | inline bool is_toplevel(); |
| 2644 | inline void set_is_toplevel(bool value); |
| 2645 | |
| 2646 | // [source code]: Source code for the function. |
| 2647 | bool HasSourceCode(); |
| 2648 | Object* GetSourceCode(); |
| 2649 | |
| 2650 | // Dispatched behavior. |
| 2651 | void SharedFunctionInfoIterateBody(ObjectVisitor* v); |
| 2652 | // Set max_length to -1 for unlimited length. |
| 2653 | void SourceCodePrint(StringStream* accumulator, int max_length); |
| 2654 | #ifdef DEBUG |
| 2655 | void SharedFunctionInfoPrint(); |
| 2656 | void SharedFunctionInfoVerify(); |
| 2657 | #endif |
| 2658 | |
| 2659 | // Casting. |
| 2660 | static inline SharedFunctionInfo* cast(Object* obj); |
| 2661 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2662 | // Constants. |
| 2663 | static const int kDontAdaptArgumentsSentinel = -1; |
| 2664 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2665 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2666 | static const int kNameOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2667 | static const int kCodeOffset = kNameOffset + kPointerSize; |
| 2668 | static const int kLengthOffset = kCodeOffset + kPointerSize; |
| 2669 | static const int kFormalParameterCountOffset = kLengthOffset + kIntSize; |
| 2670 | static const int kExpectedNofPropertiesOffset = |
| 2671 | kFormalParameterCountOffset + kIntSize; |
| 2672 | static const int kInstanceClassNameOffset = |
| 2673 | kExpectedNofPropertiesOffset + kIntSize; |
| 2674 | static const int kExternalReferenceDataOffset = |
| 2675 | kInstanceClassNameOffset + kPointerSize; |
| 2676 | static const int kLazyLoadDataOffset = |
| 2677 | kExternalReferenceDataOffset + kPointerSize; |
| 2678 | static const int kScriptOffset = kLazyLoadDataOffset + kPointerSize; |
| 2679 | static const int kStartPositionAndTypeOffset = kScriptOffset + kPointerSize; |
| 2680 | static const int kEndPositionOffset = kStartPositionAndTypeOffset + kIntSize; |
| 2681 | static const int kFunctionTokenPositionOffset = kEndPositionOffset + kIntSize; |
| 2682 | static const int kDebugInfoOffset = kFunctionTokenPositionOffset + kIntSize; |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 2683 | static const int kSize = kDebugInfoOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2684 | |
| 2685 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2686 | // Bit positions in length_and_flg. |
| 2687 | // The least significant bit is used as the flag. |
| 2688 | static const int kFlagBit = 0; |
| 2689 | static const int kLengthShift = 1; |
| 2690 | static const int kLengthMask = ~((1 << kLengthShift) - 1); |
| 2691 | |
| 2692 | // Bit positions in start_position_and_type. |
| 2693 | // The source code start position is in the 30 most significant bits of |
| 2694 | // the start_position_and_type field. |
| 2695 | static const int kIsExpressionBit = 0; |
| 2696 | static const int kIsTopLevelBit = 1; |
| 2697 | static const int kStartPositionShift = 2; |
| 2698 | static const int kStartPositionMask = ~((1 << kStartPositionShift) - 1); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2699 | |
| 2700 | DISALLOW_IMPLICIT_CONSTRUCTORS(SharedFunctionInfo); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2701 | }; |
| 2702 | |
| 2703 | |
| 2704 | // JSFunction describes JavaScript functions. |
| 2705 | class JSFunction: public JSObject { |
| 2706 | public: |
| 2707 | // [prototype_or_initial_map]: |
| 2708 | DECL_ACCESSORS(prototype_or_initial_map, Object) |
| 2709 | |
| 2710 | // [shared_function_info]: The information about the function that |
| 2711 | // can be shared by instances. |
| 2712 | DECL_ACCESSORS(shared, SharedFunctionInfo) |
| 2713 | |
| 2714 | // [context]: The context for this function. |
| 2715 | inline Context* context(); |
| 2716 | inline Object* unchecked_context(); |
| 2717 | inline void set_context(Object* context); |
| 2718 | |
| 2719 | // [code]: The generated code object for this function. Executed |
| 2720 | // when the function is invoked, e.g. foo() or new foo(). See |
| 2721 | // [[Call]] and [[Construct]] description in ECMA-262, section |
| 2722 | // 8.6.2, page 27. |
| 2723 | inline Code* code(); |
| 2724 | inline void set_code(Code* value); |
| 2725 | |
| 2726 | // Tells whether this function is a context-independent boilerplate |
| 2727 | // function. |
| 2728 | inline bool IsBoilerplate(); |
| 2729 | |
| 2730 | // Tells whether this function needs to be loaded. |
| 2731 | inline bool IsLoaded(); |
| 2732 | |
| 2733 | // [literals]: Fixed array holding the materialized literals. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2734 | // |
| 2735 | // If the function contains object, regexp or array literals, the |
| 2736 | // literals array prefix contains the object, regexp, and array |
| 2737 | // function to be used when creating these literals. This is |
| 2738 | // necessary so that we do not dynamically lookup the object, regexp |
| 2739 | // or array functions. Performing a dynamic lookup, we might end up |
| 2740 | // using the functions from a new context that we should not have |
| 2741 | // access to. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2742 | DECL_ACCESSORS(literals, FixedArray) |
| 2743 | |
| 2744 | // The initial map for an object created by this constructor. |
| 2745 | inline Map* initial_map(); |
| 2746 | inline void set_initial_map(Map* value); |
| 2747 | inline bool has_initial_map(); |
| 2748 | |
| 2749 | // Get and set the prototype property on a JSFunction. If the |
| 2750 | // function has an initial map the prototype is set on the initial |
| 2751 | // map. Otherwise, the prototype is put in the initial map field |
| 2752 | // until an initial map is needed. |
| 2753 | inline bool has_prototype(); |
| 2754 | inline bool has_instance_prototype(); |
| 2755 | inline Object* prototype(); |
| 2756 | inline Object* instance_prototype(); |
| 2757 | Object* SetInstancePrototype(Object* value); |
| 2758 | Object* SetPrototype(Object* value); |
| 2759 | |
| 2760 | // Accessor for this function's initial map's [[class]] |
| 2761 | // property. This is primarily used by ECMA native functions. This |
| 2762 | // method sets the class_name field of this function's initial map |
| 2763 | // to a given value. It creates an initial map if this function does |
| 2764 | // not have one. Note that this method does not copy the initial map |
| 2765 | // if it has one already, but simply replaces it with the new value. |
| 2766 | // Instances created afterwards will have a map whose [[class]] is |
| 2767 | // set to 'value', but there is no guarantees on instances created |
| 2768 | // before. |
| 2769 | Object* SetInstanceClassName(String* name); |
| 2770 | |
| 2771 | // Returns if this function has been compiled to native code yet. |
| 2772 | inline bool is_compiled(); |
| 2773 | |
| 2774 | // Casting. |
| 2775 | static inline JSFunction* cast(Object* obj); |
| 2776 | |
| 2777 | // Dispatched behavior. |
| 2778 | #ifdef DEBUG |
| 2779 | void JSFunctionPrint(); |
| 2780 | void JSFunctionVerify(); |
| 2781 | #endif |
| 2782 | |
| 2783 | // Returns the number of allocated literals. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2784 | inline int NumberOfLiterals(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2785 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2786 | // Retrieve the global context from a function's literal array. |
| 2787 | static Context* GlobalContextFromLiterals(FixedArray* literals); |
| 2788 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2789 | // Layout descriptors. |
| 2790 | static const int kPrototypeOrInitialMapOffset = JSObject::kHeaderSize; |
| 2791 | static const int kSharedFunctionInfoOffset = |
| 2792 | kPrototypeOrInitialMapOffset + kPointerSize; |
| 2793 | static const int kContextOffset = kSharedFunctionInfoOffset + kPointerSize; |
| 2794 | static const int kLiteralsOffset = kContextOffset + kPointerSize; |
| 2795 | static const int kSize = kLiteralsOffset + kPointerSize; |
| 2796 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2797 | // Layout of the literals array. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2798 | static const int kLiteralsPrefixSize = 1; |
| 2799 | static const int kLiteralGlobalContextIndex = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2800 | private: |
| 2801 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunction); |
| 2802 | }; |
| 2803 | |
| 2804 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2805 | // JSGlobalProxy's prototype must be a JSGlobalObject or null, |
| 2806 | // and the prototype is hidden. JSGlobalProxy always delegates |
| 2807 | // property accesses to its prototype if the prototype is not null. |
| 2808 | // |
| 2809 | // A JSGlobalProxy can be reinitialized which will preserve its identity. |
| 2810 | // |
| 2811 | // Accessing a JSGlobalProxy requires security check. |
| 2812 | |
| 2813 | class JSGlobalProxy : public JSObject { |
| 2814 | public: |
| 2815 | // [context]: the owner global context of this proxy object. |
| 2816 | // It is null value if this object is not used by any context. |
| 2817 | DECL_ACCESSORS(context, Object) |
| 2818 | |
| 2819 | // Casting. |
| 2820 | static inline JSGlobalProxy* cast(Object* obj); |
| 2821 | |
| 2822 | // Dispatched behavior. |
| 2823 | #ifdef DEBUG |
| 2824 | void JSGlobalProxyPrint(); |
| 2825 | void JSGlobalProxyVerify(); |
| 2826 | #endif |
| 2827 | |
| 2828 | // Layout description. |
| 2829 | static const int kContextOffset = JSObject::kHeaderSize; |
| 2830 | static const int kSize = kContextOffset + kPointerSize; |
| 2831 | |
| 2832 | private: |
| 2833 | |
| 2834 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalProxy); |
| 2835 | }; |
| 2836 | |
| 2837 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2838 | // Forward declaration. |
| 2839 | class JSBuiltinsObject; |
| 2840 | |
| 2841 | // Common super class for JavaScript global objects and the special |
| 2842 | // builtins global objects. |
| 2843 | class GlobalObject: public JSObject { |
| 2844 | public: |
| 2845 | // [builtins]: the object holding the runtime routines written in JS. |
| 2846 | DECL_ACCESSORS(builtins, JSBuiltinsObject) |
| 2847 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 2848 | // [global context]: the global context corresponding to this global object. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2849 | DECL_ACCESSORS(global_context, Context) |
| 2850 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2851 | // [global receiver]: the global receiver object of the context |
| 2852 | DECL_ACCESSORS(global_receiver, JSObject) |
| 2853 | |
| 2854 | // Casting. |
| 2855 | static inline GlobalObject* cast(Object* obj); |
| 2856 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2857 | // Layout description. |
| 2858 | static const int kBuiltinsOffset = JSObject::kHeaderSize; |
| 2859 | static const int kGlobalContextOffset = kBuiltinsOffset + kPointerSize; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2860 | static const int kGlobalReceiverOffset = kGlobalContextOffset + kPointerSize; |
| 2861 | static const int kHeaderSize = kGlobalReceiverOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2862 | |
| 2863 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2864 | friend class AGCCVersionRequiresThisClassToHaveAFriendSoHereItIs; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2865 | |
| 2866 | DISALLOW_IMPLICIT_CONSTRUCTORS(GlobalObject); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2867 | }; |
| 2868 | |
| 2869 | |
| 2870 | // JavaScript global object. |
| 2871 | class JSGlobalObject: public GlobalObject { |
| 2872 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2873 | // Casting. |
| 2874 | static inline JSGlobalObject* cast(Object* obj); |
| 2875 | |
| 2876 | // Dispatched behavior. |
| 2877 | #ifdef DEBUG |
| 2878 | void JSGlobalObjectPrint(); |
| 2879 | void JSGlobalObjectVerify(); |
| 2880 | #endif |
| 2881 | |
| 2882 | // Layout description. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2883 | static const int kSize = GlobalObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2884 | |
| 2885 | private: |
| 2886 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalObject); |
| 2887 | }; |
| 2888 | |
| 2889 | |
| 2890 | // Builtins global object which holds the runtime routines written in |
| 2891 | // JavaScript. |
| 2892 | class JSBuiltinsObject: public GlobalObject { |
| 2893 | public: |
| 2894 | // Accessors for the runtime routines written in JavaScript. |
| 2895 | inline Object* javascript_builtin(Builtins::JavaScript id); |
| 2896 | inline void set_javascript_builtin(Builtins::JavaScript id, Object* value); |
| 2897 | |
| 2898 | // Casting. |
| 2899 | static inline JSBuiltinsObject* cast(Object* obj); |
| 2900 | |
| 2901 | // Dispatched behavior. |
| 2902 | #ifdef DEBUG |
| 2903 | void JSBuiltinsObjectPrint(); |
| 2904 | void JSBuiltinsObjectVerify(); |
| 2905 | #endif |
| 2906 | |
| 2907 | // Layout description. The size of the builtins object includes |
| 2908 | // room for one pointer per runtime routine written in javascript. |
| 2909 | static const int kJSBuiltinsCount = Builtins::id_count; |
| 2910 | static const int kJSBuiltinsOffset = GlobalObject::kHeaderSize; |
| 2911 | static const int kSize = |
| 2912 | kJSBuiltinsOffset + (kJSBuiltinsCount * kPointerSize); |
| 2913 | private: |
| 2914 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSBuiltinsObject); |
| 2915 | }; |
| 2916 | |
| 2917 | |
| 2918 | // Representation for JS Wrapper objects, String, Number, Boolean, Date, etc. |
| 2919 | class JSValue: public JSObject { |
| 2920 | public: |
| 2921 | // [value]: the object being wrapped. |
| 2922 | DECL_ACCESSORS(value, Object) |
| 2923 | |
| 2924 | // Casting. |
| 2925 | static inline JSValue* cast(Object* obj); |
| 2926 | |
| 2927 | // Dispatched behavior. |
| 2928 | #ifdef DEBUG |
| 2929 | void JSValuePrint(); |
| 2930 | void JSValueVerify(); |
| 2931 | #endif |
| 2932 | |
| 2933 | // Layout description. |
| 2934 | static const int kValueOffset = JSObject::kHeaderSize; |
| 2935 | static const int kSize = kValueOffset + kPointerSize; |
| 2936 | |
| 2937 | private: |
| 2938 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSValue); |
| 2939 | }; |
| 2940 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2941 | // Regular expressions |
| 2942 | class JSRegExp: public JSObject { |
| 2943 | public: |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2944 | // Meaning of Type: |
| 2945 | // 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] | 2946 | // ATOM: A simple string to match against using an indexOf operation. |
| 2947 | // IRREGEXP: Compiled with Irregexp. |
| 2948 | // IRREGEXP_NATIVE: Compiled to native code with Irregexp. |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame^] | 2949 | enum Type { NOT_COMPILED, ATOM, IRREGEXP }; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2950 | enum Flag { NONE = 0, GLOBAL = 1, IGNORE_CASE = 2, MULTILINE = 4 }; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2951 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2952 | class Flags { |
| 2953 | public: |
| 2954 | explicit Flags(uint32_t value) : value_(value) { } |
| 2955 | bool is_global() { return (value_ & GLOBAL) != 0; } |
| 2956 | bool is_ignore_case() { return (value_ & IGNORE_CASE) != 0; } |
| 2957 | bool is_multiline() { return (value_ & MULTILINE) != 0; } |
| 2958 | uint32_t value() { return value_; } |
| 2959 | private: |
| 2960 | uint32_t value_; |
| 2961 | }; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2962 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2963 | DECL_ACCESSORS(data, Object) |
| 2964 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2965 | inline Type TypeTag(); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2966 | inline Flags GetFlags(); |
| 2967 | inline String* Pattern(); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2968 | inline Object* DataAt(int index); |
| 2969 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2970 | static inline JSRegExp* cast(Object* obj); |
| 2971 | |
| 2972 | // Dispatched behavior. |
| 2973 | #ifdef DEBUG |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2974 | void JSRegExpVerify(); |
| 2975 | #endif |
| 2976 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2977 | static const int kDataOffset = JSObject::kHeaderSize; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2978 | static const int kSize = kDataOffset + kIntSize; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2979 | |
| 2980 | static const int kTagIndex = 0; |
| 2981 | static const int kSourceIndex = kTagIndex + 1; |
| 2982 | static const int kFlagsIndex = kSourceIndex + 1; |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame^] | 2983 | // These two are the same since the same entry is shared for |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2984 | // different purposes in different types of regexps. |
| 2985 | static const int kAtomPatternIndex = kFlagsIndex + 1; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2986 | static const int kIrregexpDataIndex = kFlagsIndex + 1; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2987 | static const int kDataSize = kAtomPatternIndex + 1; |
| 2988 | }; |
| 2989 | |
| 2990 | |
| 2991 | class CompilationCacheTable: public HashTable<0, 2> { |
| 2992 | public: |
| 2993 | // Find cached value for a string key, otherwise return null. |
| 2994 | Object* Lookup(String* src); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame^] | 2995 | Object* LookupEval(String* src, Context* context); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2996 | Object* LookupRegExp(String* source, JSRegExp::Flags flags); |
| 2997 | Object* Put(String* src, Object* value); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame^] | 2998 | Object* PutEval(String* src, Context* context, Object* value); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2999 | Object* PutRegExp(String* src, JSRegExp::Flags flags, FixedArray* value); |
| 3000 | |
| 3001 | static inline CompilationCacheTable* cast(Object* obj); |
| 3002 | |
| 3003 | private: |
| 3004 | DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheTable); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 3005 | }; |
| 3006 | |
| 3007 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3008 | enum AllowNullsFlag {ALLOW_NULLS, DISALLOW_NULLS}; |
| 3009 | enum RobustnessFlag {ROBUST_STRING_TRAVERSAL, FAST_STRING_TRAVERSAL}; |
| 3010 | |
| 3011 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3012 | class StringHasher { |
| 3013 | public: |
| 3014 | inline StringHasher(int length); |
| 3015 | |
| 3016 | // Returns true if the hash of this string can be computed without |
| 3017 | // looking at the contents. |
| 3018 | inline bool has_trivial_hash(); |
| 3019 | |
| 3020 | // Add a character to the hash and update the array index calculation. |
| 3021 | inline void AddCharacter(uc32 c); |
| 3022 | |
| 3023 | // Adds a character to the hash but does not update the array index |
| 3024 | // calculation. This can only be called when it has been verified |
| 3025 | // that the input is not an array index. |
| 3026 | inline void AddCharacterNoIndex(uc32 c); |
| 3027 | |
| 3028 | // Returns the value to store in the hash field of a string with |
| 3029 | // the given length and contents. |
| 3030 | uint32_t GetHashField(); |
| 3031 | |
| 3032 | // Returns true if the characters seen so far make up a legal array |
| 3033 | // index. |
| 3034 | bool is_array_index() { return is_array_index_; } |
| 3035 | |
| 3036 | bool is_valid() { return is_valid_; } |
| 3037 | |
| 3038 | void invalidate() { is_valid_ = false; } |
| 3039 | |
| 3040 | private: |
| 3041 | |
| 3042 | uint32_t array_index() { |
| 3043 | ASSERT(is_array_index()); |
| 3044 | return array_index_; |
| 3045 | } |
| 3046 | |
| 3047 | inline uint32_t GetHash(); |
| 3048 | |
| 3049 | int length_; |
| 3050 | uint32_t raw_running_hash_; |
| 3051 | uint32_t array_index_; |
| 3052 | bool is_array_index_; |
| 3053 | bool is_first_char_; |
| 3054 | bool is_valid_; |
| 3055 | }; |
| 3056 | |
| 3057 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 3058 | // The characteristics of a string are stored in its map. Retrieving these |
| 3059 | // few bits of information is moderately expensive, involving two memory |
| 3060 | // loads where the second is dependent on the first. To improve efficiency |
| 3061 | // the shape of the string is given its own class so that it can be retrieved |
| 3062 | // once and used for several string operations. A StringShape is small enough |
| 3063 | // 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] | 3064 | // string can potentially alter its shape. Also be aware that a GC caused by |
| 3065 | // something else can alter the shape of a string due to ConsString |
| 3066 | // shortcutting. |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 3067 | // |
| 3068 | // Most of the methods designed to interrogate a string as to its exact nature |
| 3069 | // have been made into methods on StringShape in order to encourage the use of |
| 3070 | // StringShape. The String class has both a length() and a length(StringShape) |
| 3071 | // operation. The former is simpler to type, but the latter is faster if you |
| 3072 | // need the StringShape for some other operation immediately before or after. |
| 3073 | class StringShape BASE_EMBEDDED { |
| 3074 | public: |
| 3075 | inline explicit StringShape(String* s); |
| 3076 | inline explicit StringShape(Map* s); |
| 3077 | inline explicit StringShape(InstanceType t); |
| 3078 | inline bool IsAsciiRepresentation(); |
| 3079 | inline bool IsTwoByteRepresentation(); |
| 3080 | inline bool IsSequential(); |
| 3081 | inline bool IsExternal(); |
| 3082 | inline bool IsCons(); |
| 3083 | inline bool IsSliced(); |
| 3084 | inline bool IsExternalAscii(); |
| 3085 | inline bool IsExternalTwoByte(); |
| 3086 | inline bool IsSequentialAscii(); |
| 3087 | inline bool IsSequentialTwoByte(); |
| 3088 | inline bool IsSymbol(); |
| 3089 | inline StringRepresentationTag representation_tag(); |
| 3090 | inline uint32_t full_representation_tag(); |
| 3091 | inline uint32_t size_tag(); |
| 3092 | #ifdef DEBUG |
| 3093 | inline uint32_t type() { return type_; } |
| 3094 | inline void invalidate() { valid_ = false; } |
| 3095 | inline bool valid() { return valid_; } |
| 3096 | #else |
| 3097 | inline void invalidate() { } |
| 3098 | #endif |
| 3099 | private: |
| 3100 | uint32_t type_; |
| 3101 | #ifdef DEBUG |
| 3102 | inline void set_valid() { valid_ = true; } |
| 3103 | bool valid_; |
| 3104 | #else |
| 3105 | inline void set_valid() { } |
| 3106 | #endif |
| 3107 | }; |
| 3108 | |
| 3109 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3110 | // The String abstract class captures JavaScript string values: |
| 3111 | // |
| 3112 | // Ecma-262: |
| 3113 | // 4.3.16 String Value |
| 3114 | // A string value is a member of the type String and is a finite |
| 3115 | // ordered sequence of zero or more 16-bit unsigned integer values. |
| 3116 | // |
| 3117 | // All string values have a length field. |
| 3118 | class String: public HeapObject { |
| 3119 | public: |
| 3120 | // Get and set the length of the string. |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 3121 | // Fast version. |
| 3122 | inline int length(StringShape shape); |
| 3123 | // Easy version. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3124 | inline int length(); |
| 3125 | inline void set_length(int value); |
| 3126 | |
| 3127 | // Get and set the uninterpreted length field of the string. Notice |
| 3128 | // that the length field is also used to cache the hash value of |
| 3129 | // strings. In order to get or set the actual length of the string |
| 3130 | // use the length() and set_length methods. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3131 | inline uint32_t length_field(); |
| 3132 | inline void set_length_field(uint32_t value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3133 | |
| 3134 | // Get and set individual two byte chars in the string. |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 3135 | inline void Set(StringShape shape, int index, uint16_t value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3136 | // Get individual two byte char in the string. Repeated calls |
| 3137 | // to this method are not efficient unless the string is flat. |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 3138 | inline uint16_t Get(StringShape shape, int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3139 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 3140 | // Try to flatten the top level ConsString that is hiding behind this |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3141 | // string. This is a no-op unless the string is a ConsString or a |
| 3142 | // SlicedString. Flatten mutates the ConsString and might return a |
| 3143 | // failure. |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 3144 | Object* TryFlatten(StringShape shape); |
| 3145 | |
| 3146 | // Try to flatten the string. Checks first inline to see if it is necessary. |
| 3147 | // Do not handle allocation failures. After calling TryFlattenIfNotFlat, the |
| 3148 | // string could still be a ConsString, in which case a failure is returned. |
| 3149 | // Use FlattenString from Handles.cc to be sure to flatten. |
| 3150 | inline Object* TryFlattenIfNotFlat(StringShape shape); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3151 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3152 | Vector<const char> ToAsciiVector(); |
| 3153 | Vector<const uc16> ToUC16Vector(); |
| 3154 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3155 | // Mark the string as an undetectable object. It only applies to |
| 3156 | // ascii and two byte string types. |
| 3157 | bool MarkAsUndetectable(); |
| 3158 | |
| 3159 | // Slice the string and return a substring. |
ager@chromium.org | c3e50d8 | 2008-11-05 11:53:10 +0000 | [diff] [blame] | 3160 | Object* Slice(int from, int to); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3161 | |
| 3162 | // String equality operations. |
| 3163 | inline bool Equals(String* other); |
| 3164 | bool IsEqualTo(Vector<const char> str); |
| 3165 | |
| 3166 | // Return a UTF8 representation of the string. The string is null |
| 3167 | // terminated but may optionally contain nulls. Length is returned |
| 3168 | // in length_output if length_output is not a null pointer The string |
| 3169 | // should be nearly flat, otherwise the performance of this method may |
| 3170 | // be very slow (quadratic in the length). Setting robustness_flag to |
| 3171 | // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
| 3172 | // handles unexpected data without causing assert failures and it does not |
| 3173 | // do any heap allocations. This is useful when printing stack traces. |
| 3174 | SmartPointer<char> ToCString(AllowNullsFlag allow_nulls, |
| 3175 | RobustnessFlag robustness_flag, |
| 3176 | int offset, |
| 3177 | int length, |
| 3178 | int* length_output = 0); |
| 3179 | SmartPointer<char> ToCString( |
| 3180 | AllowNullsFlag allow_nulls = DISALLOW_NULLS, |
| 3181 | RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL, |
| 3182 | int* length_output = 0); |
| 3183 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3184 | int Utf8Length(); |
| 3185 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3186 | // Return a 16 bit Unicode representation of the string. |
| 3187 | // The string should be nearly flat, otherwise the performance of |
| 3188 | // of this method may be very bad. Setting robustness_flag to |
| 3189 | // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
| 3190 | // handles unexpected data without causing assert failures and it does not |
| 3191 | // do any heap allocations. This is useful when printing stack traces. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 3192 | SmartPointer<uc16> ToWideCString( |
| 3193 | RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3194 | |
| 3195 | // Tells whether the hash code has been computed. |
| 3196 | inline bool HasHashCode(); |
| 3197 | |
| 3198 | // Returns a hash value used for the property table |
| 3199 | inline uint32_t Hash(); |
| 3200 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3201 | static uint32_t ComputeLengthAndHashField(unibrow::CharacterStream* buffer, |
| 3202 | int length); |
| 3203 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3204 | static bool ComputeArrayIndex(unibrow::CharacterStream* buffer, |
| 3205 | uint32_t* index, |
| 3206 | int length); |
| 3207 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 3208 | // Externalization. |
| 3209 | bool MakeExternal(v8::String::ExternalStringResource* resource); |
| 3210 | bool MakeExternal(v8::String::ExternalAsciiStringResource* resource); |
| 3211 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3212 | // Conversion. |
| 3213 | inline bool AsArrayIndex(uint32_t* index); |
| 3214 | |
| 3215 | // Casting. |
| 3216 | static inline String* cast(Object* obj); |
| 3217 | |
| 3218 | void PrintOn(FILE* out); |
| 3219 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3220 | // For use during stack traces. Performs rudimentary sanity check. |
| 3221 | bool LooksValid(); |
| 3222 | |
| 3223 | // Dispatched behavior. |
| 3224 | void StringShortPrint(StringStream* accumulator); |
| 3225 | #ifdef DEBUG |
| 3226 | void StringPrint(); |
| 3227 | void StringVerify(); |
| 3228 | #endif |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 3229 | inline bool IsFlat(StringShape shape); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3230 | |
| 3231 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 3232 | static const int kLengthOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3233 | static const int kSize = kLengthOffset + kIntSize; |
| 3234 | |
| 3235 | // Limits on sizes of different types of strings. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 3236 | static const int kMaxShortStringSize = 63; |
| 3237 | static const int kMaxMediumStringSize = 16383; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3238 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3239 | static const int kMaxArrayIndexSize = 10; |
| 3240 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3241 | // Max ascii char code. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3242 | static const int kMaxAsciiCharCode = unibrow::Utf8::kMaxOneByteChar; |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame^] | 3243 | static const unsigned kMaxAsciiCharCodeU = unibrow::Utf8::kMaxOneByteChar; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 3244 | static const int kMaxUC16CharCode = 0xffff; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3245 | |
| 3246 | // Minimum length for a cons or sliced string. |
| 3247 | static const int kMinNonFlatLength = 13; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3248 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3249 | // Mask constant for checking if a string has a computed hash code |
| 3250 | // and if it is an array index. The least significant bit indicates |
| 3251 | // whether a hash code has been computed. If the hash code has been |
| 3252 | // computed the 2nd bit tells whether the string can be used as an |
| 3253 | // array index. |
| 3254 | static const int kHashComputedMask = 1; |
| 3255 | static const int kIsArrayIndexMask = 1 << 1; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3256 | static const int kNofLengthBitFields = 2; |
| 3257 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3258 | // Array index strings this short can keep their index in the hash |
| 3259 | // field. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 3260 | static const int kMaxCachedArrayIndexLength = 7; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3261 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3262 | // Shift constants for retriving length and hash code from |
| 3263 | // length/hash field. |
| 3264 | static const int kHashShift = kNofLengthBitFields; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 3265 | static const int kShortLengthShift = kHashShift + kShortStringTag; |
| 3266 | static const int kMediumLengthShift = kHashShift + kMediumStringTag; |
| 3267 | static const int kLongLengthShift = kHashShift + kLongStringTag; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3268 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3269 | // Limit for truncation in short printing. |
| 3270 | static const int kMaxShortPrintLength = 1024; |
| 3271 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3272 | // Support for regular expressions. |
| 3273 | const uc16* GetTwoByteData(); |
| 3274 | const uc16* GetTwoByteData(unsigned start); |
| 3275 | |
| 3276 | // Support for StringInputBuffer |
| 3277 | static const unibrow::byte* ReadBlock(String* input, |
| 3278 | unibrow::byte* util_buffer, |
| 3279 | unsigned capacity, |
| 3280 | unsigned* remaining, |
| 3281 | unsigned* offset); |
| 3282 | static const unibrow::byte* ReadBlock(String** input, |
| 3283 | unibrow::byte* util_buffer, |
| 3284 | unsigned capacity, |
| 3285 | unsigned* remaining, |
| 3286 | unsigned* offset); |
| 3287 | |
| 3288 | // Helper function for flattening strings. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3289 | template <typename sinkchar> |
| 3290 | static void WriteToFlat(String* source, |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 3291 | StringShape shape, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3292 | sinkchar* sink, |
| 3293 | int from, |
| 3294 | int to); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3295 | |
| 3296 | protected: |
| 3297 | class ReadBlockBuffer { |
| 3298 | public: |
| 3299 | ReadBlockBuffer(unibrow::byte* util_buffer_, |
| 3300 | unsigned cursor_, |
| 3301 | unsigned capacity_, |
| 3302 | unsigned remaining_) : |
| 3303 | util_buffer(util_buffer_), |
| 3304 | cursor(cursor_), |
| 3305 | capacity(capacity_), |
| 3306 | remaining(remaining_) { |
| 3307 | } |
| 3308 | unibrow::byte* util_buffer; |
| 3309 | unsigned cursor; |
| 3310 | unsigned capacity; |
| 3311 | unsigned remaining; |
| 3312 | }; |
| 3313 | |
| 3314 | // NOTE: If you call StringInputBuffer routines on strings that are |
| 3315 | // too deeply nested trees of cons and slice strings, then this |
| 3316 | // routine will overflow the stack. Strings that are merely deeply |
| 3317 | // nested trees of cons strings do not have a problem apart from |
| 3318 | // performance. |
| 3319 | |
| 3320 | static inline const unibrow::byte* ReadBlock(String* input, |
| 3321 | ReadBlockBuffer* buffer, |
| 3322 | unsigned* offset, |
| 3323 | unsigned max_chars); |
| 3324 | static void ReadBlockIntoBuffer(String* input, |
| 3325 | ReadBlockBuffer* buffer, |
| 3326 | unsigned* offset_ptr, |
| 3327 | unsigned max_chars); |
| 3328 | |
| 3329 | private: |
| 3330 | // Slow case of String::Equals. This implementation works on any strings |
| 3331 | // but it is most efficient on strings that are almost flat. |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 3332 | bool SlowEquals(StringShape this_shape, |
| 3333 | String* other, |
| 3334 | StringShape other_shape); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3335 | |
| 3336 | // Slow case of AsArrayIndex. |
| 3337 | bool SlowAsArrayIndex(uint32_t* index); |
| 3338 | |
| 3339 | // Compute and set the hash code. |
| 3340 | uint32_t ComputeAndSetHash(); |
| 3341 | |
| 3342 | DISALLOW_IMPLICIT_CONSTRUCTORS(String); |
| 3343 | }; |
| 3344 | |
| 3345 | |
| 3346 | // The SeqString abstract class captures sequential string values. |
| 3347 | class SeqString: public String { |
| 3348 | public: |
| 3349 | |
| 3350 | // Casting. |
| 3351 | static inline SeqString* cast(Object* obj); |
| 3352 | |
| 3353 | // Dispatched behaviour. |
| 3354 | // For regexp code. |
| 3355 | uint16_t* SeqStringGetTwoByteAddress(); |
| 3356 | |
| 3357 | private: |
| 3358 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString); |
| 3359 | }; |
| 3360 | |
| 3361 | |
| 3362 | // The AsciiString class captures sequential ascii string objects. |
| 3363 | // Each character in the AsciiString is an ascii character. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3364 | class SeqAsciiString: public SeqString { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3365 | public: |
| 3366 | // Dispatched behavior. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3367 | inline uint16_t SeqAsciiStringGet(int index); |
| 3368 | inline void SeqAsciiStringSet(int index, uint16_t value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3369 | |
| 3370 | // Get the address of the characters in this string. |
| 3371 | inline Address GetCharsAddress(); |
| 3372 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3373 | inline char* GetChars(); |
| 3374 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3375 | // Casting |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3376 | static inline SeqAsciiString* cast(Object* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3377 | |
| 3378 | // Garbage collection support. This method is called by the |
| 3379 | // garbage collector to compute the actual size of an AsciiString |
| 3380 | // instance. |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 3381 | inline int SeqAsciiStringSize(StringShape shape); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3382 | |
| 3383 | // Computes the size for an AsciiString instance of a given length. |
| 3384 | static int SizeFor(int length) { |
| 3385 | return kHeaderSize + OBJECT_SIZE_ALIGN(length * kCharSize); |
| 3386 | } |
| 3387 | |
| 3388 | // Layout description. |
| 3389 | static const int kHeaderSize = String::kSize; |
| 3390 | |
| 3391 | // Support for StringInputBuffer. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3392 | inline void SeqAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 3393 | unsigned* offset, |
| 3394 | unsigned chars); |
| 3395 | inline const unibrow::byte* SeqAsciiStringReadBlock(unsigned* remaining, |
| 3396 | unsigned* offset, |
| 3397 | unsigned chars); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3398 | |
| 3399 | private: |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3400 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqAsciiString); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3401 | }; |
| 3402 | |
| 3403 | |
| 3404 | // The TwoByteString class captures sequential unicode string objects. |
| 3405 | // Each character in the TwoByteString is a two-byte uint16_t. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3406 | class SeqTwoByteString: public SeqString { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3407 | public: |
| 3408 | // Dispatched behavior. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3409 | inline uint16_t SeqTwoByteStringGet(int index); |
| 3410 | inline void SeqTwoByteStringSet(int index, uint16_t value); |
| 3411 | |
| 3412 | // Get the address of the characters in this string. |
| 3413 | inline Address GetCharsAddress(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3414 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3415 | inline uc16* GetChars(); |
| 3416 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3417 | // For regexp code. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3418 | const uint16_t* SeqTwoByteStringGetData(unsigned start); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3419 | |
| 3420 | // Casting |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3421 | static inline SeqTwoByteString* cast(Object* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3422 | |
| 3423 | // Garbage collection support. This method is called by the |
| 3424 | // garbage collector to compute the actual size of a TwoByteString |
| 3425 | // instance. |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 3426 | inline int SeqTwoByteStringSize(StringShape shape); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3427 | |
| 3428 | // Computes the size for a TwoByteString instance of a given length. |
| 3429 | static int SizeFor(int length) { |
| 3430 | return kHeaderSize + OBJECT_SIZE_ALIGN(length * kShortSize); |
| 3431 | } |
| 3432 | |
| 3433 | // Layout description. |
| 3434 | static const int kHeaderSize = String::kSize; |
| 3435 | |
| 3436 | // Support for StringInputBuffer. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3437 | inline void SeqTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 3438 | unsigned* offset_ptr, |
| 3439 | unsigned chars); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3440 | |
| 3441 | private: |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3442 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqTwoByteString); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3443 | }; |
| 3444 | |
| 3445 | |
| 3446 | // The ConsString class describes string values built by using the |
| 3447 | // addition operator on strings. A ConsString is a pair where the |
| 3448 | // first and second components are pointers to other string values. |
| 3449 | // One or both components of a ConsString can be pointers to other |
| 3450 | // ConsStrings, creating a binary tree of ConsStrings where the leaves |
| 3451 | // are non-ConsString string values. The string value represented by |
| 3452 | // a ConsString can be obtained by concatenating the leaf string |
| 3453 | // values in a left-to-right depth-first traversal of the tree. |
| 3454 | class ConsString: public String { |
| 3455 | public: |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 3456 | // First string of the cons cell. |
| 3457 | inline String* first(); |
| 3458 | // Doesn't check that the result is a string, even in debug mode. This is |
| 3459 | // useful during GC where the mark bits confuse the checks. |
| 3460 | inline Object* unchecked_first(); |
| 3461 | inline void set_first(String* first, |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 3462 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3463 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 3464 | // Second string of the cons cell. |
| 3465 | inline String* second(); |
| 3466 | // Doesn't check that the result is a string, even in debug mode. This is |
| 3467 | // useful during GC where the mark bits confuse the checks. |
| 3468 | inline Object* unchecked_second(); |
| 3469 | inline void set_second(String* second, |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 3470 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3471 | |
| 3472 | // Dispatched behavior. |
| 3473 | uint16_t ConsStringGet(int index); |
| 3474 | |
| 3475 | // Casting. |
| 3476 | static inline ConsString* cast(Object* obj); |
| 3477 | |
| 3478 | // Garbage collection support. This method is called during garbage |
| 3479 | // collection to iterate through the heap pointers in the body of |
| 3480 | // the ConsString. |
| 3481 | void ConsStringIterateBody(ObjectVisitor* v); |
| 3482 | |
| 3483 | // Layout description. |
| 3484 | static const int kFirstOffset = String::kSize; |
| 3485 | static const int kSecondOffset = kFirstOffset + kPointerSize; |
| 3486 | static const int kSize = kSecondOffset + kPointerSize; |
| 3487 | |
| 3488 | // Support for StringInputBuffer. |
| 3489 | inline const unibrow::byte* ConsStringReadBlock(ReadBlockBuffer* buffer, |
| 3490 | unsigned* offset_ptr, |
| 3491 | unsigned chars); |
| 3492 | inline void ConsStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 3493 | unsigned* offset_ptr, |
| 3494 | unsigned chars); |
| 3495 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3496 | // Minimum length for a cons string. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3497 | static const int kMinLength = 13; |
| 3498 | |
| 3499 | private: |
| 3500 | DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString); |
| 3501 | }; |
| 3502 | |
| 3503 | |
| 3504 | // The SlicedString class describes string values that are slices of |
| 3505 | // some other string. SlicedStrings consist of a reference to an |
| 3506 | // underlying heap-allocated string value, a start index, and the |
| 3507 | // length field common to all strings. |
| 3508 | class SlicedString: public String { |
| 3509 | public: |
| 3510 | // The underlying string buffer. |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 3511 | inline String* buffer(); |
| 3512 | inline void set_buffer(String* buffer); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3513 | |
| 3514 | // The start index of the slice. |
| 3515 | inline int start(); |
| 3516 | inline void set_start(int start); |
| 3517 | |
| 3518 | // Dispatched behavior. |
| 3519 | uint16_t SlicedStringGet(int index); |
| 3520 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3521 | // Casting. |
| 3522 | static inline SlicedString* cast(Object* obj); |
| 3523 | |
| 3524 | // Garbage collection support. |
| 3525 | void SlicedStringIterateBody(ObjectVisitor* v); |
| 3526 | |
| 3527 | // Layout description |
| 3528 | static const int kBufferOffset = String::kSize; |
| 3529 | static const int kStartOffset = kBufferOffset + kPointerSize; |
| 3530 | static const int kSize = kStartOffset + kIntSize; |
| 3531 | |
| 3532 | // Support for StringInputBuffer. |
| 3533 | inline const unibrow::byte* SlicedStringReadBlock(ReadBlockBuffer* buffer, |
| 3534 | unsigned* offset_ptr, |
| 3535 | unsigned chars); |
| 3536 | inline void SlicedStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 3537 | unsigned* offset_ptr, |
| 3538 | unsigned chars); |
| 3539 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3540 | private: |
| 3541 | DISALLOW_IMPLICIT_CONSTRUCTORS(SlicedString); |
| 3542 | }; |
| 3543 | |
| 3544 | |
| 3545 | // The ExternalString class describes string values that are backed by |
| 3546 | // a string resource that lies outside the V8 heap. ExternalStrings |
| 3547 | // consist of the length field common to all strings, a pointer to the |
| 3548 | // external resource. It is important to ensure (externally) that the |
| 3549 | // resource is not deallocated while the ExternalString is live in the |
| 3550 | // V8 heap. |
| 3551 | // |
| 3552 | // The API expects that all ExternalStrings are created through the |
| 3553 | // API. Therefore, ExternalStrings should not be used internally. |
| 3554 | class ExternalString: public String { |
| 3555 | public: |
| 3556 | // Casting |
| 3557 | static inline ExternalString* cast(Object* obj); |
| 3558 | |
| 3559 | // Layout description. |
| 3560 | static const int kResourceOffset = String::kSize; |
| 3561 | static const int kSize = kResourceOffset + kPointerSize; |
| 3562 | |
| 3563 | private: |
| 3564 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString); |
| 3565 | }; |
| 3566 | |
| 3567 | |
| 3568 | // The ExternalAsciiString class is an external string backed by an |
| 3569 | // ASCII string. |
| 3570 | class ExternalAsciiString: public ExternalString { |
| 3571 | public: |
| 3572 | typedef v8::String::ExternalAsciiStringResource Resource; |
| 3573 | |
| 3574 | // The underlying resource. |
| 3575 | inline Resource* resource(); |
| 3576 | inline void set_resource(Resource* buffer); |
| 3577 | |
| 3578 | // Dispatched behavior. |
| 3579 | uint16_t ExternalAsciiStringGet(int index); |
| 3580 | |
| 3581 | // Casting. |
| 3582 | static inline ExternalAsciiString* cast(Object* obj); |
| 3583 | |
| 3584 | // Support for StringInputBuffer. |
| 3585 | const unibrow::byte* ExternalAsciiStringReadBlock(unsigned* remaining, |
| 3586 | unsigned* offset, |
| 3587 | unsigned chars); |
| 3588 | inline void ExternalAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 3589 | unsigned* offset, |
| 3590 | unsigned chars); |
| 3591 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 3592 | // Identify the map for the external string/symbol with a particular length. |
| 3593 | static inline Map* StringMap(int length); |
| 3594 | static inline Map* SymbolMap(int length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3595 | private: |
| 3596 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalAsciiString); |
| 3597 | }; |
| 3598 | |
| 3599 | |
| 3600 | // The ExternalTwoByteString class is an external string backed by a UTF-16 |
| 3601 | // encoded string. |
| 3602 | class ExternalTwoByteString: public ExternalString { |
| 3603 | public: |
| 3604 | typedef v8::String::ExternalStringResource Resource; |
| 3605 | |
| 3606 | // The underlying string resource. |
| 3607 | inline Resource* resource(); |
| 3608 | inline void set_resource(Resource* buffer); |
| 3609 | |
| 3610 | // Dispatched behavior. |
| 3611 | uint16_t ExternalTwoByteStringGet(int index); |
| 3612 | |
| 3613 | // For regexp code. |
| 3614 | const uint16_t* ExternalTwoByteStringGetData(unsigned start); |
| 3615 | |
| 3616 | // Casting. |
| 3617 | static inline ExternalTwoByteString* cast(Object* obj); |
| 3618 | |
| 3619 | // Support for StringInputBuffer. |
| 3620 | void ExternalTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 3621 | unsigned* offset_ptr, |
| 3622 | unsigned chars); |
| 3623 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 3624 | // Identify the map for the external string/symbol with a particular length. |
| 3625 | static inline Map* StringMap(int length); |
| 3626 | static inline Map* SymbolMap(int length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3627 | private: |
| 3628 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalTwoByteString); |
| 3629 | }; |
| 3630 | |
| 3631 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 3632 | // A flat string reader provides random access to the contents of a |
| 3633 | // string independent of the character width of the string. The handle |
| 3634 | // must be valid as long as the reader is being used. |
| 3635 | class FlatStringReader BASE_EMBEDDED { |
| 3636 | public: |
| 3637 | explicit FlatStringReader(Handle<String> str); |
| 3638 | explicit FlatStringReader(Vector<const char> input); |
| 3639 | ~FlatStringReader(); |
| 3640 | void RefreshState(); |
| 3641 | inline uc32 Get(int index); |
| 3642 | int length() { return length_; } |
| 3643 | static void PostGarbageCollectionProcessing(); |
| 3644 | private: |
| 3645 | String** str_; |
| 3646 | bool is_ascii_; |
| 3647 | int length_; |
| 3648 | const void* start_; |
| 3649 | FlatStringReader* prev_; |
| 3650 | static FlatStringReader* top_; |
| 3651 | }; |
| 3652 | |
| 3653 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3654 | // Note that StringInputBuffers are not valid across a GC! To fix this |
| 3655 | // it would have to store a String Handle instead of a String* and |
| 3656 | // AsciiStringReadBlock would have to be modified to use memcpy. |
| 3657 | // |
| 3658 | // StringInputBuffer is able to traverse any string regardless of how |
| 3659 | // deeply nested a sequence of ConsStrings it is made of. However, |
| 3660 | // performance will be better if deep strings are flattened before they |
| 3661 | // are traversed. Since flattening requires memory allocation this is |
| 3662 | // not always desirable, however (esp. in debugging situations). |
| 3663 | class StringInputBuffer: public unibrow::InputBuffer<String, String*, 1024> { |
| 3664 | public: |
| 3665 | virtual void Seek(unsigned pos); |
| 3666 | inline StringInputBuffer(): unibrow::InputBuffer<String, String*, 1024>() {} |
| 3667 | inline StringInputBuffer(String* backing): |
| 3668 | unibrow::InputBuffer<String, String*, 1024>(backing) {} |
| 3669 | }; |
| 3670 | |
| 3671 | |
| 3672 | class SafeStringInputBuffer |
| 3673 | : public unibrow::InputBuffer<String, String**, 256> { |
| 3674 | public: |
| 3675 | virtual void Seek(unsigned pos); |
| 3676 | inline SafeStringInputBuffer() |
| 3677 | : unibrow::InputBuffer<String, String**, 256>() {} |
| 3678 | inline SafeStringInputBuffer(String** backing) |
| 3679 | : unibrow::InputBuffer<String, String**, 256>(backing) {} |
| 3680 | }; |
| 3681 | |
| 3682 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3683 | template <typename T> |
| 3684 | class VectorIterator { |
| 3685 | public: |
| 3686 | VectorIterator(T* d, int l) : data_(Vector<const T>(d, l)), index_(0) { } |
| 3687 | explicit VectorIterator(Vector<const T> data) : data_(data), index_(0) { } |
| 3688 | T GetNext() { return data_[index_++]; } |
| 3689 | bool has_more() { return index_ < data_.length(); } |
| 3690 | private: |
| 3691 | Vector<const T> data_; |
| 3692 | int index_; |
| 3693 | }; |
| 3694 | |
| 3695 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3696 | // The Oddball describes objects null, undefined, true, and false. |
| 3697 | class Oddball: public HeapObject { |
| 3698 | public: |
| 3699 | // [to_string]: Cached to_string computed at startup. |
| 3700 | DECL_ACCESSORS(to_string, String) |
| 3701 | |
| 3702 | // [to_number]: Cached to_number computed at startup. |
| 3703 | DECL_ACCESSORS(to_number, Object) |
| 3704 | |
| 3705 | // Casting. |
| 3706 | static inline Oddball* cast(Object* obj); |
| 3707 | |
| 3708 | // Dispatched behavior. |
| 3709 | void OddballIterateBody(ObjectVisitor* v); |
| 3710 | #ifdef DEBUG |
| 3711 | void OddballVerify(); |
| 3712 | #endif |
| 3713 | |
| 3714 | // Initialize the fields. |
| 3715 | Object* Initialize(const char* to_string, Object* to_number); |
| 3716 | |
| 3717 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 3718 | static const int kToStringOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3719 | static const int kToNumberOffset = kToStringOffset + kPointerSize; |
| 3720 | static const int kSize = kToNumberOffset + kPointerSize; |
| 3721 | |
| 3722 | private: |
| 3723 | DISALLOW_IMPLICIT_CONSTRUCTORS(Oddball); |
| 3724 | }; |
| 3725 | |
| 3726 | |
| 3727 | // Proxy describes objects pointing from JavaScript to C structures. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 3728 | // Since they cannot contain references to JS HeapObjects they can be |
| 3729 | // placed in old_data_space. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3730 | class Proxy: public HeapObject { |
| 3731 | public: |
| 3732 | // [proxy]: field containing the address. |
| 3733 | inline Address proxy(); |
| 3734 | inline void set_proxy(Address value); |
| 3735 | |
| 3736 | // Casting. |
| 3737 | static inline Proxy* cast(Object* obj); |
| 3738 | |
| 3739 | // Dispatched behavior. |
| 3740 | inline void ProxyIterateBody(ObjectVisitor* v); |
| 3741 | #ifdef DEBUG |
| 3742 | void ProxyPrint(); |
| 3743 | void ProxyVerify(); |
| 3744 | #endif |
| 3745 | |
| 3746 | // Layout description. |
| 3747 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 3748 | static const int kProxyOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3749 | static const int kSize = kProxyOffset + kPointerSize; |
| 3750 | |
| 3751 | private: |
| 3752 | DISALLOW_IMPLICIT_CONSTRUCTORS(Proxy); |
| 3753 | }; |
| 3754 | |
| 3755 | |
| 3756 | // The JSArray describes JavaScript Arrays |
| 3757 | // Such an array can be in one of two modes: |
| 3758 | // - fast, backing storage is a FixedArray and length <= elements.length(); |
| 3759 | // Please note: push and pop can be used to grow and shrink the array. |
| 3760 | // - slow, backing storage is a HashTable with numbers as keys. |
| 3761 | class JSArray: public JSObject { |
| 3762 | public: |
| 3763 | // [length]: The length property. |
| 3764 | DECL_ACCESSORS(length, Object) |
| 3765 | |
| 3766 | Object* JSArrayUpdateLengthFromIndex(uint32_t index, Object* value); |
| 3767 | |
| 3768 | // Initialize the array with the given capacity. The function may |
| 3769 | // fail due to out-of-memory situations, but only if the requested |
| 3770 | // capacity is non-zero. |
| 3771 | Object* Initialize(int capacity); |
| 3772 | |
| 3773 | // Set the content of the array to the content of storage. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3774 | inline void SetContent(FixedArray* storage); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3775 | |
| 3776 | // Support for sorting |
| 3777 | Object* RemoveHoles(); |
| 3778 | |
| 3779 | // Casting. |
| 3780 | static inline JSArray* cast(Object* obj); |
| 3781 | |
| 3782 | // Dispatched behavior. |
| 3783 | #ifdef DEBUG |
| 3784 | void JSArrayPrint(); |
| 3785 | void JSArrayVerify(); |
| 3786 | #endif |
| 3787 | |
| 3788 | // Layout description. |
| 3789 | static const int kLengthOffset = JSObject::kHeaderSize; |
| 3790 | static const int kSize = kLengthOffset + kPointerSize; |
| 3791 | |
| 3792 | private: |
| 3793 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSArray); |
| 3794 | }; |
| 3795 | |
| 3796 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3797 | // An accessor must have a getter, but can have no setter. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3798 | // |
| 3799 | // When setting a property, V8 searches accessors in prototypes. |
| 3800 | // If an accessor was found and it does not have a setter, |
| 3801 | // the request is ignored. |
| 3802 | // |
| 3803 | // To allow shadow an accessor property, the accessor can |
| 3804 | // have READ_ONLY property attribute so that a new value |
| 3805 | // is added to the local object to shadow the accessor |
| 3806 | // in prototypes. |
| 3807 | class AccessorInfo: public Struct { |
| 3808 | public: |
| 3809 | DECL_ACCESSORS(getter, Object) |
| 3810 | DECL_ACCESSORS(setter, Object) |
| 3811 | DECL_ACCESSORS(data, Object) |
| 3812 | DECL_ACCESSORS(name, Object) |
| 3813 | DECL_ACCESSORS(flag, Smi) |
| 3814 | |
| 3815 | inline bool all_can_read(); |
| 3816 | inline void set_all_can_read(bool value); |
| 3817 | |
| 3818 | inline bool all_can_write(); |
| 3819 | inline void set_all_can_write(bool value); |
| 3820 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 3821 | inline bool prohibits_overwriting(); |
| 3822 | inline void set_prohibits_overwriting(bool value); |
| 3823 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3824 | inline PropertyAttributes property_attributes(); |
| 3825 | inline void set_property_attributes(PropertyAttributes attributes); |
| 3826 | |
| 3827 | static inline AccessorInfo* cast(Object* obj); |
| 3828 | |
| 3829 | #ifdef DEBUG |
| 3830 | void AccessorInfoPrint(); |
| 3831 | void AccessorInfoVerify(); |
| 3832 | #endif |
| 3833 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 3834 | static const int kGetterOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3835 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 3836 | static const int kDataOffset = kSetterOffset + kPointerSize; |
| 3837 | static const int kNameOffset = kDataOffset + kPointerSize; |
| 3838 | static const int kFlagOffset = kNameOffset + kPointerSize; |
| 3839 | static const int kSize = kFlagOffset + kPointerSize; |
| 3840 | |
| 3841 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3842 | // Bit positions in flag. |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 3843 | static const int kAllCanReadBit = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3844 | static const int kAllCanWriteBit = 1; |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 3845 | static const int kProhibitsOverwritingBit = 2; |
| 3846 | class AttributesField: public BitField<PropertyAttributes, 3, 3> {}; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 3847 | |
| 3848 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorInfo); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3849 | }; |
| 3850 | |
| 3851 | |
| 3852 | class AccessCheckInfo: public Struct { |
| 3853 | public: |
| 3854 | DECL_ACCESSORS(named_callback, Object) |
| 3855 | DECL_ACCESSORS(indexed_callback, Object) |
| 3856 | DECL_ACCESSORS(data, Object) |
| 3857 | |
| 3858 | static inline AccessCheckInfo* cast(Object* obj); |
| 3859 | |
| 3860 | #ifdef DEBUG |
| 3861 | void AccessCheckInfoPrint(); |
| 3862 | void AccessCheckInfoVerify(); |
| 3863 | #endif |
| 3864 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 3865 | static const int kNamedCallbackOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3866 | static const int kIndexedCallbackOffset = kNamedCallbackOffset + kPointerSize; |
| 3867 | static const int kDataOffset = kIndexedCallbackOffset + kPointerSize; |
| 3868 | static const int kSize = kDataOffset + kPointerSize; |
| 3869 | |
| 3870 | private: |
| 3871 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessCheckInfo); |
| 3872 | }; |
| 3873 | |
| 3874 | |
| 3875 | class InterceptorInfo: public Struct { |
| 3876 | public: |
| 3877 | DECL_ACCESSORS(getter, Object) |
| 3878 | DECL_ACCESSORS(setter, Object) |
| 3879 | DECL_ACCESSORS(query, Object) |
| 3880 | DECL_ACCESSORS(deleter, Object) |
| 3881 | DECL_ACCESSORS(enumerator, Object) |
| 3882 | DECL_ACCESSORS(data, Object) |
| 3883 | |
| 3884 | static inline InterceptorInfo* cast(Object* obj); |
| 3885 | |
| 3886 | #ifdef DEBUG |
| 3887 | void InterceptorInfoPrint(); |
| 3888 | void InterceptorInfoVerify(); |
| 3889 | #endif |
| 3890 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 3891 | static const int kGetterOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3892 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 3893 | static const int kQueryOffset = kSetterOffset + kPointerSize; |
| 3894 | static const int kDeleterOffset = kQueryOffset + kPointerSize; |
| 3895 | static const int kEnumeratorOffset = kDeleterOffset + kPointerSize; |
| 3896 | static const int kDataOffset = kEnumeratorOffset + kPointerSize; |
| 3897 | static const int kSize = kDataOffset + kPointerSize; |
| 3898 | |
| 3899 | private: |
| 3900 | DISALLOW_IMPLICIT_CONSTRUCTORS(InterceptorInfo); |
| 3901 | }; |
| 3902 | |
| 3903 | |
| 3904 | class CallHandlerInfo: public Struct { |
| 3905 | public: |
| 3906 | DECL_ACCESSORS(callback, Object) |
| 3907 | DECL_ACCESSORS(data, Object) |
| 3908 | |
| 3909 | static inline CallHandlerInfo* cast(Object* obj); |
| 3910 | |
| 3911 | #ifdef DEBUG |
| 3912 | void CallHandlerInfoPrint(); |
| 3913 | void CallHandlerInfoVerify(); |
| 3914 | #endif |
| 3915 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 3916 | static const int kCallbackOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3917 | static const int kDataOffset = kCallbackOffset + kPointerSize; |
| 3918 | static const int kSize = kDataOffset + kPointerSize; |
| 3919 | |
| 3920 | private: |
| 3921 | DISALLOW_IMPLICIT_CONSTRUCTORS(CallHandlerInfo); |
| 3922 | }; |
| 3923 | |
| 3924 | |
| 3925 | class TemplateInfo: public Struct { |
| 3926 | public: |
| 3927 | DECL_ACCESSORS(tag, Object) |
| 3928 | DECL_ACCESSORS(property_list, Object) |
| 3929 | |
| 3930 | #ifdef DEBUG |
| 3931 | void TemplateInfoVerify(); |
| 3932 | #endif |
| 3933 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 3934 | static const int kTagOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3935 | static const int kPropertyListOffset = kTagOffset + kPointerSize; |
| 3936 | static const int kHeaderSize = kPropertyListOffset + kPointerSize; |
| 3937 | protected: |
| 3938 | friend class AGCCVersionRequiresThisClassToHaveAFriendSoHereItIs; |
| 3939 | DISALLOW_IMPLICIT_CONSTRUCTORS(TemplateInfo); |
| 3940 | }; |
| 3941 | |
| 3942 | |
| 3943 | class FunctionTemplateInfo: public TemplateInfo { |
| 3944 | public: |
| 3945 | DECL_ACCESSORS(serial_number, Object) |
| 3946 | DECL_ACCESSORS(call_code, Object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3947 | DECL_ACCESSORS(property_accessors, Object) |
| 3948 | DECL_ACCESSORS(prototype_template, Object) |
| 3949 | DECL_ACCESSORS(parent_template, Object) |
| 3950 | DECL_ACCESSORS(named_property_handler, Object) |
| 3951 | DECL_ACCESSORS(indexed_property_handler, Object) |
| 3952 | DECL_ACCESSORS(instance_template, Object) |
| 3953 | DECL_ACCESSORS(class_name, Object) |
| 3954 | DECL_ACCESSORS(signature, Object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3955 | DECL_ACCESSORS(instance_call_handler, Object) |
| 3956 | DECL_ACCESSORS(access_check_info, Object) |
| 3957 | DECL_ACCESSORS(flag, Smi) |
| 3958 | |
| 3959 | // Following properties use flag bits. |
| 3960 | DECL_BOOLEAN_ACCESSORS(hidden_prototype) |
| 3961 | DECL_BOOLEAN_ACCESSORS(undetectable) |
| 3962 | // If the bit is set, object instances created by this function |
| 3963 | // requires access check. |
| 3964 | DECL_BOOLEAN_ACCESSORS(needs_access_check) |
| 3965 | |
| 3966 | static inline FunctionTemplateInfo* cast(Object* obj); |
| 3967 | |
| 3968 | #ifdef DEBUG |
| 3969 | void FunctionTemplateInfoPrint(); |
| 3970 | void FunctionTemplateInfoVerify(); |
| 3971 | #endif |
| 3972 | |
| 3973 | static const int kSerialNumberOffset = TemplateInfo::kHeaderSize; |
| 3974 | static const int kCallCodeOffset = kSerialNumberOffset + kPointerSize; |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 3975 | static const int kPropertyAccessorsOffset = kCallCodeOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3976 | static const int kPrototypeTemplateOffset = |
| 3977 | kPropertyAccessorsOffset + kPointerSize; |
| 3978 | static const int kParentTemplateOffset = |
| 3979 | kPrototypeTemplateOffset + kPointerSize; |
| 3980 | static const int kNamedPropertyHandlerOffset = |
| 3981 | kParentTemplateOffset + kPointerSize; |
| 3982 | static const int kIndexedPropertyHandlerOffset = |
| 3983 | kNamedPropertyHandlerOffset + kPointerSize; |
| 3984 | static const int kInstanceTemplateOffset = |
| 3985 | kIndexedPropertyHandlerOffset + kPointerSize; |
| 3986 | static const int kClassNameOffset = kInstanceTemplateOffset + kPointerSize; |
| 3987 | static const int kSignatureOffset = kClassNameOffset + kPointerSize; |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 3988 | static const int kInstanceCallHandlerOffset = kSignatureOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3989 | static const int kAccessCheckInfoOffset = |
| 3990 | kInstanceCallHandlerOffset + kPointerSize; |
| 3991 | static const int kFlagOffset = kAccessCheckInfoOffset + kPointerSize; |
| 3992 | static const int kSize = kFlagOffset + kPointerSize; |
| 3993 | |
| 3994 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3995 | // Bit position in the flag, from least significant bit position. |
| 3996 | static const int kHiddenPrototypeBit = 0; |
| 3997 | static const int kUndetectableBit = 1; |
| 3998 | static const int kNeedsAccessCheckBit = 2; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 3999 | |
| 4000 | DISALLOW_IMPLICIT_CONSTRUCTORS(FunctionTemplateInfo); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4001 | }; |
| 4002 | |
| 4003 | |
| 4004 | class ObjectTemplateInfo: public TemplateInfo { |
| 4005 | public: |
| 4006 | DECL_ACCESSORS(constructor, Object) |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 4007 | DECL_ACCESSORS(internal_field_count, Object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4008 | |
| 4009 | static inline ObjectTemplateInfo* cast(Object* obj); |
| 4010 | |
| 4011 | #ifdef DEBUG |
| 4012 | void ObjectTemplateInfoPrint(); |
| 4013 | void ObjectTemplateInfoVerify(); |
| 4014 | #endif |
| 4015 | |
| 4016 | static const int kConstructorOffset = TemplateInfo::kHeaderSize; |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 4017 | static const int kInternalFieldCountOffset = |
| 4018 | kConstructorOffset + kPointerSize; |
| 4019 | static const int kSize = kInternalFieldCountOffset + kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4020 | }; |
| 4021 | |
| 4022 | |
| 4023 | class SignatureInfo: public Struct { |
| 4024 | public: |
| 4025 | DECL_ACCESSORS(receiver, Object) |
| 4026 | DECL_ACCESSORS(args, Object) |
| 4027 | |
| 4028 | static inline SignatureInfo* cast(Object* obj); |
| 4029 | |
| 4030 | #ifdef DEBUG |
| 4031 | void SignatureInfoPrint(); |
| 4032 | void SignatureInfoVerify(); |
| 4033 | #endif |
| 4034 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 4035 | static const int kReceiverOffset = Struct::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4036 | static const int kArgsOffset = kReceiverOffset + kPointerSize; |
| 4037 | static const int kSize = kArgsOffset + kPointerSize; |
| 4038 | |
| 4039 | private: |
| 4040 | DISALLOW_IMPLICIT_CONSTRUCTORS(SignatureInfo); |
| 4041 | }; |
| 4042 | |
| 4043 | |
| 4044 | class TypeSwitchInfo: public Struct { |
| 4045 | public: |
| 4046 | DECL_ACCESSORS(types, Object) |
| 4047 | |
| 4048 | static inline TypeSwitchInfo* cast(Object* obj); |
| 4049 | |
| 4050 | #ifdef DEBUG |
| 4051 | void TypeSwitchInfoPrint(); |
| 4052 | void TypeSwitchInfoVerify(); |
| 4053 | #endif |
| 4054 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 4055 | static const int kTypesOffset = Struct::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4056 | static const int kSize = kTypesOffset + kPointerSize; |
| 4057 | }; |
| 4058 | |
| 4059 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4060 | // The DebugInfo class holds additional information for a function being |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4061 | // debugged. |
| 4062 | class DebugInfo: public Struct { |
| 4063 | public: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4064 | // The shared function info for the source being debugged. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4065 | DECL_ACCESSORS(shared, SharedFunctionInfo) |
| 4066 | // Code object for the original code. |
| 4067 | DECL_ACCESSORS(original_code, Code) |
| 4068 | // Code object for the patched code. This code object is the code object |
| 4069 | // currently active for the function. |
| 4070 | DECL_ACCESSORS(code, Code) |
| 4071 | // Fixed array holding status information for each active break point. |
| 4072 | DECL_ACCESSORS(break_points, FixedArray) |
| 4073 | |
| 4074 | // Check if there is a break point at a code position. |
| 4075 | bool HasBreakPoint(int code_position); |
| 4076 | // Get the break point info object for a code position. |
| 4077 | Object* GetBreakPointInfo(int code_position); |
| 4078 | // Clear a break point. |
| 4079 | static void ClearBreakPoint(Handle<DebugInfo> debug_info, |
| 4080 | int code_position, |
| 4081 | Handle<Object> break_point_object); |
| 4082 | // Set a break point. |
| 4083 | static void SetBreakPoint(Handle<DebugInfo> debug_info, int code_position, |
| 4084 | int source_position, int statement_position, |
| 4085 | Handle<Object> break_point_object); |
| 4086 | // Get the break point objects for a code position. |
| 4087 | Object* GetBreakPointObjects(int code_position); |
| 4088 | // Find the break point info holding this break point object. |
| 4089 | static Object* FindBreakPointInfo(Handle<DebugInfo> debug_info, |
| 4090 | Handle<Object> break_point_object); |
| 4091 | // Get the number of break points for this function. |
| 4092 | int GetBreakPointCount(); |
| 4093 | |
| 4094 | static inline DebugInfo* cast(Object* obj); |
| 4095 | |
| 4096 | #ifdef DEBUG |
| 4097 | void DebugInfoPrint(); |
| 4098 | void DebugInfoVerify(); |
| 4099 | #endif |
| 4100 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 4101 | static const int kSharedFunctionInfoIndex = Struct::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4102 | static const int kOriginalCodeIndex = kSharedFunctionInfoIndex + kPointerSize; |
| 4103 | static const int kPatchedCodeIndex = kOriginalCodeIndex + kPointerSize; |
| 4104 | static const int kActiveBreakPointsCountIndex = |
| 4105 | kPatchedCodeIndex + kPointerSize; |
| 4106 | static const int kBreakPointsStateIndex = |
| 4107 | kActiveBreakPointsCountIndex + kPointerSize; |
| 4108 | static const int kSize = kBreakPointsStateIndex + kPointerSize; |
| 4109 | |
| 4110 | private: |
| 4111 | static const int kNoBreakPointInfo = -1; |
| 4112 | |
| 4113 | // Lookup the index in the break_points array for a code position. |
| 4114 | int GetBreakPointInfoIndex(int code_position); |
| 4115 | |
| 4116 | DISALLOW_IMPLICIT_CONSTRUCTORS(DebugInfo); |
| 4117 | }; |
| 4118 | |
| 4119 | |
| 4120 | // The BreakPointInfo class holds information for break points set in a |
| 4121 | // function. The DebugInfo object holds a BreakPointInfo object for each code |
| 4122 | // position with one or more break points. |
| 4123 | class BreakPointInfo: public Struct { |
| 4124 | public: |
| 4125 | // The position in the code for the break point. |
| 4126 | DECL_ACCESSORS(code_position, Smi) |
| 4127 | // The position in the source for the break position. |
| 4128 | DECL_ACCESSORS(source_position, Smi) |
| 4129 | // The position in the source for the last statement before this break |
| 4130 | // position. |
| 4131 | DECL_ACCESSORS(statement_position, Smi) |
| 4132 | // List of related JavaScript break points. |
| 4133 | DECL_ACCESSORS(break_point_objects, Object) |
| 4134 | |
| 4135 | // Removes a break point. |
| 4136 | static void ClearBreakPoint(Handle<BreakPointInfo> info, |
| 4137 | Handle<Object> break_point_object); |
| 4138 | // Set a break point. |
| 4139 | static void SetBreakPoint(Handle<BreakPointInfo> info, |
| 4140 | Handle<Object> break_point_object); |
| 4141 | // Check if break point info has this break point object. |
| 4142 | static bool HasBreakPointObject(Handle<BreakPointInfo> info, |
| 4143 | Handle<Object> break_point_object); |
| 4144 | // Get the number of break points for this code position. |
| 4145 | int GetBreakPointCount(); |
| 4146 | |
| 4147 | static inline BreakPointInfo* cast(Object* obj); |
| 4148 | |
| 4149 | #ifdef DEBUG |
| 4150 | void BreakPointInfoPrint(); |
| 4151 | void BreakPointInfoVerify(); |
| 4152 | #endif |
| 4153 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 4154 | static const int kCodePositionIndex = Struct::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4155 | static const int kSourcePositionIndex = kCodePositionIndex + kPointerSize; |
| 4156 | static const int kStatementPositionIndex = |
| 4157 | kSourcePositionIndex + kPointerSize; |
| 4158 | static const int kBreakPointObjectsIndex = |
| 4159 | kStatementPositionIndex + kPointerSize; |
| 4160 | static const int kSize = kBreakPointObjectsIndex + kPointerSize; |
| 4161 | |
| 4162 | private: |
| 4163 | DISALLOW_IMPLICIT_CONSTRUCTORS(BreakPointInfo); |
| 4164 | }; |
| 4165 | |
| 4166 | |
| 4167 | #undef DECL_BOOLEAN_ACCESSORS |
| 4168 | #undef DECL_ACCESSORS |
| 4169 | |
| 4170 | |
| 4171 | // Abstract base class for visiting, and optionally modifying, the |
| 4172 | // pointers contained in Objects. Used in GC and serialization/deserialization. |
| 4173 | class ObjectVisitor BASE_EMBEDDED { |
| 4174 | public: |
| 4175 | virtual ~ObjectVisitor() {} |
| 4176 | |
| 4177 | // Visits a contiguous arrays of pointers in the half-open range |
| 4178 | // [start, end). Any or all of the values may be modified on return. |
| 4179 | virtual void VisitPointers(Object** start, Object** end) = 0; |
| 4180 | |
| 4181 | // To allow lazy clearing of inline caches the visitor has |
| 4182 | // a rich interface for iterating over Code objects.. |
| 4183 | |
| 4184 | // Called prior to visiting the body of a Code object. |
| 4185 | virtual void BeginCodeIteration(Code* code); |
| 4186 | |
| 4187 | // Visits a code target in the instruction stream. |
| 4188 | virtual void VisitCodeTarget(RelocInfo* rinfo); |
| 4189 | |
| 4190 | // Visits a runtime entry in the instruction stream. |
| 4191 | virtual void VisitRuntimeEntry(RelocInfo* rinfo) {} |
| 4192 | |
| 4193 | // Visits a debug call target in the instruction stream. |
| 4194 | virtual void VisitDebugTarget(RelocInfo* rinfo); |
| 4195 | |
| 4196 | // Called after completing visiting the body of a Code object. |
| 4197 | virtual void EndCodeIteration(Code* code) {} |
| 4198 | |
| 4199 | // Handy shorthand for visiting a single pointer. |
| 4200 | virtual void VisitPointer(Object** p) { VisitPointers(p, p + 1); } |
| 4201 | |
| 4202 | // Visits a contiguous arrays of external references (references to the C++ |
| 4203 | // heap) in the half-open range [start, end). Any or all of the values |
| 4204 | // may be modified on return. |
| 4205 | virtual void VisitExternalReferences(Address* start, Address* end) {} |
| 4206 | |
| 4207 | inline void VisitExternalReference(Address* p) { |
| 4208 | VisitExternalReferences(p, p + 1); |
| 4209 | } |
| 4210 | |
| 4211 | #ifdef DEBUG |
| 4212 | // Intended for serialization/deserialization checking: insert, or |
| 4213 | // check for the presence of, a tag at this position in the stream. |
| 4214 | virtual void Synchronize(const char* tag) {} |
| 4215 | #endif |
| 4216 | }; |
| 4217 | |
| 4218 | |
| 4219 | // BooleanBit is a helper class for setting and getting a bit in an |
| 4220 | // integer or Smi. |
| 4221 | class BooleanBit : public AllStatic { |
| 4222 | public: |
| 4223 | static inline bool get(Smi* smi, int bit_position) { |
| 4224 | return get(smi->value(), bit_position); |
| 4225 | } |
| 4226 | |
| 4227 | static inline bool get(int value, int bit_position) { |
| 4228 | return (value & (1 << bit_position)) != 0; |
| 4229 | } |
| 4230 | |
| 4231 | static inline Smi* set(Smi* smi, int bit_position, bool v) { |
| 4232 | return Smi::FromInt(set(smi->value(), bit_position, v)); |
| 4233 | } |
| 4234 | |
| 4235 | static inline int set(int value, int bit_position, bool v) { |
| 4236 | if (v) { |
| 4237 | value |= (1 << bit_position); |
| 4238 | } else { |
| 4239 | value &= ~(1 << bit_position); |
| 4240 | } |
| 4241 | return value; |
| 4242 | } |
| 4243 | }; |
| 4244 | |
| 4245 | } } // namespace v8::internal |
| 4246 | |
| 4247 | #endif // V8_OBJECTS_H_ |