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