erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_OBJECTS_H_ |
| 29 | #define V8_OBJECTS_H_ |
| 30 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 31 | #include "allocation.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 32 | #include "builtins.h" |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 33 | #include "elements-kind.h" |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 34 | #include "list.h" |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 35 | #include "property-details.h" |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 36 | #include "smart-array-pointer.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 37 | #include "unicode-inl.h" |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 38 | #if V8_TARGET_ARCH_ARM |
| 39 | #include "arm/constants-arm.h" |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 40 | #elif V8_TARGET_ARCH_MIPS |
| 41 | #include "mips/constants-mips.h" |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 42 | #endif |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 43 | #include "v8checks.h" |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 44 | #include "zone.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 45 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 46 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 47 | // |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 48 | // Most object types in the V8 JavaScript are described in this file. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 49 | // |
| 50 | // Inheritance hierarchy: |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 51 | // - MaybeObject (an object or a failure) |
| 52 | // - Failure (immediate for marking failed operation) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 53 | // - Object |
| 54 | // - Smi (immediate small integer) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 55 | // - HeapObject (superclass for everything allocated in the heap) |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 56 | // - JSReceiver (suitable for property access) |
| 57 | // - JSObject |
| 58 | // - JSArray |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 59 | // - JSSet |
| 60 | // - JSMap |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 61 | // - JSWeakMap |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 62 | // - JSRegExp |
| 63 | // - JSFunction |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 64 | // - JSModule |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 65 | // - GlobalObject |
| 66 | // - JSGlobalObject |
| 67 | // - JSBuiltinsObject |
| 68 | // - JSGlobalProxy |
| 69 | // - JSValue |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 70 | // - JSDate |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 71 | // - JSMessageObject |
| 72 | // - JSProxy |
| 73 | // - JSFunctionProxy |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 74 | // - FixedArrayBase |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 75 | // - ByteArray |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 76 | // - FixedArray |
| 77 | // - DescriptorArray |
| 78 | // - HashTable |
| 79 | // - Dictionary |
| 80 | // - SymbolTable |
| 81 | // - CompilationCacheTable |
| 82 | // - CodeCacheHashTable |
| 83 | // - MapCache |
| 84 | // - Context |
| 85 | // - JSFunctionResultCache |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 86 | // - ScopeInfo |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 87 | // - FixedDoubleArray |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 88 | // - ExternalArray |
| 89 | // - ExternalPixelArray |
| 90 | // - ExternalByteArray |
| 91 | // - ExternalUnsignedByteArray |
| 92 | // - ExternalShortArray |
| 93 | // - ExternalUnsignedShortArray |
| 94 | // - ExternalIntArray |
| 95 | // - ExternalUnsignedIntArray |
| 96 | // - ExternalFloatArray |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 97 | // - String |
| 98 | // - SeqString |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 99 | // - SeqAsciiString |
| 100 | // - SeqTwoByteString |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 101 | // - SlicedString |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 102 | // - ConsString |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 103 | // - ExternalString |
| 104 | // - ExternalAsciiString |
| 105 | // - ExternalTwoByteString |
| 106 | // - HeapNumber |
| 107 | // - Code |
| 108 | // - Map |
| 109 | // - Oddball |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 110 | // - Foreign |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 111 | // - SharedFunctionInfo |
| 112 | // - Struct |
| 113 | // - AccessorInfo |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 114 | // - AccessorPair |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 115 | // - AccessCheckInfo |
| 116 | // - InterceptorInfo |
| 117 | // - CallHandlerInfo |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 118 | // - TemplateInfo |
| 119 | // - FunctionTemplateInfo |
| 120 | // - ObjectTemplateInfo |
| 121 | // - Script |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 122 | // - SignatureInfo |
| 123 | // - TypeSwitchInfo |
| 124 | // - DebugInfo |
| 125 | // - BreakPointInfo |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 126 | // - CodeCache |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 127 | // |
| 128 | // Formats of Object*: |
| 129 | // Smi: [31 bit signed int] 0 |
| 130 | // HeapObject: [32 bit direct pointer] (4 byte aligned) | 01 |
| 131 | // Failure: [30 bit signed int] 11 |
| 132 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 133 | namespace v8 { |
| 134 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 135 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 136 | enum CompareMapMode { |
| 137 | REQUIRE_EXACT_MAP, |
| 138 | ALLOW_ELEMENT_TRANSITION_MAPS |
| 139 | }; |
| 140 | |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 141 | enum KeyedAccessGrowMode { |
| 142 | DO_NOT_ALLOW_JSARRAY_GROWTH, |
| 143 | ALLOW_JSARRAY_GROWTH |
| 144 | }; |
| 145 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 146 | // Setter that skips the write barrier if mode is SKIP_WRITE_BARRIER. |
| 147 | enum WriteBarrierMode { SKIP_WRITE_BARRIER, UPDATE_WRITE_BARRIER }; |
| 148 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 149 | |
| 150 | // PropertyNormalizationMode is used to specify whether to keep |
| 151 | // inobject properties when normalizing properties of a JSObject. |
| 152 | enum PropertyNormalizationMode { |
| 153 | CLEAR_INOBJECT_PROPERTIES, |
| 154 | KEEP_INOBJECT_PROPERTIES |
| 155 | }; |
| 156 | |
| 157 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 158 | // NormalizedMapSharingMode is used to specify whether a map may be shared |
| 159 | // by different objects with normalized properties. |
| 160 | enum NormalizedMapSharingMode { |
| 161 | UNIQUE_NORMALIZED_MAP, |
| 162 | SHARED_NORMALIZED_MAP |
| 163 | }; |
| 164 | |
| 165 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 166 | // Indicates whether a get method should implicitly create the object looked up. |
| 167 | enum CreationFlag { |
| 168 | ALLOW_CREATION, |
| 169 | OMIT_CREATION |
| 170 | }; |
| 171 | |
| 172 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 173 | // Indicates whether the search function should expect a sorted or an unsorted |
| 174 | // array as input. |
| 175 | enum SearchMode { |
| 176 | EXPECT_SORTED, |
| 177 | EXPECT_UNSORTED |
| 178 | }; |
| 179 | |
| 180 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame^] | 181 | // Indicates whether transitions can be added to a source map or not. |
| 182 | enum TransitionFlag { |
| 183 | INSERT_TRANSITION, |
| 184 | OMIT_TRANSITION |
| 185 | }; |
| 186 | |
| 187 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 188 | // Instance size sentinel for objects of variable size. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 189 | const int kVariableSizeSentinel = 0; |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 190 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 191 | const int kStubMajorKeyBits = 6; |
| 192 | const int kStubMinorKeyBits = kBitsPerInt - kSmiTagSize - kStubMajorKeyBits; |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 193 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 194 | // All Maps have a field instance_type containing a InstanceType. |
| 195 | // It describes the type of the instances. |
| 196 | // |
| 197 | // As an example, a JavaScript object is a heap object and its map |
| 198 | // instance_type is JS_OBJECT_TYPE. |
| 199 | // |
| 200 | // The names of the string instance types are intended to systematically |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 201 | // mirror their encoding in the instance_type field of the map. The default |
| 202 | // encoding is considered TWO_BYTE. It is not mentioned in the name. ASCII |
| 203 | // encoding is mentioned explicitly in the name. Likewise, the default |
| 204 | // representation is considered sequential. It is not mentioned in the |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 205 | // name. The other representations (e.g. CONS, EXTERNAL) are explicitly |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 206 | // mentioned. Finally, the string is either a SYMBOL_TYPE (if it is a |
| 207 | // symbol) or a STRING_TYPE (if it is not a symbol). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 208 | // |
| 209 | // NOTE: The following things are some that depend on the string types having |
| 210 | // instance_types that are less than those of all other types: |
| 211 | // HeapObject::Size, HeapObject::IterateBody, the typeof operator, and |
| 212 | // Object::IsString. |
| 213 | // |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 214 | // NOTE: Everything following JS_VALUE_TYPE is considered a |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 215 | // JSObject for GC purposes. The first four entries here have typeof |
| 216 | // 'object', whereas JS_FUNCTION_TYPE has typeof 'function'. |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 217 | #define INSTANCE_TYPE_LIST_ALL(V) \ |
| 218 | V(SYMBOL_TYPE) \ |
| 219 | V(ASCII_SYMBOL_TYPE) \ |
| 220 | V(CONS_SYMBOL_TYPE) \ |
| 221 | V(CONS_ASCII_SYMBOL_TYPE) \ |
| 222 | V(EXTERNAL_SYMBOL_TYPE) \ |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 223 | V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 224 | V(EXTERNAL_ASCII_SYMBOL_TYPE) \ |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 225 | V(SHORT_EXTERNAL_SYMBOL_TYPE) \ |
| 226 | V(SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE) \ |
| 227 | V(SHORT_EXTERNAL_ASCII_SYMBOL_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 228 | V(STRING_TYPE) \ |
| 229 | V(ASCII_STRING_TYPE) \ |
| 230 | V(CONS_STRING_TYPE) \ |
| 231 | V(CONS_ASCII_STRING_TYPE) \ |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 232 | V(SLICED_STRING_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 233 | V(EXTERNAL_STRING_TYPE) \ |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 234 | V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 235 | V(EXTERNAL_ASCII_STRING_TYPE) \ |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 236 | V(SHORT_EXTERNAL_STRING_TYPE) \ |
| 237 | V(SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \ |
| 238 | V(SHORT_EXTERNAL_ASCII_STRING_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 239 | V(PRIVATE_EXTERNAL_ASCII_STRING_TYPE) \ |
| 240 | \ |
| 241 | V(MAP_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 242 | V(CODE_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 243 | V(ODDBALL_TYPE) \ |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 244 | V(JS_GLOBAL_PROPERTY_CELL_TYPE) \ |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 245 | \ |
| 246 | V(HEAP_NUMBER_TYPE) \ |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 247 | V(FOREIGN_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 248 | V(BYTE_ARRAY_TYPE) \ |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 249 | V(FREE_SPACE_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 250 | /* Note: the order of these external array */ \ |
| 251 | /* types is relied upon in */ \ |
| 252 | /* Object::IsExternalArray(). */ \ |
| 253 | V(EXTERNAL_BYTE_ARRAY_TYPE) \ |
| 254 | V(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE) \ |
| 255 | V(EXTERNAL_SHORT_ARRAY_TYPE) \ |
| 256 | V(EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE) \ |
| 257 | V(EXTERNAL_INT_ARRAY_TYPE) \ |
| 258 | V(EXTERNAL_UNSIGNED_INT_ARRAY_TYPE) \ |
| 259 | V(EXTERNAL_FLOAT_ARRAY_TYPE) \ |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 260 | V(EXTERNAL_PIXEL_ARRAY_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 261 | V(FILLER_TYPE) \ |
| 262 | \ |
| 263 | V(ACCESSOR_INFO_TYPE) \ |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 264 | V(ACCESSOR_PAIR_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 265 | V(ACCESS_CHECK_INFO_TYPE) \ |
| 266 | V(INTERCEPTOR_INFO_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 267 | V(CALL_HANDLER_INFO_TYPE) \ |
| 268 | V(FUNCTION_TEMPLATE_INFO_TYPE) \ |
| 269 | V(OBJECT_TEMPLATE_INFO_TYPE) \ |
| 270 | V(SIGNATURE_INFO_TYPE) \ |
| 271 | V(TYPE_SWITCH_INFO_TYPE) \ |
| 272 | V(SCRIPT_TYPE) \ |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 273 | V(CODE_CACHE_TYPE) \ |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 274 | V(POLYMORPHIC_CODE_CACHE_TYPE) \ |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 275 | V(TYPE_FEEDBACK_INFO_TYPE) \ |
| 276 | V(ALIASED_ARGUMENTS_ENTRY_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 277 | \ |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 278 | V(FIXED_ARRAY_TYPE) \ |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 279 | V(FIXED_DOUBLE_ARRAY_TYPE) \ |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 280 | V(SHARED_FUNCTION_INFO_TYPE) \ |
| 281 | \ |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 282 | V(JS_MESSAGE_OBJECT_TYPE) \ |
| 283 | \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 284 | V(JS_VALUE_TYPE) \ |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 285 | V(JS_DATE_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 286 | V(JS_OBJECT_TYPE) \ |
| 287 | V(JS_CONTEXT_EXTENSION_OBJECT_TYPE) \ |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 288 | V(JS_MODULE_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 289 | V(JS_GLOBAL_OBJECT_TYPE) \ |
| 290 | V(JS_BUILTINS_OBJECT_TYPE) \ |
| 291 | V(JS_GLOBAL_PROXY_TYPE) \ |
| 292 | V(JS_ARRAY_TYPE) \ |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 293 | V(JS_PROXY_TYPE) \ |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 294 | V(JS_WEAK_MAP_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 295 | V(JS_REGEXP_TYPE) \ |
| 296 | \ |
| 297 | V(JS_FUNCTION_TYPE) \ |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 298 | V(JS_FUNCTION_PROXY_TYPE) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 299 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 300 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 301 | #define INSTANCE_TYPE_LIST_DEBUGGER(V) \ |
| 302 | V(DEBUG_INFO_TYPE) \ |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 303 | V(BREAK_POINT_INFO_TYPE) |
| 304 | #else |
| 305 | #define INSTANCE_TYPE_LIST_DEBUGGER(V) |
| 306 | #endif |
| 307 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 308 | #define INSTANCE_TYPE_LIST(V) \ |
| 309 | INSTANCE_TYPE_LIST_ALL(V) \ |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 310 | INSTANCE_TYPE_LIST_DEBUGGER(V) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 311 | |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 312 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 313 | // Since string types are not consecutive, this macro is used to |
| 314 | // iterate over them. |
| 315 | #define STRING_TYPE_LIST(V) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 316 | V(SYMBOL_TYPE, \ |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 317 | kVariableSizeSentinel, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 318 | symbol, \ |
| 319 | Symbol) \ |
| 320 | V(ASCII_SYMBOL_TYPE, \ |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 321 | kVariableSizeSentinel, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 322 | ascii_symbol, \ |
| 323 | AsciiSymbol) \ |
| 324 | V(CONS_SYMBOL_TYPE, \ |
| 325 | ConsString::kSize, \ |
| 326 | cons_symbol, \ |
| 327 | ConsSymbol) \ |
| 328 | V(CONS_ASCII_SYMBOL_TYPE, \ |
| 329 | ConsString::kSize, \ |
| 330 | cons_ascii_symbol, \ |
| 331 | ConsAsciiSymbol) \ |
| 332 | V(EXTERNAL_SYMBOL_TYPE, \ |
| 333 | ExternalTwoByteString::kSize, \ |
| 334 | external_symbol, \ |
| 335 | ExternalSymbol) \ |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 336 | V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \ |
| 337 | ExternalTwoByteString::kSize, \ |
| 338 | external_symbol_with_ascii_data, \ |
| 339 | ExternalSymbolWithAsciiData) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 340 | V(EXTERNAL_ASCII_SYMBOL_TYPE, \ |
| 341 | ExternalAsciiString::kSize, \ |
| 342 | external_ascii_symbol, \ |
| 343 | ExternalAsciiSymbol) \ |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 344 | V(SHORT_EXTERNAL_SYMBOL_TYPE, \ |
| 345 | ExternalTwoByteString::kShortSize, \ |
| 346 | short_external_symbol, \ |
| 347 | ShortExternalSymbol) \ |
| 348 | V(SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \ |
| 349 | ExternalTwoByteString::kShortSize, \ |
| 350 | short_external_symbol_with_ascii_data, \ |
| 351 | ShortExternalSymbolWithAsciiData) \ |
| 352 | V(SHORT_EXTERNAL_ASCII_SYMBOL_TYPE, \ |
| 353 | ExternalAsciiString::kShortSize, \ |
| 354 | short_external_ascii_symbol, \ |
| 355 | ShortExternalAsciiSymbol) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 356 | V(STRING_TYPE, \ |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 357 | kVariableSizeSentinel, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 358 | string, \ |
| 359 | String) \ |
| 360 | V(ASCII_STRING_TYPE, \ |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 361 | kVariableSizeSentinel, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 362 | ascii_string, \ |
| 363 | AsciiString) \ |
| 364 | V(CONS_STRING_TYPE, \ |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 365 | ConsString::kSize, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 366 | cons_string, \ |
| 367 | ConsString) \ |
| 368 | V(CONS_ASCII_STRING_TYPE, \ |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 369 | ConsString::kSize, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 370 | cons_ascii_string, \ |
| 371 | ConsAsciiString) \ |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 372 | V(SLICED_STRING_TYPE, \ |
| 373 | SlicedString::kSize, \ |
| 374 | sliced_string, \ |
| 375 | SlicedString) \ |
| 376 | V(SLICED_ASCII_STRING_TYPE, \ |
| 377 | SlicedString::kSize, \ |
| 378 | sliced_ascii_string, \ |
| 379 | SlicedAsciiString) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 380 | V(EXTERNAL_STRING_TYPE, \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 381 | ExternalTwoByteString::kSize, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 382 | external_string, \ |
| 383 | ExternalString) \ |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 384 | V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \ |
| 385 | ExternalTwoByteString::kSize, \ |
| 386 | external_string_with_ascii_data, \ |
| 387 | ExternalStringWithAsciiData) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 388 | V(EXTERNAL_ASCII_STRING_TYPE, \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 389 | ExternalAsciiString::kSize, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 390 | external_ascii_string, \ |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 391 | ExternalAsciiString) \ |
| 392 | V(SHORT_EXTERNAL_STRING_TYPE, \ |
| 393 | ExternalTwoByteString::kShortSize, \ |
| 394 | short_external_string, \ |
| 395 | ShortExternalString) \ |
| 396 | V(SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \ |
| 397 | ExternalTwoByteString::kShortSize, \ |
| 398 | short_external_string_with_ascii_data, \ |
| 399 | ShortExternalStringWithAsciiData) \ |
| 400 | V(SHORT_EXTERNAL_ASCII_STRING_TYPE, \ |
| 401 | ExternalAsciiString::kShortSize, \ |
| 402 | short_external_ascii_string, \ |
| 403 | ShortExternalAsciiString) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 404 | |
| 405 | // A struct is a simple object a set of object-valued fields. Including an |
| 406 | // object type in this causes the compiler to generate most of the boilerplate |
| 407 | // code for the class including allocation and garbage collection routines, |
| 408 | // casts and predicates. All you need to define is the class, methods and |
| 409 | // object verification routines. Easy, no? |
| 410 | // |
| 411 | // Note that for subtle reasons related to the ordering or numerical values of |
| 412 | // type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST |
| 413 | // manually. |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 414 | #define STRUCT_LIST_ALL(V) \ |
| 415 | V(ACCESSOR_INFO, AccessorInfo, accessor_info) \ |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 416 | V(ACCESSOR_PAIR, AccessorPair, accessor_pair) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 417 | V(ACCESS_CHECK_INFO, AccessCheckInfo, access_check_info) \ |
| 418 | V(INTERCEPTOR_INFO, InterceptorInfo, interceptor_info) \ |
| 419 | V(CALL_HANDLER_INFO, CallHandlerInfo, call_handler_info) \ |
| 420 | V(FUNCTION_TEMPLATE_INFO, FunctionTemplateInfo, function_template_info) \ |
| 421 | V(OBJECT_TEMPLATE_INFO, ObjectTemplateInfo, object_template_info) \ |
| 422 | V(SIGNATURE_INFO, SignatureInfo, signature_info) \ |
| 423 | V(TYPE_SWITCH_INFO, TypeSwitchInfo, type_switch_info) \ |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 424 | V(SCRIPT, Script, script) \ |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 425 | V(CODE_CACHE, CodeCache, code_cache) \ |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 426 | V(POLYMORPHIC_CODE_CACHE, PolymorphicCodeCache, polymorphic_code_cache) \ |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 427 | V(TYPE_FEEDBACK_INFO, TypeFeedbackInfo, type_feedback_info) \ |
| 428 | V(ALIASED_ARGUMENTS_ENTRY, AliasedArgumentsEntry, aliased_arguments_entry) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 429 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 430 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 431 | #define STRUCT_LIST_DEBUGGER(V) \ |
| 432 | V(DEBUG_INFO, DebugInfo, debug_info) \ |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 433 | V(BREAK_POINT_INFO, BreakPointInfo, break_point_info) |
| 434 | #else |
| 435 | #define STRUCT_LIST_DEBUGGER(V) |
| 436 | #endif |
| 437 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 438 | #define STRUCT_LIST(V) \ |
| 439 | STRUCT_LIST_ALL(V) \ |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 440 | STRUCT_LIST_DEBUGGER(V) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 441 | |
| 442 | // We use the full 8 bits of the instance_type field to encode heap object |
| 443 | // instance types. The high-order bit (bit 7) is set if the object is not a |
| 444 | // string, and cleared if it is a string. |
| 445 | const uint32_t kIsNotStringMask = 0x80; |
| 446 | const uint32_t kStringTag = 0x0; |
| 447 | const uint32_t kNotStringTag = 0x80; |
| 448 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 449 | // Bit 6 indicates that the object is a symbol (if set) or not (if cleared). |
| 450 | // There are not enough types that the non-string types (with bit 7 set) can |
| 451 | // have bit 6 set too. |
| 452 | const uint32_t kIsSymbolMask = 0x40; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 453 | const uint32_t kNotSymbolTag = 0x0; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 454 | const uint32_t kSymbolTag = 0x40; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 455 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 456 | // If bit 7 is clear then bit 2 indicates whether the string consists of |
| 457 | // two-byte characters or one-byte characters. |
| 458 | const uint32_t kStringEncodingMask = 0x4; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 459 | const uint32_t kTwoByteStringTag = 0x0; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 460 | const uint32_t kAsciiStringTag = 0x4; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 461 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 462 | // 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] | 463 | // of the string. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 464 | const uint32_t kStringRepresentationMask = 0x03; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 465 | enum StringRepresentationTag { |
| 466 | kSeqStringTag = 0x0, |
| 467 | kConsStringTag = 0x1, |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 468 | kExternalStringTag = 0x2, |
| 469 | kSlicedStringTag = 0x3 |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 470 | }; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 471 | const uint32_t kIsIndirectStringMask = 0x1; |
| 472 | const uint32_t kIsIndirectStringTag = 0x1; |
| 473 | STATIC_ASSERT((kSeqStringTag & kIsIndirectStringMask) == 0); |
| 474 | STATIC_ASSERT((kExternalStringTag & kIsIndirectStringMask) == 0); |
| 475 | STATIC_ASSERT( |
| 476 | (kConsStringTag & kIsIndirectStringMask) == kIsIndirectStringTag); |
| 477 | STATIC_ASSERT( |
| 478 | (kSlicedStringTag & kIsIndirectStringMask) == kIsIndirectStringTag); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 479 | |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 480 | // Use this mask to distinguish between cons and slice only after making |
| 481 | // sure that the string is one of the two (an indirect string). |
| 482 | const uint32_t kSlicedNotConsMask = kSlicedStringTag & ~kConsStringTag; |
| 483 | STATIC_ASSERT(IS_POWER_OF_TWO(kSlicedNotConsMask) && kSlicedNotConsMask != 0); |
| 484 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 485 | // If bit 7 is clear, then bit 3 indicates whether this two-byte |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 486 | // string actually contains ASCII data. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 487 | const uint32_t kAsciiDataHintMask = 0x08; |
| 488 | const uint32_t kAsciiDataHintTag = 0x08; |
| 489 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 490 | // If bit 7 is clear and string representation indicates an external string, |
| 491 | // then bit 4 indicates whether the data pointer is cached. |
| 492 | const uint32_t kShortExternalStringMask = 0x10; |
| 493 | const uint32_t kShortExternalStringTag = 0x10; |
| 494 | |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 495 | |
| 496 | // A ConsString with an empty string as the right side is a candidate |
| 497 | // for being shortcut by the garbage collector unless it is a |
| 498 | // symbol. It's not common to have non-flat symbols, so we do not |
| 499 | // shortcut them thereby avoiding turning symbols into strings. See |
| 500 | // heap.cc and mark-compact.cc. |
| 501 | const uint32_t kShortcutTypeMask = |
| 502 | kIsNotStringMask | |
| 503 | kIsSymbolMask | |
| 504 | kStringRepresentationMask; |
| 505 | const uint32_t kShortcutTypeTag = kConsStringTag; |
| 506 | |
| 507 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 508 | enum InstanceType { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 509 | // String types. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 510 | SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kSeqStringTag, |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 511 | ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kSeqStringTag, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 512 | CONS_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kConsStringTag, |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 513 | CONS_ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kConsStringTag, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 514 | SHORT_EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | |
| 515 | kExternalStringTag | kShortExternalStringTag, |
| 516 | SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE = |
| 517 | kTwoByteStringTag | kSymbolTag | kExternalStringTag | |
| 518 | kAsciiDataHintTag | kShortExternalStringTag, |
| 519 | SHORT_EXTERNAL_ASCII_SYMBOL_TYPE = kAsciiStringTag | kExternalStringTag | |
| 520 | kSymbolTag | kShortExternalStringTag, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 521 | EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kExternalStringTag, |
| 522 | EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE = |
| 523 | kTwoByteStringTag | kSymbolTag | kExternalStringTag | kAsciiDataHintTag, |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 524 | EXTERNAL_ASCII_SYMBOL_TYPE = |
| 525 | kAsciiStringTag | kSymbolTag | kExternalStringTag, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 526 | STRING_TYPE = kTwoByteStringTag | kSeqStringTag, |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 527 | ASCII_STRING_TYPE = kAsciiStringTag | kSeqStringTag, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 528 | CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag, |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 529 | CONS_ASCII_STRING_TYPE = kAsciiStringTag | kConsStringTag, |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 530 | SLICED_STRING_TYPE = kTwoByteStringTag | kSlicedStringTag, |
| 531 | SLICED_ASCII_STRING_TYPE = kAsciiStringTag | kSlicedStringTag, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 532 | SHORT_EXTERNAL_STRING_TYPE = |
| 533 | kTwoByteStringTag | kExternalStringTag | kShortExternalStringTag, |
| 534 | SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE = |
| 535 | kTwoByteStringTag | kExternalStringTag | |
| 536 | kAsciiDataHintTag | kShortExternalStringTag, |
| 537 | SHORT_EXTERNAL_ASCII_STRING_TYPE = |
| 538 | kAsciiStringTag | kExternalStringTag | kShortExternalStringTag, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 539 | EXTERNAL_STRING_TYPE = kTwoByteStringTag | kExternalStringTag, |
| 540 | EXTERNAL_STRING_WITH_ASCII_DATA_TYPE = |
| 541 | kTwoByteStringTag | kExternalStringTag | kAsciiDataHintTag, |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 542 | // LAST_STRING_TYPE |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 543 | EXTERNAL_ASCII_STRING_TYPE = kAsciiStringTag | kExternalStringTag, |
| 544 | PRIVATE_EXTERNAL_ASCII_STRING_TYPE = EXTERNAL_ASCII_STRING_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 545 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 546 | // Objects allocated in their own spaces (never in new space). |
| 547 | MAP_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 548 | CODE_TYPE, |
| 549 | ODDBALL_TYPE, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 550 | JS_GLOBAL_PROPERTY_CELL_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 551 | |
| 552 | // "Data", objects that cannot contain non-map-word pointers to heap |
| 553 | // objects. |
| 554 | HEAP_NUMBER_TYPE, |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 555 | FOREIGN_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 556 | BYTE_ARRAY_TYPE, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 557 | FREE_SPACE_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 558 | EXTERNAL_BYTE_ARRAY_TYPE, // FIRST_EXTERNAL_ARRAY_TYPE |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 559 | EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE, |
| 560 | EXTERNAL_SHORT_ARRAY_TYPE, |
| 561 | EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE, |
| 562 | EXTERNAL_INT_ARRAY_TYPE, |
| 563 | EXTERNAL_UNSIGNED_INT_ARRAY_TYPE, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 564 | EXTERNAL_FLOAT_ARRAY_TYPE, |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 565 | EXTERNAL_DOUBLE_ARRAY_TYPE, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 566 | EXTERNAL_PIXEL_ARRAY_TYPE, // LAST_EXTERNAL_ARRAY_TYPE |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 567 | FIXED_DOUBLE_ARRAY_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 568 | FILLER_TYPE, // LAST_DATA_TYPE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 569 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 570 | // Structs. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 571 | ACCESSOR_INFO_TYPE, |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 572 | ACCESSOR_PAIR_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 573 | ACCESS_CHECK_INFO_TYPE, |
| 574 | INTERCEPTOR_INFO_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 575 | CALL_HANDLER_INFO_TYPE, |
| 576 | FUNCTION_TEMPLATE_INFO_TYPE, |
| 577 | OBJECT_TEMPLATE_INFO_TYPE, |
| 578 | SIGNATURE_INFO_TYPE, |
| 579 | TYPE_SWITCH_INFO_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 580 | SCRIPT_TYPE, |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 581 | CODE_CACHE_TYPE, |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 582 | POLYMORPHIC_CODE_CACHE_TYPE, |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 583 | TYPE_FEEDBACK_INFO_TYPE, |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 584 | ALIASED_ARGUMENTS_ENTRY_TYPE, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 585 | // The following two instance types are only used when ENABLE_DEBUGGER_SUPPORT |
| 586 | // is defined. However as include/v8.h contain some of the instance type |
| 587 | // constants always having them avoids them getting different numbers |
| 588 | // depending on whether ENABLE_DEBUGGER_SUPPORT is defined or not. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 589 | DEBUG_INFO_TYPE, |
| 590 | BREAK_POINT_INFO_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 591 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 592 | FIXED_ARRAY_TYPE, |
| 593 | SHARED_FUNCTION_INFO_TYPE, |
| 594 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 595 | JS_MESSAGE_OBJECT_TYPE, |
| 596 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 597 | // All the following types are subtypes of JSReceiver, which corresponds to |
| 598 | // objects in the JS sense. The first and the last type in this range are |
| 599 | // the two forms of function. This organization enables using the same |
| 600 | // compares for checking the JS_RECEIVER/SPEC_OBJECT range and the |
| 601 | // NONCALLABLE_JS_OBJECT range. |
| 602 | JS_FUNCTION_PROXY_TYPE, // FIRST_JS_RECEIVER_TYPE, FIRST_JS_PROXY_TYPE |
| 603 | JS_PROXY_TYPE, // LAST_JS_PROXY_TYPE |
| 604 | |
| 605 | JS_VALUE_TYPE, // FIRST_JS_OBJECT_TYPE |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 606 | JS_DATE_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 607 | JS_OBJECT_TYPE, |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 608 | JS_CONTEXT_EXTENSION_OBJECT_TYPE, |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 609 | JS_MODULE_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 610 | JS_GLOBAL_OBJECT_TYPE, |
| 611 | JS_BUILTINS_OBJECT_TYPE, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 612 | JS_GLOBAL_PROXY_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 613 | JS_ARRAY_TYPE, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 614 | JS_SET_TYPE, |
| 615 | JS_MAP_TYPE, |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 616 | JS_WEAK_MAP_TYPE, |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 617 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 618 | JS_REGEXP_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 619 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 620 | JS_FUNCTION_TYPE, // LAST_JS_OBJECT_TYPE, LAST_JS_RECEIVER_TYPE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 621 | |
| 622 | // Pseudo-types |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 623 | FIRST_TYPE = 0x0, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 624 | LAST_TYPE = JS_FUNCTION_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 625 | INVALID_TYPE = FIRST_TYPE - 1, |
| 626 | FIRST_NONSTRING_TYPE = MAP_TYPE, |
| 627 | // Boundaries for testing for an external array. |
| 628 | FIRST_EXTERNAL_ARRAY_TYPE = EXTERNAL_BYTE_ARRAY_TYPE, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 629 | LAST_EXTERNAL_ARRAY_TYPE = EXTERNAL_PIXEL_ARRAY_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 630 | // Boundary for promotion to old data space/old pointer space. |
| 631 | LAST_DATA_TYPE = FILLER_TYPE, |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 632 | // Boundary for objects represented as JSReceiver (i.e. JSObject or JSProxy). |
| 633 | // Note that there is no range for JSObject or JSProxy, since their subtypes |
| 634 | // are not continuous in this enum! The enum ranges instead reflect the |
| 635 | // external class names, where proxies are treated as either ordinary objects, |
| 636 | // or functions. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 637 | FIRST_JS_RECEIVER_TYPE = JS_FUNCTION_PROXY_TYPE, |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 638 | LAST_JS_RECEIVER_TYPE = LAST_TYPE, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 639 | // Boundaries for testing the types represented as JSObject |
| 640 | FIRST_JS_OBJECT_TYPE = JS_VALUE_TYPE, |
| 641 | LAST_JS_OBJECT_TYPE = LAST_TYPE, |
| 642 | // Boundaries for testing the types represented as JSProxy |
| 643 | FIRST_JS_PROXY_TYPE = JS_FUNCTION_PROXY_TYPE, |
| 644 | LAST_JS_PROXY_TYPE = JS_PROXY_TYPE, |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 645 | // Boundaries for testing whether the type is a JavaScript object. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 646 | FIRST_SPEC_OBJECT_TYPE = FIRST_JS_RECEIVER_TYPE, |
| 647 | LAST_SPEC_OBJECT_TYPE = LAST_JS_RECEIVER_TYPE, |
| 648 | // Boundaries for testing the types for which typeof is "object". |
| 649 | FIRST_NONCALLABLE_SPEC_OBJECT_TYPE = JS_PROXY_TYPE, |
| 650 | LAST_NONCALLABLE_SPEC_OBJECT_TYPE = JS_REGEXP_TYPE, |
| 651 | // Note that the types for which typeof is "function" are not continuous. |
| 652 | // Define this so that we can put assertions on discrete checks. |
| 653 | NUM_OF_CALLABLE_SPEC_OBJECT_TYPES = 2 |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 654 | }; |
| 655 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 656 | const int kExternalArrayTypeCount = |
| 657 | LAST_EXTERNAL_ARRAY_TYPE - FIRST_EXTERNAL_ARRAY_TYPE + 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 658 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 659 | STATIC_CHECK(JS_OBJECT_TYPE == Internals::kJSObjectType); |
| 660 | STATIC_CHECK(FIRST_NONSTRING_TYPE == Internals::kFirstNonstringType); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 661 | STATIC_CHECK(ODDBALL_TYPE == Internals::kOddballType); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 662 | STATIC_CHECK(FOREIGN_TYPE == Internals::kForeignType); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 663 | |
| 664 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 665 | enum CompareResult { |
| 666 | LESS = -1, |
| 667 | EQUAL = 0, |
| 668 | GREATER = 1, |
| 669 | |
| 670 | NOT_EQUAL = GREATER |
| 671 | }; |
| 672 | |
| 673 | |
| 674 | #define DECL_BOOLEAN_ACCESSORS(name) \ |
| 675 | inline bool name(); \ |
| 676 | inline void set_##name(bool value); \ |
| 677 | |
| 678 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 679 | #define DECL_ACCESSORS(name, type) \ |
| 680 | inline type* name(); \ |
| 681 | inline void set_##name(type* value, \ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 682 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 683 | |
| 684 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 685 | class AccessorPair; |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 686 | class DictionaryElementsAccessor; |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 687 | class ElementsAccessor; |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 688 | class Failure; |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 689 | class FixedArrayBase; |
| 690 | class ObjectVisitor; |
| 691 | class StringStream; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 692 | |
| 693 | struct ValueInfo : public Malloced { |
| 694 | ValueInfo() : type(FIRST_TYPE), ptr(NULL), str(NULL), number(0) { } |
| 695 | InstanceType type; |
| 696 | Object* ptr; |
| 697 | const char* str; |
| 698 | double number; |
| 699 | }; |
| 700 | |
| 701 | |
| 702 | // A template-ized version of the IsXXX functions. |
| 703 | template <class C> static inline bool Is(Object* obj); |
| 704 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 705 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 706 | class MaybeObject BASE_EMBEDDED { |
| 707 | public: |
| 708 | inline bool IsFailure(); |
| 709 | inline bool IsRetryAfterGC(); |
| 710 | inline bool IsOutOfMemory(); |
| 711 | inline bool IsException(); |
| 712 | INLINE(bool IsTheHole()); |
| 713 | inline bool ToObject(Object** obj) { |
| 714 | if (IsFailure()) return false; |
| 715 | *obj = reinterpret_cast<Object*>(this); |
| 716 | return true; |
| 717 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 718 | inline Failure* ToFailureUnchecked() { |
| 719 | ASSERT(IsFailure()); |
| 720 | return reinterpret_cast<Failure*>(this); |
| 721 | } |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 722 | inline Object* ToObjectUnchecked() { |
| 723 | ASSERT(!IsFailure()); |
| 724 | return reinterpret_cast<Object*>(this); |
| 725 | } |
| 726 | inline Object* ToObjectChecked() { |
| 727 | CHECK(!IsFailure()); |
| 728 | return reinterpret_cast<Object*>(this); |
| 729 | } |
| 730 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 731 | template<typename T> |
| 732 | inline bool To(T** obj) { |
| 733 | if (IsFailure()) return false; |
| 734 | *obj = T::cast(reinterpret_cast<Object*>(this)); |
| 735 | return true; |
| 736 | } |
| 737 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 738 | #ifdef OBJECT_PRINT |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 739 | // Prints this object with details. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 740 | inline void Print() { |
| 741 | Print(stdout); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 742 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 743 | inline void PrintLn() { |
| 744 | PrintLn(stdout); |
| 745 | } |
| 746 | void Print(FILE* out); |
| 747 | void PrintLn(FILE* out); |
| 748 | #endif |
| 749 | #ifdef DEBUG |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 750 | // Verifies the object. |
| 751 | void Verify(); |
| 752 | #endif |
| 753 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 754 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 755 | |
| 756 | #define OBJECT_TYPE_LIST(V) \ |
| 757 | V(Smi) \ |
| 758 | V(HeapObject) \ |
| 759 | V(Number) \ |
| 760 | |
| 761 | #define HEAP_OBJECT_TYPE_LIST(V) \ |
| 762 | V(HeapNumber) \ |
| 763 | V(String) \ |
| 764 | V(Symbol) \ |
| 765 | V(SeqString) \ |
| 766 | V(ExternalString) \ |
| 767 | V(ConsString) \ |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 768 | V(SlicedString) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 769 | V(ExternalTwoByteString) \ |
| 770 | V(ExternalAsciiString) \ |
| 771 | V(SeqTwoByteString) \ |
| 772 | V(SeqAsciiString) \ |
| 773 | \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 774 | V(ExternalArray) \ |
| 775 | V(ExternalByteArray) \ |
| 776 | V(ExternalUnsignedByteArray) \ |
| 777 | V(ExternalShortArray) \ |
| 778 | V(ExternalUnsignedShortArray) \ |
| 779 | V(ExternalIntArray) \ |
| 780 | V(ExternalUnsignedIntArray) \ |
| 781 | V(ExternalFloatArray) \ |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 782 | V(ExternalDoubleArray) \ |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 783 | V(ExternalPixelArray) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 784 | V(ByteArray) \ |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 785 | V(FreeSpace) \ |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 786 | V(JSReceiver) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 787 | V(JSObject) \ |
| 788 | V(JSContextExtensionObject) \ |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 789 | V(JSModule) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 790 | V(Map) \ |
| 791 | V(DescriptorArray) \ |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 792 | V(TransitionArray) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 793 | V(DeoptimizationInputData) \ |
| 794 | V(DeoptimizationOutputData) \ |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 795 | V(TypeFeedbackCells) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 796 | V(FixedArray) \ |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 797 | V(FixedDoubleArray) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 798 | V(Context) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 799 | V(GlobalContext) \ |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 800 | V(ModuleContext) \ |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 801 | V(ScopeInfo) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 802 | V(JSFunction) \ |
| 803 | V(Code) \ |
| 804 | V(Oddball) \ |
| 805 | V(SharedFunctionInfo) \ |
| 806 | V(JSValue) \ |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 807 | V(JSDate) \ |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 808 | V(JSMessageObject) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 809 | V(StringWrapper) \ |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 810 | V(Foreign) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 811 | V(Boolean) \ |
| 812 | V(JSArray) \ |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 813 | V(JSProxy) \ |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 814 | V(JSFunctionProxy) \ |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 815 | V(JSSet) \ |
| 816 | V(JSMap) \ |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 817 | V(JSWeakMap) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 818 | V(JSRegExp) \ |
| 819 | V(HashTable) \ |
| 820 | V(Dictionary) \ |
| 821 | V(SymbolTable) \ |
| 822 | V(JSFunctionResultCache) \ |
| 823 | V(NormalizedMapCache) \ |
| 824 | V(CompilationCacheTable) \ |
| 825 | V(CodeCacheHashTable) \ |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 826 | V(PolymorphicCodeCacheHashTable) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 827 | V(MapCache) \ |
| 828 | V(Primitive) \ |
| 829 | V(GlobalObject) \ |
| 830 | V(JSGlobalObject) \ |
| 831 | V(JSBuiltinsObject) \ |
| 832 | V(JSGlobalProxy) \ |
| 833 | V(UndetectableObject) \ |
| 834 | V(AccessCheckNeeded) \ |
| 835 | V(JSGlobalPropertyCell) \ |
| 836 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 837 | |
| 838 | class JSReceiver; |
| 839 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 840 | // Object is the abstract superclass for all classes in the |
| 841 | // object hierarchy. |
| 842 | // Object does not use any virtual functions to avoid the |
| 843 | // allocation of the C++ vtable. |
| 844 | // Since Smi and Failure are subclasses of Object no |
| 845 | // data members can be present in Object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 846 | class Object : public MaybeObject { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 847 | public: |
| 848 | // Type testing. |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 849 | bool IsObject() { return true; } |
| 850 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 851 | #define IS_TYPE_FUNCTION_DECL(type_) inline bool Is##type_(); |
| 852 | OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
| 853 | HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
| 854 | #undef IS_TYPE_FUNCTION_DECL |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 855 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 856 | inline bool IsFixedArrayBase(); |
| 857 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 858 | // Returns true if this object is an instance of the specified |
| 859 | // function template. |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 860 | inline bool IsInstanceOf(FunctionTemplateInfo* type); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 861 | |
| 862 | inline bool IsStruct(); |
| 863 | #define DECLARE_STRUCT_PREDICATE(NAME, Name, name) inline bool Is##Name(); |
| 864 | STRUCT_LIST(DECLARE_STRUCT_PREDICATE) |
| 865 | #undef DECLARE_STRUCT_PREDICATE |
| 866 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 867 | INLINE(bool IsSpecObject()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 868 | INLINE(bool IsSpecFunction()); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 869 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 870 | // Oddball testing. |
| 871 | INLINE(bool IsUndefined()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 872 | INLINE(bool IsNull()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 873 | INLINE(bool IsTheHole()); // Shadows MaybeObject's implementation. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 874 | INLINE(bool IsTrue()); |
| 875 | INLINE(bool IsFalse()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 876 | inline bool IsArgumentsMarker(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 877 | inline bool NonFailureIsHeapObject(); |
| 878 | |
| 879 | // Filler objects (fillers and free space objects). |
| 880 | inline bool IsFiller(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 881 | |
| 882 | // Extract the number. |
| 883 | inline double Number(); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 884 | inline bool IsNaN(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 885 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 886 | // Returns true if the object is of the correct type to be used as a |
| 887 | // implementation of a JSObject's elements. |
| 888 | inline bool HasValidElements(); |
| 889 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 890 | inline bool HasSpecificClassOf(String* name); |
| 891 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 892 | MUST_USE_RESULT MaybeObject* ToObject(); // ECMA-262 9.9. |
| 893 | Object* ToBoolean(); // ECMA-262 9.2. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 894 | |
| 895 | // Convert to a JSObject if needed. |
| 896 | // global_context is used when creating wrapper object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 897 | MUST_USE_RESULT MaybeObject* ToObject(Context* global_context); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 898 | |
| 899 | // Converts this to a Smi if possible. |
| 900 | // Failure is returned otherwise. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 901 | MUST_USE_RESULT inline MaybeObject* ToSmi(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 902 | |
| 903 | void Lookup(String* name, LookupResult* result); |
| 904 | |
| 905 | // Property access. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 906 | MUST_USE_RESULT inline MaybeObject* GetProperty(String* key); |
| 907 | MUST_USE_RESULT inline MaybeObject* GetProperty( |
| 908 | String* key, |
| 909 | PropertyAttributes* attributes); |
| 910 | MUST_USE_RESULT MaybeObject* GetPropertyWithReceiver( |
| 911 | Object* receiver, |
| 912 | String* key, |
| 913 | PropertyAttributes* attributes); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 914 | |
| 915 | static Handle<Object> GetProperty(Handle<Object> object, |
| 916 | Handle<Object> receiver, |
| 917 | LookupResult* result, |
| 918 | Handle<String> key, |
| 919 | PropertyAttributes* attributes); |
| 920 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 921 | MUST_USE_RESULT MaybeObject* GetProperty(Object* receiver, |
| 922 | LookupResult* result, |
| 923 | String* key, |
| 924 | PropertyAttributes* attributes); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 925 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 926 | MUST_USE_RESULT MaybeObject* GetPropertyWithDefinedGetter(Object* receiver, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 927 | JSReceiver* getter); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 928 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 929 | static Handle<Object> GetElement(Handle<Object> object, uint32_t index); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 930 | MUST_USE_RESULT inline MaybeObject* GetElement(uint32_t index); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 931 | // For use when we know that no exception can be thrown. |
| 932 | inline Object* GetElementNoExceptionThrown(uint32_t index); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 933 | MUST_USE_RESULT MaybeObject* GetElementWithReceiver(Object* receiver, |
| 934 | uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 935 | |
| 936 | // Return the object's prototype (might be Heap::null_value()). |
| 937 | Object* GetPrototype(); |
| 938 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 939 | // Returns the permanent hash code associated with this object depending on |
| 940 | // the actual object type. Might return a failure in case no hash was |
| 941 | // created yet or GC was caused by creation. |
| 942 | MUST_USE_RESULT MaybeObject* GetHash(CreationFlag flag); |
| 943 | |
| 944 | // Checks whether this object has the same value as the given one. This |
| 945 | // function is implemented according to ES5, section 9.12 and can be used |
| 946 | // to implement the Harmony "egal" function. |
| 947 | bool SameValue(Object* other); |
| 948 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 949 | // Tries to convert an object to an array index. Returns true and sets |
| 950 | // the output parameter if it succeeds. |
| 951 | inline bool ToArrayIndex(uint32_t* index); |
| 952 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 953 | // Returns true if this is a JSValue containing a string and the index is |
| 954 | // < the length of the string. Used to implement [] on strings. |
| 955 | inline bool IsStringObjectWithCharacterAt(uint32_t index); |
| 956 | |
| 957 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 958 | // Verify a pointer is a valid object pointer. |
| 959 | static void VerifyPointer(Object* p); |
| 960 | #endif |
| 961 | |
| 962 | // Prints this object without details. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 963 | inline void ShortPrint() { |
| 964 | ShortPrint(stdout); |
| 965 | } |
| 966 | void ShortPrint(FILE* out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 967 | |
| 968 | // Prints this object without details to a message accumulator. |
| 969 | void ShortPrint(StringStream* accumulator); |
| 970 | |
| 971 | // Casting: This cast is only needed to satisfy macros in objects-inl.h. |
| 972 | static Object* cast(Object* value) { return value; } |
| 973 | |
| 974 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 975 | 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] | 976 | |
| 977 | private: |
| 978 | DISALLOW_IMPLICIT_CONSTRUCTORS(Object); |
| 979 | }; |
| 980 | |
| 981 | |
| 982 | // Smi represents integer Numbers that can be stored in 31 bits. |
| 983 | // Smis are immediate which means they are NOT allocated in the heap. |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 984 | // The this pointer has the following format: [31 bit signed int] 0 |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 985 | // For long smis it has the following format: |
| 986 | // [32 bit signed int] [31 bits zero padding] 0 |
| 987 | // Smi stands for small integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 988 | class Smi: public Object { |
| 989 | public: |
| 990 | // Returns the integer value. |
| 991 | inline int value(); |
| 992 | |
| 993 | // Convert a value to a Smi object. |
| 994 | static inline Smi* FromInt(int value); |
| 995 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 996 | static inline Smi* FromIntptr(intptr_t value); |
| 997 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 998 | // Returns whether value can be represented in a Smi. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 999 | static inline bool IsValid(intptr_t value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1000 | |
| 1001 | // Casting. |
| 1002 | static inline Smi* cast(Object* object); |
| 1003 | |
| 1004 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1005 | inline void SmiPrint() { |
| 1006 | SmiPrint(stdout); |
| 1007 | } |
| 1008 | void SmiPrint(FILE* out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1009 | void SmiPrint(StringStream* accumulator); |
| 1010 | #ifdef DEBUG |
| 1011 | void SmiVerify(); |
| 1012 | #endif |
| 1013 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 1014 | static const int kMinValue = |
| 1015 | (static_cast<unsigned int>(-1)) << (kSmiValueSize - 1); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1016 | static const int kMaxValue = -(kMinValue + 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1017 | |
| 1018 | private: |
| 1019 | DISALLOW_IMPLICIT_CONSTRUCTORS(Smi); |
| 1020 | }; |
| 1021 | |
| 1022 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1023 | // Failure is used for reporting out of memory situations and |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1024 | // propagating exceptions through the runtime system. Failure objects |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1025 | // are transient and cannot occur as part of the object graph. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1026 | // |
| 1027 | // Failures are a single word, encoded as follows: |
| 1028 | // +-------------------------+---+--+--+ |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1029 | // |.........unused..........|sss|tt|11| |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1030 | // +-------------------------+---+--+--+ |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1031 | // 7 6 4 32 10 |
| 1032 | // |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1033 | // |
| 1034 | // The low two bits, 0-1, are the failure tag, 11. The next two bits, |
| 1035 | // 2-3, are a failure type tag 'tt' with possible values: |
| 1036 | // 00 RETRY_AFTER_GC |
| 1037 | // 01 EXCEPTION |
| 1038 | // 10 INTERNAL_ERROR |
| 1039 | // 11 OUT_OF_MEMORY_EXCEPTION |
| 1040 | // |
| 1041 | // The next three bits, 4-6, are an allocation space tag 'sss'. The |
| 1042 | // allocation space tag is 000 for all failure types except |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1043 | // RETRY_AFTER_GC. For RETRY_AFTER_GC, the possible values are the |
| 1044 | // allocation spaces (the encoding is found in globals.h). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1045 | |
| 1046 | // Failure type tag info. |
| 1047 | const int kFailureTypeTagSize = 2; |
| 1048 | const int kFailureTypeTagMask = (1 << kFailureTypeTagSize) - 1; |
| 1049 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1050 | class Failure: public MaybeObject { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1051 | public: |
| 1052 | // RuntimeStubs assumes EXCEPTION = 1 in the compiler-generated code. |
| 1053 | enum Type { |
| 1054 | RETRY_AFTER_GC = 0, |
| 1055 | EXCEPTION = 1, // Returning this marker tells the real exception |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1056 | // is in Isolate::pending_exception. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1057 | INTERNAL_ERROR = 2, |
| 1058 | OUT_OF_MEMORY_EXCEPTION = 3 |
| 1059 | }; |
| 1060 | |
| 1061 | inline Type type() const; |
| 1062 | |
| 1063 | // Returns the space that needs to be collected for RetryAfterGC failures. |
| 1064 | inline AllocationSpace allocation_space() const; |
| 1065 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1066 | inline bool IsInternalError() const; |
| 1067 | inline bool IsOutOfMemoryException() const; |
| 1068 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1069 | static inline Failure* RetryAfterGC(AllocationSpace space); |
| 1070 | static inline Failure* RetryAfterGC(); // NEW_SPACE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1071 | static inline Failure* Exception(); |
| 1072 | static inline Failure* InternalError(); |
| 1073 | static inline Failure* OutOfMemoryException(); |
| 1074 | // Casting. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1075 | static inline Failure* cast(MaybeObject* object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1076 | |
| 1077 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1078 | inline void FailurePrint() { |
| 1079 | FailurePrint(stdout); |
| 1080 | } |
| 1081 | void FailurePrint(FILE* out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1082 | void FailurePrint(StringStream* accumulator); |
| 1083 | #ifdef DEBUG |
| 1084 | void FailureVerify(); |
| 1085 | #endif |
| 1086 | |
| 1087 | private: |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1088 | inline intptr_t value() const; |
| 1089 | static inline Failure* Construct(Type type, intptr_t value = 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1090 | |
| 1091 | DISALLOW_IMPLICIT_CONSTRUCTORS(Failure); |
| 1092 | }; |
| 1093 | |
| 1094 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1095 | // Heap objects typically have a map pointer in their first word. However, |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1096 | // during GC other data (e.g. mark bits, forwarding addresses) is sometimes |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1097 | // encoded in the first word. The class MapWord is an abstraction of the |
| 1098 | // value in a heap object's first word. |
| 1099 | class MapWord BASE_EMBEDDED { |
| 1100 | public: |
| 1101 | // Normal state: the map word contains a map pointer. |
| 1102 | |
| 1103 | // Create a map word from a map pointer. |
| 1104 | static inline MapWord FromMap(Map* map); |
| 1105 | |
| 1106 | // View this map word as a map pointer. |
| 1107 | inline Map* ToMap(); |
| 1108 | |
| 1109 | |
| 1110 | // Scavenge collection: the map word of live objects in the from space |
| 1111 | // contains a forwarding address (a heap object pointer in the to space). |
| 1112 | |
| 1113 | // True if this map word is a forwarding address for a scavenge |
| 1114 | // collection. Only valid during a scavenge collection (specifically, |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1115 | // when all map words are heap object pointers, i.e. not during a full GC). |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1116 | inline bool IsForwardingAddress(); |
| 1117 | |
| 1118 | // Create a map word from a forwarding address. |
| 1119 | static inline MapWord FromForwardingAddress(HeapObject* object); |
| 1120 | |
| 1121 | // View this map word as a forwarding address. |
| 1122 | inline HeapObject* ToForwardingAddress(); |
| 1123 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1124 | static inline MapWord FromRawValue(uintptr_t value) { |
| 1125 | return MapWord(value); |
| 1126 | } |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1127 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1128 | inline uintptr_t ToRawValue() { |
| 1129 | return value_; |
| 1130 | } |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1131 | |
| 1132 | private: |
| 1133 | // HeapObject calls the private constructor and directly reads the value. |
| 1134 | friend class HeapObject; |
| 1135 | |
| 1136 | explicit MapWord(uintptr_t value) : value_(value) {} |
| 1137 | |
| 1138 | uintptr_t value_; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1139 | }; |
| 1140 | |
| 1141 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1142 | // HeapObject is the superclass for all classes describing heap allocated |
| 1143 | // objects. |
| 1144 | class HeapObject: public Object { |
| 1145 | public: |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1146 | // [map]: Contains a map which contains the object's reflective |
| 1147 | // information. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1148 | inline Map* map(); |
| 1149 | inline void set_map(Map* value); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1150 | // The no-write-barrier version. This is OK if the object is white and in |
| 1151 | // new space, or if the value is an immortal immutable object, like the maps |
| 1152 | // of primitive (non-JS) objects like strings, heap numbers etc. |
| 1153 | inline void set_map_no_write_barrier(Map* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1154 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1155 | // During garbage collection, the map word of a heap object does not |
| 1156 | // necessarily contain a map pointer. |
| 1157 | inline MapWord map_word(); |
| 1158 | inline void set_map_word(MapWord map_word); |
| 1159 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1160 | // The Heap the object was allocated in. Used also to access Isolate. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1161 | inline Heap* GetHeap(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1162 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1163 | // Convenience method to get current isolate. This method can be |
| 1164 | // accessed only when its result is the same as |
| 1165 | // Isolate::Current(), it ASSERTs this. See also comment for GetHeap. |
| 1166 | inline Isolate* GetIsolate(); |
| 1167 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1168 | // Converts an address to a HeapObject pointer. |
| 1169 | static inline HeapObject* FromAddress(Address address); |
| 1170 | |
| 1171 | // Returns the address of this HeapObject. |
| 1172 | inline Address address(); |
| 1173 | |
| 1174 | // Iterates over pointers contained in the object (including the Map) |
| 1175 | void Iterate(ObjectVisitor* v); |
| 1176 | |
| 1177 | // Iterates over all pointers contained in the object except the |
| 1178 | // first map pointer. The object type is given in the first |
| 1179 | // parameter. This function does not access the map pointer in the |
| 1180 | // object, and so is safe to call while the map pointer is modified. |
| 1181 | void IterateBody(InstanceType type, int object_size, ObjectVisitor* v); |
| 1182 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1183 | // Returns the heap object's size in bytes |
| 1184 | inline int Size(); |
| 1185 | |
| 1186 | // Given a heap object's map pointer, returns the heap size in bytes |
| 1187 | // Useful when the map pointer field is used for other purposes. |
| 1188 | // GC internal. |
| 1189 | inline int SizeFromMap(Map* map); |
| 1190 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 1191 | // Returns the field at offset in obj, as a read/write Object* reference. |
| 1192 | // Does no checking, and is safe to use during GC, while maps are invalid. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1193 | // Does not invoke write barrier, so should only be assigned to |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 1194 | // during marking GC. |
| 1195 | static inline Object** RawField(HeapObject* obj, int offset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1196 | |
| 1197 | // Casting. |
| 1198 | static inline HeapObject* cast(Object* obj); |
| 1199 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1200 | // Return the write barrier mode for this. Callers of this function |
| 1201 | // must be able to present a reference to an AssertNoAllocation |
| 1202 | // object as a sign that they are not going to use this function |
| 1203 | // from code that allocates and thus invalidates the returned write |
| 1204 | // barrier mode. |
| 1205 | inline WriteBarrierMode GetWriteBarrierMode(const AssertNoAllocation&); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1206 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1207 | // Dispatched behavior. |
| 1208 | void HeapObjectShortPrint(StringStream* accumulator); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1209 | #ifdef OBJECT_PRINT |
| 1210 | inline void HeapObjectPrint() { |
| 1211 | HeapObjectPrint(stdout); |
| 1212 | } |
| 1213 | void HeapObjectPrint(FILE* out); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1214 | void PrintHeader(FILE* out, const char* id); |
| 1215 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1216 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1217 | #ifdef DEBUG |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1218 | void HeapObjectVerify(); |
| 1219 | inline void VerifyObjectField(int offset); |
| 1220 | inline void VerifySmiField(int offset); |
| 1221 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1222 | // Verify a pointer is a valid HeapObject pointer that points to object |
| 1223 | // areas in the heap. |
| 1224 | static void VerifyHeapPointer(Object* p); |
| 1225 | #endif |
| 1226 | |
| 1227 | // Layout description. |
| 1228 | // First field in a heap object is map. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1229 | static const int kMapOffset = Object::kHeaderSize; |
| 1230 | static const int kHeaderSize = kMapOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1231 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1232 | STATIC_CHECK(kMapOffset == Internals::kHeapObjectMapOffset); |
| 1233 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1234 | protected: |
| 1235 | // helpers for calling an ObjectVisitor to iterate over pointers in the |
| 1236 | // half-open range [start, end) specified as integer offsets |
| 1237 | inline void IteratePointers(ObjectVisitor* v, int start, int end); |
| 1238 | // as above, for the single element at "offset" |
| 1239 | inline void IteratePointer(ObjectVisitor* v, int offset); |
| 1240 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1241 | private: |
| 1242 | DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject); |
| 1243 | }; |
| 1244 | |
| 1245 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1246 | #define SLOT_ADDR(obj, offset) \ |
| 1247 | reinterpret_cast<Object**>((obj)->address() + offset) |
| 1248 | |
| 1249 | // This class describes a body of an object of a fixed size |
| 1250 | // in which all pointer fields are located in the [start_offset, end_offset) |
| 1251 | // interval. |
| 1252 | template<int start_offset, int end_offset, int size> |
| 1253 | class FixedBodyDescriptor { |
| 1254 | public: |
| 1255 | static const int kStartOffset = start_offset; |
| 1256 | static const int kEndOffset = end_offset; |
| 1257 | static const int kSize = size; |
| 1258 | |
| 1259 | static inline void IterateBody(HeapObject* obj, ObjectVisitor* v); |
| 1260 | |
| 1261 | template<typename StaticVisitor> |
| 1262 | static inline void IterateBody(HeapObject* obj) { |
| 1263 | StaticVisitor::VisitPointers(SLOT_ADDR(obj, start_offset), |
| 1264 | SLOT_ADDR(obj, end_offset)); |
| 1265 | } |
| 1266 | }; |
| 1267 | |
| 1268 | |
| 1269 | // This class describes a body of an object of a variable size |
| 1270 | // in which all pointer fields are located in the [start_offset, object_size) |
| 1271 | // interval. |
| 1272 | template<int start_offset> |
| 1273 | class FlexibleBodyDescriptor { |
| 1274 | public: |
| 1275 | static const int kStartOffset = start_offset; |
| 1276 | |
| 1277 | static inline void IterateBody(HeapObject* obj, |
| 1278 | int object_size, |
| 1279 | ObjectVisitor* v); |
| 1280 | |
| 1281 | template<typename StaticVisitor> |
| 1282 | static inline void IterateBody(HeapObject* obj, int object_size) { |
| 1283 | StaticVisitor::VisitPointers(SLOT_ADDR(obj, start_offset), |
| 1284 | SLOT_ADDR(obj, object_size)); |
| 1285 | } |
| 1286 | }; |
| 1287 | |
| 1288 | #undef SLOT_ADDR |
| 1289 | |
| 1290 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1291 | // The HeapNumber class describes heap allocated numbers that cannot be |
| 1292 | // represented in a Smi (small integer) |
| 1293 | class HeapNumber: public HeapObject { |
| 1294 | public: |
| 1295 | // [value]: number value. |
| 1296 | inline double value(); |
| 1297 | inline void set_value(double value); |
| 1298 | |
| 1299 | // Casting. |
| 1300 | static inline HeapNumber* cast(Object* obj); |
| 1301 | |
| 1302 | // Dispatched behavior. |
| 1303 | Object* HeapNumberToBoolean(); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1304 | inline void HeapNumberPrint() { |
| 1305 | HeapNumberPrint(stdout); |
| 1306 | } |
| 1307 | void HeapNumberPrint(FILE* out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1308 | void HeapNumberPrint(StringStream* accumulator); |
| 1309 | #ifdef DEBUG |
| 1310 | void HeapNumberVerify(); |
| 1311 | #endif |
| 1312 | |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 1313 | inline int get_exponent(); |
| 1314 | inline int get_sign(); |
| 1315 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1316 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1317 | static const int kValueOffset = HeapObject::kHeaderSize; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1318 | // IEEE doubles are two 32 bit words. The first is just mantissa, the second |
| 1319 | // is a mixture of sign, exponent and mantissa. Our current platforms are all |
| 1320 | // little endian apart from non-EABI arm which is little endian with big |
| 1321 | // endian floating point word ordering! |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1322 | static const int kMantissaOffset = kValueOffset; |
| 1323 | static const int kExponentOffset = kValueOffset + 4; |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1324 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1325 | static const int kSize = kValueOffset + kDoubleSize; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1326 | static const uint32_t kSignMask = 0x80000000u; |
| 1327 | static const uint32_t kExponentMask = 0x7ff00000u; |
| 1328 | static const uint32_t kMantissaMask = 0xfffffu; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1329 | static const int kMantissaBits = 52; |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1330 | static const int kExponentBits = 11; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1331 | static const int kExponentBias = 1023; |
| 1332 | static const int kExponentShift = 20; |
| 1333 | static const int kMantissaBitsInTopWord = 20; |
| 1334 | static const int kNonMantissaBitsInTopWord = 12; |
| 1335 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1336 | private: |
| 1337 | DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumber); |
| 1338 | }; |
| 1339 | |
| 1340 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1341 | enum EnsureElementsMode { |
| 1342 | DONT_ALLOW_DOUBLE_ELEMENTS, |
| 1343 | ALLOW_COPIED_DOUBLE_ELEMENTS, |
| 1344 | ALLOW_CONVERTED_DOUBLE_ELEMENTS |
| 1345 | }; |
| 1346 | |
| 1347 | |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 1348 | // Indicates whether a property should be set or (re)defined. Setting of a |
| 1349 | // property causes attributes to remain unchanged, writability to be checked |
| 1350 | // and callbacks to be called. Defining of a property causes attributes to |
| 1351 | // be updated and callbacks to be overridden. |
| 1352 | enum SetPropertyMode { |
| 1353 | SET_PROPERTY, |
| 1354 | DEFINE_PROPERTY |
| 1355 | }; |
| 1356 | |
| 1357 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1358 | // Indicator for one component of an AccessorPair. |
| 1359 | enum AccessorComponent { |
| 1360 | ACCESSOR_GETTER, |
| 1361 | ACCESSOR_SETTER |
| 1362 | }; |
| 1363 | |
| 1364 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1365 | // JSReceiver includes types on which properties can be defined, i.e., |
| 1366 | // JSObject and JSProxy. |
| 1367 | class JSReceiver: public HeapObject { |
| 1368 | public: |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1369 | enum DeleteMode { |
| 1370 | NORMAL_DELETION, |
| 1371 | STRICT_DELETION, |
| 1372 | FORCE_DELETION |
| 1373 | }; |
| 1374 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1375 | // A non-keyed store is of the form a.x = foo or a["x"] = foo whereas |
| 1376 | // a keyed store is of the form a[expression] = foo. |
| 1377 | enum StoreFromKeyed { |
| 1378 | MAY_BE_STORE_FROM_KEYED, |
| 1379 | CERTAINLY_NOT_STORE_FROM_KEYED |
| 1380 | }; |
| 1381 | |
mstarzinger@chromium.org | ccab367 | 2012-06-14 15:01:16 +0000 | [diff] [blame] | 1382 | // Internal properties (e.g. the hidden properties dictionary) might |
| 1383 | // be added even though the receiver is non-extensible. |
| 1384 | enum ExtensibilityCheck { |
| 1385 | PERFORM_EXTENSIBILITY_CHECK, |
| 1386 | OMIT_EXTENSIBILITY_CHECK |
| 1387 | }; |
| 1388 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1389 | // Casting. |
| 1390 | static inline JSReceiver* cast(Object* obj); |
| 1391 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1392 | static Handle<Object> SetProperty(Handle<JSReceiver> object, |
| 1393 | Handle<String> key, |
| 1394 | Handle<Object> value, |
| 1395 | PropertyAttributes attributes, |
| 1396 | StrictModeFlag strict_mode); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1397 | // Can cause GC. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1398 | MUST_USE_RESULT MaybeObject* SetProperty( |
| 1399 | String* key, |
| 1400 | Object* value, |
| 1401 | PropertyAttributes attributes, |
| 1402 | StrictModeFlag strict_mode, |
| 1403 | StoreFromKeyed store_from_keyed = MAY_BE_STORE_FROM_KEYED); |
| 1404 | MUST_USE_RESULT MaybeObject* SetProperty( |
| 1405 | LookupResult* result, |
| 1406 | String* key, |
| 1407 | Object* value, |
| 1408 | PropertyAttributes attributes, |
| 1409 | StrictModeFlag strict_mode, |
| 1410 | StoreFromKeyed store_from_keyed = MAY_BE_STORE_FROM_KEYED); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1411 | MUST_USE_RESULT MaybeObject* SetPropertyWithDefinedSetter(JSReceiver* setter, |
| 1412 | Object* value); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1413 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1414 | MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1415 | MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode); |
| 1416 | |
| 1417 | // Set the index'th array element. |
| 1418 | // Can cause GC, or return failure if GC is required. |
| 1419 | MUST_USE_RESULT MaybeObject* SetElement(uint32_t index, |
| 1420 | Object* value, |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 1421 | PropertyAttributes attributes, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1422 | StrictModeFlag strict_mode, |
| 1423 | bool check_prototype); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1424 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1425 | // Tests for the fast common case for property enumeration. |
| 1426 | bool IsSimpleEnum(); |
| 1427 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1428 | // Returns the class name ([[Class]] property in the specification). |
| 1429 | String* class_name(); |
| 1430 | |
| 1431 | // Returns the constructor name (the name (possibly, inferred name) of the |
| 1432 | // function that was used to instantiate the object). |
| 1433 | String* constructor_name(); |
| 1434 | |
| 1435 | inline PropertyAttributes GetPropertyAttribute(String* name); |
| 1436 | PropertyAttributes GetPropertyAttributeWithReceiver(JSReceiver* receiver, |
| 1437 | String* name); |
| 1438 | PropertyAttributes GetLocalPropertyAttribute(String* name); |
| 1439 | |
| 1440 | // Can cause a GC. |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1441 | inline bool HasProperty(String* name); |
| 1442 | inline bool HasLocalProperty(String* name); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1443 | inline bool HasElement(uint32_t index); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1444 | |
| 1445 | // Return the object's prototype (might be Heap::null_value()). |
| 1446 | inline Object* GetPrototype(); |
| 1447 | |
yangguo@chromium.org | c74d674 | 2012-06-29 15:15:45 +0000 | [diff] [blame] | 1448 | // Return the constructor function (may be Heap::null_value()). |
| 1449 | inline Object* GetConstructor(); |
| 1450 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1451 | // Set the object's prototype (only JSReceiver and null are allowed). |
| 1452 | MUST_USE_RESULT MaybeObject* SetPrototype(Object* value, |
| 1453 | bool skip_hidden_prototypes); |
| 1454 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1455 | // Retrieves a permanent object identity hash code. The undefined value might |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1456 | // be returned in case no hash was created yet and OMIT_CREATION was used. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1457 | inline MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag); |
| 1458 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1459 | // Lookup a property. If found, the result is valid and has |
| 1460 | // detailed information. |
| 1461 | void LocalLookup(String* name, LookupResult* result); |
| 1462 | void Lookup(String* name, LookupResult* result); |
| 1463 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1464 | protected: |
| 1465 | Smi* GenerateIdentityHash(); |
| 1466 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1467 | private: |
| 1468 | PropertyAttributes GetPropertyAttribute(JSReceiver* receiver, |
| 1469 | LookupResult* result, |
| 1470 | String* name, |
| 1471 | bool continue_search); |
| 1472 | |
| 1473 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSReceiver); |
| 1474 | }; |
| 1475 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1476 | // The JSObject describes real heap allocated JavaScript objects with |
| 1477 | // properties. |
| 1478 | // Note that the map of JSObject changes during execution to enable inline |
| 1479 | // caching. |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1480 | class JSObject: public JSReceiver { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1481 | public: |
| 1482 | // [properties]: Backing storage for properties. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1483 | // properties is a FixedArray in the fast case and a Dictionary in the |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1484 | // slow case. |
| 1485 | DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1486 | inline void initialize_properties(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1487 | inline bool HasFastProperties(); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 1488 | inline StringDictionary* property_dictionary(); // Gets slow properties. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1489 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1490 | // [elements]: The elements (properties with names that are integers). |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1491 | // |
| 1492 | // Elements can be in two general modes: fast and slow. Each mode |
| 1493 | // corrensponds to a set of object representations of elements that |
| 1494 | // have something in common. |
| 1495 | // |
| 1496 | // In the fast mode elements is a FixedArray and so each element can |
| 1497 | // be quickly accessed. This fact is used in the generated code. The |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1498 | // elements array can have one of three maps in this mode: |
| 1499 | // fixed_array_map, non_strict_arguments_elements_map or |
| 1500 | // fixed_cow_array_map (for copy-on-write arrays). In the latter case |
| 1501 | // the elements array may be shared by a few objects and so before |
| 1502 | // writing to any element the array must be copied. Use |
| 1503 | // EnsureWritableFastElements in this case. |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1504 | // |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1505 | // In the slow mode the elements is either a NumberDictionary, an |
| 1506 | // ExternalArray, or a FixedArray parameter map for a (non-strict) |
| 1507 | // arguments object. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1508 | DECL_ACCESSORS(elements, FixedArrayBase) |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1509 | inline void initialize_elements(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1510 | MUST_USE_RESULT inline MaybeObject* ResetElements(); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1511 | inline ElementsKind GetElementsKind(); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1512 | inline ElementsAccessor* GetElementsAccessor(); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1513 | // Returns true if an object has elements of FAST_SMI_ELEMENTS ElementsKind. |
| 1514 | inline bool HasFastSmiElements(); |
| 1515 | // Returns true if an object has elements of FAST_ELEMENTS ElementsKind. |
| 1516 | inline bool HasFastObjectElements(); |
| 1517 | // Returns true if an object has elements of FAST_ELEMENTS or |
| 1518 | // FAST_SMI_ONLY_ELEMENTS. |
| 1519 | inline bool HasFastSmiOrObjectElements(); |
| 1520 | // Returns true if an object has elements of FAST_DOUBLE_ELEMENTS |
| 1521 | // ElementsKind. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1522 | inline bool HasFastDoubleElements(); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1523 | // Returns true if an object has elements of FAST_HOLEY_*_ELEMENTS |
| 1524 | // ElementsKind. |
| 1525 | inline bool HasFastHoleyElements(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1526 | inline bool HasNonStrictArgumentsElements(); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1527 | inline bool HasDictionaryElements(); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1528 | inline bool HasExternalPixelElements(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1529 | inline bool HasExternalArrayElements(); |
| 1530 | inline bool HasExternalByteElements(); |
| 1531 | inline bool HasExternalUnsignedByteElements(); |
| 1532 | inline bool HasExternalShortElements(); |
| 1533 | inline bool HasExternalUnsignedShortElements(); |
| 1534 | inline bool HasExternalIntElements(); |
| 1535 | inline bool HasExternalUnsignedIntElements(); |
| 1536 | inline bool HasExternalFloatElements(); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 1537 | inline bool HasExternalDoubleElements(); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1538 | bool HasFastArgumentsElements(); |
| 1539 | bool HasDictionaryArgumentsElements(); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1540 | inline SeededNumberDictionary* element_dictionary(); // Gets slow elements. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1541 | |
svenpanne@chromium.org | 3c93e77 | 2012-01-02 09:26:59 +0000 | [diff] [blame] | 1542 | inline void set_map_and_elements( |
| 1543 | Map* map, |
| 1544 | FixedArrayBase* value, |
| 1545 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 1546 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1547 | // Requires: HasFastElements(). |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1548 | MUST_USE_RESULT inline MaybeObject* EnsureWritableFastElements(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1549 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 1550 | // Collects elements starting at index 0. |
| 1551 | // Undefined values are placed after non-undefined values. |
| 1552 | // Returns the number of non-undefined values. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1553 | MUST_USE_RESULT MaybeObject* PrepareElementsForSort(uint32_t limit); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 1554 | // As PrepareElementsForSort, but only on objects where elements is |
| 1555 | // a dictionary, and it will stay a dictionary. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1556 | MUST_USE_RESULT MaybeObject* PrepareSlowElementsForSort(uint32_t limit); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 1557 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1558 | MUST_USE_RESULT MaybeObject* GetPropertyWithCallback(Object* receiver, |
| 1559 | Object* structure, |
| 1560 | String* name); |
| 1561 | |
| 1562 | // Can cause GC. |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1563 | MUST_USE_RESULT MaybeObject* SetPropertyForResult(LookupResult* result, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1564 | String* key, |
| 1565 | Object* value, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1566 | PropertyAttributes attributes, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1567 | StrictModeFlag strict_mode, |
| 1568 | StoreFromKeyed store_mode); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1569 | MUST_USE_RESULT MaybeObject* SetPropertyWithFailedAccessCheck( |
| 1570 | LookupResult* result, |
| 1571 | String* name, |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1572 | Object* value, |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 1573 | bool check_prototype, |
| 1574 | StrictModeFlag strict_mode); |
| 1575 | MUST_USE_RESULT MaybeObject* SetPropertyWithCallback( |
| 1576 | Object* structure, |
| 1577 | String* name, |
| 1578 | Object* value, |
| 1579 | JSObject* holder, |
| 1580 | StrictModeFlag strict_mode); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1581 | MUST_USE_RESULT MaybeObject* SetPropertyWithInterceptor( |
| 1582 | String* name, |
| 1583 | Object* value, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1584 | PropertyAttributes attributes, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1585 | StrictModeFlag strict_mode); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1586 | MUST_USE_RESULT MaybeObject* SetPropertyPostInterceptor( |
| 1587 | String* name, |
| 1588 | Object* value, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1589 | PropertyAttributes attributes, |
mstarzinger@chromium.org | ccab367 | 2012-06-14 15:01:16 +0000 | [diff] [blame] | 1590 | StrictModeFlag strict_mode, |
| 1591 | ExtensibilityCheck extensibility_check); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1592 | |
| 1593 | static Handle<Object> SetLocalPropertyIgnoreAttributes( |
| 1594 | Handle<JSObject> object, |
| 1595 | Handle<String> key, |
| 1596 | Handle<Object> value, |
| 1597 | PropertyAttributes attributes); |
| 1598 | |
| 1599 | // Can cause GC. |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1600 | MUST_USE_RESULT MaybeObject* SetLocalPropertyIgnoreAttributes( |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1601 | String* key, |
| 1602 | Object* value, |
| 1603 | PropertyAttributes attributes); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1604 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1605 | // Retrieve a value in a normalized object given a lookup result. |
| 1606 | // Handles the special representation of JS global objects. |
| 1607 | Object* GetNormalizedProperty(LookupResult* result); |
| 1608 | |
| 1609 | // Sets the property value in a normalized object given a lookup result. |
| 1610 | // Handles the special representation of JS global objects. |
| 1611 | Object* SetNormalizedProperty(LookupResult* result, Object* value); |
| 1612 | |
| 1613 | // Sets the property value in a normalized object given (key, value, details). |
| 1614 | // Handles the special representation of JS global objects. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1615 | static Handle<Object> SetNormalizedProperty(Handle<JSObject> object, |
| 1616 | Handle<String> key, |
| 1617 | Handle<Object> value, |
| 1618 | PropertyDetails details); |
| 1619 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1620 | MUST_USE_RESULT MaybeObject* SetNormalizedProperty(String* name, |
| 1621 | Object* value, |
| 1622 | PropertyDetails details); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1623 | |
| 1624 | // Deletes the named property in a normalized object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1625 | MUST_USE_RESULT MaybeObject* DeleteNormalizedProperty(String* name, |
| 1626 | DeleteMode mode); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1627 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1628 | MUST_USE_RESULT MaybeObject* OptimizeAsPrototype(); |
| 1629 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1630 | // Retrieve interceptors. |
| 1631 | InterceptorInfo* GetNamedInterceptor(); |
| 1632 | InterceptorInfo* GetIndexedInterceptor(); |
| 1633 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1634 | // Used from JSReceiver. |
| 1635 | PropertyAttributes GetPropertyAttributePostInterceptor(JSObject* receiver, |
| 1636 | String* name, |
| 1637 | bool continue_search); |
| 1638 | PropertyAttributes GetPropertyAttributeWithInterceptor(JSObject* receiver, |
| 1639 | String* name, |
| 1640 | bool continue_search); |
| 1641 | PropertyAttributes GetPropertyAttributeWithFailedAccessCheck( |
| 1642 | Object* receiver, |
| 1643 | LookupResult* result, |
| 1644 | String* name, |
| 1645 | bool continue_search); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1646 | |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 1647 | static void DefineAccessor(Handle<JSObject> object, |
| 1648 | Handle<String> name, |
| 1649 | Handle<Object> getter, |
| 1650 | Handle<Object> setter, |
| 1651 | PropertyAttributes attributes); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1652 | MUST_USE_RESULT MaybeObject* DefineAccessor(String* name, |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 1653 | Object* getter, |
| 1654 | Object* setter, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1655 | PropertyAttributes attributes); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1656 | // Try to define a single accessor paying attention to map transitions. |
| 1657 | // Returns a JavaScript null if this was not possible and we have to use the |
| 1658 | // slow case. Note that we can fail due to allocations, too. |
| 1659 | MUST_USE_RESULT MaybeObject* DefineFastAccessor( |
| 1660 | String* name, |
| 1661 | AccessorComponent component, |
| 1662 | Object* accessor, |
| 1663 | PropertyAttributes attributes); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1664 | Object* LookupAccessor(String* name, AccessorComponent component); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1665 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1666 | MUST_USE_RESULT MaybeObject* DefineAccessor(AccessorInfo* info); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1667 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1668 | // Used from Object::GetProperty(). |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 1669 | MUST_USE_RESULT MaybeObject* GetPropertyWithFailedAccessCheck( |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1670 | Object* receiver, |
| 1671 | LookupResult* result, |
| 1672 | String* name, |
| 1673 | PropertyAttributes* attributes); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 1674 | MUST_USE_RESULT MaybeObject* GetPropertyWithInterceptor( |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1675 | JSReceiver* receiver, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1676 | String* name, |
| 1677 | PropertyAttributes* attributes); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 1678 | MUST_USE_RESULT MaybeObject* GetPropertyPostInterceptor( |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1679 | JSReceiver* receiver, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1680 | String* name, |
| 1681 | PropertyAttributes* attributes); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 1682 | MUST_USE_RESULT MaybeObject* GetLocalPropertyPostInterceptor( |
| 1683 | JSReceiver* receiver, |
| 1684 | String* name, |
| 1685 | PropertyAttributes* attributes); |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 1686 | |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 1687 | // Returns true if this is an instance of an api function and has |
| 1688 | // been modified since it was created. May give false positives. |
| 1689 | bool IsDirty(); |
| 1690 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1691 | // If the receiver is a JSGlobalProxy this method will return its prototype, |
| 1692 | // otherwise the result is the receiver itself. |
| 1693 | inline Object* BypassGlobalProxy(); |
| 1694 | |
| 1695 | // Accessors for hidden properties object. |
| 1696 | // |
| 1697 | // Hidden properties are not local properties of the object itself. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1698 | // Instead they are stored in an auxiliary structure kept as a local |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1699 | // property with a special name Heap::hidden_symbol(). But if the |
| 1700 | // receiver is a JSGlobalProxy then the auxiliary object is a property |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1701 | // of its prototype, and if it's a detached proxy, then you can't have |
| 1702 | // hidden properties. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1703 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1704 | // Sets a hidden property on this object. Returns this object if successful, |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1705 | // undefined if called on a detached proxy. |
| 1706 | static Handle<Object> SetHiddenProperty(Handle<JSObject> obj, |
| 1707 | Handle<String> key, |
| 1708 | Handle<Object> value); |
| 1709 | // Returns a failure if a GC is required. |
jkummerow@chromium.org | ab7dad4 | 2012-02-07 12:07:34 +0000 | [diff] [blame] | 1710 | MUST_USE_RESULT MaybeObject* SetHiddenProperty(String* key, Object* value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1711 | // Gets the value of a hidden property with the given key. Returns undefined |
| 1712 | // if the property doesn't exist (or if called on a detached proxy), |
| 1713 | // otherwise returns the value set for the key. |
| 1714 | Object* GetHiddenProperty(String* key); |
| 1715 | // Deletes a hidden property. Deleting a non-existing property is |
| 1716 | // considered successful. |
| 1717 | void DeleteHiddenProperty(String* key); |
| 1718 | // Returns true if the object has a property with the hidden symbol as name. |
| 1719 | bool HasHiddenProperties(); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1720 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1721 | static int GetIdentityHash(Handle<JSObject> obj); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1722 | MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag); |
| 1723 | MUST_USE_RESULT MaybeObject* SetIdentityHash(Object* hash, CreationFlag flag); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1724 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1725 | static Handle<Object> DeleteProperty(Handle<JSObject> obj, |
| 1726 | Handle<String> name); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1727 | MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1728 | |
| 1729 | static Handle<Object> DeleteElement(Handle<JSObject> obj, uint32_t index); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1730 | MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1731 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1732 | inline void ValidateElements(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1733 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1734 | // Makes sure that this object can contain HeapObject as elements. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 1735 | MUST_USE_RESULT inline MaybeObject* EnsureCanContainHeapObjectElements(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1736 | |
| 1737 | // Makes sure that this object can contain the specified elements. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 1738 | MUST_USE_RESULT inline MaybeObject* EnsureCanContainElements( |
| 1739 | Object** elements, |
| 1740 | uint32_t count, |
| 1741 | EnsureElementsMode mode); |
| 1742 | MUST_USE_RESULT inline MaybeObject* EnsureCanContainElements( |
| 1743 | FixedArrayBase* elements, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1744 | uint32_t length, |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 1745 | EnsureElementsMode mode); |
| 1746 | MUST_USE_RESULT MaybeObject* EnsureCanContainElements( |
| 1747 | Arguments* arguments, |
| 1748 | uint32_t first_arg, |
| 1749 | uint32_t arg_count, |
| 1750 | EnsureElementsMode mode); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1751 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1752 | // Do we want to keep the elements in fast case when increasing the |
| 1753 | // capacity? |
| 1754 | bool ShouldConvertToSlowElements(int new_capacity); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1755 | // Returns true if the backing storage for the slow-case elements of |
| 1756 | // this object takes up nearly as much space as a fast-case backing |
| 1757 | // storage would. In that case the JSObject should have fast |
| 1758 | // elements. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1759 | bool ShouldConvertToFastElements(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1760 | // Returns true if the elements of JSObject contains only values that can be |
svenpanne@chromium.org | 3c93e77 | 2012-01-02 09:26:59 +0000 | [diff] [blame] | 1761 | // represented in a FixedDoubleArray and has at least one value that can only |
| 1762 | // be represented as a double and not a Smi. |
| 1763 | bool ShouldConvertToFastDoubleElements(bool* has_smi_only_elements); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1764 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1765 | // Tells whether the index'th element is present. |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1766 | bool HasElementWithReceiver(JSReceiver* receiver, uint32_t index); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1767 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1768 | // Computes the new capacity when expanding the elements of a JSObject. |
| 1769 | static int NewElementsCapacity(int old_capacity) { |
| 1770 | // (old_capacity + 50%) + 16 |
| 1771 | return old_capacity + (old_capacity >> 1) + 16; |
| 1772 | } |
| 1773 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1774 | // Tells whether the index'th element is present and how it is stored. |
| 1775 | enum LocalElementType { |
| 1776 | // There is no element with given index. |
| 1777 | UNDEFINED_ELEMENT, |
| 1778 | |
| 1779 | // Element with given index is handled by interceptor. |
| 1780 | INTERCEPTED_ELEMENT, |
| 1781 | |
| 1782 | // Element with given index is character in string. |
| 1783 | STRING_CHARACTER_ELEMENT, |
| 1784 | |
| 1785 | // Element with given index is stored in fast backing store. |
| 1786 | FAST_ELEMENT, |
| 1787 | |
| 1788 | // Element with given index is stored in slow backing store. |
| 1789 | DICTIONARY_ELEMENT |
| 1790 | }; |
| 1791 | |
| 1792 | LocalElementType HasLocalElement(uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1793 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1794 | bool HasElementWithInterceptor(JSReceiver* receiver, uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1795 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1796 | MUST_USE_RESULT MaybeObject* SetFastElement(uint32_t index, |
| 1797 | Object* value, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1798 | StrictModeFlag strict_mode, |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1799 | bool check_prototype); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1800 | |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 1801 | MUST_USE_RESULT MaybeObject* SetDictionaryElement( |
| 1802 | uint32_t index, |
| 1803 | Object* value, |
| 1804 | PropertyAttributes attributes, |
| 1805 | StrictModeFlag strict_mode, |
| 1806 | bool check_prototype, |
| 1807 | SetPropertyMode set_mode = SET_PROPERTY); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1808 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1809 | MUST_USE_RESULT MaybeObject* SetFastDoubleElement( |
| 1810 | uint32_t index, |
| 1811 | Object* value, |
| 1812 | StrictModeFlag strict_mode, |
| 1813 | bool check_prototype = true); |
| 1814 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1815 | static Handle<Object> SetOwnElement(Handle<JSObject> object, |
| 1816 | uint32_t index, |
| 1817 | Handle<Object> value, |
| 1818 | StrictModeFlag strict_mode); |
| 1819 | |
| 1820 | // Empty handle is returned if the element cannot be set to the given value. |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 1821 | static MUST_USE_RESULT Handle<Object> SetElement( |
| 1822 | Handle<JSObject> object, |
| 1823 | uint32_t index, |
| 1824 | Handle<Object> value, |
| 1825 | PropertyAttributes attr, |
| 1826 | StrictModeFlag strict_mode, |
| 1827 | SetPropertyMode set_mode = SET_PROPERTY); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1828 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1829 | // A Failure object is returned if GC is needed. |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 1830 | MUST_USE_RESULT MaybeObject* SetElement( |
| 1831 | uint32_t index, |
| 1832 | Object* value, |
| 1833 | PropertyAttributes attributes, |
| 1834 | StrictModeFlag strict_mode, |
| 1835 | bool check_prototype = true, |
| 1836 | SetPropertyMode set_mode = SET_PROPERTY); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1837 | |
| 1838 | // Returns the index'th element. |
| 1839 | // The undefined object if index is out of bounds. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 1840 | MUST_USE_RESULT MaybeObject* GetElementWithInterceptor(Object* receiver, |
| 1841 | uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1842 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1843 | enum SetFastElementsCapacitySmiMode { |
| 1844 | kAllowSmiElements, |
| 1845 | kForceSmiElements, |
| 1846 | kDontAllowSmiElements |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1847 | }; |
| 1848 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1849 | // Replace the elements' backing store with fast elements of the given |
| 1850 | // capacity. Update the length for JSArrays. Returns the new backing |
| 1851 | // store. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1852 | MUST_USE_RESULT MaybeObject* SetFastElementsCapacityAndLength( |
| 1853 | int capacity, |
| 1854 | int length, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1855 | SetFastElementsCapacitySmiMode smi_mode); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1856 | MUST_USE_RESULT MaybeObject* SetFastDoubleElementsCapacityAndLength( |
| 1857 | int capacity, |
| 1858 | int length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1859 | |
| 1860 | // Lookup interceptors are used for handling properties controlled by host |
| 1861 | // objects. |
| 1862 | inline bool HasNamedInterceptor(); |
| 1863 | inline bool HasIndexedInterceptor(); |
| 1864 | |
| 1865 | // Support functions for v8 api (needed for correct interceptor behavior). |
| 1866 | bool HasRealNamedProperty(String* key); |
| 1867 | bool HasRealElementProperty(uint32_t index); |
| 1868 | bool HasRealNamedCallbackProperty(String* key); |
| 1869 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1870 | // Get the header size for a JSObject. Used to compute the index of |
| 1871 | // internal fields as well as the number of internal fields. |
| 1872 | inline int GetHeaderSize(); |
| 1873 | |
| 1874 | inline int GetInternalFieldCount(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1875 | inline int GetInternalFieldOffset(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1876 | inline Object* GetInternalField(int index); |
| 1877 | inline void SetInternalField(int index, Object* value); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1878 | inline void SetInternalField(int index, Smi* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1879 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1880 | // The following lookup functions skip interceptors. |
| 1881 | void LocalLookupRealNamedProperty(String* name, LookupResult* result); |
| 1882 | void LookupRealNamedProperty(String* name, LookupResult* result); |
| 1883 | void LookupRealNamedPropertyInPrototypes(String* name, LookupResult* result); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1884 | MUST_USE_RESULT MaybeObject* SetElementWithCallbackSetterInPrototypes( |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 1885 | uint32_t index, Object* value, bool* found, StrictModeFlag strict_mode); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame^] | 1886 | void LookupCallbackProperty(String* name, LookupResult* result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1887 | |
| 1888 | // Returns the number of properties on this object filtering out properties |
| 1889 | // with the specified attributes (ignoring interceptors). |
jkummerow@chromium.org | ab7dad4 | 2012-02-07 12:07:34 +0000 | [diff] [blame] | 1890 | int NumberOfLocalProperties(PropertyAttributes filter = NONE); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 1891 | // Fill in details for properties into storage starting at the specified |
| 1892 | // index. |
| 1893 | void GetLocalPropertyNames(FixedArray* storage, int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1894 | |
| 1895 | // Returns the number of properties on this object filtering out properties |
| 1896 | // with the specified attributes (ignoring interceptors). |
| 1897 | int NumberOfLocalElements(PropertyAttributes filter); |
| 1898 | // Returns the number of enumerable elements (ignoring interceptors). |
| 1899 | int NumberOfEnumElements(); |
| 1900 | // Returns the number of elements on this object filtering out elements |
| 1901 | // with the specified attributes (ignoring interceptors). |
| 1902 | int GetLocalElementKeys(FixedArray* storage, PropertyAttributes filter); |
| 1903 | // Count and fill in the enumerable elements into storage. |
| 1904 | // (storage->length() == NumberOfEnumElements()). |
| 1905 | // If storage is NULL, will count the elements without adding |
| 1906 | // them to any storage. |
| 1907 | // Returns the number of enumerable elements. |
| 1908 | int GetEnumElementKeys(FixedArray* storage); |
| 1909 | |
| 1910 | // Add a property to a fast-case object using a map transition to |
| 1911 | // new_map. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1912 | MUST_USE_RESULT MaybeObject* AddFastPropertyUsingMap(Map* new_map, |
| 1913 | String* name, |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 1914 | Object* value, |
| 1915 | int field_index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1916 | |
| 1917 | // 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] | 1918 | // This leaves a CONSTANT_TRANSITION in the old map, and |
| 1919 | // if it is called on a second object with this map, a |
| 1920 | // normal property is added instead, with a map transition. |
| 1921 | // This avoids the creation of many maps with the same constant |
| 1922 | // function, all orphaned. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1923 | MUST_USE_RESULT MaybeObject* AddConstantFunctionProperty( |
| 1924 | String* name, |
| 1925 | JSFunction* function, |
| 1926 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1927 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1928 | MUST_USE_RESULT MaybeObject* ReplaceSlowProperty( |
| 1929 | String* name, |
| 1930 | Object* value, |
| 1931 | PropertyAttributes attributes); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1932 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1933 | // Returns a new map with all transitions dropped from the object's current |
| 1934 | // map and the ElementsKind set. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1935 | static Handle<Map> GetElementsTransitionMap(Handle<JSObject> object, |
| 1936 | ElementsKind to_kind); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1937 | inline MUST_USE_RESULT MaybeObject* GetElementsTransitionMap( |
| 1938 | Isolate* isolate, |
| 1939 | ElementsKind elements_kind); |
| 1940 | MUST_USE_RESULT MaybeObject* GetElementsTransitionMapSlow( |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1941 | ElementsKind elements_kind); |
| 1942 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1943 | static Handle<Object> TransitionElementsKind(Handle<JSObject> object, |
| 1944 | ElementsKind to_kind); |
| 1945 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1946 | MUST_USE_RESULT MaybeObject* TransitionElementsKind(ElementsKind to_kind); |
| 1947 | |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 1948 | // Replaces an existing transition with a transition to a map with a FIELD. |
| 1949 | MUST_USE_RESULT MaybeObject* ConvertTransitionToMapTransition( |
| 1950 | int transition_index, |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1951 | String* name, |
| 1952 | Object* new_value, |
| 1953 | PropertyAttributes attributes); |
| 1954 | |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 1955 | // Converts a descriptor of any other type to a real field, backed by the |
| 1956 | // properties array. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1957 | MUST_USE_RESULT MaybeObject* ConvertDescriptorToField( |
| 1958 | String* name, |
| 1959 | Object* new_value, |
| 1960 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1961 | |
| 1962 | // Add a property to a fast-case object. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1963 | MUST_USE_RESULT MaybeObject* AddFastProperty( |
| 1964 | String* name, |
| 1965 | Object* value, |
| 1966 | PropertyAttributes attributes, |
| 1967 | StoreFromKeyed store_mode = MAY_BE_STORE_FROM_KEYED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1968 | |
| 1969 | // Add a property to a slow-case object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1970 | MUST_USE_RESULT MaybeObject* AddSlowProperty(String* name, |
| 1971 | Object* value, |
| 1972 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1973 | |
| 1974 | // Add a property to an object. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1975 | MUST_USE_RESULT MaybeObject* AddProperty( |
| 1976 | String* name, |
| 1977 | Object* value, |
| 1978 | PropertyAttributes attributes, |
| 1979 | StrictModeFlag strict_mode, |
mstarzinger@chromium.org | ccab367 | 2012-06-14 15:01:16 +0000 | [diff] [blame] | 1980 | StoreFromKeyed store_mode = MAY_BE_STORE_FROM_KEYED, |
| 1981 | ExtensibilityCheck extensibility_check = PERFORM_EXTENSIBILITY_CHECK); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1982 | |
| 1983 | // Convert the object to use the canonical dictionary |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1984 | // representation. If the object is expected to have additional properties |
| 1985 | // added this number can be indicated to have the backing store allocated to |
| 1986 | // an initial capacity for holding these properties. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1987 | static void NormalizeProperties(Handle<JSObject> object, |
| 1988 | PropertyNormalizationMode mode, |
| 1989 | int expected_additional_properties); |
| 1990 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1991 | MUST_USE_RESULT MaybeObject* NormalizeProperties( |
| 1992 | PropertyNormalizationMode mode, |
| 1993 | int expected_additional_properties); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1994 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1995 | // Convert and update the elements backing store to be a |
| 1996 | // SeededNumberDictionary dictionary. Returns the backing after conversion. |
| 1997 | static Handle<SeededNumberDictionary> NormalizeElements( |
| 1998 | Handle<JSObject> object); |
| 1999 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2000 | MUST_USE_RESULT MaybeObject* NormalizeElements(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2001 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2002 | static void UpdateMapCodeCache(Handle<JSObject> object, |
| 2003 | Handle<String> name, |
| 2004 | Handle<Code> code); |
| 2005 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2006 | MUST_USE_RESULT MaybeObject* UpdateMapCodeCache(String* name, Code* code); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2007 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2008 | // Transform slow named properties to fast variants. |
| 2009 | // Returns failure if allocation failed. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2010 | static void TransformToFastProperties(Handle<JSObject> object, |
| 2011 | int unused_property_fields); |
| 2012 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2013 | MUST_USE_RESULT MaybeObject* TransformToFastProperties( |
| 2014 | int unused_property_fields); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2015 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2016 | // Access fast-case object properties at index. |
| 2017 | inline Object* FastPropertyAt(int index); |
| 2018 | inline Object* FastPropertyAtPut(int index, Object* value); |
| 2019 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2020 | // Access to in object properties. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2021 | inline int GetInObjectPropertyOffset(int index); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2022 | inline Object* InObjectPropertyAt(int index); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2023 | inline Object* InObjectPropertyAtPut(int index, |
| 2024 | Object* value, |
| 2025 | WriteBarrierMode mode |
| 2026 | = UPDATE_WRITE_BARRIER); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2027 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2028 | // Initializes the body after properties slot, properties slot is |
| 2029 | // initialized by set_properties. Fill the pre-allocated fields with |
| 2030 | // pre_allocated_value and the rest with filler_value. |
| 2031 | // Note: this call does not update write barrier, the caller is responsible |
| 2032 | // to ensure that |filler_value| can be collected without WB here. |
| 2033 | inline void InitializeBody(Map* map, |
| 2034 | Object* pre_allocated_value, |
| 2035 | Object* filler_value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2036 | |
| 2037 | // Check whether this object references another object |
| 2038 | bool ReferencesObject(Object* obj); |
| 2039 | |
| 2040 | // Casting. |
| 2041 | static inline JSObject* cast(Object* obj); |
| 2042 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2043 | // Disalow further properties to be added to the object. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2044 | static Handle<Object> PreventExtensions(Handle<JSObject> object); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2045 | MUST_USE_RESULT MaybeObject* PreventExtensions(); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2046 | |
| 2047 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2048 | // Dispatched behavior. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2049 | void JSObjectShortPrint(StringStream* accumulator); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2050 | #ifdef OBJECT_PRINT |
| 2051 | inline void JSObjectPrint() { |
| 2052 | JSObjectPrint(stdout); |
| 2053 | } |
| 2054 | void JSObjectPrint(FILE* out); |
| 2055 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2056 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2057 | void JSObjectVerify(); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2058 | #endif |
| 2059 | #ifdef OBJECT_PRINT |
| 2060 | inline void PrintProperties() { |
| 2061 | PrintProperties(stdout); |
| 2062 | } |
| 2063 | void PrintProperties(FILE* out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2064 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2065 | inline void PrintElements() { |
| 2066 | PrintElements(stdout); |
| 2067 | } |
| 2068 | void PrintElements(FILE* out); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 2069 | inline void PrintTransitions() { |
| 2070 | PrintTransitions(stdout); |
| 2071 | } |
| 2072 | void PrintTransitions(FILE* out); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2073 | #endif |
| 2074 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2075 | void PrintElementsTransition( |
| 2076 | FILE* file, ElementsKind from_kind, FixedArrayBase* from_elements, |
| 2077 | ElementsKind to_kind, FixedArrayBase* to_elements); |
| 2078 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2079 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2080 | // Structure for collecting spill information about JSObjects. |
| 2081 | class SpillInformation { |
| 2082 | public: |
| 2083 | void Clear(); |
| 2084 | void Print(); |
| 2085 | int number_of_objects_; |
| 2086 | int number_of_objects_with_fast_properties_; |
| 2087 | int number_of_objects_with_fast_elements_; |
| 2088 | int number_of_fast_used_fields_; |
| 2089 | int number_of_fast_unused_fields_; |
| 2090 | int number_of_slow_used_properties_; |
| 2091 | int number_of_slow_unused_properties_; |
| 2092 | int number_of_fast_used_elements_; |
| 2093 | int number_of_fast_unused_elements_; |
| 2094 | int number_of_slow_used_elements_; |
| 2095 | int number_of_slow_unused_elements_; |
| 2096 | }; |
| 2097 | |
| 2098 | void IncrementSpillStatistics(SpillInformation* info); |
| 2099 | #endif |
| 2100 | Object* SlowReverseLookup(Object* value); |
| 2101 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2102 | // Maximal number of fast properties for the JSObject. Used to |
| 2103 | // restrict the number of map transitions to avoid an explosion in |
| 2104 | // the number of maps for objects used as dictionaries. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2105 | inline bool TooManyFastProperties(int properties, StoreFromKeyed store_mode); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2106 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2107 | // Maximal number of elements (numbered 0 .. kMaxElementCount - 1). |
| 2108 | // Also maximal value of JSArray's length property. |
| 2109 | static const uint32_t kMaxElementCount = 0xffffffffu; |
| 2110 | |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 2111 | // Constants for heuristics controlling conversion of fast elements |
| 2112 | // to slow elements. |
| 2113 | |
| 2114 | // Maximal gap that can be introduced by adding an element beyond |
| 2115 | // the current elements length. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2116 | static const uint32_t kMaxGap = 1024; |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 2117 | |
| 2118 | // Maximal length of fast elements array that won't be checked for |
| 2119 | // being dense enough on expansion. |
| 2120 | static const int kMaxUncheckedFastElementsLength = 5000; |
| 2121 | |
| 2122 | // Same as above but for old arrays. This limit is more strict. We |
| 2123 | // don't want to be wasteful with long lived objects. |
| 2124 | static const int kMaxUncheckedOldFastElementsLength = 500; |
| 2125 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2126 | static const int kInitialMaxFastElementArray = 100000; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2127 | static const int kFastPropertiesSoftLimit = 12; |
| 2128 | static const int kMaxFastProperties = 64; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2129 | static const int kMaxInstanceSize = 255 * kPointerSize; |
| 2130 | // When extending the backing storage for property values, we increase |
| 2131 | // its size by more than the 1 entry necessary, so sequentially adding fields |
| 2132 | // to the same object requires fewer allocations and copies. |
| 2133 | static const int kFieldsAdded = 3; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2134 | |
| 2135 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2136 | static const int kPropertiesOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2137 | static const int kElementsOffset = kPropertiesOffset + kPointerSize; |
| 2138 | static const int kHeaderSize = kElementsOffset + kPointerSize; |
| 2139 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2140 | STATIC_CHECK(kHeaderSize == Internals::kJSObjectHeaderSize); |
| 2141 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2142 | class BodyDescriptor : public FlexibleBodyDescriptor<kPropertiesOffset> { |
| 2143 | public: |
| 2144 | static inline int SizeOf(Map* map, HeapObject* object); |
| 2145 | }; |
| 2146 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2147 | private: |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2148 | friend class DictionaryElementsAccessor; |
| 2149 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2150 | MUST_USE_RESULT MaybeObject* GetElementWithCallback(Object* receiver, |
| 2151 | Object* structure, |
| 2152 | uint32_t index, |
| 2153 | Object* holder); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2154 | MUST_USE_RESULT MaybeObject* SetElementWithCallback( |
| 2155 | Object* structure, |
| 2156 | uint32_t index, |
| 2157 | Object* value, |
| 2158 | JSObject* holder, |
| 2159 | StrictModeFlag strict_mode); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2160 | MUST_USE_RESULT MaybeObject* SetElementWithInterceptor( |
| 2161 | uint32_t index, |
| 2162 | Object* value, |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 2163 | PropertyAttributes attributes, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2164 | StrictModeFlag strict_mode, |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 2165 | bool check_prototype, |
| 2166 | SetPropertyMode set_mode); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 2167 | MUST_USE_RESULT MaybeObject* SetElementWithoutInterceptor( |
| 2168 | uint32_t index, |
| 2169 | Object* value, |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 2170 | PropertyAttributes attributes, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2171 | StrictModeFlag strict_mode, |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 2172 | bool check_prototype, |
| 2173 | SetPropertyMode set_mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2174 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2175 | // Searches the prototype chain for property 'name'. If it is found and |
| 2176 | // has a setter, invoke it and set '*done' to true. If it is found and is |
| 2177 | // read-only, reject and set '*done' to true. Otherwise, set '*done' to |
| 2178 | // false. Can cause GC and can return a failure result with '*done==true'. |
| 2179 | MUST_USE_RESULT MaybeObject* SetPropertyViaPrototypes( |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2180 | String* name, |
| 2181 | Object* value, |
| 2182 | PropertyAttributes attributes, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2183 | StrictModeFlag strict_mode, |
| 2184 | bool* done); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2185 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2186 | MUST_USE_RESULT MaybeObject* DeletePropertyPostInterceptor(String* name, |
| 2187 | DeleteMode mode); |
| 2188 | MUST_USE_RESULT MaybeObject* DeletePropertyWithInterceptor(String* name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2189 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2190 | MUST_USE_RESULT MaybeObject* DeleteElementWithInterceptor(uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2191 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2192 | MUST_USE_RESULT MaybeObject* DeleteFastElement(uint32_t index); |
| 2193 | MUST_USE_RESULT MaybeObject* DeleteDictionaryElement(uint32_t index, |
| 2194 | DeleteMode mode); |
| 2195 | |
| 2196 | bool ReferencesObjectFromElements(FixedArray* elements, |
| 2197 | ElementsKind kind, |
| 2198 | Object* object); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2199 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2200 | // Returns true if most of the elements backing storage is used. |
| 2201 | bool HasDenseElements(); |
| 2202 | |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 2203 | // Gets the current elements capacity and the number of used elements. |
| 2204 | void GetElementsCapacityAndUsage(int* capacity, int* used); |
| 2205 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2206 | bool CanSetCallback(String* name); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2207 | MUST_USE_RESULT MaybeObject* SetElementCallback( |
| 2208 | uint32_t index, |
| 2209 | Object* structure, |
| 2210 | PropertyAttributes attributes); |
| 2211 | MUST_USE_RESULT MaybeObject* SetPropertyCallback( |
| 2212 | String* name, |
| 2213 | Object* structure, |
| 2214 | PropertyAttributes attributes); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 2215 | MUST_USE_RESULT MaybeObject* DefineElementAccessor( |
| 2216 | uint32_t index, |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 2217 | Object* getter, |
| 2218 | Object* setter, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2219 | PropertyAttributes attributes); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 2220 | MUST_USE_RESULT MaybeObject* CreateAccessorPairFor(String* name); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 2221 | MUST_USE_RESULT MaybeObject* DefinePropertyAccessor( |
| 2222 | String* name, |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 2223 | Object* getter, |
| 2224 | Object* setter, |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 2225 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2226 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2227 | // Returns the hidden properties backing store object, currently |
| 2228 | // a StringDictionary, stored on this object. |
| 2229 | // If no hidden properties object has been put on this object, |
| 2230 | // return undefined, unless create_if_absent is true, in which case |
| 2231 | // a new dictionary is created, added to this object, and returned. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2232 | MUST_USE_RESULT MaybeObject* GetHiddenPropertiesDictionary( |
| 2233 | bool create_if_absent); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2234 | // Updates the existing hidden properties dictionary. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2235 | MUST_USE_RESULT MaybeObject* SetHiddenPropertiesDictionary( |
| 2236 | StringDictionary* dictionary); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2237 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2238 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject); |
| 2239 | }; |
| 2240 | |
| 2241 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2242 | // Common superclass for FixedArrays that allow implementations to share |
| 2243 | // common accessors and some code paths. |
| 2244 | class FixedArrayBase: public HeapObject { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2245 | public: |
| 2246 | // [length]: length of the array. |
| 2247 | inline int length(); |
| 2248 | inline void set_length(int value); |
| 2249 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2250 | inline static FixedArrayBase* cast(Object* object); |
| 2251 | |
| 2252 | // Layout description. |
| 2253 | // Length is smi tagged when it is stored. |
| 2254 | static const int kLengthOffset = HeapObject::kHeaderSize; |
| 2255 | static const int kHeaderSize = kLengthOffset + kPointerSize; |
| 2256 | }; |
| 2257 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2258 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 2259 | class FixedDoubleArray; |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 2260 | class IncrementalMarking; |
| 2261 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2262 | |
| 2263 | // FixedArray describes fixed-sized arrays with element type Object*. |
| 2264 | class FixedArray: public FixedArrayBase { |
| 2265 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2266 | // Setter and getter for elements. |
| 2267 | inline Object* get(int index); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2268 | // Setter that uses write barrier. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2269 | inline void set(int index, Object* value); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2270 | inline bool is_the_hole(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2271 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2272 | // Setter that doesn't need write barrier). |
| 2273 | inline void set(int index, Smi* value); |
| 2274 | // Setter with explicit barrier mode. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2275 | inline void set(int index, Object* value, WriteBarrierMode mode); |
| 2276 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2277 | // Setters for frequently used oddballs located in old space. |
| 2278 | inline void set_undefined(int index); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2279 | // TODO(isolates): duplicate. |
| 2280 | inline void set_undefined(Heap* heap, int index); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2281 | inline void set_null(int index); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2282 | // TODO(isolates): duplicate. |
| 2283 | inline void set_null(Heap* heap, int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2284 | inline void set_the_hole(int index); |
| 2285 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 2286 | // Setters with less debug checks for the GC to use. |
| 2287 | inline void set_unchecked(int index, Smi* value); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2288 | inline void set_null_unchecked(Heap* heap, int index); |
| 2289 | inline void set_unchecked(Heap* heap, int index, Object* value, |
| 2290 | WriteBarrierMode mode); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 2291 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2292 | // Gives access to raw memory which stores the array's data. |
| 2293 | inline Object** data_start(); |
| 2294 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2295 | inline Object** GetFirstElementAddress(); |
| 2296 | inline bool ContainsOnlySmisOrHoles(); |
| 2297 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2298 | // Copy operations. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2299 | MUST_USE_RESULT inline MaybeObject* Copy(); |
| 2300 | MUST_USE_RESULT MaybeObject* CopySize(int new_length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2301 | |
| 2302 | // Add the elements of a JSArray to this FixedArray. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2303 | MUST_USE_RESULT MaybeObject* AddKeysFromJSArray(JSArray* array); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2304 | |
| 2305 | // Compute the union of this and other. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2306 | MUST_USE_RESULT MaybeObject* UnionOfKeys(FixedArray* other); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2307 | |
| 2308 | // Copy a sub array from the receiver to dest. |
| 2309 | void CopyTo(int pos, FixedArray* dest, int dest_pos, int len); |
| 2310 | |
| 2311 | // Garbage collection support. |
| 2312 | static int SizeFor(int length) { return kHeaderSize + length * kPointerSize; } |
| 2313 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2314 | // Code Generation support. |
| 2315 | static int OffsetOfElementAt(int index) { return SizeFor(index); } |
| 2316 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2317 | // Casting. |
| 2318 | static inline FixedArray* cast(Object* obj); |
| 2319 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2320 | // Maximal allowed size, in bytes, of a single FixedArray. |
| 2321 | // Prevents overflowing size computations, as well as extreme memory |
| 2322 | // consumption. |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2323 | static const int kMaxSize = 128 * MB * kPointerSize; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2324 | // Maximally allowed length of a FixedArray. |
| 2325 | static const int kMaxLength = (kMaxSize - kHeaderSize) / kPointerSize; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2326 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2327 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2328 | #ifdef OBJECT_PRINT |
| 2329 | inline void FixedArrayPrint() { |
| 2330 | FixedArrayPrint(stdout); |
| 2331 | } |
| 2332 | void FixedArrayPrint(FILE* out); |
| 2333 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2334 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2335 | void FixedArrayVerify(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2336 | // Checks if two FixedArrays have identical contents. |
| 2337 | bool IsEqualTo(FixedArray* other); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2338 | #endif |
| 2339 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2340 | // Swap two elements in a pair of arrays. If this array and the |
| 2341 | // numbers array are the same object, the elements are only swapped |
| 2342 | // once. |
| 2343 | void SwapPairs(FixedArray* numbers, int i, int j); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2344 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2345 | // Sort prefix of this array and the numbers array as pairs wrt. the |
| 2346 | // numbers. If the numbers array and the this array are the same |
| 2347 | // object, the prefix of this array is sorted. |
| 2348 | void SortPairs(FixedArray* numbers, uint32_t len); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2349 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2350 | class BodyDescriptor : public FlexibleBodyDescriptor<kHeaderSize> { |
| 2351 | public: |
| 2352 | static inline int SizeOf(Map* map, HeapObject* object) { |
| 2353 | return SizeFor(reinterpret_cast<FixedArray*>(object)->length()); |
| 2354 | } |
| 2355 | }; |
| 2356 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 2357 | // WhitenessWitness is used to prove that a descriptor array is white |
| 2358 | // (unmarked), so incremental write barriers can be skipped because the |
| 2359 | // marking invariant cannot be broken and slots pointing into evacuation |
| 2360 | // candidates will be discovered when the object is scanned. A witness is |
| 2361 | // always stack-allocated right after creating an array. By allocating a |
| 2362 | // witness, incremental marking is globally disabled. The witness is then |
| 2363 | // passed along wherever needed to statically prove that the array is known to |
| 2364 | // be white. |
| 2365 | class WhitenessWitness { |
| 2366 | public: |
| 2367 | inline explicit WhitenessWitness(FixedArray* array); |
| 2368 | inline ~WhitenessWitness(); |
| 2369 | |
| 2370 | private: |
| 2371 | IncrementalMarking* marking_; |
| 2372 | }; |
| 2373 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2374 | protected: |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2375 | // Set operation on FixedArray without using write barriers. Can |
| 2376 | // only be used for storing old space objects or smis. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2377 | static inline void NoWriteBarrierSet(FixedArray* array, |
| 2378 | int index, |
| 2379 | Object* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2380 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2381 | // Set operation on FixedArray without incremental write barrier. Can |
| 2382 | // only be used if the object is guaranteed to be white (whiteness witness |
| 2383 | // is present). |
| 2384 | static inline void NoIncrementalWriteBarrierSet(FixedArray* array, |
| 2385 | int index, |
| 2386 | Object* value); |
| 2387 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2388 | private: |
| 2389 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedArray); |
| 2390 | }; |
| 2391 | |
| 2392 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2393 | // FixedDoubleArray describes fixed-sized arrays with element type double. |
| 2394 | class FixedDoubleArray: public FixedArrayBase { |
| 2395 | public: |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2396 | // Setter and getter for elements. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2397 | inline double get_scalar(int index); |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 2398 | inline int64_t get_representation(int index); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2399 | MUST_USE_RESULT inline MaybeObject* get(int index); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2400 | inline void set(int index, double value); |
| 2401 | inline void set_the_hole(int index); |
| 2402 | |
| 2403 | // Checking for the hole. |
| 2404 | inline bool is_the_hole(int index); |
| 2405 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2406 | // Copy operations |
| 2407 | MUST_USE_RESULT inline MaybeObject* Copy(); |
| 2408 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2409 | // Garbage collection support. |
| 2410 | inline static int SizeFor(int length) { |
| 2411 | return kHeaderSize + length * kDoubleSize; |
| 2412 | } |
| 2413 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 2414 | // Code Generation support. |
| 2415 | static int OffsetOfElementAt(int index) { return SizeFor(index); } |
| 2416 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2417 | inline static bool is_the_hole_nan(double value); |
| 2418 | inline static double hole_nan_as_double(); |
| 2419 | inline static double canonical_not_the_hole_nan_as_double(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2420 | |
| 2421 | // Casting. |
| 2422 | static inline FixedDoubleArray* cast(Object* obj); |
| 2423 | |
| 2424 | // Maximal allowed size, in bytes, of a single FixedDoubleArray. |
| 2425 | // Prevents overflowing size computations, as well as extreme memory |
| 2426 | // consumption. |
| 2427 | static const int kMaxSize = 512 * MB; |
| 2428 | // Maximally allowed length of a FixedArray. |
| 2429 | static const int kMaxLength = (kMaxSize - kHeaderSize) / kDoubleSize; |
| 2430 | |
| 2431 | // Dispatched behavior. |
| 2432 | #ifdef OBJECT_PRINT |
| 2433 | inline void FixedDoubleArrayPrint() { |
| 2434 | FixedDoubleArrayPrint(stdout); |
| 2435 | } |
| 2436 | void FixedDoubleArrayPrint(FILE* out); |
| 2437 | #endif |
| 2438 | |
| 2439 | #ifdef DEBUG |
| 2440 | void FixedDoubleArrayVerify(); |
| 2441 | #endif |
| 2442 | |
| 2443 | private: |
| 2444 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedDoubleArray); |
| 2445 | }; |
| 2446 | |
| 2447 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2448 | // DescriptorArrays are fixed arrays used to hold instance descriptors. |
| 2449 | // The format of the these objects is: |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2450 | // TODO(1399): It should be possible to make room for bit_field3 in the map |
| 2451 | // without overloading the instance descriptors field in the map |
| 2452 | // (and storing it in the DescriptorArray when the map has one). |
| 2453 | // [0]: storage for bit_field3 for Map owning this object (Smi) |
| 2454 | // [1]: point to a fixed array with (value, detail) pairs. |
| 2455 | // [2]: next enumeration index (Smi), or pointer to small fixed array: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2456 | // [0]: next enumeration index (Smi) |
| 2457 | // [1]: pointer to fixed array with enum cache |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2458 | // [3]: first key |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 2459 | // [length() - kDescriptorSize]: last key |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2460 | // |
| 2461 | class DescriptorArray: public FixedArray { |
| 2462 | public: |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2463 | // Returns true for both shared empty_descriptor_array and for smis, which the |
| 2464 | // map uses to encode additional bit fields when the descriptor array is not |
| 2465 | // yet used. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2466 | inline bool IsEmpty(); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2467 | inline bool MayContainTransitions(); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 2468 | inline bool HasTransitionArray(); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2469 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 2470 | DECL_ACCESSORS(transitions, TransitionArray) |
| 2471 | inline void ClearTransitions(); |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 2472 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2473 | // Returns the number of descriptors in the array. |
| 2474 | int number_of_descriptors() { |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 2475 | ASSERT(MayContainTransitions() || IsEmpty()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2476 | int len = length(); |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2477 | return len <= kFirstIndex ? 0 : (len - kFirstIndex) / kDescriptorSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2478 | } |
| 2479 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 2480 | inline int number_of_entries() { return number_of_descriptors(); } |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 2481 | inline int NextEnumerationIndex() { return number_of_descriptors() + 1; } |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 2482 | |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 2483 | int LastAdded() { |
| 2484 | ASSERT(!IsEmpty()); |
| 2485 | Object* obj = get(kLastAddedIndex); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2486 | if (obj->IsSmi()) { |
| 2487 | return Smi::cast(obj)->value(); |
| 2488 | } else { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 2489 | Object* index = FixedArray::cast(obj)->get(kEnumCacheBridgeLastAdded); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2490 | return Smi::cast(index)->value(); |
| 2491 | } |
| 2492 | } |
| 2493 | |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 2494 | // Set index of the last added descriptor and flush any enum cache. |
| 2495 | void SetLastAdded(int index) { |
| 2496 | ASSERT(!IsEmpty() || index > 0); |
| 2497 | set(kLastAddedIndex, Smi::FromInt(index)); |
| 2498 | } |
| 2499 | |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 2500 | int NumberOfSetDescriptors() { |
| 2501 | ASSERT(!IsEmpty()); |
| 2502 | if (LastAdded() == kNoneAdded) return 0; |
| 2503 | return GetDetails(LastAdded()).index(); |
| 2504 | } |
| 2505 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2506 | bool HasEnumCache() { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 2507 | return !IsEmpty() && !get(kLastAddedIndex)->IsSmi(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2508 | } |
| 2509 | |
| 2510 | Object* GetEnumCache() { |
| 2511 | ASSERT(HasEnumCache()); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 2512 | FixedArray* bridge = FixedArray::cast(get(kLastAddedIndex)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2513 | return bridge->get(kEnumCacheBridgeCacheIndex); |
| 2514 | } |
| 2515 | |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2516 | Object** GetEnumCacheSlot() { |
| 2517 | ASSERT(HasEnumCache()); |
| 2518 | return HeapObject::RawField(reinterpret_cast<HeapObject*>(this), |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 2519 | kLastAddedOffset); |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2520 | } |
| 2521 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2522 | Object** GetTransitionsSlot() { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2523 | return HeapObject::RawField(reinterpret_cast<HeapObject*>(this), |
| 2524 | kTransitionsOffset); |
| 2525 | } |
| 2526 | |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 2527 | DECL_ACCESSORS(back_pointer_storage, Object) |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2528 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2529 | // Initialize or change the enum cache, |
| 2530 | // using the supplied storage for the small "bridge". |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 2531 | void SetEnumCache(FixedArray* bridge_storage, |
| 2532 | FixedArray* new_cache, |
| 2533 | Object* new_index_cache); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2534 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2535 | // Accessors for fetching instance descriptor at descriptor number. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2536 | inline String* GetKey(int descriptor_number); |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2537 | inline Object** GetKeySlot(int descriptor_number); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2538 | inline Object* GetValue(int descriptor_number); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 2539 | inline Object** GetValueSlot(int descriptor_number); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 2540 | inline PropertyDetails GetDetails(int descriptor_number); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2541 | inline PropertyType GetType(int descriptor_number); |
| 2542 | inline int GetFieldIndex(int descriptor_number); |
| 2543 | inline JSFunction* GetConstantFunction(int descriptor_number); |
| 2544 | inline Object* GetCallbacksObject(int descriptor_number); |
| 2545 | inline AccessorDescriptor* GetCallbacks(int descriptor_number); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2546 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2547 | // Accessor for complete descriptor. |
| 2548 | inline void Get(int descriptor_number, Descriptor* desc); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2549 | inline void Set(int descriptor_number, |
| 2550 | Descriptor* desc, |
| 2551 | const WhitenessWitness&); |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 2552 | // Append automatically sets the enumeration index. This should only be used |
| 2553 | // to add descriptors in bulk at the end, followed by sorting the descriptor |
| 2554 | // array. |
| 2555 | inline void Append(Descriptor* desc, |
| 2556 | const WhitenessWitness&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2557 | |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 2558 | // Transfer a complete descriptor from the src descriptor array to this |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame^] | 2559 | // descriptor array. |
| 2560 | void CopyFrom(int dst_index, |
| 2561 | DescriptorArray* src, |
| 2562 | int src_index, |
| 2563 | const WhitenessWitness&); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2564 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame^] | 2565 | // Copy the descriptor array, inserting new descriptor. Its enumeration index |
| 2566 | // is automatically set to the size of the descriptor array to which it was |
| 2567 | // added first. |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 2568 | MUST_USE_RESULT MaybeObject* CopyAdd(Descriptor* descriptor); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame^] | 2569 | |
| 2570 | // Copy the descriptor array, replacing a descriptor. Its enumeration index is |
| 2571 | // kept. |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 2572 | MUST_USE_RESULT MaybeObject* CopyReplace(Descriptor* descriptor, |
| 2573 | int insertion_index); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2574 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2575 | // Indicates whether the search function should expect a sorted or an unsorted |
| 2576 | // descriptor array as input. |
| 2577 | enum SharedMode { |
| 2578 | MAY_BE_SHARED, |
| 2579 | CANNOT_BE_SHARED |
| 2580 | }; |
| 2581 | |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 2582 | // Return a copy of the array with all transitions and null descriptors |
| 2583 | // removed. Return a Failure object in case of an allocation failure. |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 2584 | MUST_USE_RESULT MaybeObject* Copy(SharedMode shared_mode); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2585 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2586 | // Sort the instance descriptors by the hash codes of their keys. |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 2587 | // Does not check for duplicates. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2588 | void SortUnchecked(const WhitenessWitness&); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 2589 | |
| 2590 | // Sort the instance descriptors by the hash codes of their keys. |
| 2591 | // Checks the result for duplicates. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2592 | void Sort(const WhitenessWitness&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2593 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2594 | // Search the instance descriptors for given name. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2595 | INLINE(int Search(String* name)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2596 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2597 | // As the above, but uses DescriptorLookupCache and updates it when |
| 2598 | // necessary. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2599 | INLINE(int SearchWithCache(String* name)); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2600 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2601 | // Tells whether the name is present int the array. |
| 2602 | bool Contains(String* name) { return kNotFound != Search(name); } |
| 2603 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2604 | // Allocates a DescriptorArray, but returns the singleton |
| 2605 | // empty descriptor array object if number_of_descriptors is 0. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2606 | MUST_USE_RESULT static MaybeObject* Allocate(int number_of_descriptors, |
| 2607 | SharedMode shared_mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2608 | |
| 2609 | // Casting. |
| 2610 | static inline DescriptorArray* cast(Object* obj); |
| 2611 | |
| 2612 | // Constant for denoting key was not found. |
| 2613 | static const int kNotFound = -1; |
| 2614 | |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 2615 | // Constant for denoting that the LastAdded field was not yet set. |
| 2616 | static const int kNoneAdded = -1; |
| 2617 | |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 2618 | static const int kBackPointerStorageIndex = 0; |
| 2619 | static const int kLastAddedIndex = 1; |
verwaest@chromium.org | 5091559 | 2012-06-18 12:15:44 +0000 | [diff] [blame] | 2620 | static const int kTransitionsIndex = 2; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2621 | static const int kFirstIndex = 3; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2622 | |
| 2623 | // The length of the "bridge" to the enum cache. |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 2624 | static const int kEnumCacheBridgeLength = 3; |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 2625 | static const int kEnumCacheBridgeLastAdded = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2626 | static const int kEnumCacheBridgeCacheIndex = 1; |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 2627 | static const int kEnumCacheBridgeIndicesCacheIndex = 2; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2628 | |
| 2629 | // Layout description. |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 2630 | static const int kBackPointerStorageOffset = FixedArray::kHeaderSize; |
| 2631 | static const int kLastAddedOffset = kBackPointerStorageOffset + |
| 2632 | kPointerSize; |
| 2633 | static const int kTransitionsOffset = kLastAddedOffset + kPointerSize; |
verwaest@chromium.org | 5091559 | 2012-06-18 12:15:44 +0000 | [diff] [blame] | 2634 | static const int kFirstOffset = kTransitionsOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2635 | |
| 2636 | // Layout description for the bridge array. |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 2637 | static const int kEnumCacheBridgeLastAddedOffset = FixedArray::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2638 | static const int kEnumCacheBridgeCacheOffset = |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 2639 | kEnumCacheBridgeLastAddedOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2640 | |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2641 | // Layout of descriptor. |
| 2642 | static const int kDescriptorKey = 0; |
| 2643 | static const int kDescriptorDetails = 1; |
| 2644 | static const int kDescriptorValue = 2; |
| 2645 | static const int kDescriptorSize = 3; |
| 2646 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2647 | #ifdef OBJECT_PRINT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2648 | // Print all the descriptors. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2649 | inline void PrintDescriptors() { |
| 2650 | PrintDescriptors(stdout); |
| 2651 | } |
| 2652 | void PrintDescriptors(FILE* out); |
| 2653 | #endif |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 2654 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2655 | #ifdef DEBUG |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 2656 | // Is the descriptor array sorted and without duplicates? |
| 2657 | bool IsSortedNoDuplicates(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2658 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 2659 | // Is the descriptor array consistent with the back pointers in targets? |
| 2660 | bool IsConsistentWithBackPointers(Map* current_map); |
| 2661 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2662 | // Are two DescriptorArrays equal? |
| 2663 | bool IsEqualTo(DescriptorArray* other); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2664 | #endif |
| 2665 | |
| 2666 | // The maximum number of descriptors we want in a descriptor array (should |
| 2667 | // fit in a page). |
| 2668 | static const int kMaxNumberOfDescriptors = 1024 + 512; |
| 2669 | |
| 2670 | private: |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2671 | // An entry in a DescriptorArray, represented as an (array, index) pair. |
| 2672 | class Entry { |
| 2673 | public: |
| 2674 | inline explicit Entry(DescriptorArray* descs, int index) : |
| 2675 | descs_(descs), index_(index) { } |
| 2676 | |
| 2677 | inline PropertyType type() { return descs_->GetType(index_); } |
| 2678 | inline Object* GetCallbackObject() { return descs_->GetValue(index_); } |
| 2679 | |
| 2680 | private: |
| 2681 | DescriptorArray* descs_; |
| 2682 | int index_; |
| 2683 | }; |
| 2684 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2685 | // Conversion from descriptor number to array indices. |
| 2686 | static int ToKeyIndex(int descriptor_number) { |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2687 | return kFirstIndex + |
| 2688 | (descriptor_number * kDescriptorSize) + |
| 2689 | kDescriptorKey; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2690 | } |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 2691 | |
| 2692 | static int ToDetailsIndex(int descriptor_number) { |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2693 | return kFirstIndex + |
| 2694 | (descriptor_number * kDescriptorSize) + |
| 2695 | kDescriptorDetails; |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 2696 | } |
| 2697 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2698 | static int ToValueIndex(int descriptor_number) { |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2699 | return kFirstIndex + |
| 2700 | (descriptor_number * kDescriptorSize) + |
| 2701 | kDescriptorValue; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2702 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2703 | |
| 2704 | // Swap operation on FixedArray without using write barriers. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2705 | static inline void NoIncrementalWriteBarrierSwap( |
| 2706 | FixedArray* array, int first, int second); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2707 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 2708 | // Swap first and second descriptor. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2709 | inline void NoIncrementalWriteBarrierSwapDescriptors( |
| 2710 | int first, int second); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2711 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2712 | DISALLOW_IMPLICIT_CONSTRUCTORS(DescriptorArray); |
| 2713 | }; |
| 2714 | |
| 2715 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 2716 | template<typename T> |
| 2717 | inline int LinearSearch(T* array, SearchMode mode, String* name, int len); |
| 2718 | |
| 2719 | |
| 2720 | template<typename T> |
| 2721 | inline int Search(T* array, String* name); |
| 2722 | |
| 2723 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2724 | // HashTable is a subclass of FixedArray that implements a hash table |
| 2725 | // that uses open addressing and quadratic probing. |
| 2726 | // |
| 2727 | // In order for the quadratic probing to work, elements that have not |
| 2728 | // yet been used and elements that have been deleted are |
| 2729 | // distinguished. Probing continues when deleted elements are |
| 2730 | // encountered and stops when unused elements are encountered. |
| 2731 | // |
| 2732 | // - Elements with key == undefined have not been used yet. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2733 | // - Elements with key == the_hole have been deleted. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2734 | // |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2735 | // The hash table class is parameterized with a Shape and a Key. |
| 2736 | // Shape must be a class with the following interface: |
| 2737 | // class ExampleShape { |
| 2738 | // public: |
| 2739 | // // Tells whether key matches other. |
| 2740 | // static bool IsMatch(Key key, Object* other); |
| 2741 | // // Returns the hash value for key. |
| 2742 | // static uint32_t Hash(Key key); |
| 2743 | // // Returns the hash value for object. |
| 2744 | // static uint32_t HashForObject(Key key, Object* object); |
| 2745 | // // Convert key to an object. |
| 2746 | // static inline Object* AsObject(Key key); |
| 2747 | // // The prefix size indicates number of elements in the beginning |
| 2748 | // // of the backing storage. |
| 2749 | // static const int kPrefixSize = ..; |
| 2750 | // // The Element size indicates number of elements per entry. |
| 2751 | // static const int kEntrySize = ..; |
| 2752 | // }; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2753 | // The prefix size indicates an amount of memory in the |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2754 | // beginning of the backing storage that can be used for non-element |
| 2755 | // information by subclasses. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2756 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2757 | template<typename Key> |
| 2758 | class BaseShape { |
| 2759 | public: |
| 2760 | static const bool UsesSeed = false; |
| 2761 | static uint32_t Hash(Key key) { return 0; } |
| 2762 | static uint32_t SeededHash(Key key, uint32_t seed) { |
| 2763 | ASSERT(UsesSeed); |
| 2764 | return Hash(key); |
| 2765 | } |
| 2766 | static uint32_t HashForObject(Key key, Object* object) { return 0; } |
| 2767 | static uint32_t SeededHashForObject(Key key, uint32_t seed, Object* object) { |
| 2768 | ASSERT(UsesSeed); |
| 2769 | return HashForObject(key, object); |
| 2770 | } |
| 2771 | }; |
| 2772 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2773 | template<typename Shape, typename Key> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2774 | class HashTable: public FixedArray { |
| 2775 | public: |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2776 | // Wrapper methods |
| 2777 | inline uint32_t Hash(Key key) { |
| 2778 | if (Shape::UsesSeed) { |
| 2779 | return Shape::SeededHash(key, |
| 2780 | GetHeap()->HashSeed()); |
| 2781 | } else { |
| 2782 | return Shape::Hash(key); |
| 2783 | } |
| 2784 | } |
| 2785 | |
| 2786 | inline uint32_t HashForObject(Key key, Object* object) { |
| 2787 | if (Shape::UsesSeed) { |
| 2788 | return Shape::SeededHashForObject(key, |
| 2789 | GetHeap()->HashSeed(), object); |
| 2790 | } else { |
| 2791 | return Shape::HashForObject(key, object); |
| 2792 | } |
| 2793 | } |
| 2794 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2795 | // Returns the number of elements in the hash table. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2796 | int NumberOfElements() { |
| 2797 | return Smi::cast(get(kNumberOfElementsIndex))->value(); |
| 2798 | } |
| 2799 | |
kasperl@chromium.org | edf0cd1 | 2010-01-05 13:29:12 +0000 | [diff] [blame] | 2800 | // Returns the number of deleted elements in the hash table. |
| 2801 | int NumberOfDeletedElements() { |
| 2802 | return Smi::cast(get(kNumberOfDeletedElementsIndex))->value(); |
| 2803 | } |
| 2804 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2805 | // Returns the capacity of the hash table. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2806 | int Capacity() { |
| 2807 | return Smi::cast(get(kCapacityIndex))->value(); |
| 2808 | } |
| 2809 | |
| 2810 | // ElementAdded should be called whenever an element is added to a |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2811 | // hash table. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2812 | void ElementAdded() { SetNumberOfElements(NumberOfElements() + 1); } |
| 2813 | |
| 2814 | // ElementRemoved should be called whenever an element is removed from |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2815 | // a hash table. |
kasperl@chromium.org | edf0cd1 | 2010-01-05 13:29:12 +0000 | [diff] [blame] | 2816 | void ElementRemoved() { |
| 2817 | SetNumberOfElements(NumberOfElements() - 1); |
| 2818 | SetNumberOfDeletedElements(NumberOfDeletedElements() + 1); |
| 2819 | } |
| 2820 | void ElementsRemoved(int n) { |
| 2821 | SetNumberOfElements(NumberOfElements() - n); |
| 2822 | SetNumberOfDeletedElements(NumberOfDeletedElements() + n); |
| 2823 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2824 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2825 | // Returns a new HashTable object. Might return Failure. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2826 | MUST_USE_RESULT static MaybeObject* Allocate( |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2827 | int at_least_space_for, |
| 2828 | PretenureFlag pretenure = NOT_TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2829 | |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 2830 | // Computes the required capacity for a table holding the given |
| 2831 | // number of elements. May be more than HashTable::kMaxCapacity. |
| 2832 | static int ComputeCapacity(int at_least_space_for); |
| 2833 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2834 | // Returns the key at entry. |
| 2835 | Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } |
| 2836 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2837 | // Tells whether k is a real key. The hole and undefined are not allowed |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2838 | // as keys and can be used to indicate missing or deleted elements. |
| 2839 | bool IsKey(Object* k) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2840 | return !k->IsTheHole() && !k->IsUndefined(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2841 | } |
| 2842 | |
| 2843 | // Garbage collection support. |
| 2844 | void IteratePrefix(ObjectVisitor* visitor); |
| 2845 | void IterateElements(ObjectVisitor* visitor); |
| 2846 | |
| 2847 | // Casting. |
| 2848 | static inline HashTable* cast(Object* obj); |
| 2849 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2850 | // Compute the probe offset (quadratic probing). |
| 2851 | INLINE(static uint32_t GetProbeOffset(uint32_t n)) { |
| 2852 | return (n + n * n) >> 1; |
| 2853 | } |
| 2854 | |
| 2855 | static const int kNumberOfElementsIndex = 0; |
kasperl@chromium.org | edf0cd1 | 2010-01-05 13:29:12 +0000 | [diff] [blame] | 2856 | static const int kNumberOfDeletedElementsIndex = 1; |
| 2857 | static const int kCapacityIndex = 2; |
| 2858 | static const int kPrefixStartIndex = 3; |
| 2859 | static const int kElementsStartIndex = |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2860 | kPrefixStartIndex + Shape::kPrefixSize; |
kasperl@chromium.org | edf0cd1 | 2010-01-05 13:29:12 +0000 | [diff] [blame] | 2861 | static const int kEntrySize = Shape::kEntrySize; |
| 2862 | static const int kElementsStartOffset = |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2863 | kHeaderSize + kElementsStartIndex * kPointerSize; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2864 | static const int kCapacityOffset = |
| 2865 | kHeaderSize + kCapacityIndex * kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2866 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2867 | // Constant used for denoting a absent entry. |
| 2868 | static const int kNotFound = -1; |
| 2869 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2870 | // Maximal capacity of HashTable. Based on maximal length of underlying |
| 2871 | // FixedArray. Staying below kMaxCapacity also ensures that EntryToIndex |
| 2872 | // cannot overflow. |
| 2873 | static const int kMaxCapacity = |
| 2874 | (FixedArray::kMaxLength - kElementsStartOffset) / kEntrySize; |
| 2875 | |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2876 | // Find entry for key otherwise return kNotFound. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2877 | inline int FindEntry(Key key); |
| 2878 | int FindEntry(Isolate* isolate, Key key); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2879 | |
| 2880 | protected: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2881 | // Find the entry at which to insert element with the given key that |
| 2882 | // has the given hash value. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2883 | uint32_t FindInsertionEntry(uint32_t hash); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2884 | |
| 2885 | // Returns the index for an entry (of the key) |
| 2886 | static inline int EntryToIndex(int entry) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2887 | return (entry * kEntrySize) + kElementsStartIndex; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2888 | } |
| 2889 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2890 | // Update the number of elements in the hash table. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2891 | void SetNumberOfElements(int nof) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2892 | set(kNumberOfElementsIndex, Smi::FromInt(nof)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2893 | } |
| 2894 | |
kasperl@chromium.org | edf0cd1 | 2010-01-05 13:29:12 +0000 | [diff] [blame] | 2895 | // Update the number of deleted elements in the hash table. |
| 2896 | void SetNumberOfDeletedElements(int nod) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2897 | set(kNumberOfDeletedElementsIndex, Smi::FromInt(nod)); |
kasperl@chromium.org | edf0cd1 | 2010-01-05 13:29:12 +0000 | [diff] [blame] | 2898 | } |
| 2899 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2900 | // Sets the capacity of the hash table. |
| 2901 | void SetCapacity(int capacity) { |
| 2902 | // To scale a computed hash code to fit within the hash table, we |
| 2903 | // use bit-wise AND with a mask, so the capacity must be positive |
| 2904 | // and non-zero. |
| 2905 | ASSERT(capacity > 0); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2906 | ASSERT(capacity <= kMaxCapacity); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2907 | set(kCapacityIndex, Smi::FromInt(capacity)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2908 | } |
| 2909 | |
| 2910 | |
| 2911 | // Returns probe entry. |
| 2912 | static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size) { |
| 2913 | ASSERT(IsPowerOf2(size)); |
| 2914 | return (hash + GetProbeOffset(number)) & (size - 1); |
| 2915 | } |
| 2916 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2917 | static uint32_t FirstProbe(uint32_t hash, uint32_t size) { |
| 2918 | return hash & (size - 1); |
| 2919 | } |
| 2920 | |
| 2921 | static uint32_t NextProbe(uint32_t last, uint32_t number, uint32_t size) { |
| 2922 | return (last + number) & (size - 1); |
| 2923 | } |
| 2924 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 2925 | // Rehashes this hash-table into the new table. |
| 2926 | MUST_USE_RESULT MaybeObject* Rehash(HashTable* new_table, Key key); |
| 2927 | |
| 2928 | // Attempt to shrink hash table after removal of key. |
| 2929 | MUST_USE_RESULT MaybeObject* Shrink(Key key); |
| 2930 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2931 | // Ensure enough space for n additional elements. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2932 | MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2933 | }; |
| 2934 | |
| 2935 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2936 | // HashTableKey is an abstract superclass for virtual key behavior. |
| 2937 | class HashTableKey { |
| 2938 | public: |
| 2939 | // Returns whether the other object matches this key. |
| 2940 | virtual bool IsMatch(Object* other) = 0; |
| 2941 | // Returns the hash value for this key. |
| 2942 | virtual uint32_t Hash() = 0; |
| 2943 | // Returns the hash value for object. |
| 2944 | virtual uint32_t HashForObject(Object* key) = 0; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2945 | // Returns the key object for storing into the hash table. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2946 | // If allocations fails a failure object is returned. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2947 | MUST_USE_RESULT virtual MaybeObject* AsObject() = 0; |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2948 | // Required. |
| 2949 | virtual ~HashTableKey() {} |
| 2950 | }; |
| 2951 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2952 | |
| 2953 | class SymbolTableShape : public BaseShape<HashTableKey*> { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2954 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2955 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2956 | return key->IsMatch(value); |
| 2957 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2958 | static inline uint32_t Hash(HashTableKey* key) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2959 | return key->Hash(); |
| 2960 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2961 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2962 | return key->HashForObject(object); |
| 2963 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2964 | MUST_USE_RESULT static inline MaybeObject* AsObject(HashTableKey* key) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2965 | return key->AsObject(); |
| 2966 | } |
| 2967 | |
| 2968 | static const int kPrefixSize = 0; |
| 2969 | static const int kEntrySize = 1; |
| 2970 | }; |
| 2971 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2972 | class SeqAsciiString; |
| 2973 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2974 | // SymbolTable. |
| 2975 | // |
| 2976 | // No special elements in the prefix and the element size is 1 |
| 2977 | // because only the symbol itself (the key) needs to be stored. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2978 | class SymbolTable: public HashTable<SymbolTableShape, HashTableKey*> { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2979 | public: |
| 2980 | // Find symbol in the symbol table. If it is not there yet, it is |
| 2981 | // added. The return value is the symbol table which might have |
| 2982 | // been enlarged. If the return value is not a failure, the symbol |
| 2983 | // pointer *s is set to the symbol found. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2984 | MUST_USE_RESULT MaybeObject* LookupSymbol(Vector<const char> str, Object** s); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 2985 | MUST_USE_RESULT MaybeObject* LookupAsciiSymbol(Vector<const char> str, |
| 2986 | Object** s); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2987 | MUST_USE_RESULT MaybeObject* LookupSubStringAsciiSymbol( |
| 2988 | Handle<SeqAsciiString> str, |
| 2989 | int from, |
| 2990 | int length, |
| 2991 | Object** s); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 2992 | MUST_USE_RESULT MaybeObject* LookupTwoByteSymbol(Vector<const uc16> str, |
| 2993 | Object** s); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2994 | MUST_USE_RESULT MaybeObject* LookupString(String* key, Object** s); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2995 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2996 | // Looks up a symbol that is equal to the given string and returns |
| 2997 | // true if it is found, assigning the symbol to the given output |
| 2998 | // parameter. |
| 2999 | bool LookupSymbolIfExists(String* str, String** symbol); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 3000 | bool LookupTwoCharsSymbolIfExists(uint32_t c1, uint32_t c2, String** symbol); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3001 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3002 | // Casting. |
| 3003 | static inline SymbolTable* cast(Object* obj); |
| 3004 | |
| 3005 | private: |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3006 | MUST_USE_RESULT MaybeObject* LookupKey(HashTableKey* key, Object** s); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3007 | |
| 3008 | DISALLOW_IMPLICIT_CONSTRUCTORS(SymbolTable); |
| 3009 | }; |
| 3010 | |
| 3011 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3012 | class MapCacheShape : public BaseShape<HashTableKey*> { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3013 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3014 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3015 | return key->IsMatch(value); |
| 3016 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3017 | static inline uint32_t Hash(HashTableKey* key) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3018 | return key->Hash(); |
| 3019 | } |
| 3020 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3021 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3022 | return key->HashForObject(object); |
| 3023 | } |
| 3024 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3025 | MUST_USE_RESULT static inline MaybeObject* AsObject(HashTableKey* key) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3026 | return key->AsObject(); |
| 3027 | } |
| 3028 | |
| 3029 | static const int kPrefixSize = 0; |
| 3030 | static const int kEntrySize = 2; |
| 3031 | }; |
| 3032 | |
| 3033 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 3034 | // MapCache. |
| 3035 | // |
| 3036 | // Maps keys that are a fixed array of symbols to a map. |
| 3037 | // Used for canonicalize maps for object literals. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3038 | class MapCache: public HashTable<MapCacheShape, HashTableKey*> { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 3039 | public: |
| 3040 | // Find cached value for a string key, otherwise return null. |
| 3041 | Object* Lookup(FixedArray* key); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3042 | MUST_USE_RESULT MaybeObject* Put(FixedArray* key, Map* value); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 3043 | static inline MapCache* cast(Object* obj); |
| 3044 | |
| 3045 | private: |
| 3046 | DISALLOW_IMPLICIT_CONSTRUCTORS(MapCache); |
| 3047 | }; |
| 3048 | |
| 3049 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3050 | template <typename Shape, typename Key> |
| 3051 | class Dictionary: public HashTable<Shape, Key> { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3052 | public: |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3053 | static inline Dictionary<Shape, Key>* cast(Object* obj) { |
| 3054 | return reinterpret_cast<Dictionary<Shape, Key>*>(obj); |
| 3055 | } |
| 3056 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3057 | // Returns the value at entry. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 3058 | Object* ValueAt(int entry) { |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3059 | return this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 1); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 3060 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3061 | |
| 3062 | // Set the value for entry. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3063 | void ValueAtPut(int entry, Object* value) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3064 | this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 1, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3065 | } |
| 3066 | |
| 3067 | // Returns the property details for the property at entry. |
| 3068 | PropertyDetails DetailsAt(int entry) { |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 3069 | ASSERT(entry >= 0); // Not found is -1, which is not caught by get(). |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3070 | return PropertyDetails( |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 3071 | Smi::cast(this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 2))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3072 | } |
| 3073 | |
| 3074 | // Set the details for entry. |
| 3075 | void DetailsAtPut(int entry, PropertyDetails value) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 3076 | this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 2, value.AsSmi()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3077 | } |
| 3078 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3079 | // Sorting support |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3080 | void CopyValuesTo(FixedArray* elements); |
| 3081 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3082 | // Delete a property from the dictionary. |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 3083 | Object* DeleteProperty(int entry, JSObject::DeleteMode mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3084 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 3085 | // Attempt to shrink the dictionary after deletion of key. |
| 3086 | MUST_USE_RESULT MaybeObject* Shrink(Key key); |
| 3087 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3088 | // Returns the number of elements in the dictionary filtering out properties |
| 3089 | // with the specified attributes. |
| 3090 | int NumberOfElementsFilterAttributes(PropertyAttributes filter); |
| 3091 | |
| 3092 | // Returns the number of enumerable elements in the dictionary. |
| 3093 | int NumberOfEnumElements(); |
| 3094 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 3095 | enum SortMode { UNSORTED, SORTED }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3096 | // Copies keys to preallocated fixed array. |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 3097 | void CopyKeysTo(FixedArray* storage, |
| 3098 | PropertyAttributes filter, |
| 3099 | SortMode sort_mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3100 | // Fill in details for properties into storage. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3101 | void CopyKeysTo(FixedArray* storage, int index, SortMode sort_mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3102 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3103 | // Accessors for next enumeration index. |
| 3104 | void SetNextEnumerationIndex(int index) { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 3105 | ASSERT(index != 0); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3106 | this->set(kNextEnumerationIndexIndex, Smi::FromInt(index)); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3107 | } |
| 3108 | |
| 3109 | int NextEnumerationIndex() { |
| 3110 | return Smi::cast(FixedArray::get(kNextEnumerationIndexIndex))->value(); |
| 3111 | } |
| 3112 | |
| 3113 | // Returns a new array for dictionary usage. Might return Failure. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3114 | MUST_USE_RESULT static MaybeObject* Allocate(int at_least_space_for); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3115 | |
| 3116 | // Ensure enough space for n additional elements. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3117 | MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3118 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3119 | #ifdef OBJECT_PRINT |
| 3120 | inline void Print() { |
| 3121 | Print(stdout); |
| 3122 | } |
| 3123 | void Print(FILE* out); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3124 | #endif |
| 3125 | // Returns the key (slow). |
| 3126 | Object* SlowReverseLookup(Object* value); |
| 3127 | |
| 3128 | // Sets the entry to (key, value) pair. |
| 3129 | inline void SetEntry(int entry, |
| 3130 | Object* key, |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3131 | Object* value); |
| 3132 | inline void SetEntry(int entry, |
| 3133 | Object* key, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3134 | Object* value, |
| 3135 | PropertyDetails details); |
| 3136 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3137 | MUST_USE_RESULT MaybeObject* Add(Key key, |
| 3138 | Object* value, |
| 3139 | PropertyDetails details); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3140 | |
| 3141 | protected: |
| 3142 | // Generic at put operation. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3143 | MUST_USE_RESULT MaybeObject* AtPut(Key key, Object* value); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3144 | |
| 3145 | // Add entry to dictionary. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3146 | MUST_USE_RESULT MaybeObject* AddEntry(Key key, |
| 3147 | Object* value, |
| 3148 | PropertyDetails details, |
| 3149 | uint32_t hash); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3150 | |
| 3151 | // Generate new enumeration indices to avoid enumeration index overflow. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3152 | MUST_USE_RESULT MaybeObject* GenerateNewEnumerationIndices(); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3153 | static const int kMaxNumberKeyIndex = |
| 3154 | HashTable<Shape, Key>::kPrefixStartIndex; |
| 3155 | static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1; |
| 3156 | }; |
| 3157 | |
| 3158 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3159 | class StringDictionaryShape : public BaseShape<String*> { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3160 | public: |
| 3161 | static inline bool IsMatch(String* key, Object* other); |
| 3162 | static inline uint32_t Hash(String* key); |
| 3163 | static inline uint32_t HashForObject(String* key, Object* object); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3164 | MUST_USE_RESULT static inline MaybeObject* AsObject(String* key); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3165 | static const int kPrefixSize = 2; |
| 3166 | static const int kEntrySize = 3; |
| 3167 | static const bool kIsEnumerable = true; |
| 3168 | }; |
| 3169 | |
| 3170 | |
| 3171 | class StringDictionary: public Dictionary<StringDictionaryShape, String*> { |
| 3172 | public: |
| 3173 | static inline StringDictionary* cast(Object* obj) { |
| 3174 | ASSERT(obj->IsDictionary()); |
| 3175 | return reinterpret_cast<StringDictionary*>(obj); |
| 3176 | } |
| 3177 | |
| 3178 | // Copies enumerable keys to preallocated fixed array. |
| 3179 | void CopyEnumKeysTo(FixedArray* storage, FixedArray* sort_array); |
| 3180 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3181 | // For transforming properties of a JSObject. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3182 | MUST_USE_RESULT MaybeObject* TransformPropertiesToFastFor( |
| 3183 | JSObject* obj, |
| 3184 | int unused_property_fields); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 3185 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3186 | // Find entry for key, otherwise return kNotFound. Optimized version of |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 3187 | // HashTable::FindEntry. |
| 3188 | int FindEntry(String* key); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3189 | }; |
| 3190 | |
| 3191 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3192 | class NumberDictionaryShape : public BaseShape<uint32_t> { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3193 | public: |
| 3194 | static inline bool IsMatch(uint32_t key, Object* other); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3195 | MUST_USE_RESULT static inline MaybeObject* AsObject(uint32_t key); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3196 | static const int kEntrySize = 3; |
| 3197 | static const bool kIsEnumerable = false; |
| 3198 | }; |
| 3199 | |
| 3200 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3201 | class SeededNumberDictionaryShape : public NumberDictionaryShape { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3202 | public: |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3203 | static const bool UsesSeed = true; |
| 3204 | static const int kPrefixSize = 2; |
| 3205 | |
| 3206 | static inline uint32_t SeededHash(uint32_t key, uint32_t seed); |
| 3207 | static inline uint32_t SeededHashForObject(uint32_t key, |
| 3208 | uint32_t seed, |
| 3209 | Object* object); |
| 3210 | }; |
| 3211 | |
| 3212 | |
| 3213 | class UnseededNumberDictionaryShape : public NumberDictionaryShape { |
| 3214 | public: |
| 3215 | static const int kPrefixSize = 0; |
| 3216 | |
| 3217 | static inline uint32_t Hash(uint32_t key); |
| 3218 | static inline uint32_t HashForObject(uint32_t key, Object* object); |
| 3219 | }; |
| 3220 | |
| 3221 | |
| 3222 | class SeededNumberDictionary |
| 3223 | : public Dictionary<SeededNumberDictionaryShape, uint32_t> { |
| 3224 | public: |
| 3225 | static SeededNumberDictionary* cast(Object* obj) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3226 | ASSERT(obj->IsDictionary()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3227 | return reinterpret_cast<SeededNumberDictionary*>(obj); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3228 | } |
| 3229 | |
| 3230 | // Type specific at put (default NONE attributes is used when adding). |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3231 | MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value); |
| 3232 | MUST_USE_RESULT MaybeObject* AddNumberEntry(uint32_t key, |
| 3233 | Object* value, |
| 3234 | PropertyDetails details); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3235 | |
| 3236 | // Set an existing entry or add a new one if needed. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3237 | // Return the updated dictionary. |
| 3238 | MUST_USE_RESULT static Handle<SeededNumberDictionary> Set( |
| 3239 | Handle<SeededNumberDictionary> dictionary, |
| 3240 | uint32_t index, |
| 3241 | Handle<Object> value, |
| 3242 | PropertyDetails details); |
| 3243 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3244 | MUST_USE_RESULT MaybeObject* Set(uint32_t key, |
| 3245 | Object* value, |
| 3246 | PropertyDetails details); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3247 | |
| 3248 | void UpdateMaxNumberKey(uint32_t key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3249 | |
| 3250 | // If slow elements are required we will never go back to fast-case |
| 3251 | // for the elements kept in this dictionary. We require slow |
| 3252 | // 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] | 3253 | // kRequiresSlowElementsLimit or set_requires_slow_elements() has been called |
| 3254 | // when defining a getter or setter with a number key. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3255 | inline bool requires_slow_elements(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3256 | inline void set_requires_slow_elements(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3257 | |
| 3258 | // Get the value of the max number key that has been added to this |
| 3259 | // dictionary. max_number_key can only be called if |
| 3260 | // requires_slow_elements returns false. |
| 3261 | inline uint32_t max_number_key(); |
| 3262 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3263 | // Bit masks. |
| 3264 | static const int kRequiresSlowElementsMask = 1; |
| 3265 | static const int kRequiresSlowElementsTagSize = 1; |
| 3266 | static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3267 | }; |
| 3268 | |
| 3269 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3270 | class UnseededNumberDictionary |
| 3271 | : public Dictionary<UnseededNumberDictionaryShape, uint32_t> { |
| 3272 | public: |
| 3273 | static UnseededNumberDictionary* cast(Object* obj) { |
| 3274 | ASSERT(obj->IsDictionary()); |
| 3275 | return reinterpret_cast<UnseededNumberDictionary*>(obj); |
| 3276 | } |
| 3277 | |
| 3278 | // Type specific at put (default NONE attributes is used when adding). |
| 3279 | MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value); |
| 3280 | MUST_USE_RESULT MaybeObject* AddNumberEntry(uint32_t key, Object* value); |
| 3281 | |
| 3282 | // Set an existing entry or add a new one if needed. |
| 3283 | // Return the updated dictionary. |
| 3284 | MUST_USE_RESULT static Handle<UnseededNumberDictionary> Set( |
| 3285 | Handle<UnseededNumberDictionary> dictionary, |
| 3286 | uint32_t index, |
| 3287 | Handle<Object> value); |
| 3288 | |
| 3289 | MUST_USE_RESULT MaybeObject* Set(uint32_t key, Object* value); |
| 3290 | }; |
| 3291 | |
| 3292 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3293 | template <int entrysize> |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3294 | class ObjectHashTableShape : public BaseShape<Object*> { |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 3295 | public: |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3296 | static inline bool IsMatch(Object* key, Object* other); |
| 3297 | static inline uint32_t Hash(Object* key); |
| 3298 | static inline uint32_t HashForObject(Object* key, Object* object); |
| 3299 | MUST_USE_RESULT static inline MaybeObject* AsObject(Object* key); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 3300 | static const int kPrefixSize = 0; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3301 | static const int kEntrySize = entrysize; |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 3302 | }; |
| 3303 | |
| 3304 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3305 | // ObjectHashSet holds keys that are arbitrary objects by using the identity |
| 3306 | // hash of the key for hashing purposes. |
| 3307 | class ObjectHashSet: public HashTable<ObjectHashTableShape<1>, Object*> { |
| 3308 | public: |
| 3309 | static inline ObjectHashSet* cast(Object* obj) { |
| 3310 | ASSERT(obj->IsHashTable()); |
| 3311 | return reinterpret_cast<ObjectHashSet*>(obj); |
| 3312 | } |
| 3313 | |
| 3314 | // Looks up whether the given key is part of this hash set. |
| 3315 | bool Contains(Object* key); |
| 3316 | |
| 3317 | // Adds the given key to this hash set. |
| 3318 | MUST_USE_RESULT MaybeObject* Add(Object* key); |
| 3319 | |
| 3320 | // Removes the given key from this hash set. |
| 3321 | MUST_USE_RESULT MaybeObject* Remove(Object* key); |
| 3322 | }; |
| 3323 | |
| 3324 | |
| 3325 | // ObjectHashTable maps keys that are arbitrary objects to object values by |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 3326 | // using the identity hash of the key for hashing purposes. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3327 | class ObjectHashTable: public HashTable<ObjectHashTableShape<2>, Object*> { |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 3328 | public: |
| 3329 | static inline ObjectHashTable* cast(Object* obj) { |
| 3330 | ASSERT(obj->IsHashTable()); |
| 3331 | return reinterpret_cast<ObjectHashTable*>(obj); |
| 3332 | } |
| 3333 | |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3334 | // Looks up the value associated with the given key. The hole value is |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 3335 | // returned in case the key is not present. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3336 | Object* Lookup(Object* key); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 3337 | |
| 3338 | // Adds (or overwrites) the value associated with the given key. Mapping a |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3339 | // key to the hole value causes removal of the whole entry. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3340 | MUST_USE_RESULT MaybeObject* Put(Object* key, Object* value); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 3341 | |
| 3342 | private: |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3343 | friend class MarkCompactCollector; |
| 3344 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3345 | void AddEntry(int entry, Object* key, Object* value); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3346 | void RemoveEntry(int entry); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3347 | |
| 3348 | // Returns the index to the value of an entry. |
| 3349 | static inline int EntryToValueIndex(int entry) { |
| 3350 | return EntryToIndex(entry) + 1; |
| 3351 | } |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 3352 | }; |
| 3353 | |
| 3354 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 3355 | // JSFunctionResultCache caches results of some JSFunction invocation. |
| 3356 | // It is a fixed array with fixed structure: |
| 3357 | // [0]: factory function |
| 3358 | // [1]: finger index |
| 3359 | // [2]: current cache size |
| 3360 | // [3]: dummy field. |
| 3361 | // The rest of array are key/value pairs. |
| 3362 | class JSFunctionResultCache: public FixedArray { |
| 3363 | public: |
| 3364 | static const int kFactoryIndex = 0; |
| 3365 | static const int kFingerIndex = kFactoryIndex + 1; |
| 3366 | static const int kCacheSizeIndex = kFingerIndex + 1; |
| 3367 | static const int kDummyIndex = kCacheSizeIndex + 1; |
| 3368 | static const int kEntriesIndex = kDummyIndex + 1; |
antonm@chromium.org | 397e23c | 2010-04-21 12:00:05 +0000 | [diff] [blame] | 3369 | |
| 3370 | static const int kEntrySize = 2; // key + value |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3371 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3372 | static const int kFactoryOffset = kHeaderSize; |
| 3373 | static const int kFingerOffset = kFactoryOffset + kPointerSize; |
| 3374 | static const int kCacheSizeOffset = kFingerOffset + kPointerSize; |
| 3375 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3376 | inline void MakeZeroSize(); |
| 3377 | inline void Clear(); |
| 3378 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3379 | inline int size(); |
| 3380 | inline void set_size(int size); |
| 3381 | inline int finger_index(); |
| 3382 | inline void set_finger_index(int finger_index); |
| 3383 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3384 | // Casting |
| 3385 | static inline JSFunctionResultCache* cast(Object* obj); |
| 3386 | |
| 3387 | #ifdef DEBUG |
| 3388 | void JSFunctionResultCacheVerify(); |
| 3389 | #endif |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 3390 | }; |
| 3391 | |
| 3392 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3393 | // ScopeInfo represents information about different scopes of a source |
| 3394 | // program and the allocation of the scope's variables. Scope information |
| 3395 | // is stored in a compressed form in ScopeInfo objects and is used |
| 3396 | // at runtime (stack dumps, deoptimization, etc.). |
| 3397 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3398 | // This object provides quick access to scope info details for runtime |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3399 | // routines. |
| 3400 | class ScopeInfo : public FixedArray { |
| 3401 | public: |
| 3402 | static inline ScopeInfo* cast(Object* object); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3403 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3404 | // Return the type of this scope. |
| 3405 | ScopeType Type(); |
| 3406 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3407 | // Does this scope call eval? |
| 3408 | bool CallsEval(); |
| 3409 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3410 | // Return the language mode of this scope. |
| 3411 | LanguageMode language_mode(); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3412 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3413 | // Does this scope make a non-strict eval call? |
| 3414 | bool CallsNonStrictEval() { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3415 | return CallsEval() && (language_mode() == CLASSIC_MODE); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3416 | } |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3417 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3418 | // Return the total number of locals allocated on the stack and in the |
| 3419 | // context. This includes the parameters that are allocated in the context. |
| 3420 | int LocalCount(); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3421 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3422 | // Return the number of stack slots for code. This number consists of two |
| 3423 | // parts: |
| 3424 | // 1. One stack slot per stack allocated local. |
| 3425 | // 2. One stack slot for the function name if it is stack allocated. |
| 3426 | int StackSlotCount(); |
| 3427 | |
| 3428 | // Return the number of context slots for code if a context is allocated. This |
| 3429 | // number consists of three parts: |
| 3430 | // 1. Size of fixed header for every context: Context::MIN_CONTEXT_SLOTS |
| 3431 | // 2. One context slot per context allocated local. |
| 3432 | // 3. One context slot for the function name if it is context allocated. |
| 3433 | // Parameters allocated in the context count as context allocated locals. If |
| 3434 | // no contexts are allocated for this scope ContextLength returns 0. |
| 3435 | int ContextLength(); |
| 3436 | |
| 3437 | // Is this scope the scope of a named function expression? |
| 3438 | bool HasFunctionName(); |
| 3439 | |
| 3440 | // Return if this has context allocated locals. |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3441 | bool HasHeapAllocatedLocals(); |
| 3442 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3443 | // Return if contexts are allocated for this scope. |
| 3444 | bool HasContext(); |
| 3445 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3446 | // Return the function_name if present. |
| 3447 | String* FunctionName(); |
| 3448 | |
| 3449 | // Return the name of the given parameter. |
| 3450 | String* ParameterName(int var); |
| 3451 | |
| 3452 | // Return the name of the given local. |
| 3453 | String* LocalName(int var); |
| 3454 | |
| 3455 | // Return the name of the given stack local. |
| 3456 | String* StackLocalName(int var); |
| 3457 | |
| 3458 | // Return the name of the given context local. |
| 3459 | String* ContextLocalName(int var); |
| 3460 | |
| 3461 | // Return the mode of the given context local. |
| 3462 | VariableMode ContextLocalMode(int var); |
| 3463 | |
| 3464 | // Return the initialization flag of the given context local. |
| 3465 | InitializationFlag ContextLocalInitFlag(int var); |
| 3466 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3467 | // Lookup support for serialized scope info. Returns the |
| 3468 | // the stack slot index for a given slot name if the slot is |
| 3469 | // present; otherwise returns a value < 0. The name must be a symbol |
| 3470 | // (canonicalized). |
| 3471 | int StackSlotIndex(String* name); |
| 3472 | |
| 3473 | // Lookup support for serialized scope info. Returns the |
| 3474 | // context slot index for a given slot name if the slot is present; otherwise |
| 3475 | // returns a value < 0. The name must be a symbol (canonicalized). |
| 3476 | // If the slot is present and mode != NULL, sets *mode to the corresponding |
| 3477 | // mode for that variable. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3478 | int ContextSlotIndex(String* name, |
| 3479 | VariableMode* mode, |
| 3480 | InitializationFlag* init_flag); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3481 | |
| 3482 | // Lookup support for serialized scope info. Returns the |
| 3483 | // parameter index for a given parameter name if the parameter is present; |
| 3484 | // otherwise returns a value < 0. The name must be a symbol (canonicalized). |
| 3485 | int ParameterIndex(String* name); |
| 3486 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3487 | // Lookup support for serialized scope info. Returns the function context |
| 3488 | // slot index if the function name is present and context-allocated (named |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3489 | // function expressions, only), otherwise returns a value < 0. The name |
| 3490 | // must be a symbol (canonicalized). |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3491 | int FunctionContextSlotIndex(String* name, VariableMode* mode); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3492 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3493 | static Handle<ScopeInfo> Create(Scope* scope, Zone* zone); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3494 | |
| 3495 | // Serializes empty scope info. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3496 | static ScopeInfo* Empty(); |
| 3497 | |
| 3498 | #ifdef DEBUG |
| 3499 | void Print(); |
| 3500 | #endif |
| 3501 | |
| 3502 | // The layout of the static part of a ScopeInfo is as follows. Each entry is |
| 3503 | // numeric and occupies one array slot. |
| 3504 | // 1. A set of properties of the scope |
| 3505 | // 2. The number of parameters. This only applies to function scopes. For |
| 3506 | // non-function scopes this is 0. |
| 3507 | // 3. The number of non-parameter variables allocated on the stack. |
| 3508 | // 4. The number of non-parameter and parameter variables allocated in the |
| 3509 | // context. |
| 3510 | #define FOR_EACH_NUMERIC_FIELD(V) \ |
| 3511 | V(Flags) \ |
| 3512 | V(ParameterCount) \ |
| 3513 | V(StackLocalCount) \ |
| 3514 | V(ContextLocalCount) |
| 3515 | |
| 3516 | #define FIELD_ACCESSORS(name) \ |
| 3517 | void Set##name(int value) { \ |
| 3518 | set(k##name, Smi::FromInt(value)); \ |
| 3519 | } \ |
| 3520 | int name() { \ |
| 3521 | if (length() > 0) { \ |
| 3522 | return Smi::cast(get(k##name))->value(); \ |
| 3523 | } else { \ |
| 3524 | return 0; \ |
| 3525 | } \ |
| 3526 | } |
| 3527 | FOR_EACH_NUMERIC_FIELD(FIELD_ACCESSORS) |
| 3528 | #undef FIELD_ACCESSORS |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3529 | |
| 3530 | private: |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3531 | enum { |
| 3532 | #define DECL_INDEX(name) k##name, |
| 3533 | FOR_EACH_NUMERIC_FIELD(DECL_INDEX) |
| 3534 | #undef DECL_INDEX |
| 3535 | #undef FOR_EACH_NUMERIC_FIELD |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3536 | kVariablePartIndex |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3537 | }; |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3538 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3539 | // The layout of the variable part of a ScopeInfo is as follows: |
| 3540 | // 1. ParameterEntries: |
| 3541 | // This part stores the names of the parameters for function scopes. One |
| 3542 | // slot is used per parameter, so in total this part occupies |
| 3543 | // ParameterCount() slots in the array. For other scopes than function |
| 3544 | // scopes ParameterCount() is 0. |
| 3545 | // 2. StackLocalEntries: |
| 3546 | // Contains the names of local variables that are allocated on the stack, |
| 3547 | // in increasing order of the stack slot index. One slot is used per stack |
| 3548 | // local, so in total this part occupies StackLocalCount() slots in the |
| 3549 | // array. |
| 3550 | // 3. ContextLocalNameEntries: |
| 3551 | // Contains the names of local variables and parameters that are allocated |
| 3552 | // in the context. They are stored in increasing order of the context slot |
| 3553 | // index starting with Context::MIN_CONTEXT_SLOTS. One slot is used per |
| 3554 | // context local, so in total this part occupies ContextLocalCount() slots |
| 3555 | // in the array. |
| 3556 | // 4. ContextLocalInfoEntries: |
| 3557 | // Contains the variable modes and initialization flags corresponding to |
| 3558 | // the context locals in ContextLocalNameEntries. One slot is used per |
| 3559 | // context local, so in total this part occupies ContextLocalCount() |
| 3560 | // slots in the array. |
| 3561 | // 5. FunctionNameEntryIndex: |
| 3562 | // If the scope belongs to a named function expression this part contains |
| 3563 | // information about the function variable. It always occupies two array |
| 3564 | // slots: a. The name of the function variable. |
| 3565 | // b. The context or stack slot index for the variable. |
| 3566 | int ParameterEntriesIndex(); |
| 3567 | int StackLocalEntriesIndex(); |
| 3568 | int ContextLocalNameEntriesIndex(); |
| 3569 | int ContextLocalInfoEntriesIndex(); |
| 3570 | int FunctionNameEntryIndex(); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3571 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3572 | // Location of the function variable for named function expressions. |
| 3573 | enum FunctionVariableInfo { |
| 3574 | NONE, // No function name present. |
| 3575 | STACK, // Function |
| 3576 | CONTEXT, |
| 3577 | UNUSED |
| 3578 | }; |
| 3579 | |
| 3580 | // Properties of scopes. |
| 3581 | class TypeField: public BitField<ScopeType, 0, 3> {}; |
| 3582 | class CallsEvalField: public BitField<bool, 3, 1> {}; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3583 | class LanguageModeField: public BitField<LanguageMode, 4, 2> {}; |
| 3584 | class FunctionVariableField: public BitField<FunctionVariableInfo, 6, 2> {}; |
| 3585 | class FunctionVariableMode: public BitField<VariableMode, 8, 3> {}; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3586 | |
| 3587 | // BitFields representing the encoded information for context locals in the |
| 3588 | // ContextLocalInfoEntries part. |
| 3589 | class ContextLocalMode: public BitField<VariableMode, 0, 3> {}; |
| 3590 | class ContextLocalInitFlag: public BitField<InitializationFlag, 3, 1> {}; |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3591 | }; |
| 3592 | |
| 3593 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3594 | // The cache for maps used by normalized (dictionary mode) objects. |
| 3595 | // Such maps do not have property descriptors, so a typical program |
| 3596 | // needs very limited number of distinct normalized maps. |
| 3597 | class NormalizedMapCache: public FixedArray { |
| 3598 | public: |
| 3599 | static const int kEntries = 64; |
| 3600 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3601 | MUST_USE_RESULT MaybeObject* Get(JSObject* object, |
| 3602 | PropertyNormalizationMode mode); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3603 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3604 | void Clear(); |
| 3605 | |
| 3606 | // Casting |
| 3607 | static inline NormalizedMapCache* cast(Object* obj); |
| 3608 | |
| 3609 | #ifdef DEBUG |
| 3610 | void NormalizedMapCacheVerify(); |
| 3611 | #endif |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3612 | }; |
| 3613 | |
| 3614 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3615 | // ByteArray represents fixed sized byte arrays. Used for the relocation info |
| 3616 | // that is attached to code objects. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3617 | class ByteArray: public FixedArrayBase { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3618 | public: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3619 | inline int Size() { return RoundUp(length() + kHeaderSize, kPointerSize); } |
| 3620 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3621 | // Setter and getter. |
| 3622 | inline byte get(int index); |
| 3623 | inline void set(int index, byte value); |
| 3624 | |
| 3625 | // Treat contents as an int array. |
| 3626 | inline int get_int(int index); |
| 3627 | |
| 3628 | static int SizeFor(int length) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3629 | return OBJECT_POINTER_ALIGN(kHeaderSize + length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3630 | } |
| 3631 | // We use byte arrays for free blocks in the heap. Given a desired size in |
| 3632 | // bytes that is a multiple of the word size and big enough to hold a byte |
| 3633 | // array, this function returns the number of elements a byte array should |
| 3634 | // have. |
| 3635 | static int LengthFor(int size_in_bytes) { |
| 3636 | ASSERT(IsAligned(size_in_bytes, kPointerSize)); |
| 3637 | ASSERT(size_in_bytes >= kHeaderSize); |
| 3638 | return size_in_bytes - kHeaderSize; |
| 3639 | } |
| 3640 | |
| 3641 | // Returns data start address. |
| 3642 | inline Address GetDataStartAddress(); |
| 3643 | |
| 3644 | // Returns a pointer to the ByteArray object for a given data start address. |
| 3645 | static inline ByteArray* FromDataStartAddress(Address address); |
| 3646 | |
| 3647 | // Casting. |
| 3648 | static inline ByteArray* cast(Object* obj); |
| 3649 | |
| 3650 | // Dispatched behavior. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3651 | inline int ByteArraySize() { |
| 3652 | return SizeFor(this->length()); |
| 3653 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3654 | #ifdef OBJECT_PRINT |
| 3655 | inline void ByteArrayPrint() { |
| 3656 | ByteArrayPrint(stdout); |
| 3657 | } |
| 3658 | void ByteArrayPrint(FILE* out); |
| 3659 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3660 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3661 | void ByteArrayVerify(); |
| 3662 | #endif |
| 3663 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3664 | // Layout description. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3665 | static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 3666 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3667 | // Maximal memory consumption for a single ByteArray. |
| 3668 | static const int kMaxSize = 512 * MB; |
| 3669 | // Maximal length of a single ByteArray. |
| 3670 | static const int kMaxLength = kMaxSize - kHeaderSize; |
| 3671 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3672 | private: |
| 3673 | DISALLOW_IMPLICIT_CONSTRUCTORS(ByteArray); |
| 3674 | }; |
| 3675 | |
| 3676 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3677 | // FreeSpace represents fixed sized areas of the heap that are not currently in |
| 3678 | // use. Used by the heap and GC. |
| 3679 | class FreeSpace: public HeapObject { |
| 3680 | public: |
| 3681 | // [size]: size of the free space including the header. |
| 3682 | inline int size(); |
| 3683 | inline void set_size(int value); |
| 3684 | |
| 3685 | inline int Size() { return size(); } |
| 3686 | |
| 3687 | // Casting. |
| 3688 | static inline FreeSpace* cast(Object* obj); |
| 3689 | |
| 3690 | #ifdef OBJECT_PRINT |
| 3691 | inline void FreeSpacePrint() { |
| 3692 | FreeSpacePrint(stdout); |
| 3693 | } |
| 3694 | void FreeSpacePrint(FILE* out); |
| 3695 | #endif |
| 3696 | #ifdef DEBUG |
| 3697 | void FreeSpaceVerify(); |
| 3698 | #endif |
| 3699 | |
| 3700 | // Layout description. |
| 3701 | // Size is smi tagged when it is stored. |
| 3702 | static const int kSizeOffset = HeapObject::kHeaderSize; |
| 3703 | static const int kHeaderSize = kSizeOffset + kPointerSize; |
| 3704 | |
| 3705 | static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); |
| 3706 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3707 | private: |
| 3708 | DISALLOW_IMPLICIT_CONSTRUCTORS(FreeSpace); |
| 3709 | }; |
| 3710 | |
| 3711 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3712 | // An ExternalArray represents a fixed-size array of primitive values |
| 3713 | // which live outside the JavaScript heap. Its subclasses are used to |
| 3714 | // implement the CanvasArray types being defined in the WebGL |
| 3715 | // specification. As of this writing the first public draft is not yet |
| 3716 | // available, but Khronos members can access the draft at: |
| 3717 | // https://cvs.khronos.org/svn/repos/3dweb/trunk/doc/spec/WebGL-spec.html |
| 3718 | // |
| 3719 | // The semantics of these arrays differ from CanvasPixelArray. |
| 3720 | // Out-of-range values passed to the setter are converted via a C |
| 3721 | // cast, not clamping. Out-of-range indices cause exceptions to be |
| 3722 | // raised rather than being silently ignored. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3723 | class ExternalArray: public FixedArrayBase { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3724 | public: |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3725 | inline bool is_the_hole(int index) { return false; } |
| 3726 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3727 | // [external_pointer]: The pointer to the external memory area backing this |
| 3728 | // external array. |
| 3729 | DECL_ACCESSORS(external_pointer, void) // Pointer to the data store. |
| 3730 | |
| 3731 | // Casting. |
| 3732 | static inline ExternalArray* cast(Object* obj); |
| 3733 | |
| 3734 | // Maximal acceptable length for an external array. |
| 3735 | static const int kMaxLength = 0x3fffffff; |
| 3736 | |
| 3737 | // ExternalArray headers are not quadword aligned. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3738 | static const int kExternalPointerOffset = |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3739 | POINTER_SIZE_ALIGN(FixedArrayBase::kLengthOffset + kPointerSize); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3740 | static const int kHeaderSize = kExternalPointerOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3741 | static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3742 | |
| 3743 | private: |
| 3744 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalArray); |
| 3745 | }; |
| 3746 | |
| 3747 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3748 | // A ExternalPixelArray represents a fixed-size byte array with special |
| 3749 | // semantics used for implementing the CanvasPixelArray object. Please see the |
| 3750 | // specification at: |
| 3751 | |
| 3752 | // http://www.whatwg.org/specs/web-apps/current-work/ |
| 3753 | // multipage/the-canvas-element.html#canvaspixelarray |
| 3754 | // In particular, write access clamps the value written to 0 or 255 if the |
| 3755 | // value written is outside this range. |
| 3756 | class ExternalPixelArray: public ExternalArray { |
| 3757 | public: |
| 3758 | inline uint8_t* external_pixel_pointer(); |
| 3759 | |
| 3760 | // Setter and getter. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3761 | inline uint8_t get_scalar(int index); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3762 | MUST_USE_RESULT inline MaybeObject* get(int index); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3763 | inline void set(int index, uint8_t value); |
| 3764 | |
| 3765 | // This accessor applies the correct conversion from Smi, HeapNumber and |
| 3766 | // undefined and clamps the converted value between 0 and 255. |
| 3767 | Object* SetValue(uint32_t index, Object* value); |
| 3768 | |
| 3769 | // Casting. |
| 3770 | static inline ExternalPixelArray* cast(Object* obj); |
| 3771 | |
| 3772 | #ifdef OBJECT_PRINT |
| 3773 | inline void ExternalPixelArrayPrint() { |
| 3774 | ExternalPixelArrayPrint(stdout); |
| 3775 | } |
| 3776 | void ExternalPixelArrayPrint(FILE* out); |
| 3777 | #endif |
| 3778 | #ifdef DEBUG |
| 3779 | void ExternalPixelArrayVerify(); |
| 3780 | #endif // DEBUG |
| 3781 | |
| 3782 | private: |
| 3783 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalPixelArray); |
| 3784 | }; |
| 3785 | |
| 3786 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3787 | class ExternalByteArray: public ExternalArray { |
| 3788 | public: |
| 3789 | // Setter and getter. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3790 | inline int8_t get_scalar(int index); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3791 | MUST_USE_RESULT inline MaybeObject* get(int index); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3792 | inline void set(int index, int8_t value); |
| 3793 | |
| 3794 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3795 | // and undefined. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3796 | MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3797 | |
| 3798 | // Casting. |
| 3799 | static inline ExternalByteArray* cast(Object* obj); |
| 3800 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3801 | #ifdef OBJECT_PRINT |
| 3802 | inline void ExternalByteArrayPrint() { |
| 3803 | ExternalByteArrayPrint(stdout); |
| 3804 | } |
| 3805 | void ExternalByteArrayPrint(FILE* out); |
| 3806 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3807 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3808 | void ExternalByteArrayVerify(); |
| 3809 | #endif // DEBUG |
| 3810 | |
| 3811 | private: |
| 3812 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalByteArray); |
| 3813 | }; |
| 3814 | |
| 3815 | |
| 3816 | class ExternalUnsignedByteArray: public ExternalArray { |
| 3817 | public: |
| 3818 | // Setter and getter. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3819 | inline uint8_t get_scalar(int index); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3820 | MUST_USE_RESULT inline MaybeObject* get(int index); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3821 | inline void set(int index, uint8_t value); |
| 3822 | |
| 3823 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3824 | // and undefined. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3825 | MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3826 | |
| 3827 | // Casting. |
| 3828 | static inline ExternalUnsignedByteArray* cast(Object* obj); |
| 3829 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3830 | #ifdef OBJECT_PRINT |
| 3831 | inline void ExternalUnsignedByteArrayPrint() { |
| 3832 | ExternalUnsignedByteArrayPrint(stdout); |
| 3833 | } |
| 3834 | void ExternalUnsignedByteArrayPrint(FILE* out); |
| 3835 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3836 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3837 | void ExternalUnsignedByteArrayVerify(); |
| 3838 | #endif // DEBUG |
| 3839 | |
| 3840 | private: |
| 3841 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedByteArray); |
| 3842 | }; |
| 3843 | |
| 3844 | |
| 3845 | class ExternalShortArray: public ExternalArray { |
| 3846 | public: |
| 3847 | // Setter and getter. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3848 | inline int16_t get_scalar(int index); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3849 | MUST_USE_RESULT inline MaybeObject* get(int index); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3850 | inline void set(int index, int16_t value); |
| 3851 | |
| 3852 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3853 | // and undefined. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3854 | MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3855 | |
| 3856 | // Casting. |
| 3857 | static inline ExternalShortArray* cast(Object* obj); |
| 3858 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3859 | #ifdef OBJECT_PRINT |
| 3860 | inline void ExternalShortArrayPrint() { |
| 3861 | ExternalShortArrayPrint(stdout); |
| 3862 | } |
| 3863 | void ExternalShortArrayPrint(FILE* out); |
| 3864 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3865 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3866 | void ExternalShortArrayVerify(); |
| 3867 | #endif // DEBUG |
| 3868 | |
| 3869 | private: |
| 3870 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalShortArray); |
| 3871 | }; |
| 3872 | |
| 3873 | |
| 3874 | class ExternalUnsignedShortArray: public ExternalArray { |
| 3875 | public: |
| 3876 | // Setter and getter. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3877 | inline uint16_t get_scalar(int index); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3878 | MUST_USE_RESULT inline MaybeObject* get(int index); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3879 | inline void set(int index, uint16_t value); |
| 3880 | |
| 3881 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3882 | // and undefined. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3883 | MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3884 | |
| 3885 | // Casting. |
| 3886 | static inline ExternalUnsignedShortArray* cast(Object* obj); |
| 3887 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3888 | #ifdef OBJECT_PRINT |
| 3889 | inline void ExternalUnsignedShortArrayPrint() { |
| 3890 | ExternalUnsignedShortArrayPrint(stdout); |
| 3891 | } |
| 3892 | void ExternalUnsignedShortArrayPrint(FILE* out); |
| 3893 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3894 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3895 | void ExternalUnsignedShortArrayVerify(); |
| 3896 | #endif // DEBUG |
| 3897 | |
| 3898 | private: |
| 3899 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedShortArray); |
| 3900 | }; |
| 3901 | |
| 3902 | |
| 3903 | class ExternalIntArray: public ExternalArray { |
| 3904 | public: |
| 3905 | // Setter and getter. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3906 | inline int32_t get_scalar(int index); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3907 | MUST_USE_RESULT inline MaybeObject* get(int index); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3908 | inline void set(int index, int32_t value); |
| 3909 | |
| 3910 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3911 | // and undefined. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3912 | MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3913 | |
| 3914 | // Casting. |
| 3915 | static inline ExternalIntArray* cast(Object* obj); |
| 3916 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3917 | #ifdef OBJECT_PRINT |
| 3918 | inline void ExternalIntArrayPrint() { |
| 3919 | ExternalIntArrayPrint(stdout); |
| 3920 | } |
| 3921 | void ExternalIntArrayPrint(FILE* out); |
| 3922 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3923 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3924 | void ExternalIntArrayVerify(); |
| 3925 | #endif // DEBUG |
| 3926 | |
| 3927 | private: |
| 3928 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalIntArray); |
| 3929 | }; |
| 3930 | |
| 3931 | |
| 3932 | class ExternalUnsignedIntArray: public ExternalArray { |
| 3933 | public: |
| 3934 | // Setter and getter. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3935 | inline uint32_t get_scalar(int index); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3936 | MUST_USE_RESULT inline MaybeObject* get(int index); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3937 | inline void set(int index, uint32_t value); |
| 3938 | |
| 3939 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3940 | // and undefined. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3941 | MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3942 | |
| 3943 | // Casting. |
| 3944 | static inline ExternalUnsignedIntArray* cast(Object* obj); |
| 3945 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3946 | #ifdef OBJECT_PRINT |
| 3947 | inline void ExternalUnsignedIntArrayPrint() { |
| 3948 | ExternalUnsignedIntArrayPrint(stdout); |
| 3949 | } |
| 3950 | void ExternalUnsignedIntArrayPrint(FILE* out); |
| 3951 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3952 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3953 | void ExternalUnsignedIntArrayVerify(); |
| 3954 | #endif // DEBUG |
| 3955 | |
| 3956 | private: |
| 3957 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedIntArray); |
| 3958 | }; |
| 3959 | |
| 3960 | |
| 3961 | class ExternalFloatArray: public ExternalArray { |
| 3962 | public: |
| 3963 | // Setter and getter. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3964 | inline float get_scalar(int index); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3965 | MUST_USE_RESULT inline MaybeObject* get(int index); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3966 | inline void set(int index, float value); |
| 3967 | |
| 3968 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3969 | // and undefined. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3970 | MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3971 | |
| 3972 | // Casting. |
| 3973 | static inline ExternalFloatArray* cast(Object* obj); |
| 3974 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3975 | #ifdef OBJECT_PRINT |
| 3976 | inline void ExternalFloatArrayPrint() { |
| 3977 | ExternalFloatArrayPrint(stdout); |
| 3978 | } |
| 3979 | void ExternalFloatArrayPrint(FILE* out); |
| 3980 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3981 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3982 | void ExternalFloatArrayVerify(); |
| 3983 | #endif // DEBUG |
| 3984 | |
| 3985 | private: |
| 3986 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalFloatArray); |
| 3987 | }; |
| 3988 | |
| 3989 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 3990 | class ExternalDoubleArray: public ExternalArray { |
| 3991 | public: |
| 3992 | // Setter and getter. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3993 | inline double get_scalar(int index); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3994 | MUST_USE_RESULT inline MaybeObject* get(int index); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 3995 | inline void set(int index, double value); |
| 3996 | |
| 3997 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3998 | // and undefined. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3999 | MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 4000 | |
| 4001 | // Casting. |
| 4002 | static inline ExternalDoubleArray* cast(Object* obj); |
| 4003 | |
| 4004 | #ifdef OBJECT_PRINT |
| 4005 | inline void ExternalDoubleArrayPrint() { |
| 4006 | ExternalDoubleArrayPrint(stdout); |
| 4007 | } |
| 4008 | void ExternalDoubleArrayPrint(FILE* out); |
| 4009 | #endif // OBJECT_PRINT |
| 4010 | #ifdef DEBUG |
| 4011 | void ExternalDoubleArrayVerify(); |
| 4012 | #endif // DEBUG |
| 4013 | |
| 4014 | private: |
| 4015 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalDoubleArray); |
| 4016 | }; |
| 4017 | |
| 4018 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4019 | // DeoptimizationInputData is a fixed array used to hold the deoptimization |
| 4020 | // data for code generated by the Hydrogen/Lithium compiler. It also |
| 4021 | // contains information about functions that were inlined. If N different |
| 4022 | // functions were inlined then first N elements of the literal array will |
| 4023 | // contain these functions. |
| 4024 | // |
| 4025 | // It can be empty. |
| 4026 | class DeoptimizationInputData: public FixedArray { |
| 4027 | public: |
| 4028 | // Layout description. Indices in the array. |
| 4029 | static const int kTranslationByteArrayIndex = 0; |
| 4030 | static const int kInlinedFunctionCountIndex = 1; |
| 4031 | static const int kLiteralArrayIndex = 2; |
| 4032 | static const int kOsrAstIdIndex = 3; |
| 4033 | static const int kOsrPcOffsetIndex = 4; |
| 4034 | static const int kFirstDeoptEntryIndex = 5; |
| 4035 | |
| 4036 | // Offsets of deopt entry elements relative to the start of the entry. |
| 4037 | static const int kAstIdOffset = 0; |
| 4038 | static const int kTranslationIndexOffset = 1; |
| 4039 | static const int kArgumentsStackHeightOffset = 2; |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 4040 | static const int kPcOffset = 3; |
| 4041 | static const int kDeoptEntrySize = 4; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4042 | |
| 4043 | // Simple element accessors. |
| 4044 | #define DEFINE_ELEMENT_ACCESSORS(name, type) \ |
| 4045 | type* name() { \ |
| 4046 | return type::cast(get(k##name##Index)); \ |
| 4047 | } \ |
| 4048 | void Set##name(type* value) { \ |
| 4049 | set(k##name##Index, value); \ |
| 4050 | } |
| 4051 | |
| 4052 | DEFINE_ELEMENT_ACCESSORS(TranslationByteArray, ByteArray) |
| 4053 | DEFINE_ELEMENT_ACCESSORS(InlinedFunctionCount, Smi) |
| 4054 | DEFINE_ELEMENT_ACCESSORS(LiteralArray, FixedArray) |
| 4055 | DEFINE_ELEMENT_ACCESSORS(OsrAstId, Smi) |
| 4056 | DEFINE_ELEMENT_ACCESSORS(OsrPcOffset, Smi) |
| 4057 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4058 | #undef DEFINE_ELEMENT_ACCESSORS |
| 4059 | |
| 4060 | // Accessors for elements of the ith deoptimization entry. |
| 4061 | #define DEFINE_ENTRY_ACCESSORS(name, type) \ |
| 4062 | type* name(int i) { \ |
| 4063 | return type::cast(get(IndexForEntry(i) + k##name##Offset)); \ |
| 4064 | } \ |
| 4065 | void Set##name(int i, type* value) { \ |
| 4066 | set(IndexForEntry(i) + k##name##Offset, value); \ |
| 4067 | } |
| 4068 | |
| 4069 | DEFINE_ENTRY_ACCESSORS(AstId, Smi) |
| 4070 | DEFINE_ENTRY_ACCESSORS(TranslationIndex, Smi) |
| 4071 | DEFINE_ENTRY_ACCESSORS(ArgumentsStackHeight, Smi) |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 4072 | DEFINE_ENTRY_ACCESSORS(Pc, Smi) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4073 | |
| 4074 | #undef DEFINE_ENTRY_ACCESSORS |
| 4075 | |
| 4076 | int DeoptCount() { |
| 4077 | return (length() - kFirstDeoptEntryIndex) / kDeoptEntrySize; |
| 4078 | } |
| 4079 | |
| 4080 | // Allocates a DeoptimizationInputData. |
| 4081 | MUST_USE_RESULT static MaybeObject* Allocate(int deopt_entry_count, |
| 4082 | PretenureFlag pretenure); |
| 4083 | |
| 4084 | // Casting. |
| 4085 | static inline DeoptimizationInputData* cast(Object* obj); |
| 4086 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4087 | #ifdef ENABLE_DISASSEMBLER |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4088 | void DeoptimizationInputDataPrint(FILE* out); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4089 | #endif |
| 4090 | |
| 4091 | private: |
| 4092 | static int IndexForEntry(int i) { |
| 4093 | return kFirstDeoptEntryIndex + (i * kDeoptEntrySize); |
| 4094 | } |
| 4095 | |
| 4096 | static int LengthFor(int entry_count) { |
| 4097 | return IndexForEntry(entry_count); |
| 4098 | } |
| 4099 | }; |
| 4100 | |
| 4101 | |
| 4102 | // DeoptimizationOutputData is a fixed array used to hold the deoptimization |
| 4103 | // data for code generated by the full compiler. |
| 4104 | // The format of the these objects is |
| 4105 | // [i * 2]: Ast ID for ith deoptimization. |
| 4106 | // [i * 2 + 1]: PC and state of ith deoptimization |
| 4107 | class DeoptimizationOutputData: public FixedArray { |
| 4108 | public: |
| 4109 | int DeoptPoints() { return length() / 2; } |
| 4110 | Smi* AstId(int index) { return Smi::cast(get(index * 2)); } |
| 4111 | void SetAstId(int index, Smi* id) { set(index * 2, id); } |
| 4112 | Smi* PcAndState(int index) { return Smi::cast(get(1 + index * 2)); } |
| 4113 | void SetPcAndState(int index, Smi* offset) { set(1 + index * 2, offset); } |
| 4114 | |
| 4115 | static int LengthOfFixedArray(int deopt_points) { |
| 4116 | return deopt_points * 2; |
| 4117 | } |
| 4118 | |
| 4119 | // Allocates a DeoptimizationOutputData. |
| 4120 | MUST_USE_RESULT static MaybeObject* Allocate(int number_of_deopt_points, |
| 4121 | PretenureFlag pretenure); |
| 4122 | |
| 4123 | // Casting. |
| 4124 | static inline DeoptimizationOutputData* cast(Object* obj); |
| 4125 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4126 | #if defined(OBJECT_PRINT) || defined(ENABLE_DISASSEMBLER) |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4127 | void DeoptimizationOutputDataPrint(FILE* out); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4128 | #endif |
| 4129 | }; |
| 4130 | |
| 4131 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4132 | // Forward declaration. |
| 4133 | class JSGlobalPropertyCell; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4134 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4135 | // TypeFeedbackCells is a fixed array used to hold the association between |
| 4136 | // cache cells and AST ids for code generated by the full compiler. |
| 4137 | // The format of the these objects is |
| 4138 | // [i * 2]: Global property cell of ith cache cell. |
| 4139 | // [i * 2 + 1]: Ast ID for ith cache cell. |
| 4140 | class TypeFeedbackCells: public FixedArray { |
| 4141 | public: |
| 4142 | int CellCount() { return length() / 2; } |
| 4143 | static int LengthOfFixedArray(int cell_count) { return cell_count * 2; } |
| 4144 | |
| 4145 | // Accessors for AST ids associated with cache values. |
| 4146 | inline Smi* AstId(int index); |
| 4147 | inline void SetAstId(int index, Smi* id); |
| 4148 | |
| 4149 | // Accessors for global property cells holding the cache values. |
| 4150 | inline JSGlobalPropertyCell* Cell(int index); |
| 4151 | inline void SetCell(int index, JSGlobalPropertyCell* cell); |
| 4152 | |
| 4153 | // The object that indicates an uninitialized cache. |
| 4154 | static inline Handle<Object> UninitializedSentinel(Isolate* isolate); |
| 4155 | |
| 4156 | // The object that indicates a megamorphic state. |
| 4157 | static inline Handle<Object> MegamorphicSentinel(Isolate* isolate); |
| 4158 | |
| 4159 | // A raw version of the uninitialized sentinel that's safe to read during |
| 4160 | // garbage collection (e.g., for patching the cache). |
| 4161 | static inline Object* RawUninitializedSentinel(Heap* heap); |
| 4162 | |
| 4163 | // Casting. |
| 4164 | static inline TypeFeedbackCells* cast(Object* obj); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 4165 | |
| 4166 | static const int kForInFastCaseMarker = 0; |
| 4167 | static const int kForInSlowCaseMarker = 1; |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4168 | }; |
| 4169 | |
| 4170 | |
| 4171 | // Forward declaration. |
| 4172 | class SafepointEntry; |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 4173 | class TypeFeedbackInfo; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4174 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4175 | // Code describes objects with on-the-fly generated machine code. |
| 4176 | class Code: public HeapObject { |
| 4177 | public: |
| 4178 | // Opaque data type for encapsulating code flags like kind, inline |
| 4179 | // cache state, and arguments count. |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 4180 | // FLAGS_MIN_VALUE and FLAGS_MAX_VALUE are specified to ensure that |
| 4181 | // enumeration type has correct value range (see Issue 830 for more details). |
| 4182 | enum Flags { |
| 4183 | FLAGS_MIN_VALUE = kMinInt, |
| 4184 | FLAGS_MAX_VALUE = kMaxInt |
| 4185 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4186 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame^] | 4187 | #define CODE_KIND_LIST(V) \ |
| 4188 | V(FUNCTION) \ |
| 4189 | V(OPTIMIZED_FUNCTION) \ |
| 4190 | V(STUB) \ |
| 4191 | V(BUILTIN) \ |
| 4192 | V(LOAD_IC) \ |
| 4193 | V(KEYED_LOAD_IC) \ |
| 4194 | V(CALL_IC) \ |
| 4195 | V(KEYED_CALL_IC) \ |
| 4196 | V(STORE_IC) \ |
| 4197 | V(KEYED_STORE_IC) \ |
| 4198 | V(UNARY_OP_IC) \ |
| 4199 | V(BINARY_OP_IC) \ |
| 4200 | V(COMPARE_IC) \ |
| 4201 | V(TO_BOOLEAN_IC) |
| 4202 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4203 | enum Kind { |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame^] | 4204 | #define DEFINE_CODE_KIND_ENUM(name) name, |
| 4205 | CODE_KIND_LIST(DEFINE_CODE_KIND_ENUM) |
| 4206 | #undef DEFINE_CODE_KIND_ENUM |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4207 | |
| 4208 | // Pseudo-kinds. |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame^] | 4209 | LAST_CODE_KIND = TO_BOOLEAN_IC, |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 4210 | REGEXP = BUILTIN, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4211 | FIRST_IC_KIND = LOAD_IC, |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 4212 | LAST_IC_KIND = TO_BOOLEAN_IC |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4213 | }; |
| 4214 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame^] | 4215 | // No more than 16 kinds. The value is currently encoded in four bits in |
| 4216 | // Flags. |
| 4217 | STATIC_ASSERT(LAST_CODE_KIND < 16); |
| 4218 | |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 4219 | // Types of stubs. |
| 4220 | enum StubType { |
| 4221 | NORMAL, |
| 4222 | FIELD, |
| 4223 | CONSTANT_FUNCTION, |
| 4224 | CALLBACKS, |
| 4225 | INTERCEPTOR, |
| 4226 | MAP_TRANSITION, |
| 4227 | NONEXISTENT |
| 4228 | }; |
| 4229 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4230 | enum { |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 4231 | NUMBER_OF_KINDS = LAST_IC_KIND + 1 |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4232 | }; |
| 4233 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 4234 | typedef int ExtraICState; |
| 4235 | |
| 4236 | static const ExtraICState kNoExtraICState = 0; |
| 4237 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 4238 | #ifdef ENABLE_DISASSEMBLER |
| 4239 | // Printing |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4240 | static const char* Kind2String(Kind kind); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4241 | static const char* ICState2String(InlineCacheState state); |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 4242 | static const char* StubType2String(StubType type); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4243 | static void PrintExtraICState(FILE* out, Kind kind, ExtraICState extra); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4244 | inline void Disassemble(const char* name) { |
| 4245 | Disassemble(name, stdout); |
| 4246 | } |
| 4247 | void Disassemble(const char* name, FILE* out); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 4248 | #endif // ENABLE_DISASSEMBLER |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4249 | |
| 4250 | // [instruction_size]: Size of the native instructions |
| 4251 | inline int instruction_size(); |
| 4252 | inline void set_instruction_size(int value); |
| 4253 | |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4254 | // [relocation_info]: Code relocation information |
| 4255 | DECL_ACCESSORS(relocation_info, ByteArray) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4256 | void InvalidateRelocation(); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4257 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4258 | // [handler_table]: Fixed array containing offsets of exception handlers. |
| 4259 | DECL_ACCESSORS(handler_table, FixedArray) |
| 4260 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4261 | // [deoptimization_data]: Array containing data for deopt. |
| 4262 | DECL_ACCESSORS(deoptimization_data, FixedArray) |
| 4263 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 4264 | // [type_feedback_info]: Struct containing type feedback information. |
| 4265 | // Will contain either a TypeFeedbackInfo object, or undefined. |
| 4266 | DECL_ACCESSORS(type_feedback_info, Object) |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4267 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 4268 | // [gc_metadata]: Field used to hold GC related metadata. The contents of this |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4269 | // field does not have to be traced during garbage collection since |
| 4270 | // it is only used by the garbage collector itself. |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 4271 | DECL_ACCESSORS(gc_metadata, Object) |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4272 | |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 4273 | // [ic_age]: Inline caching age: the value of the Heap::global_ic_age |
| 4274 | // at the moment when this object was created. |
| 4275 | inline void set_ic_age(int count); |
| 4276 | inline int ic_age(); |
| 4277 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4278 | // Unchecked accessors to be used during GC. |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4279 | inline ByteArray* unchecked_relocation_info(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4280 | inline FixedArray* unchecked_deoptimization_data(); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4281 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4282 | inline int relocation_size(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4283 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4284 | // [flags]: Various code flags. |
| 4285 | inline Flags flags(); |
| 4286 | inline void set_flags(Flags flags); |
| 4287 | |
| 4288 | // [flags]: Access to specific code flags. |
| 4289 | inline Kind kind(); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4290 | inline InlineCacheState ic_state(); // Only valid for IC stubs. |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 4291 | inline ExtraICState extra_ic_state(); // Only valid for IC stubs. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 4292 | inline StubType type(); // Only valid for monomorphic IC stubs. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4293 | inline int arguments_count(); // Only valid for call IC stubs. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4294 | |
| 4295 | // Testers for IC stub kinds. |
| 4296 | inline bool is_inline_cache_stub(); |
| 4297 | inline bool is_load_stub() { return kind() == LOAD_IC; } |
| 4298 | inline bool is_keyed_load_stub() { return kind() == KEYED_LOAD_IC; } |
| 4299 | inline bool is_store_stub() { return kind() == STORE_IC; } |
| 4300 | inline bool is_keyed_store_stub() { return kind() == KEYED_STORE_IC; } |
| 4301 | inline bool is_call_stub() { return kind() == CALL_IC; } |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 4302 | inline bool is_keyed_call_stub() { return kind() == KEYED_CALL_IC; } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 4303 | inline bool is_unary_op_stub() { return kind() == UNARY_OP_IC; } |
| 4304 | inline bool is_binary_op_stub() { return kind() == BINARY_OP_IC; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4305 | inline bool is_compare_ic_stub() { return kind() == COMPARE_IC; } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 4306 | inline bool is_to_boolean_ic_stub() { return kind() == TO_BOOLEAN_IC; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4307 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4308 | // [major_key]: For kind STUB or BINARY_OP_IC, the major key. |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 4309 | inline int major_key(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4310 | inline void set_major_key(int value); |
| 4311 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4312 | // For stubs, tells whether they should always exist, so that they can be |
| 4313 | // called from other stubs. |
| 4314 | inline bool is_pregenerated(); |
| 4315 | inline void set_is_pregenerated(bool value); |
| 4316 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4317 | // [optimizable]: For FUNCTION kind, tells if it is optimizable. |
| 4318 | inline bool optimizable(); |
| 4319 | inline void set_optimizable(bool value); |
| 4320 | |
| 4321 | // [has_deoptimization_support]: For FUNCTION kind, tells if it has |
| 4322 | // deoptimization support. |
| 4323 | inline bool has_deoptimization_support(); |
| 4324 | inline void set_has_deoptimization_support(bool value); |
| 4325 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4326 | // [has_debug_break_slots]: For FUNCTION kind, tells if it has |
| 4327 | // been compiled with debug break slots. |
| 4328 | inline bool has_debug_break_slots(); |
| 4329 | inline void set_has_debug_break_slots(bool value); |
| 4330 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4331 | // [compiled_with_optimizing]: For FUNCTION kind, tells if it has |
| 4332 | // been compiled with IsOptimizing set to true. |
| 4333 | inline bool is_compiled_optimizable(); |
| 4334 | inline void set_compiled_optimizable(bool value); |
| 4335 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4336 | // [allow_osr_at_loop_nesting_level]: For FUNCTION kind, tells for |
| 4337 | // how long the function has been marked for OSR and therefore which |
| 4338 | // level of loop nesting we are willing to do on-stack replacement |
| 4339 | // for. |
| 4340 | inline void set_allow_osr_at_loop_nesting_level(int level); |
| 4341 | inline int allow_osr_at_loop_nesting_level(); |
| 4342 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 4343 | // [profiler_ticks]: For FUNCTION kind, tells for how many profiler ticks |
| 4344 | // the code object was seen on the stack with no IC patching going on. |
| 4345 | inline int profiler_ticks(); |
| 4346 | inline void set_profiler_ticks(int ticks); |
| 4347 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4348 | // [stack_slots]: For kind OPTIMIZED_FUNCTION, the number of stack slots |
| 4349 | // reserved in the code prologue. |
| 4350 | inline unsigned stack_slots(); |
| 4351 | inline void set_stack_slots(unsigned slots); |
| 4352 | |
| 4353 | // [safepoint_table_start]: For kind OPTIMIZED_CODE, the offset in |
| 4354 | // the instruction stream where the safepoint table starts. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4355 | inline unsigned safepoint_table_offset(); |
| 4356 | inline void set_safepoint_table_offset(unsigned offset); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4357 | |
| 4358 | // [stack_check_table_start]: For kind FUNCTION, the offset in the |
| 4359 | // instruction stream where the stack check table starts. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4360 | inline unsigned stack_check_table_offset(); |
| 4361 | inline void set_stack_check_table_offset(unsigned offset); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4362 | |
| 4363 | // [check type]: For kind CALL_IC, tells how to check if the |
| 4364 | // receiver is valid for the given call. |
| 4365 | inline CheckType check_type(); |
| 4366 | inline void set_check_type(CheckType value); |
| 4367 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 4368 | // [type-recording unary op type]: For kind UNARY_OP_IC. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4369 | inline byte unary_op_type(); |
| 4370 | inline void set_unary_op_type(byte value); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 4371 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 4372 | // [type-recording binary op type]: For kind BINARY_OP_IC. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4373 | inline byte binary_op_type(); |
| 4374 | inline void set_binary_op_type(byte value); |
| 4375 | inline byte binary_op_result_type(); |
| 4376 | inline void set_binary_op_result_type(byte value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4377 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 4378 | // [compare state]: For kind COMPARE_IC, tells what state the stub is in. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4379 | inline byte compare_state(); |
| 4380 | inline void set_compare_state(byte value); |
| 4381 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 4382 | // [compare_operation]: For kind COMPARE_IC tells what compare operation the |
| 4383 | // stub was generated for. |
| 4384 | inline byte compare_operation(); |
| 4385 | inline void set_compare_operation(byte value); |
| 4386 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 4387 | // [to_boolean_foo]: For kind TO_BOOLEAN_IC tells what state the stub is in. |
| 4388 | inline byte to_boolean_state(); |
| 4389 | inline void set_to_boolean_state(byte value); |
| 4390 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4391 | // [has_function_cache]: For kind STUB tells whether there is a function |
| 4392 | // cache is passed to the stub. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4393 | inline bool has_function_cache(); |
| 4394 | inline void set_has_function_cache(bool flag); |
| 4395 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4396 | bool allowed_in_shared_map_code_cache(); |
| 4397 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4398 | // Get the safepoint entry for the given pc. |
| 4399 | SafepointEntry GetSafepointEntry(Address pc); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4400 | |
| 4401 | // Mark this code object as not having a stack check table. Assumes kind |
| 4402 | // is FUNCTION. |
| 4403 | void SetNoStackCheckTable(); |
| 4404 | |
| 4405 | // Find the first map in an IC stub. |
| 4406 | Map* FindFirstMap(); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4407 | |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4408 | class ExtraICStateStrictMode: public BitField<StrictModeFlag, 0, 1> {}; |
| 4409 | class ExtraICStateKeyedAccessGrowMode: |
| 4410 | public BitField<KeyedAccessGrowMode, 1, 1> {}; // NOLINT |
| 4411 | |
| 4412 | static const int kExtraICStateGrowModeShift = 1; |
| 4413 | |
| 4414 | static inline StrictModeFlag GetStrictMode(ExtraICState extra_ic_state) { |
| 4415 | return ExtraICStateStrictMode::decode(extra_ic_state); |
| 4416 | } |
| 4417 | |
| 4418 | static inline KeyedAccessGrowMode GetKeyedAccessGrowMode( |
| 4419 | ExtraICState extra_ic_state) { |
| 4420 | return ExtraICStateKeyedAccessGrowMode::decode(extra_ic_state); |
| 4421 | } |
| 4422 | |
| 4423 | static inline ExtraICState ComputeExtraICState( |
| 4424 | KeyedAccessGrowMode grow_mode, |
| 4425 | StrictModeFlag strict_mode) { |
| 4426 | return ExtraICStateKeyedAccessGrowMode::encode(grow_mode) | |
| 4427 | ExtraICStateStrictMode::encode(strict_mode); |
| 4428 | } |
| 4429 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4430 | // Flags operations. |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 4431 | static inline Flags ComputeFlags( |
| 4432 | Kind kind, |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 4433 | InlineCacheState ic_state = UNINITIALIZED, |
| 4434 | ExtraICState extra_ic_state = kNoExtraICState, |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 4435 | StubType type = NORMAL, |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 4436 | int argc = -1, |
| 4437 | InlineCacheHolderFlag holder = OWN_MAP); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4438 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4439 | static inline Flags ComputeMonomorphicFlags( |
| 4440 | Kind kind, |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 4441 | StubType type, |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 4442 | ExtraICState extra_ic_state = kNoExtraICState, |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4443 | InlineCacheHolderFlag holder = OWN_MAP, |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4444 | int argc = -1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4445 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4446 | static inline InlineCacheState ExtractICStateFromFlags(Flags flags); |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 4447 | static inline StubType ExtractTypeFromFlags(Flags flags); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4448 | static inline Kind ExtractKindFromFlags(Flags flags); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4449 | static inline InlineCacheHolderFlag ExtractCacheHolderFromFlags(Flags flags); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4450 | static inline ExtraICState ExtractExtraICStateFromFlags(Flags flags); |
| 4451 | static inline int ExtractArgumentsCountFromFlags(Flags flags); |
| 4452 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4453 | static inline Flags RemoveTypeFromFlags(Flags flags); |
| 4454 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 4455 | // Convert a target address into a code object. |
| 4456 | static inline Code* GetCodeFromTargetAddress(Address address); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4457 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 4458 | // Convert an entry address into an object. |
| 4459 | static inline Object* GetObjectFromEntryAddress(Address location_of_address); |
| 4460 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4461 | // Returns the address of the first instruction. |
| 4462 | inline byte* instruction_start(); |
| 4463 | |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4464 | // Returns the address right after the last instruction. |
| 4465 | inline byte* instruction_end(); |
| 4466 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4467 | // Returns the size of the instructions, padding, and relocation information. |
| 4468 | inline int body_size(); |
| 4469 | |
| 4470 | // Returns the address of the first relocation info (read backwards!). |
| 4471 | inline byte* relocation_start(); |
| 4472 | |
| 4473 | // Code entry point. |
| 4474 | inline byte* entry(); |
| 4475 | |
| 4476 | // Returns true if pc is inside this object's instructions. |
| 4477 | inline bool contains(byte* pc); |
| 4478 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4479 | // Relocate the code by delta bytes. Called to signal that this code |
| 4480 | // object has been moved by delta bytes. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4481 | void Relocate(intptr_t delta); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4482 | |
| 4483 | // Migrate code described by desc. |
| 4484 | void CopyFrom(const CodeDesc& desc); |
| 4485 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4486 | // Returns the object size for a given body (used for allocation). |
| 4487 | static int SizeFor(int body_size) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4488 | ASSERT_SIZE_TAG_ALIGNED(body_size); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4489 | return RoundUp(kHeaderSize + body_size, kCodeAlignment); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4490 | } |
| 4491 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4492 | // Calculate the size of the code object to report for log events. This takes |
| 4493 | // the layout of the code object into account. |
| 4494 | int ExecutableSize() { |
| 4495 | // Check that the assumptions about the layout of the code object holds. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 4496 | ASSERT_EQ(static_cast<int>(instruction_start() - address()), |
| 4497 | Code::kHeaderSize); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4498 | return instruction_size() + Code::kHeaderSize; |
| 4499 | } |
| 4500 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4501 | // Locating source position. |
| 4502 | int SourcePosition(Address pc); |
| 4503 | int SourceStatementPosition(Address pc); |
| 4504 | |
| 4505 | // Casting. |
| 4506 | static inline Code* cast(Object* obj); |
| 4507 | |
| 4508 | // Dispatched behavior. |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4509 | int CodeSize() { return SizeFor(body_size()); } |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4510 | inline void CodeIterateBody(ObjectVisitor* v); |
| 4511 | |
| 4512 | template<typename StaticVisitor> |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4513 | inline void CodeIterateBody(Heap* heap); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4514 | #ifdef OBJECT_PRINT |
| 4515 | inline void CodePrint() { |
| 4516 | CodePrint(stdout); |
| 4517 | } |
| 4518 | void CodePrint(FILE* out); |
| 4519 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4520 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4521 | void CodeVerify(); |
| 4522 | #endif |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 4523 | void ClearInlineCaches(); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 4524 | void ClearTypeFeedbackCells(Heap* heap); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4525 | |
| 4526 | // Max loop nesting marker used to postpose OSR. We don't take loop |
| 4527 | // nesting that is deeper than 5 levels into account. |
| 4528 | static const int kMaxLoopNestingMarker = 6; |
| 4529 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4530 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 4531 | static const int kInstructionSizeOffset = HeapObject::kHeaderSize; |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4532 | static const int kRelocationInfoOffset = kInstructionSizeOffset + kIntSize; |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4533 | static const int kHandlerTableOffset = kRelocationInfoOffset + kPointerSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4534 | static const int kDeoptimizationDataOffset = |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4535 | kHandlerTableOffset + kPointerSize; |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 4536 | static const int kTypeFeedbackInfoOffset = |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4537 | kDeoptimizationDataOffset + kPointerSize; |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 4538 | static const int kGCMetadataOffset = kTypeFeedbackInfoOffset + kPointerSize; |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 4539 | static const int kICAgeOffset = |
| 4540 | kGCMetadataOffset + kPointerSize; |
| 4541 | static const int kFlagsOffset = kICAgeOffset + kIntSize; |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 4542 | static const int kKindSpecificFlags1Offset = kFlagsOffset + kIntSize; |
| 4543 | static const int kKindSpecificFlags2Offset = |
| 4544 | kKindSpecificFlags1Offset + kIntSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4545 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 4546 | static const int kHeaderPaddingStart = kKindSpecificFlags2Offset + kIntSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4547 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4548 | // Add padding to align the instruction start following right after |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 4549 | // the Code object header. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4550 | static const int kHeaderSize = |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4551 | (kHeaderPaddingStart + kCodeAlignmentMask) & ~kCodeAlignmentMask; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4552 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 4553 | // Byte offsets within kKindSpecificFlags1Offset. |
| 4554 | static const int kOptimizableOffset = kKindSpecificFlags1Offset; |
| 4555 | static const int kCheckTypeOffset = kKindSpecificFlags1Offset; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4556 | |
| 4557 | static const int kFullCodeFlags = kOptimizableOffset + 1; |
| 4558 | class FullCodeFlagsHasDeoptimizationSupportField: |
| 4559 | public BitField<bool, 0, 1> {}; // NOLINT |
| 4560 | class FullCodeFlagsHasDebugBreakSlotsField: public BitField<bool, 1, 1> {}; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4561 | class FullCodeFlagsIsCompiledOptimizable: public BitField<bool, 2, 1> {}; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4562 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4563 | static const int kAllowOSRAtLoopNestingLevelOffset = kFullCodeFlags + 1; |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 4564 | static const int kProfilerTicksOffset = kAllowOSRAtLoopNestingLevelOffset + 1; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4565 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4566 | // Flags layout. BitField<type, shift, size>. |
| 4567 | class ICStateField: public BitField<InlineCacheState, 0, 3> {}; |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 4568 | class TypeField: public BitField<StubType, 3, 3> {}; |
| 4569 | class CacheHolderField: public BitField<InlineCacheHolderFlag, 6, 1> {}; |
| 4570 | class KindField: public BitField<Kind, 7, 4> {}; |
| 4571 | class ExtraICStateField: public BitField<ExtraICState, 11, 2> {}; |
| 4572 | class IsPregeneratedField: public BitField<bool, 13, 1> {}; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4573 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 4574 | // KindSpecificFlags1 layout (STUB and OPTIMIZED_FUNCTION) |
| 4575 | static const int kStackSlotsFirstBit = 0; |
| 4576 | static const int kStackSlotsBitCount = 24; |
| 4577 | static const int kUnaryOpTypeFirstBit = |
| 4578 | kStackSlotsFirstBit + kStackSlotsBitCount; |
| 4579 | static const int kUnaryOpTypeBitCount = 3; |
| 4580 | static const int kBinaryOpTypeFirstBit = |
| 4581 | kStackSlotsFirstBit + kStackSlotsBitCount; |
| 4582 | static const int kBinaryOpTypeBitCount = 3; |
| 4583 | static const int kBinaryOpResultTypeFirstBit = |
| 4584 | kBinaryOpTypeFirstBit + kBinaryOpTypeBitCount; |
| 4585 | static const int kBinaryOpResultTypeBitCount = 3; |
| 4586 | static const int kCompareStateFirstBit = |
| 4587 | kStackSlotsFirstBit + kStackSlotsBitCount; |
| 4588 | static const int kCompareStateBitCount = 3; |
| 4589 | static const int kCompareOperationFirstBit = |
| 4590 | kCompareStateFirstBit + kCompareStateBitCount; |
| 4591 | static const int kCompareOperationBitCount = 4; |
| 4592 | static const int kToBooleanStateFirstBit = |
| 4593 | kStackSlotsFirstBit + kStackSlotsBitCount; |
| 4594 | static const int kToBooleanStateBitCount = 8; |
| 4595 | static const int kHasFunctionCacheFirstBit = |
| 4596 | kStackSlotsFirstBit + kStackSlotsBitCount; |
| 4597 | static const int kHasFunctionCacheBitCount = 1; |
| 4598 | |
| 4599 | STATIC_ASSERT(kStackSlotsFirstBit + kStackSlotsBitCount <= 32); |
| 4600 | STATIC_ASSERT(kUnaryOpTypeFirstBit + kUnaryOpTypeBitCount <= 32); |
| 4601 | STATIC_ASSERT(kBinaryOpTypeFirstBit + kBinaryOpTypeBitCount <= 32); |
| 4602 | STATIC_ASSERT(kBinaryOpResultTypeFirstBit + |
| 4603 | kBinaryOpResultTypeBitCount <= 32); |
| 4604 | STATIC_ASSERT(kCompareStateFirstBit + kCompareStateBitCount <= 32); |
| 4605 | STATIC_ASSERT(kCompareOperationFirstBit + kCompareOperationBitCount <= 32); |
| 4606 | STATIC_ASSERT(kToBooleanStateFirstBit + kToBooleanStateBitCount <= 32); |
| 4607 | STATIC_ASSERT(kHasFunctionCacheFirstBit + kHasFunctionCacheBitCount <= 32); |
| 4608 | |
| 4609 | class StackSlotsField: public BitField<int, |
| 4610 | kStackSlotsFirstBit, kStackSlotsBitCount> {}; // NOLINT |
| 4611 | class UnaryOpTypeField: public BitField<int, |
| 4612 | kUnaryOpTypeFirstBit, kUnaryOpTypeBitCount> {}; // NOLINT |
| 4613 | class BinaryOpTypeField: public BitField<int, |
| 4614 | kBinaryOpTypeFirstBit, kBinaryOpTypeBitCount> {}; // NOLINT |
| 4615 | class BinaryOpResultTypeField: public BitField<int, |
| 4616 | kBinaryOpResultTypeFirstBit, kBinaryOpResultTypeBitCount> {}; // NOLINT |
| 4617 | class CompareStateField: public BitField<int, |
| 4618 | kCompareStateFirstBit, kCompareStateBitCount> {}; // NOLINT |
| 4619 | class CompareOperationField: public BitField<int, |
| 4620 | kCompareOperationFirstBit, kCompareOperationBitCount> {}; // NOLINT |
| 4621 | class ToBooleanStateField: public BitField<int, |
| 4622 | kToBooleanStateFirstBit, kToBooleanStateBitCount> {}; // NOLINT |
| 4623 | class HasFunctionCacheField: public BitField<bool, |
| 4624 | kHasFunctionCacheFirstBit, kHasFunctionCacheBitCount> {}; // NOLINT |
| 4625 | |
| 4626 | // KindSpecificFlags2 layout (STUB and OPTIMIZED_FUNCTION) |
| 4627 | static const int kStubMajorKeyFirstBit = 0; |
| 4628 | static const int kSafepointTableOffsetFirstBit = |
| 4629 | kStubMajorKeyFirstBit + kStubMajorKeyBits; |
| 4630 | static const int kSafepointTableOffsetBitCount = 26; |
| 4631 | |
| 4632 | STATIC_ASSERT(kStubMajorKeyFirstBit + kStubMajorKeyBits <= 32); |
| 4633 | STATIC_ASSERT(kSafepointTableOffsetFirstBit + |
| 4634 | kSafepointTableOffsetBitCount <= 32); |
| 4635 | |
| 4636 | class SafepointTableOffsetField: public BitField<int, |
| 4637 | kSafepointTableOffsetFirstBit, |
| 4638 | kSafepointTableOffsetBitCount> {}; // NOLINT |
| 4639 | class StubMajorKeyField: public BitField<int, |
| 4640 | kStubMajorKeyFirstBit, kStubMajorKeyBits> {}; // NOLINT |
| 4641 | |
| 4642 | // KindSpecificFlags2 layout (FUNCTION) |
| 4643 | class StackCheckTableOffsetField: public BitField<int, 0, 31> {}; |
| 4644 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4645 | // Signed field cannot be encoded using the BitField class. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 4646 | static const int kArgumentsCountShift = 14; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4647 | static const int kArgumentsCountMask = ~((1 << kArgumentsCountShift) - 1); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4648 | |
jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 4649 | // This constant should be encodable in an ARM instruction. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4650 | static const int kFlagsNotUsedInLookup = |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4651 | TypeField::kMask | CacheHolderField::kMask; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4652 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4653 | private: |
| 4654 | DISALLOW_IMPLICIT_CONSTRUCTORS(Code); |
| 4655 | }; |
| 4656 | |
| 4657 | |
| 4658 | // All heap objects have a Map that describes their structure. |
| 4659 | // A Map contains information about: |
| 4660 | // - Size information about the object |
| 4661 | // - How to iterate over an object (for garbage collection) |
| 4662 | class Map: public HeapObject { |
| 4663 | public: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4664 | // Instance size. |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 4665 | // Size in bytes or kVariableSizeSentinel if instances do not have |
| 4666 | // a fixed size. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4667 | inline int instance_size(); |
| 4668 | inline void set_instance_size(int value); |
| 4669 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4670 | // Count of properties allocated in the object. |
| 4671 | inline int inobject_properties(); |
| 4672 | inline void set_inobject_properties(int value); |
| 4673 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4674 | // Count of property fields pre-allocated in the object when first allocated. |
| 4675 | inline int pre_allocated_property_fields(); |
| 4676 | inline void set_pre_allocated_property_fields(int value); |
| 4677 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4678 | // Instance type. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4679 | inline InstanceType instance_type(); |
| 4680 | inline void set_instance_type(InstanceType value); |
| 4681 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4682 | // Tells how many unused property fields are available in the |
| 4683 | // instance (only used for JSObject in fast mode). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4684 | inline int unused_property_fields(); |
| 4685 | inline void set_unused_property_fields(int value); |
| 4686 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4687 | // Bit field. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4688 | inline byte bit_field(); |
| 4689 | inline void set_bit_field(byte value); |
| 4690 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 4691 | // Bit field 2. |
| 4692 | inline byte bit_field2(); |
| 4693 | inline void set_bit_field2(byte value); |
| 4694 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4695 | // Bit field 3. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4696 | inline int bit_field3(); |
| 4697 | inline void set_bit_field3(int value); |
| 4698 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4699 | // Tells whether the object in the prototype property will be used |
| 4700 | // for instances created from this function. If the prototype |
| 4701 | // property is set to a value that is not a JSObject, the prototype |
| 4702 | // property will not be used to create instances of the function. |
| 4703 | // See ECMA-262, 13.2.2. |
| 4704 | inline void set_non_instance_prototype(bool value); |
| 4705 | inline bool has_non_instance_prototype(); |
| 4706 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 4707 | // Tells whether function has special prototype property. If not, prototype |
| 4708 | // property will not be created when accessed (will return undefined), |
| 4709 | // and construction from this function will not be allowed. |
| 4710 | inline void set_function_with_prototype(bool value); |
| 4711 | inline bool function_with_prototype(); |
| 4712 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4713 | // Tells whether the instance with this map should be ignored by the |
| 4714 | // __proto__ accessor. |
| 4715 | inline void set_is_hidden_prototype() { |
| 4716 | set_bit_field(bit_field() | (1 << kIsHiddenPrototype)); |
| 4717 | } |
| 4718 | |
| 4719 | inline bool is_hidden_prototype() { |
| 4720 | return ((1 << kIsHiddenPrototype) & bit_field()) != 0; |
| 4721 | } |
| 4722 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 4723 | // Records and queries whether the instance has a named interceptor. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4724 | inline void set_has_named_interceptor() { |
| 4725 | set_bit_field(bit_field() | (1 << kHasNamedInterceptor)); |
| 4726 | } |
| 4727 | |
| 4728 | inline bool has_named_interceptor() { |
| 4729 | return ((1 << kHasNamedInterceptor) & bit_field()) != 0; |
| 4730 | } |
| 4731 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 4732 | // Records and queries whether the instance has an indexed interceptor. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4733 | inline void set_has_indexed_interceptor() { |
| 4734 | set_bit_field(bit_field() | (1 << kHasIndexedInterceptor)); |
| 4735 | } |
| 4736 | |
| 4737 | inline bool has_indexed_interceptor() { |
| 4738 | return ((1 << kHasIndexedInterceptor) & bit_field()) != 0; |
| 4739 | } |
| 4740 | |
| 4741 | // Tells whether the instance is undetectable. |
| 4742 | // An undetectable object is a special class of JSObject: 'typeof' operator |
| 4743 | // returns undefined, ToBoolean returns false. Otherwise it behaves like |
| 4744 | // a normal JS object. It is useful for implementing undetectable |
| 4745 | // document.all in Firefox & Safari. |
| 4746 | // See https://bugzilla.mozilla.org/show_bug.cgi?id=248549. |
| 4747 | inline void set_is_undetectable() { |
| 4748 | set_bit_field(bit_field() | (1 << kIsUndetectable)); |
| 4749 | } |
| 4750 | |
| 4751 | inline bool is_undetectable() { |
| 4752 | return ((1 << kIsUndetectable) & bit_field()) != 0; |
| 4753 | } |
| 4754 | |
| 4755 | // Tells whether the instance has a call-as-function handler. |
| 4756 | inline void set_has_instance_call_handler() { |
| 4757 | set_bit_field(bit_field() | (1 << kHasInstanceCallHandler)); |
| 4758 | } |
| 4759 | |
| 4760 | inline bool has_instance_call_handler() { |
| 4761 | return ((1 << kHasInstanceCallHandler) & bit_field()) != 0; |
| 4762 | } |
| 4763 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4764 | inline void set_is_extensible(bool value); |
| 4765 | inline bool is_extensible(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4766 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4767 | inline void set_elements_kind(ElementsKind elements_kind) { |
| 4768 | ASSERT(elements_kind < kElementsKindCount); |
| 4769 | ASSERT(kElementsKindCount <= (1 << kElementsKindBitCount)); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4770 | set_bit_field2((bit_field2() & ~kElementsKindMask) | |
| 4771 | (elements_kind << kElementsKindShift)); |
| 4772 | ASSERT(this->elements_kind() == elements_kind); |
| 4773 | } |
| 4774 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4775 | inline ElementsKind elements_kind() { |
| 4776 | return static_cast<ElementsKind>( |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4777 | (bit_field2() & kElementsKindMask) >> kElementsKindShift); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 4778 | } |
| 4779 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4780 | // Tells whether the instance has fast elements that are only Smis. |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4781 | inline bool has_fast_smi_elements() { |
| 4782 | return IsFastSmiElementsKind(elements_kind()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4783 | } |
| 4784 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4785 | // Tells whether the instance has fast elements. |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4786 | inline bool has_fast_object_elements() { |
| 4787 | return IsFastObjectElementsKind(elements_kind()); |
| 4788 | } |
| 4789 | |
| 4790 | inline bool has_fast_smi_or_object_elements() { |
| 4791 | return IsFastSmiOrObjectElementsKind(elements_kind()); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4792 | } |
| 4793 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4794 | inline bool has_fast_double_elements() { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4795 | return IsFastDoubleElementsKind(elements_kind()); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4796 | } |
| 4797 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4798 | inline bool has_non_strict_arguments_elements() { |
| 4799 | return elements_kind() == NON_STRICT_ARGUMENTS_ELEMENTS; |
| 4800 | } |
| 4801 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4802 | inline bool has_external_array_elements() { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4803 | return IsExternalArrayElementsKind(elements_kind()); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4804 | } |
| 4805 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4806 | inline bool has_dictionary_elements() { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4807 | return IsDictionaryElementsKind(elements_kind()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4808 | } |
| 4809 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4810 | inline bool has_slow_elements_kind() { |
| 4811 | return elements_kind() == DICTIONARY_ELEMENTS |
| 4812 | || elements_kind() == NON_STRICT_ARGUMENTS_ELEMENTS; |
| 4813 | } |
| 4814 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4815 | static bool IsValidElementsTransition(ElementsKind from_kind, |
| 4816 | ElementsKind to_kind); |
| 4817 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 4818 | inline bool HasTransitionArray(); |
| 4819 | inline bool HasElementsTransition(); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4820 | inline Map* elements_transition_map(); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 4821 | MUST_USE_RESULT inline MaybeObject* set_elements_transition_map( |
| 4822 | Map* transitioned_map); |
| 4823 | inline TransitionArray* transitions(); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame^] | 4824 | inline void SetTransition(int index, Map* target); |
| 4825 | MUST_USE_RESULT inline MaybeObject* AddTransition(String* key, Map* target); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 4826 | MUST_USE_RESULT inline MaybeObject* set_transitions( |
| 4827 | TransitionArray* transitions); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 4828 | inline void ClearTransitions(Heap* heap, |
| 4829 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4830 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4831 | // Tells whether the map is attached to SharedFunctionInfo |
| 4832 | // (for inobject slack tracking). |
| 4833 | inline void set_attached_to_shared_function_info(bool value); |
| 4834 | |
| 4835 | inline bool attached_to_shared_function_info(); |
| 4836 | |
| 4837 | // Tells whether the map is shared between objects that may have different |
| 4838 | // behavior. If true, the map should never be modified, instead a clone |
| 4839 | // should be created and modified. |
| 4840 | inline void set_is_shared(bool value); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4841 | inline bool is_shared(); |
| 4842 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4843 | // Tells whether the instance needs security checks when accessing its |
| 4844 | // properties. |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 4845 | inline void set_is_access_check_needed(bool access_check_needed); |
| 4846 | inline bool is_access_check_needed(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4847 | |
| 4848 | // [prototype]: implicit prototype object. |
| 4849 | DECL_ACCESSORS(prototype, Object) |
| 4850 | |
| 4851 | // [constructor]: points back to the function responsible for this map. |
| 4852 | DECL_ACCESSORS(constructor, Object) |
| 4853 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4854 | inline JSFunction* unchecked_constructor(); |
| 4855 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4856 | // [instance descriptors]: describes the object. |
| 4857 | DECL_ACCESSORS(instance_descriptors, DescriptorArray) |
| 4858 | |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 4859 | // Should only be called to clear a descriptor array that was only used to |
| 4860 | // store transitions and does not contain any live transitions anymore. |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 4861 | inline void ClearDescriptorArray(Heap* heap, WriteBarrierMode mode); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4862 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4863 | // [stub cache]: contains stubs compiled for this map. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4864 | DECL_ACCESSORS(code_cache, Object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4865 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 4866 | // [back pointer]: points back to the parent map from which a transition |
| 4867 | // leads to this map. The field overlaps with prototype transitions and the |
| 4868 | // back pointer will be moved into the prototype transitions array if |
| 4869 | // required. |
| 4870 | inline Object* GetBackPointer(); |
| 4871 | inline void SetBackPointer(Object* value, |
| 4872 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 4873 | inline void init_back_pointer(Object* undefined); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 4874 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 4875 | // [prototype transitions]: cache of prototype transitions. |
| 4876 | // Prototype transition is a transition that happens |
| 4877 | // when we change object's prototype to a new one. |
| 4878 | // Cache format: |
| 4879 | // 0: finger - index of the first free cell in the cache |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 4880 | // 1: back pointer that overlaps with prototype transitions field. |
| 4881 | // 2 + 2 * i: prototype |
| 4882 | // 3 + 2 * i: target map |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 4883 | inline FixedArray* GetPrototypeTransitions(); |
| 4884 | MUST_USE_RESULT inline MaybeObject* SetPrototypeTransitions( |
| 4885 | FixedArray* prototype_transitions); |
| 4886 | inline bool HasPrototypeTransitions(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4887 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 4888 | inline HeapObject* UncheckedPrototypeTransitions(); |
| 4889 | inline TransitionArray* unchecked_transition_array(); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 4890 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 4891 | static const int kProtoTransitionHeaderSize = 1; |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4892 | static const int kProtoTransitionNumberOfEntriesOffset = 0; |
| 4893 | static const int kProtoTransitionElementsPerEntry = 2; |
| 4894 | static const int kProtoTransitionPrototypeOffset = 0; |
| 4895 | static const int kProtoTransitionMapOffset = 1; |
| 4896 | |
| 4897 | inline int NumberOfProtoTransitions() { |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 4898 | FixedArray* cache = GetPrototypeTransitions(); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4899 | if (cache->length() == 0) return 0; |
| 4900 | return |
| 4901 | Smi::cast(cache->get(kProtoTransitionNumberOfEntriesOffset))->value(); |
| 4902 | } |
| 4903 | |
| 4904 | inline void SetNumberOfProtoTransitions(int value) { |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 4905 | FixedArray* cache = GetPrototypeTransitions(); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4906 | ASSERT(cache->length() != 0); |
| 4907 | cache->set_unchecked(kProtoTransitionNumberOfEntriesOffset, |
| 4908 | Smi::FromInt(value)); |
| 4909 | } |
| 4910 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4911 | // Lookup in the map's instance descriptors and fill out the result |
| 4912 | // with the given holder if the name is found. The holder may be |
| 4913 | // NULL when this function is used from the compiler. |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 4914 | void LookupDescriptor(JSObject* holder, |
| 4915 | String* name, |
| 4916 | LookupResult* result); |
| 4917 | |
| 4918 | void LookupTransition(JSObject* holder, |
| 4919 | String* name, |
| 4920 | LookupResult* result); |
| 4921 | |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 4922 | MUST_USE_RESULT MaybeObject* RawCopy(int instance_size); |
| 4923 | MUST_USE_RESULT MaybeObject* CopyWithPreallocatedFieldDescriptors(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4924 | MUST_USE_RESULT MaybeObject* CopyDropDescriptors(); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 4925 | MUST_USE_RESULT MaybeObject* CopyReplaceDescriptors( |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame^] | 4926 | DescriptorArray* descriptors, String* name, TransitionFlag flag); |
| 4927 | MUST_USE_RESULT MaybeObject* CopyAddDescriptor(Descriptor* descriptor, |
| 4928 | TransitionFlag flag); |
| 4929 | MUST_USE_RESULT MaybeObject* CopyInsertDescriptor(Descriptor* descriptor, |
| 4930 | TransitionFlag flag); |
| 4931 | MUST_USE_RESULT MaybeObject* CopyReplaceDescriptor(Descriptor* descriptor, |
| 4932 | int index, |
| 4933 | TransitionFlag flag); |
| 4934 | MUST_USE_RESULT MaybeObject* CopyAsElementsKind(ElementsKind kind, |
| 4935 | TransitionFlag flag); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4936 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4937 | MUST_USE_RESULT MaybeObject* CopyNormalized(PropertyNormalizationMode mode, |
| 4938 | NormalizedMapSharingMode sharing); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4939 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 4940 | // Returns a copy of the map, with all transitions dropped from the |
| 4941 | // instance descriptors. |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame^] | 4942 | MUST_USE_RESULT MaybeObject* Copy(DescriptorArray::SharedMode shared_mode); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 4943 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4944 | // Returns the property index for name (only valid for FAST MODE). |
| 4945 | int PropertyIndexFor(String* name); |
| 4946 | |
| 4947 | // Returns the next free property index (only valid for FAST MODE). |
| 4948 | int NextFreePropertyIndex(); |
| 4949 | |
jkummerow@chromium.org | ab7dad4 | 2012-02-07 12:07:34 +0000 | [diff] [blame] | 4950 | // Returns the number of properties described in instance_descriptors |
| 4951 | // filtering out properties with the specified attributes. |
| 4952 | int NumberOfDescribedProperties(PropertyAttributes filter = NONE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4953 | |
| 4954 | // Casting. |
| 4955 | static inline Map* cast(Object* obj); |
| 4956 | |
| 4957 | // Locate an accessor in the instance descriptor. |
| 4958 | AccessorDescriptor* FindAccessor(String* name); |
| 4959 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4960 | // Code cache operations. |
| 4961 | |
| 4962 | // Clears the code cache. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4963 | inline void ClearCodeCache(Heap* heap); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4964 | |
| 4965 | // Update code cache. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4966 | static void UpdateCodeCache(Handle<Map> map, |
| 4967 | Handle<String> name, |
| 4968 | Handle<Code> code); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4969 | MUST_USE_RESULT MaybeObject* UpdateCodeCache(String* name, Code* code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4970 | |
| 4971 | // Returns the found code or undefined if absent. |
| 4972 | Object* FindInCodeCache(String* name, Code::Flags flags); |
| 4973 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4974 | // Returns the non-negative index of the code object if it is in the |
| 4975 | // cache and -1 otherwise. |
sgjesse@chromium.org | 99a37fa | 2010-03-11 09:23:46 +0000 | [diff] [blame] | 4976 | int IndexInCodeCache(Object* name, Code* code); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4977 | |
| 4978 | // Removes a code object from the code cache at the given index. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4979 | void RemoveFromCodeCache(String* name, Code* code, int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4980 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 4981 | // Set all map transitions from this map to dead maps to null. Also clear |
| 4982 | // back pointers in transition targets so that we do not process this map |
| 4983 | // again while following back pointers. |
| 4984 | void ClearNonLiveTransitions(Heap* heap); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4985 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 4986 | // Computes a hash value for this map, to be used in HashTables and such. |
| 4987 | int Hash(); |
| 4988 | |
| 4989 | // Compares this map to another to see if they describe equivalent objects. |
| 4990 | // If |mode| is set to CLEAR_INOBJECT_PROPERTIES, |other| is treated as if |
| 4991 | // it had exactly zero inobject properties. |
| 4992 | // The "shared" flags of both this map and |other| are ignored. |
| 4993 | bool EquivalentToForNormalization(Map* other, PropertyNormalizationMode mode); |
| 4994 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 4995 | // Returns the map that this map transitions to if its elements_kind |
| 4996 | // is changed to |elements_kind|, or NULL if no such map is cached yet. |
| 4997 | // |safe_to_add_transitions| is set to false if adding transitions is not |
| 4998 | // allowed. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4999 | Map* LookupElementsTransitionMap(ElementsKind elements_kind); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 5000 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5001 | // Returns the transitioned map for this map with the most generic |
| 5002 | // elements_kind that's found in |candidates|, or null handle if no match is |
| 5003 | // found at all. |
| 5004 | Handle<Map> FindTransitionedMap(MapHandleList* candidates); |
| 5005 | Map* FindTransitionedMap(MapList* candidates); |
| 5006 | |
yangguo@chromium.org | 5f0b8ea | 2012-05-16 12:37:04 +0000 | [diff] [blame] | 5007 | // Zaps the contents of backing data structures in debug mode. Note that the |
| 5008 | // heap verifier (i.e. VerifyMarkingVisitor) relies on zapping of objects |
| 5009 | // holding weak references when incremental marking is used, because it also |
| 5010 | // iterates over objects that are otherwise unreachable. |
| 5011 | #ifdef DEBUG |
yangguo@chromium.org | 5f0b8ea | 2012-05-16 12:37:04 +0000 | [diff] [blame] | 5012 | void ZapPrototypeTransitions(); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 5013 | void ZapTransitions(); |
yangguo@chromium.org | 5f0b8ea | 2012-05-16 12:37:04 +0000 | [diff] [blame] | 5014 | #endif |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5015 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5016 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5017 | #ifdef OBJECT_PRINT |
| 5018 | inline void MapPrint() { |
| 5019 | MapPrint(stdout); |
| 5020 | } |
| 5021 | void MapPrint(FILE* out); |
| 5022 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5023 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5024 | void MapVerify(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 5025 | void SharedMapVerify(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5026 | #endif |
| 5027 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 5028 | inline int visitor_id(); |
| 5029 | inline void set_visitor_id(int visitor_id); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 5030 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 5031 | typedef void (*TraverseCallback)(Map* map, void* data); |
| 5032 | |
| 5033 | void TraverseTransitionTree(TraverseCallback callback, void* data); |
| 5034 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5035 | // When you set the prototype of an object using the __proto__ accessor you |
| 5036 | // need a new map for the object (the prototype is stored in the map). In |
| 5037 | // order not to multiply maps unnecessarily we store these as transitions in |
| 5038 | // the original map. That way we can transition to the same map if the same |
| 5039 | // prototype is set, rather than creating a new map every time. The |
| 5040 | // transitions are in the form of a map where the keys are prototype objects |
ulan@chromium.org | f6a0c41 | 2012-06-15 12:31:06 +0000 | [diff] [blame] | 5041 | // and the values are the maps the are transitioned to. |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 5042 | static const int kMaxCachedPrototypeTransitions = 256; |
| 5043 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5044 | Map* GetPrototypeTransition(Object* prototype); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 5045 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 5046 | MUST_USE_RESULT MaybeObject* PutPrototypeTransition(Object* prototype, |
| 5047 | Map* map); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 5048 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5049 | static const int kMaxPreAllocatedPropertyFields = 255; |
| 5050 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5051 | // Layout description. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5052 | static const int kInstanceSizesOffset = HeapObject::kHeaderSize; |
| 5053 | static const int kInstanceAttributesOffset = kInstanceSizesOffset + kIntSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5054 | static const int kPrototypeOffset = kInstanceAttributesOffset + kIntSize; |
| 5055 | static const int kConstructorOffset = kPrototypeOffset + kPointerSize; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 5056 | // Storage for instance descriptors is overloaded to also contain additional |
| 5057 | // map flags when unused (bit_field3). When the map has instance descriptors, |
| 5058 | // the flags are transferred to the instance descriptor array and accessed |
| 5059 | // through an extra indirection. |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 5060 | static const int kInstanceDescriptorsOrBackPointerOffset = |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5061 | kConstructorOffset + kPointerSize; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 5062 | static const int kCodeCacheOffset = |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 5063 | kInstanceDescriptorsOrBackPointerOffset + kPointerSize; |
| 5064 | static const int kBitField3Offset = kCodeCacheOffset + kPointerSize; |
| 5065 | static const int kPadStart = kBitField3Offset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5066 | static const int kSize = MAP_POINTER_ALIGN(kPadStart); |
| 5067 | |
| 5068 | // Layout of pointer fields. Heap iteration code relies on them |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5069 | // being continuously allocated. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5070 | static const int kPointerFieldsBeginOffset = Map::kPrototypeOffset; |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 5071 | static const int kPointerFieldsEndOffset = kBitField3Offset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5072 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5073 | // Byte offsets within kInstanceSizesOffset. |
| 5074 | static const int kInstanceSizeOffset = kInstanceSizesOffset + 0; |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 5075 | static const int kInObjectPropertiesByte = 1; |
| 5076 | static const int kInObjectPropertiesOffset = |
| 5077 | kInstanceSizesOffset + kInObjectPropertiesByte; |
| 5078 | static const int kPreAllocatedPropertyFieldsByte = 2; |
| 5079 | static const int kPreAllocatedPropertyFieldsOffset = |
| 5080 | kInstanceSizesOffset + kPreAllocatedPropertyFieldsByte; |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 5081 | static const int kVisitorIdByte = 3; |
| 5082 | static const int kVisitorIdOffset = kInstanceSizesOffset + kVisitorIdByte; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5083 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5084 | // Byte offsets within kInstanceAttributesOffset attributes. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5085 | static const int kInstanceTypeOffset = kInstanceAttributesOffset + 0; |
| 5086 | static const int kUnusedPropertyFieldsOffset = kInstanceAttributesOffset + 1; |
| 5087 | static const int kBitFieldOffset = kInstanceAttributesOffset + 2; |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 5088 | static const int kBitField2Offset = kInstanceAttributesOffset + 3; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5089 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5090 | STATIC_CHECK(kInstanceTypeOffset == Internals::kMapInstanceTypeOffset); |
| 5091 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5092 | // Bit positions for bit field. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5093 | 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] | 5094 | static const int kHasNonInstancePrototype = 1; |
| 5095 | static const int kIsHiddenPrototype = 2; |
| 5096 | static const int kHasNamedInterceptor = 3; |
| 5097 | static const int kHasIndexedInterceptor = 4; |
| 5098 | static const int kIsUndetectable = 5; |
| 5099 | static const int kHasInstanceCallHandler = 6; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5100 | static const int kIsAccessCheckNeeded = 7; |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 5101 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 5102 | // Bit positions for bit field 2 |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 5103 | static const int kIsExtensible = 0; |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 5104 | static const int kStringWrapperSafeForDefaultValueOf = 1; |
| 5105 | static const int kAttachedToSharedFunctionInfo = 2; |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 5106 | // No bits can be used after kElementsKindFirstBit, they are all reserved for |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5107 | // storing ElementKind. |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 5108 | static const int kElementsKindShift = 3; |
| 5109 | static const int kElementsKindBitCount = 5; |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 5110 | |
| 5111 | // Derived values from bit field 2 |
| 5112 | static const int kElementsKindMask = (-1 << kElementsKindShift) & |
| 5113 | ((1 << (kElementsKindShift + kElementsKindBitCount)) - 1); |
| 5114 | static const int8_t kMaximumBitField2FastElementValue = static_cast<int8_t>( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5115 | (FAST_ELEMENTS + 1) << Map::kElementsKindShift) - 1; |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 5116 | static const int8_t kMaximumBitField2FastSmiElementValue = |
| 5117 | static_cast<int8_t>((FAST_SMI_ELEMENTS + 1) << |
| 5118 | Map::kElementsKindShift) - 1; |
| 5119 | static const int8_t kMaximumBitField2FastHoleyElementValue = |
| 5120 | static_cast<int8_t>((FAST_HOLEY_ELEMENTS + 1) << |
| 5121 | Map::kElementsKindShift) - 1; |
| 5122 | static const int8_t kMaximumBitField2FastHoleySmiElementValue = |
| 5123 | static_cast<int8_t>((FAST_HOLEY_SMI_ELEMENTS + 1) << |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5124 | Map::kElementsKindShift) - 1; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 5125 | |
| 5126 | // Bit positions for bit field 3 |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 5127 | static const int kIsShared = 0; |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 5128 | static const int kFunctionWithPrototype = 1; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5129 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 5130 | typedef FixedBodyDescriptor<kPointerFieldsBeginOffset, |
| 5131 | kPointerFieldsEndOffset, |
| 5132 | kSize> BodyDescriptor; |
| 5133 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5134 | private: |
| 5135 | DISALLOW_IMPLICIT_CONSTRUCTORS(Map); |
| 5136 | }; |
| 5137 | |
| 5138 | |
| 5139 | // An abstract superclass, a marker class really, for simple structure classes. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5140 | // It doesn't carry much functionality but allows struct classes to be |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5141 | // identified in the type system. |
| 5142 | class Struct: public HeapObject { |
| 5143 | public: |
| 5144 | inline void InitializeBody(int object_size); |
| 5145 | static inline Struct* cast(Object* that); |
| 5146 | }; |
| 5147 | |
| 5148 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5149 | // Script describes a script which has been added to the VM. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5150 | class Script: public Struct { |
| 5151 | public: |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 5152 | // Script types. |
| 5153 | enum Type { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 5154 | TYPE_NATIVE = 0, |
| 5155 | TYPE_EXTENSION = 1, |
| 5156 | TYPE_NORMAL = 2 |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 5157 | }; |
| 5158 | |
| 5159 | // Script compilation types. |
| 5160 | enum CompilationType { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 5161 | COMPILATION_TYPE_HOST = 0, |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 5162 | COMPILATION_TYPE_EVAL = 1 |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 5163 | }; |
| 5164 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 5165 | // Script compilation state. |
| 5166 | enum CompilationState { |
| 5167 | COMPILATION_STATE_INITIAL = 0, |
| 5168 | COMPILATION_STATE_COMPILED = 1 |
| 5169 | }; |
| 5170 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5171 | // [source]: the script source. |
| 5172 | DECL_ACCESSORS(source, Object) |
| 5173 | |
| 5174 | // [name]: the script name. |
| 5175 | DECL_ACCESSORS(name, Object) |
| 5176 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5177 | // [id]: the script id. |
| 5178 | DECL_ACCESSORS(id, Object) |
| 5179 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5180 | // [line_offset]: script line offset in resource from where it was extracted. |
| 5181 | DECL_ACCESSORS(line_offset, Smi) |
| 5182 | |
| 5183 | // [column_offset]: script column offset in resource from where it was |
| 5184 | // extracted. |
| 5185 | DECL_ACCESSORS(column_offset, Smi) |
| 5186 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5187 | // [data]: additional data associated with this script. |
| 5188 | DECL_ACCESSORS(data, Object) |
| 5189 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 5190 | // [context_data]: context data for the context this script was compiled in. |
| 5191 | DECL_ACCESSORS(context_data, Object) |
| 5192 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5193 | // [wrapper]: the wrapper cache. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5194 | DECL_ACCESSORS(wrapper, Foreign) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5195 | |
| 5196 | // [type]: the script type. |
| 5197 | DECL_ACCESSORS(type, Smi) |
| 5198 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 5199 | // [compilation]: how the the script was compiled. |
| 5200 | DECL_ACCESSORS(compilation_type, Smi) |
| 5201 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 5202 | // [is_compiled]: determines whether the script has already been compiled. |
| 5203 | DECL_ACCESSORS(compilation_state, Smi) |
| 5204 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 5205 | // [line_ends]: FixedArray of line ends positions. |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 5206 | DECL_ACCESSORS(line_ends, Object) |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 5207 | |
sgjesse@chromium.org | 9818059 | 2009-12-02 08:17:28 +0000 | [diff] [blame] | 5208 | // [eval_from_shared]: for eval scripts the shared funcion info for the |
| 5209 | // function from which eval was called. |
| 5210 | DECL_ACCESSORS(eval_from_shared, Object) |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 5211 | |
| 5212 | // [eval_from_instructions_offset]: the instruction offset in the code for the |
| 5213 | // function from which eval was called where eval was called. |
| 5214 | DECL_ACCESSORS(eval_from_instructions_offset, Smi) |
| 5215 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5216 | static inline Script* cast(Object* obj); |
| 5217 | |
sgjesse@chromium.org | 152a0b0 | 2009-10-07 13:50:16 +0000 | [diff] [blame] | 5218 | // If script source is an external string, check that the underlying |
| 5219 | // resource is accessible. Otherwise, always return true. |
| 5220 | inline bool HasValidSource(); |
| 5221 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5222 | #ifdef OBJECT_PRINT |
| 5223 | inline void ScriptPrint() { |
| 5224 | ScriptPrint(stdout); |
| 5225 | } |
| 5226 | void ScriptPrint(FILE* out); |
| 5227 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5228 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5229 | void ScriptVerify(); |
| 5230 | #endif |
| 5231 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5232 | static const int kSourceOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5233 | static const int kNameOffset = kSourceOffset + kPointerSize; |
| 5234 | static const int kLineOffsetOffset = kNameOffset + kPointerSize; |
| 5235 | static const int kColumnOffsetOffset = kLineOffsetOffset + kPointerSize; |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5236 | static const int kDataOffset = kColumnOffsetOffset + kPointerSize; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 5237 | static const int kContextOffset = kDataOffset + kPointerSize; |
| 5238 | static const int kWrapperOffset = kContextOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5239 | static const int kTypeOffset = kWrapperOffset + kPointerSize; |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 5240 | static const int kCompilationTypeOffset = kTypeOffset + kPointerSize; |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 5241 | static const int kCompilationStateOffset = |
| 5242 | kCompilationTypeOffset + kPointerSize; |
| 5243 | static const int kLineEndsOffset = kCompilationStateOffset + kPointerSize; |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 5244 | static const int kIdOffset = kLineEndsOffset + kPointerSize; |
sgjesse@chromium.org | 9818059 | 2009-12-02 08:17:28 +0000 | [diff] [blame] | 5245 | static const int kEvalFromSharedOffset = kIdOffset + kPointerSize; |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 5246 | static const int kEvalFrominstructionsOffsetOffset = |
sgjesse@chromium.org | 9818059 | 2009-12-02 08:17:28 +0000 | [diff] [blame] | 5247 | kEvalFromSharedOffset + kPointerSize; |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 5248 | static const int kSize = kEvalFrominstructionsOffsetOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5249 | |
| 5250 | private: |
| 5251 | DISALLOW_IMPLICIT_CONSTRUCTORS(Script); |
| 5252 | }; |
| 5253 | |
| 5254 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5255 | // List of builtin functions we want to identify to improve code |
| 5256 | // generation. |
| 5257 | // |
| 5258 | // Each entry has a name of a global object property holding an object |
| 5259 | // optionally followed by ".prototype", a name of a builtin function |
| 5260 | // on the object (the one the id is set for), and a label. |
| 5261 | // |
| 5262 | // Installation of ids for the selected builtin functions is handled |
| 5263 | // by the bootstrapper. |
| 5264 | // |
| 5265 | // NOTE: Order is important: math functions should be at the end of |
| 5266 | // the list and MathFloor should be the first math function. |
| 5267 | #define FUNCTIONS_WITH_ID_LIST(V) \ |
| 5268 | V(Array.prototype, push, ArrayPush) \ |
| 5269 | V(Array.prototype, pop, ArrayPop) \ |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 5270 | V(Function.prototype, apply, FunctionApply) \ |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5271 | V(String.prototype, charCodeAt, StringCharCodeAt) \ |
| 5272 | V(String.prototype, charAt, StringCharAt) \ |
| 5273 | V(String, fromCharCode, StringFromCharCode) \ |
| 5274 | V(Math, floor, MathFloor) \ |
| 5275 | V(Math, round, MathRound) \ |
| 5276 | V(Math, ceil, MathCeil) \ |
| 5277 | V(Math, abs, MathAbs) \ |
| 5278 | V(Math, log, MathLog) \ |
| 5279 | V(Math, sin, MathSin) \ |
| 5280 | V(Math, cos, MathCos) \ |
| 5281 | V(Math, tan, MathTan) \ |
| 5282 | V(Math, asin, MathASin) \ |
| 5283 | V(Math, acos, MathACos) \ |
| 5284 | V(Math, atan, MathATan) \ |
| 5285 | V(Math, exp, MathExp) \ |
| 5286 | V(Math, sqrt, MathSqrt) \ |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5287 | V(Math, pow, MathPow) \ |
| 5288 | V(Math, random, MathRandom) \ |
| 5289 | V(Math, max, MathMax) \ |
| 5290 | V(Math, min, MathMin) |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5291 | |
| 5292 | |
| 5293 | enum BuiltinFunctionId { |
| 5294 | #define DECLARE_FUNCTION_ID(ignored1, ignore2, name) \ |
| 5295 | k##name, |
| 5296 | FUNCTIONS_WITH_ID_LIST(DECLARE_FUNCTION_ID) |
| 5297 | #undef DECLARE_FUNCTION_ID |
| 5298 | // Fake id for a special case of Math.pow. Note, it continues the |
| 5299 | // list of math functions. |
| 5300 | kMathPowHalf, |
| 5301 | kFirstMathFunctionId = kMathFloor |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5302 | }; |
| 5303 | |
| 5304 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5305 | // SharedFunctionInfo describes the JSFunction information that can be |
| 5306 | // shared by multiple instances of the function. |
| 5307 | class SharedFunctionInfo: public HeapObject { |
| 5308 | public: |
| 5309 | // [name]: Function name. |
| 5310 | DECL_ACCESSORS(name, Object) |
| 5311 | |
| 5312 | // [code]: Function code. |
| 5313 | DECL_ACCESSORS(code, Code) |
| 5314 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 5315 | // [optimized_code_map]: Map from global context to optimized code |
| 5316 | // and a shared literals array or Smi 0 if none. |
| 5317 | DECL_ACCESSORS(optimized_code_map, Object) |
| 5318 | |
| 5319 | // Returns index i of the entry with the specified context. At position |
| 5320 | // i - 1 is the context, position i the code, and i + 1 the literals array. |
| 5321 | // Returns -1 when no matching entry is found. |
| 5322 | int SearchOptimizedCodeMap(Context* global_context); |
| 5323 | |
ulan@chromium.org | d9e468a | 2012-06-25 09:47:40 +0000 | [diff] [blame] | 5324 | // Installs optimized code from the code map on the given closure. The |
| 5325 | // index has to be consistent with a search result as defined above. |
| 5326 | void InstallFromOptimizedCodeMap(JSFunction* function, int index); |
| 5327 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 5328 | // Clear optimized code map. |
| 5329 | void ClearOptimizedCodeMap(); |
| 5330 | |
| 5331 | // Add a new entry to the optimized code map. |
| 5332 | static void AddToOptimizedCodeMap(Handle<SharedFunctionInfo> shared, |
| 5333 | Handle<Context> global_context, |
| 5334 | Handle<Code> code, |
| 5335 | Handle<FixedArray> literals); |
| 5336 | static const int kEntryLength = 3; |
| 5337 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 5338 | // [scope_info]: Scope info. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5339 | DECL_ACCESSORS(scope_info, ScopeInfo) |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 5340 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 5341 | // [construct stub]: Code stub for constructing instances of this function. |
| 5342 | DECL_ACCESSORS(construct_stub, Code) |
| 5343 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 5344 | inline Code* unchecked_code(); |
| 5345 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5346 | // Returns if this function has been compiled to native code yet. |
| 5347 | inline bool is_compiled(); |
| 5348 | |
| 5349 | // [length]: The function length - usually the number of declared parameters. |
| 5350 | // Use up to 2^30 parameters. |
| 5351 | inline int length(); |
| 5352 | inline void set_length(int value); |
| 5353 | |
| 5354 | // [formal parameter count]: The declared number of parameters. |
| 5355 | inline int formal_parameter_count(); |
| 5356 | inline void set_formal_parameter_count(int value); |
| 5357 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 5358 | // Set the formal parameter count so the function code will be |
| 5359 | // called without using argument adaptor frames. |
| 5360 | inline void DontAdaptArguments(); |
| 5361 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5362 | // [expected_nof_properties]: Expected number of properties for the function. |
| 5363 | inline int expected_nof_properties(); |
| 5364 | inline void set_expected_nof_properties(int value); |
| 5365 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 5366 | // Inobject slack tracking is the way to reclaim unused inobject space. |
| 5367 | // |
| 5368 | // The instance size is initially determined by adding some slack to |
| 5369 | // expected_nof_properties (to allow for a few extra properties added |
| 5370 | // after the constructor). There is no guarantee that the extra space |
| 5371 | // will not be wasted. |
| 5372 | // |
| 5373 | // Here is the algorithm to reclaim the unused inobject space: |
| 5374 | // - Detect the first constructor call for this SharedFunctionInfo. |
| 5375 | // When it happens enter the "in progress" state: remember the |
| 5376 | // constructor's initial_map and install a special construct stub that |
| 5377 | // counts constructor calls. |
| 5378 | // - While the tracking is in progress create objects filled with |
| 5379 | // one_pointer_filler_map instead of undefined_value. This way they can be |
| 5380 | // resized quickly and safely. |
| 5381 | // - Once enough (kGenerousAllocationCount) objects have been created |
| 5382 | // compute the 'slack' (traverse the map transition tree starting from the |
| 5383 | // initial_map and find the lowest value of unused_property_fields). |
| 5384 | // - Traverse the transition tree again and decrease the instance size |
| 5385 | // of every map. Existing objects will resize automatically (they are |
| 5386 | // filled with one_pointer_filler_map). All further allocations will |
| 5387 | // use the adjusted instance size. |
| 5388 | // - Decrease expected_nof_properties so that an allocations made from |
| 5389 | // another context will use the adjusted instance size too. |
| 5390 | // - Exit "in progress" state by clearing the reference to the initial_map |
| 5391 | // and setting the regular construct stub (generic or inline). |
| 5392 | // |
| 5393 | // The above is the main event sequence. Some special cases are possible |
| 5394 | // while the tracking is in progress: |
| 5395 | // |
| 5396 | // - GC occurs. |
| 5397 | // Check if the initial_map is referenced by any live objects (except this |
| 5398 | // SharedFunctionInfo). If it is, continue tracking as usual. |
| 5399 | // If it is not, clear the reference and reset the tracking state. The |
| 5400 | // tracking will be initiated again on the next constructor call. |
| 5401 | // |
| 5402 | // - The constructor is called from another context. |
| 5403 | // Immediately complete the tracking, perform all the necessary changes |
| 5404 | // to maps. This is necessary because there is no efficient way to track |
| 5405 | // multiple initial_maps. |
| 5406 | // Proceed to create an object in the current context (with the adjusted |
| 5407 | // size). |
| 5408 | // |
| 5409 | // - A different constructor function sharing the same SharedFunctionInfo is |
| 5410 | // called in the same context. This could be another closure in the same |
| 5411 | // context, or the first function could have been disposed. |
| 5412 | // This is handled the same way as the previous case. |
| 5413 | // |
| 5414 | // Important: inobject slack tracking is not attempted during the snapshot |
| 5415 | // creation. |
| 5416 | |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 5417 | static const int kGenerousAllocationCount = 8; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 5418 | |
| 5419 | // [construction_count]: Counter for constructor calls made during |
| 5420 | // the tracking phase. |
| 5421 | inline int construction_count(); |
| 5422 | inline void set_construction_count(int value); |
| 5423 | |
| 5424 | // [initial_map]: initial map of the first function called as a constructor. |
| 5425 | // Saved for the duration of the tracking phase. |
| 5426 | // This is a weak link (GC resets it to undefined_value if no other live |
| 5427 | // object reference this map). |
| 5428 | DECL_ACCESSORS(initial_map, Object) |
| 5429 | |
| 5430 | // True if the initial_map is not undefined and the countdown stub is |
| 5431 | // installed. |
| 5432 | inline bool IsInobjectSlackTrackingInProgress(); |
| 5433 | |
| 5434 | // Starts the tracking. |
| 5435 | // Stores the initial map and installs the countdown stub. |
| 5436 | // IsInobjectSlackTrackingInProgress is normally true after this call, |
| 5437 | // except when tracking have not been started (e.g. the map has no unused |
| 5438 | // properties or the snapshot is being built). |
| 5439 | void StartInobjectSlackTracking(Map* map); |
| 5440 | |
| 5441 | // Completes the tracking. |
| 5442 | // IsInobjectSlackTrackingInProgress is false after this call. |
| 5443 | void CompleteInobjectSlackTracking(); |
| 5444 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 5445 | // Invoked before pointers in SharedFunctionInfo are being marked. |
| 5446 | // Also clears the optimized code map. |
| 5447 | inline void BeforeVisitingPointers(); |
| 5448 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 5449 | // Clears the initial_map before the GC marking phase to ensure the reference |
| 5450 | // is weak. IsInobjectSlackTrackingInProgress is false after this call. |
| 5451 | void DetachInitialMap(); |
| 5452 | |
| 5453 | // Restores the link to the initial map after the GC marking phase. |
| 5454 | // IsInobjectSlackTrackingInProgress is true after this call. |
| 5455 | void AttachInitialMap(Map* map); |
| 5456 | |
| 5457 | // False if there are definitely no live objects created from this function. |
| 5458 | // True if live objects _may_ exist (existence not guaranteed). |
| 5459 | // May go back from true to false after GC. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5460 | DECL_BOOLEAN_ACCESSORS(live_objects_may_exist) |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 5461 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5462 | // [instance class name]: class name for instances. |
| 5463 | DECL_ACCESSORS(instance_class_name, Object) |
| 5464 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 5465 | // [function data]: This field holds some additional data for function. |
| 5466 | // Currently it either has FunctionTemplateInfo to make benefit the API |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5467 | // or Smi identifying a builtin function. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5468 | // In the long run we don't want all functions to have this field but |
| 5469 | // we can fix that when we have a better model for storing hidden data |
| 5470 | // on objects. |
| 5471 | DECL_ACCESSORS(function_data, Object) |
| 5472 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 5473 | inline bool IsApiFunction(); |
| 5474 | inline FunctionTemplateInfo* get_api_func_data(); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5475 | inline bool HasBuiltinFunctionId(); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5476 | inline BuiltinFunctionId builtin_function_id(); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 5477 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5478 | // [script info]: Script from which the function originates. |
| 5479 | DECL_ACCESSORS(script, Object) |
| 5480 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 5481 | // [num_literals]: Number of literals used by this function. |
| 5482 | inline int num_literals(); |
| 5483 | inline void set_num_literals(int value); |
| 5484 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5485 | // [start_position_and_type]: Field used to store both the source code |
| 5486 | // position, whether or not the function is a function expression, |
| 5487 | // and whether or not the function is a toplevel function. The two |
| 5488 | // least significants bit indicates whether the function is an |
| 5489 | // expression and the rest contains the source code position. |
| 5490 | inline int start_position_and_type(); |
| 5491 | inline void set_start_position_and_type(int value); |
| 5492 | |
| 5493 | // [debug info]: Debug information. |
| 5494 | DECL_ACCESSORS(debug_info, Object) |
| 5495 | |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 5496 | // [inferred name]: Name inferred from variable or property |
| 5497 | // assignment of this function. Used to facilitate debugging and |
| 5498 | // profiling of JavaScript code written in OO style, where almost |
| 5499 | // all functions are anonymous but are assigned to object |
| 5500 | // properties. |
| 5501 | DECL_ACCESSORS(inferred_name, String) |
| 5502 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 5503 | // The function's name if it is non-empty, otherwise the inferred name. |
| 5504 | String* DebugName(); |
| 5505 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5506 | // Position of the 'function' token in the script source. |
| 5507 | inline int function_token_position(); |
| 5508 | inline void set_function_token_position(int function_token_position); |
| 5509 | |
| 5510 | // Position of this function in the script source. |
| 5511 | inline int start_position(); |
| 5512 | inline void set_start_position(int start_position); |
| 5513 | |
| 5514 | // End position of this function in the script source. |
| 5515 | inline int end_position(); |
| 5516 | inline void set_end_position(int end_position); |
| 5517 | |
| 5518 | // Is this function a function expression in the source code. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 5519 | DECL_BOOLEAN_ACCESSORS(is_expression) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5520 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 5521 | // Is this function a top-level function (scripts, evals). |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 5522 | DECL_BOOLEAN_ACCESSORS(is_toplevel) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5523 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5524 | // Bit field containing various information collected by the compiler to |
| 5525 | // drive optimization. |
| 5526 | inline int compiler_hints(); |
| 5527 | inline void set_compiler_hints(int value); |
| 5528 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5529 | inline int ast_node_count(); |
| 5530 | inline void set_ast_node_count(int count); |
| 5531 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5532 | // A counter used to determine when to stress the deoptimizer with a |
| 5533 | // deopt. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5534 | inline int stress_deopt_counter(); |
| 5535 | inline void set_stress_deopt_counter(int counter); |
svenpanne@chromium.org | b1df11d | 2012-02-08 10:26:21 +0000 | [diff] [blame] | 5536 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 5537 | inline int profiler_ticks(); |
| 5538 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5539 | // Inline cache age is used to infer whether the function survived a context |
| 5540 | // disposal or not. In the former case we reset the opt_count. |
| 5541 | inline int ic_age(); |
| 5542 | inline void set_ic_age(int age); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5543 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5544 | // Add information on assignments of the form this.x = ...; |
| 5545 | void SetThisPropertyAssignmentsInfo( |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5546 | bool has_only_simple_this_property_assignments, |
| 5547 | FixedArray* this_property_assignments); |
| 5548 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5549 | // Clear information on assignments of the form this.x = ...; |
| 5550 | void ClearThisPropertyAssignmentsInfo(); |
| 5551 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5552 | // Indicate that this function only consists of assignments of the form |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5553 | // this.x = y; where y is either a constant or refers to an argument. |
| 5554 | inline bool has_only_simple_this_property_assignments(); |
| 5555 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 5556 | // Indicates if this function can be lazy compiled. |
| 5557 | // This is used to determine if we can safely flush code from a function |
| 5558 | // when doing GC if we expect that the function will no longer be used. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5559 | DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation) |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 5560 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 5561 | // Indicates if this function can be lazy compiled without a context. |
| 5562 | // This is used to determine if we can force compilation without reaching |
| 5563 | // the function through program execution but through other means (e.g. heap |
| 5564 | // iteration by the debugger). |
| 5565 | DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation_without_context) |
| 5566 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 5567 | // Indicates how many full GCs this function has survived with assigned |
| 5568 | // code object. Used to determine when it is relatively safe to flush |
| 5569 | // this code object and replace it with lazy compilation stub. |
| 5570 | // Age is reset when GC notices that the code object is referenced |
| 5571 | // from the stack or compilation cache. |
| 5572 | inline int code_age(); |
| 5573 | inline void set_code_age(int age); |
| 5574 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5575 | // Indicates whether optimizations have been disabled for this |
| 5576 | // shared function info. If a function is repeatedly optimized or if |
| 5577 | // we cannot optimize the function we disable optimization to avoid |
| 5578 | // spending time attempting to optimize it again. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5579 | DECL_BOOLEAN_ACCESSORS(optimization_disabled) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5580 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5581 | // Indicates the language mode of the function's code as defined by the |
| 5582 | // current harmony drafts for the next ES language standard. Possible |
| 5583 | // values are: |
| 5584 | // 1. CLASSIC_MODE - Unrestricted syntax and semantics, same as in ES5. |
| 5585 | // 2. STRICT_MODE - Restricted syntax and semantics, same as in ES5. |
| 5586 | // 3. EXTENDED_MODE - Only available under the harmony flag, not part of ES5. |
| 5587 | inline LanguageMode language_mode(); |
| 5588 | inline void set_language_mode(LanguageMode language_mode); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5589 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5590 | // Indicates whether the language mode of this function is CLASSIC_MODE. |
| 5591 | inline bool is_classic_mode(); |
| 5592 | |
| 5593 | // Indicates whether the language mode of this function is EXTENDED_MODE. |
| 5594 | inline bool is_extended_mode(); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5595 | |
| 5596 | // False if the function definitely does not allocate an arguments object. |
| 5597 | DECL_BOOLEAN_ACCESSORS(uses_arguments) |
| 5598 | |
| 5599 | // True if the function has any duplicated parameter names. |
| 5600 | DECL_BOOLEAN_ACCESSORS(has_duplicate_parameters) |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 5601 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 5602 | // Indicates whether the function is a native function. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 5603 | // These needs special treatment in .call and .apply since |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 5604 | // null passed as the receiver should not be translated to the |
| 5605 | // global object. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 5606 | DECL_BOOLEAN_ACCESSORS(native) |
| 5607 | |
| 5608 | // Indicates that the function was created by the Function function. |
| 5609 | // Though it's anonymous, toString should treat it as if it had the name |
| 5610 | // "anonymous". We don't set the name itself so that the system does not |
| 5611 | // see a binding for it. |
| 5612 | DECL_BOOLEAN_ACCESSORS(name_should_print_as_anonymous) |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 5613 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5614 | // Indicates whether the function is a bound function created using |
| 5615 | // the bind function. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 5616 | DECL_BOOLEAN_ACCESSORS(bound) |
| 5617 | |
| 5618 | // Indicates that the function is anonymous (the name field can be set |
| 5619 | // through the API, which does not change this flag). |
| 5620 | DECL_BOOLEAN_ACCESSORS(is_anonymous) |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5621 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 5622 | // Is this a function or top-level/eval code. |
| 5623 | DECL_BOOLEAN_ACCESSORS(is_function) |
| 5624 | |
| 5625 | // Indicates that the function cannot be optimized. |
| 5626 | DECL_BOOLEAN_ACCESSORS(dont_optimize) |
svenpanne@chromium.org | b1df11d | 2012-02-08 10:26:21 +0000 | [diff] [blame] | 5627 | |
| 5628 | // Indicates that the function cannot be inlined. |
| 5629 | DECL_BOOLEAN_ACCESSORS(dont_inline) |
| 5630 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 5631 | // Indicates that code for this function cannot be cached. |
| 5632 | DECL_BOOLEAN_ACCESSORS(dont_cache) |
| 5633 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5634 | // Indicates whether or not the code in the shared function support |
| 5635 | // deoptimization. |
| 5636 | inline bool has_deoptimization_support(); |
| 5637 | |
| 5638 | // Enable deoptimization support through recompiled code. |
| 5639 | void EnableDeoptimizationSupport(Code* recompiled); |
| 5640 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5641 | // Disable (further) attempted optimization of all functions sharing this |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 5642 | // shared function info. |
| 5643 | void DisableOptimization(); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5644 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5645 | // Lookup the bailout ID and ASSERT that it exists in the non-optimized |
| 5646 | // code, returns whether it asserted (i.e., always true if assertions are |
| 5647 | // disabled). |
| 5648 | bool VerifyBailoutId(int id); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 5649 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5650 | // Check whether a inlined constructor can be generated with the given |
| 5651 | // prototype. |
| 5652 | bool CanGenerateInlineConstructor(Object* prototype); |
| 5653 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 5654 | // Prevents further attempts to generate inline constructors. |
| 5655 | // To be called if generation failed for any reason. |
| 5656 | void ForbidInlineConstructor(); |
| 5657 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5658 | // For functions which only contains this property assignments this provides |
| 5659 | // access to the names for the properties assigned. |
| 5660 | DECL_ACCESSORS(this_property_assignments, Object) |
| 5661 | inline int this_property_assignments_count(); |
| 5662 | inline void set_this_property_assignments_count(int value); |
| 5663 | String* GetThisPropertyAssignmentName(int index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5664 | bool IsThisPropertyAssignmentArgument(int index); |
| 5665 | int GetThisPropertyAssignmentArgument(int index); |
| 5666 | Object* GetThisPropertyAssignmentConstant(int index); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5667 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5668 | // [source code]: Source code for the function. |
| 5669 | bool HasSourceCode(); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 5670 | Handle<Object> GetSourceCode(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5671 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5672 | // Number of times the function was optimized. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5673 | inline int opt_count(); |
| 5674 | inline void set_opt_count(int opt_count); |
| 5675 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5676 | // Number of times the function was deoptimized. |
| 5677 | inline void set_deopt_count(int value); |
| 5678 | inline int deopt_count(); |
| 5679 | inline void increment_deopt_count(); |
| 5680 | |
| 5681 | // Number of time we tried to re-enable optimization after it |
| 5682 | // was disabled due to high number of deoptimizations. |
| 5683 | inline void set_opt_reenable_tries(int value); |
| 5684 | inline int opt_reenable_tries(); |
| 5685 | |
| 5686 | inline void TryReenableOptimization(); |
| 5687 | |
| 5688 | // Stores deopt_count, opt_reenable_tries and ic_age as bit-fields. |
| 5689 | inline void set_counters(int value); |
| 5690 | inline int counters(); |
| 5691 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5692 | // Source size of this function. |
| 5693 | int SourceSize(); |
| 5694 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5695 | // Calculate the instance size. |
| 5696 | int CalculateInstanceSize(); |
| 5697 | |
| 5698 | // Calculate the number of in-object properties. |
| 5699 | int CalculateInObjectProperties(); |
| 5700 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5701 | // Dispatched behavior. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5702 | // Set max_length to -1 for unlimited length. |
| 5703 | void SourceCodePrint(StringStream* accumulator, int max_length); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5704 | #ifdef OBJECT_PRINT |
| 5705 | inline void SharedFunctionInfoPrint() { |
| 5706 | SharedFunctionInfoPrint(stdout); |
| 5707 | } |
| 5708 | void SharedFunctionInfoPrint(FILE* out); |
| 5709 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5710 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5711 | void SharedFunctionInfoVerify(); |
| 5712 | #endif |
| 5713 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5714 | void ResetForNewContext(int new_ic_age); |
| 5715 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 5716 | // Helper to compile the shared code. Returns true on success, false on |
| 5717 | // failure (e.g., stack overflow during compilation). This is only used by |
| 5718 | // the debugger, it is not possible to compile without a context otherwise. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5719 | static bool CompileLazy(Handle<SharedFunctionInfo> shared, |
| 5720 | ClearExceptionFlag flag); |
| 5721 | |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 5722 | void SharedFunctionInfoIterateBody(ObjectVisitor* v); |
| 5723 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5724 | // Casting. |
| 5725 | static inline SharedFunctionInfo* cast(Object* obj); |
| 5726 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 5727 | // Constants. |
| 5728 | static const int kDontAdaptArgumentsSentinel = -1; |
| 5729 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5730 | // Layout description. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5731 | // Pointer fields. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5732 | static const int kNameOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5733 | static const int kCodeOffset = kNameOffset + kPointerSize; |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 5734 | static const int kOptimizedCodeMapOffset = kCodeOffset + kPointerSize; |
| 5735 | static const int kScopeInfoOffset = kOptimizedCodeMapOffset + kPointerSize; |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 5736 | static const int kConstructStubOffset = kScopeInfoOffset + kPointerSize; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5737 | static const int kInstanceClassNameOffset = |
| 5738 | kConstructStubOffset + kPointerSize; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 5739 | static const int kFunctionDataOffset = |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5740 | kInstanceClassNameOffset + kPointerSize; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 5741 | static const int kScriptOffset = kFunctionDataOffset + kPointerSize; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5742 | static const int kDebugInfoOffset = kScriptOffset + kPointerSize; |
| 5743 | static const int kInferredNameOffset = kDebugInfoOffset + kPointerSize; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 5744 | static const int kInitialMapOffset = |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5745 | kInferredNameOffset + kPointerSize; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 5746 | static const int kThisPropertyAssignmentsOffset = |
| 5747 | kInitialMapOffset + kPointerSize; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5748 | // ast_node_count is a Smi field. It could be grouped with another Smi field |
| 5749 | // into a PSEUDO_SMI_ACCESSORS pair (on x64), if one becomes available. |
| 5750 | static const int kAstNodeCountOffset = |
| 5751 | kThisPropertyAssignmentsOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5752 | #if V8_HOST_ARCH_32_BIT |
| 5753 | // Smi fields. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5754 | static const int kLengthOffset = |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5755 | kAstNodeCountOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5756 | static const int kFormalParameterCountOffset = kLengthOffset + kPointerSize; |
| 5757 | static const int kExpectedNofPropertiesOffset = |
| 5758 | kFormalParameterCountOffset + kPointerSize; |
| 5759 | static const int kNumLiteralsOffset = |
| 5760 | kExpectedNofPropertiesOffset + kPointerSize; |
| 5761 | static const int kStartPositionAndTypeOffset = |
| 5762 | kNumLiteralsOffset + kPointerSize; |
| 5763 | static const int kEndPositionOffset = |
| 5764 | kStartPositionAndTypeOffset + kPointerSize; |
| 5765 | static const int kFunctionTokenPositionOffset = |
| 5766 | kEndPositionOffset + kPointerSize; |
| 5767 | static const int kCompilerHintsOffset = |
| 5768 | kFunctionTokenPositionOffset + kPointerSize; |
| 5769 | static const int kThisPropertyAssignmentsCountOffset = |
| 5770 | kCompilerHintsOffset + kPointerSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5771 | static const int kOptCountOffset = |
| 5772 | kThisPropertyAssignmentsCountOffset + kPointerSize; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5773 | static const int kCountersOffset = kOptCountOffset + kPointerSize; |
| 5774 | static const int kStressDeoptCounterOffset = kCountersOffset + kPointerSize; |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 5775 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5776 | // Total size. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5777 | static const int kSize = kStressDeoptCounterOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5778 | #else |
| 5779 | // The only reason to use smi fields instead of int fields |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 5780 | // is to allow iteration without maps decoding during |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5781 | // garbage collections. |
| 5782 | // To avoid wasting space on 64-bit architectures we use |
| 5783 | // the following trick: we group integer fields into pairs |
| 5784 | // First integer in each pair is shifted left by 1. |
| 5785 | // By doing this we guarantee that LSB of each kPointerSize aligned |
| 5786 | // word is not set and thus this word cannot be treated as pointer |
| 5787 | // to HeapObject during old space traversal. |
| 5788 | static const int kLengthOffset = |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5789 | kAstNodeCountOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5790 | static const int kFormalParameterCountOffset = |
| 5791 | kLengthOffset + kIntSize; |
| 5792 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5793 | static const int kExpectedNofPropertiesOffset = |
| 5794 | kFormalParameterCountOffset + kIntSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5795 | static const int kNumLiteralsOffset = |
| 5796 | kExpectedNofPropertiesOffset + kIntSize; |
| 5797 | |
| 5798 | static const int kEndPositionOffset = |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 5799 | kNumLiteralsOffset + kIntSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5800 | static const int kStartPositionAndTypeOffset = |
| 5801 | kEndPositionOffset + kIntSize; |
| 5802 | |
| 5803 | static const int kFunctionTokenPositionOffset = |
| 5804 | kStartPositionAndTypeOffset + kIntSize; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5805 | static const int kCompilerHintsOffset = |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5806 | kFunctionTokenPositionOffset + kIntSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5807 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5808 | static const int kThisPropertyAssignmentsCountOffset = |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5809 | kCompilerHintsOffset + kIntSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5810 | static const int kOptCountOffset = |
| 5811 | kThisPropertyAssignmentsCountOffset + kIntSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5812 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5813 | static const int kCountersOffset = kOptCountOffset + kIntSize; |
| 5814 | static const int kStressDeoptCounterOffset = kCountersOffset + kIntSize; |
svenpanne@chromium.org | b1df11d | 2012-02-08 10:26:21 +0000 | [diff] [blame] | 5815 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5816 | // Total size. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5817 | static const int kSize = kStressDeoptCounterOffset + kIntSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5818 | |
| 5819 | #endif |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 5820 | |
| 5821 | // The construction counter for inobject slack tracking is stored in the |
| 5822 | // most significant byte of compiler_hints which is otherwise unused. |
| 5823 | // Its offset depends on the endian-ness of the architecture. |
| 5824 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 5825 | static const int kConstructionCountOffset = kCompilerHintsOffset + 3; |
| 5826 | #elif __BYTE_ORDER == __BIG_ENDIAN |
| 5827 | static const int kConstructionCountOffset = kCompilerHintsOffset + 0; |
| 5828 | #else |
| 5829 | #error Unknown byte ordering |
| 5830 | #endif |
| 5831 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 5832 | static const int kAlignedSize = POINTER_SIZE_ALIGN(kSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5833 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 5834 | typedef FixedBodyDescriptor<kNameOffset, |
| 5835 | kThisPropertyAssignmentsOffset + kPointerSize, |
| 5836 | kSize> BodyDescriptor; |
| 5837 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5838 | // Bit positions in start_position_and_type. |
| 5839 | // The source code start position is in the 30 most significant bits of |
| 5840 | // the start_position_and_type field. |
| 5841 | static const int kIsExpressionBit = 0; |
| 5842 | static const int kIsTopLevelBit = 1; |
| 5843 | static const int kStartPositionShift = 2; |
| 5844 | static const int kStartPositionMask = ~((1 << kStartPositionShift) - 1); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5845 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5846 | // Bit positions in compiler_hints. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5847 | static const int kCodeAgeSize = 3; |
| 5848 | static const int kCodeAgeMask = (1 << kCodeAgeSize) - 1; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5849 | |
| 5850 | enum CompilerHints { |
| 5851 | kHasOnlySimpleThisPropertyAssignments, |
| 5852 | kAllowLazyCompilation, |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 5853 | kAllowLazyCompilationWithoutContext, |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5854 | kLiveObjectsMayExist, |
| 5855 | kCodeAgeShift, |
| 5856 | kOptimizationDisabled = kCodeAgeShift + kCodeAgeSize, |
| 5857 | kStrictModeFunction, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5858 | kExtendedModeFunction, |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5859 | kUsesArguments, |
| 5860 | kHasDuplicateParameters, |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 5861 | kNative, |
| 5862 | kBoundFunction, |
| 5863 | kIsAnonymous, |
| 5864 | kNameShouldPrintAsAnonymous, |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 5865 | kIsFunction, |
| 5866 | kDontOptimize, |
svenpanne@chromium.org | b1df11d | 2012-02-08 10:26:21 +0000 | [diff] [blame] | 5867 | kDontInline, |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 5868 | kDontCache, |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 5869 | kCompilerHintsCount // Pseudo entry |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5870 | }; |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5871 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5872 | class DeoptCountBits: public BitField<int, 0, 4> {}; |
| 5873 | class OptReenableTriesBits: public BitField<int, 4, 18> {}; |
| 5874 | class ICAgeBits: public BitField<int, 22, 8> {}; |
| 5875 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 5876 | private: |
| 5877 | #if V8_HOST_ARCH_32_BIT |
| 5878 | // On 32 bit platforms, compiler hints is a smi. |
| 5879 | static const int kCompilerHintsSmiTagSize = kSmiTagSize; |
| 5880 | static const int kCompilerHintsSize = kPointerSize; |
| 5881 | #else |
| 5882 | // On 64 bit platforms, compiler hints is not a smi, see comment above. |
| 5883 | static const int kCompilerHintsSmiTagSize = 0; |
| 5884 | static const int kCompilerHintsSize = kIntSize; |
| 5885 | #endif |
| 5886 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 5887 | STATIC_ASSERT(SharedFunctionInfo::kCompilerHintsCount <= |
| 5888 | SharedFunctionInfo::kCompilerHintsSize * kBitsPerByte); |
| 5889 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 5890 | public: |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 5891 | // Constants for optimizing codegen for strict mode function and |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 5892 | // native tests. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5893 | // Allows to use byte-width instructions. |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 5894 | static const int kStrictModeBitWithinByte = |
| 5895 | (kStrictModeFunction + kCompilerHintsSmiTagSize) % kBitsPerByte; |
| 5896 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5897 | static const int kExtendedModeBitWithinByte = |
| 5898 | (kExtendedModeFunction + kCompilerHintsSmiTagSize) % kBitsPerByte; |
| 5899 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 5900 | static const int kNativeBitWithinByte = |
| 5901 | (kNative + kCompilerHintsSmiTagSize) % kBitsPerByte; |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 5902 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 5903 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 5904 | static const int kStrictModeByteOffset = kCompilerHintsOffset + |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 5905 | (kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5906 | static const int kExtendedModeByteOffset = kCompilerHintsOffset + |
| 5907 | (kExtendedModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 5908 | static const int kNativeByteOffset = kCompilerHintsOffset + |
| 5909 | (kNative + kCompilerHintsSmiTagSize) / kBitsPerByte; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 5910 | #elif __BYTE_ORDER == __BIG_ENDIAN |
| 5911 | static const int kStrictModeByteOffset = kCompilerHintsOffset + |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 5912 | (kCompilerHintsSize - 1) - |
| 5913 | ((kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5914 | static const int kExtendedModeByteOffset = kCompilerHintsOffset + |
| 5915 | (kCompilerHintsSize - 1) - |
| 5916 | ((kExtendedModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 5917 | static const int kNativeByteOffset = kCompilerHintsOffset + |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 5918 | (kCompilerHintsSize - 1) - |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 5919 | ((kNative + kCompilerHintsSmiTagSize) / kBitsPerByte); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 5920 | #else |
| 5921 | #error Unknown byte ordering |
| 5922 | #endif |
| 5923 | |
| 5924 | private: |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5925 | DISALLOW_IMPLICIT_CONSTRUCTORS(SharedFunctionInfo); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5926 | }; |
| 5927 | |
| 5928 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 5929 | // Representation for module instance objects. |
| 5930 | class JSModule: public JSObject { |
| 5931 | public: |
| 5932 | // [context]: the context holding the module's locals, or undefined if none. |
| 5933 | DECL_ACCESSORS(context, Object) |
| 5934 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 5935 | // [scope_info]: Scope info. |
| 5936 | DECL_ACCESSORS(scope_info, ScopeInfo) |
| 5937 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 5938 | // Casting. |
| 5939 | static inline JSModule* cast(Object* obj); |
| 5940 | |
| 5941 | // Dispatched behavior. |
| 5942 | #ifdef OBJECT_PRINT |
| 5943 | inline void JSModulePrint() { |
| 5944 | JSModulePrint(stdout); |
| 5945 | } |
| 5946 | void JSModulePrint(FILE* out); |
| 5947 | #endif |
| 5948 | #ifdef DEBUG |
| 5949 | void JSModuleVerify(); |
| 5950 | #endif |
| 5951 | |
| 5952 | // Layout description. |
| 5953 | static const int kContextOffset = JSObject::kHeaderSize; |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 5954 | static const int kScopeInfoOffset = kContextOffset + kPointerSize; |
| 5955 | static const int kSize = kScopeInfoOffset + kPointerSize; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 5956 | |
| 5957 | private: |
| 5958 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSModule); |
| 5959 | }; |
| 5960 | |
| 5961 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5962 | // JSFunction describes JavaScript functions. |
| 5963 | class JSFunction: public JSObject { |
| 5964 | public: |
| 5965 | // [prototype_or_initial_map]: |
| 5966 | DECL_ACCESSORS(prototype_or_initial_map, Object) |
| 5967 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 5968 | // [shared]: The information about the function that |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5969 | // can be shared by instances. |
| 5970 | DECL_ACCESSORS(shared, SharedFunctionInfo) |
| 5971 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 5972 | inline SharedFunctionInfo* unchecked_shared(); |
| 5973 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5974 | // [context]: The context for this function. |
| 5975 | inline Context* context(); |
| 5976 | inline Object* unchecked_context(); |
| 5977 | inline void set_context(Object* context); |
| 5978 | |
| 5979 | // [code]: The generated code object for this function. Executed |
| 5980 | // when the function is invoked, e.g. foo() or new foo(). See |
| 5981 | // [[Call]] and [[Construct]] description in ECMA-262, section |
| 5982 | // 8.6.2, page 27. |
| 5983 | inline Code* code(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5984 | inline void set_code(Code* code); |
| 5985 | inline void ReplaceCode(Code* code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5986 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 5987 | inline Code* unchecked_code(); |
| 5988 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 5989 | // Tells whether this function is builtin. |
| 5990 | inline bool IsBuiltin(); |
| 5991 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5992 | // Tells whether or not the function needs arguments adaption. |
| 5993 | inline bool NeedsArgumentsAdaption(); |
| 5994 | |
| 5995 | // Tells whether or not this function has been optimized. |
| 5996 | inline bool IsOptimized(); |
| 5997 | |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 5998 | // Tells whether or not this function can be optimized. |
| 5999 | inline bool IsOptimizable(); |
| 6000 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6001 | // Mark this function for lazy recompilation. The function will be |
| 6002 | // recompiled the next time it is executed. |
| 6003 | void MarkForLazyRecompilation(); |
| 6004 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6005 | // Helpers to compile this function. Returns true on success, false on |
| 6006 | // failure (e.g., stack overflow during compilation). |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 6007 | static bool EnsureCompiled(Handle<JSFunction> function, |
| 6008 | ClearExceptionFlag flag); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6009 | static bool CompileLazy(Handle<JSFunction> function, |
| 6010 | ClearExceptionFlag flag); |
| 6011 | static bool CompileOptimized(Handle<JSFunction> function, |
| 6012 | int osr_ast_id, |
| 6013 | ClearExceptionFlag flag); |
| 6014 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6015 | // Tells whether or not the function is already marked for lazy |
| 6016 | // recompilation. |
| 6017 | inline bool IsMarkedForLazyRecompilation(); |
| 6018 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6019 | // Check whether or not this function is inlineable. |
| 6020 | bool IsInlineable(); |
| 6021 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6022 | // [literals_or_bindings]: Fixed array holding either |
| 6023 | // the materialized literals or the bindings of a bound function. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 6024 | // |
| 6025 | // If the function contains object, regexp or array literals, the |
| 6026 | // literals array prefix contains the object, regexp, and array |
| 6027 | // function to be used when creating these literals. This is |
| 6028 | // necessary so that we do not dynamically lookup the object, regexp |
| 6029 | // or array functions. Performing a dynamic lookup, we might end up |
| 6030 | // using the functions from a new context that we should not have |
| 6031 | // access to. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6032 | // |
| 6033 | // On bound functions, the array is a (copy-on-write) fixed-array containing |
| 6034 | // the function that was bound, bound this-value and any bound |
| 6035 | // arguments. Bound functions never contain literals. |
| 6036 | DECL_ACCESSORS(literals_or_bindings, FixedArray) |
| 6037 | |
| 6038 | inline FixedArray* literals(); |
| 6039 | inline void set_literals(FixedArray* literals); |
| 6040 | |
| 6041 | inline FixedArray* function_bindings(); |
| 6042 | inline void set_function_bindings(FixedArray* bindings); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6043 | |
| 6044 | // The initial map for an object created by this constructor. |
| 6045 | inline Map* initial_map(); |
| 6046 | inline void set_initial_map(Map* value); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 6047 | MUST_USE_RESULT inline MaybeObject* set_initial_map_and_cache_transitions( |
| 6048 | Map* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6049 | inline bool has_initial_map(); |
| 6050 | |
| 6051 | // Get and set the prototype property on a JSFunction. If the |
| 6052 | // function has an initial map the prototype is set on the initial |
| 6053 | // map. Otherwise, the prototype is put in the initial map field |
| 6054 | // until an initial map is needed. |
| 6055 | inline bool has_prototype(); |
| 6056 | inline bool has_instance_prototype(); |
| 6057 | inline Object* prototype(); |
| 6058 | inline Object* instance_prototype(); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 6059 | MUST_USE_RESULT MaybeObject* SetInstancePrototype(Object* value); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 6060 | MUST_USE_RESULT MaybeObject* SetPrototype(Object* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6061 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 6062 | // After prototype is removed, it will not be created when accessed, and |
| 6063 | // [[Construct]] from this function will not be allowed. |
| 6064 | Object* RemovePrototype(); |
| 6065 | inline bool should_have_prototype(); |
| 6066 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6067 | // Accessor for this function's initial map's [[class]] |
| 6068 | // property. This is primarily used by ECMA native functions. This |
| 6069 | // method sets the class_name field of this function's initial map |
| 6070 | // to a given value. It creates an initial map if this function does |
| 6071 | // not have one. Note that this method does not copy the initial map |
| 6072 | // if it has one already, but simply replaces it with the new value. |
| 6073 | // Instances created afterwards will have a map whose [[class]] is |
| 6074 | // set to 'value', but there is no guarantees on instances created |
| 6075 | // before. |
| 6076 | Object* SetInstanceClassName(String* name); |
| 6077 | |
| 6078 | // Returns if this function has been compiled to native code yet. |
| 6079 | inline bool is_compiled(); |
| 6080 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6081 | // [next_function_link]: Field for linking functions. This list is treated as |
| 6082 | // a weak list by the GC. |
| 6083 | DECL_ACCESSORS(next_function_link, Object) |
| 6084 | |
| 6085 | // Prints the name of the function using PrintF. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6086 | inline void PrintName() { |
| 6087 | PrintName(stdout); |
| 6088 | } |
| 6089 | void PrintName(FILE* out); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6090 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6091 | // Casting. |
| 6092 | static inline JSFunction* cast(Object* obj); |
| 6093 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 6094 | // Iterates the objects, including code objects indirectly referenced |
| 6095 | // through pointers to the first instruction in the code object. |
| 6096 | void JSFunctionIterateBody(int object_size, ObjectVisitor* v); |
| 6097 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6098 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6099 | #ifdef OBJECT_PRINT |
| 6100 | inline void JSFunctionPrint() { |
| 6101 | JSFunctionPrint(stdout); |
| 6102 | } |
| 6103 | void JSFunctionPrint(FILE* out); |
| 6104 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6105 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6106 | void JSFunctionVerify(); |
| 6107 | #endif |
| 6108 | |
| 6109 | // Returns the number of allocated literals. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6110 | inline int NumberOfLiterals(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6111 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6112 | // Retrieve the global context from a function's literal array. |
| 6113 | static Context* GlobalContextFromLiterals(FixedArray* literals); |
| 6114 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6115 | // Layout descriptors. The last property (from kNonWeakFieldsEndOffset to |
| 6116 | // kSize) is weak and has special handling during garbage collection. |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 6117 | static const int kCodeEntryOffset = JSObject::kHeaderSize; |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 6118 | static const int kPrototypeOrInitialMapOffset = |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 6119 | kCodeEntryOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6120 | static const int kSharedFunctionInfoOffset = |
| 6121 | kPrototypeOrInitialMapOffset + kPointerSize; |
| 6122 | static const int kContextOffset = kSharedFunctionInfoOffset + kPointerSize; |
| 6123 | static const int kLiteralsOffset = kContextOffset + kPointerSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6124 | static const int kNonWeakFieldsEndOffset = kLiteralsOffset + kPointerSize; |
| 6125 | static const int kNextFunctionLinkOffset = kNonWeakFieldsEndOffset; |
| 6126 | static const int kSize = kNextFunctionLinkOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6127 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 6128 | // Layout of the literals array. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6129 | static const int kLiteralsPrefixSize = 1; |
| 6130 | static const int kLiteralGlobalContextIndex = 0; |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 6131 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6132 | // Layout of the bound-function binding array. |
| 6133 | static const int kBoundFunctionIndex = 0; |
| 6134 | static const int kBoundThisIndex = 1; |
| 6135 | static const int kBoundArgumentsStartIndex = 2; |
| 6136 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6137 | private: |
| 6138 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunction); |
| 6139 | }; |
| 6140 | |
| 6141 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 6142 | // JSGlobalProxy's prototype must be a JSGlobalObject or null, |
| 6143 | // and the prototype is hidden. JSGlobalProxy always delegates |
| 6144 | // property accesses to its prototype if the prototype is not null. |
| 6145 | // |
| 6146 | // A JSGlobalProxy can be reinitialized which will preserve its identity. |
| 6147 | // |
| 6148 | // Accessing a JSGlobalProxy requires security check. |
| 6149 | |
| 6150 | class JSGlobalProxy : public JSObject { |
| 6151 | public: |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6152 | // [context]: the owner global context of this global proxy object. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 6153 | // It is null value if this object is not used by any context. |
| 6154 | DECL_ACCESSORS(context, Object) |
| 6155 | |
| 6156 | // Casting. |
| 6157 | static inline JSGlobalProxy* cast(Object* obj); |
| 6158 | |
| 6159 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6160 | #ifdef OBJECT_PRINT |
| 6161 | inline void JSGlobalProxyPrint() { |
| 6162 | JSGlobalProxyPrint(stdout); |
| 6163 | } |
| 6164 | void JSGlobalProxyPrint(FILE* out); |
| 6165 | #endif |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 6166 | #ifdef DEBUG |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 6167 | void JSGlobalProxyVerify(); |
| 6168 | #endif |
| 6169 | |
| 6170 | // Layout description. |
| 6171 | static const int kContextOffset = JSObject::kHeaderSize; |
| 6172 | static const int kSize = kContextOffset + kPointerSize; |
| 6173 | |
| 6174 | private: |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 6175 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalProxy); |
| 6176 | }; |
| 6177 | |
| 6178 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6179 | // Forward declaration. |
| 6180 | class JSBuiltinsObject; |
| 6181 | |
| 6182 | // Common super class for JavaScript global objects and the special |
| 6183 | // builtins global objects. |
| 6184 | class GlobalObject: public JSObject { |
| 6185 | public: |
| 6186 | // [builtins]: the object holding the runtime routines written in JS. |
| 6187 | DECL_ACCESSORS(builtins, JSBuiltinsObject) |
| 6188 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 6189 | // [global context]: the global context corresponding to this global object. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6190 | DECL_ACCESSORS(global_context, Context) |
| 6191 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 6192 | // [global receiver]: the global receiver object of the context |
| 6193 | DECL_ACCESSORS(global_receiver, JSObject) |
| 6194 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6195 | // Retrieve the property cell used to store a property. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6196 | JSGlobalPropertyCell* GetPropertyCell(LookupResult* result); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6197 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 6198 | // This is like GetProperty, but is used when you know the lookup won't fail |
| 6199 | // by throwing an exception. This is for the debug and builtins global |
| 6200 | // objects, where it is known which properties can be expected to be present |
| 6201 | // on the object. |
| 6202 | Object* GetPropertyNoExceptionThrown(String* key) { |
| 6203 | Object* answer = GetProperty(key)->ToObjectUnchecked(); |
| 6204 | return answer; |
| 6205 | } |
| 6206 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 6207 | // Ensure that the global object has a cell for the given property name. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6208 | static Handle<JSGlobalPropertyCell> EnsurePropertyCell( |
| 6209 | Handle<GlobalObject> global, |
| 6210 | Handle<String> name); |
| 6211 | // TODO(kmillikin): This function can be eliminated once the stub cache is |
| 6212 | // full handlified (and the static helper can be written directly). |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 6213 | MUST_USE_RESULT MaybeObject* EnsurePropertyCell(String* name); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 6214 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 6215 | // Casting. |
| 6216 | static inline GlobalObject* cast(Object* obj); |
| 6217 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6218 | // Layout description. |
| 6219 | static const int kBuiltinsOffset = JSObject::kHeaderSize; |
| 6220 | static const int kGlobalContextOffset = kBuiltinsOffset + kPointerSize; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 6221 | static const int kGlobalReceiverOffset = kGlobalContextOffset + kPointerSize; |
| 6222 | static const int kHeaderSize = kGlobalReceiverOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6223 | |
| 6224 | private: |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 6225 | DISALLOW_IMPLICIT_CONSTRUCTORS(GlobalObject); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6226 | }; |
| 6227 | |
| 6228 | |
| 6229 | // JavaScript global object. |
| 6230 | class JSGlobalObject: public GlobalObject { |
| 6231 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6232 | // Casting. |
| 6233 | static inline JSGlobalObject* cast(Object* obj); |
| 6234 | |
| 6235 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6236 | #ifdef OBJECT_PRINT |
| 6237 | inline void JSGlobalObjectPrint() { |
| 6238 | JSGlobalObjectPrint(stdout); |
| 6239 | } |
| 6240 | void JSGlobalObjectPrint(FILE* out); |
| 6241 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6242 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6243 | void JSGlobalObjectVerify(); |
| 6244 | #endif |
| 6245 | |
| 6246 | // Layout description. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 6247 | static const int kSize = GlobalObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6248 | |
| 6249 | private: |
| 6250 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalObject); |
| 6251 | }; |
| 6252 | |
| 6253 | |
| 6254 | // Builtins global object which holds the runtime routines written in |
| 6255 | // JavaScript. |
| 6256 | class JSBuiltinsObject: public GlobalObject { |
| 6257 | public: |
| 6258 | // Accessors for the runtime routines written in JavaScript. |
| 6259 | inline Object* javascript_builtin(Builtins::JavaScript id); |
| 6260 | inline void set_javascript_builtin(Builtins::JavaScript id, Object* value); |
| 6261 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 6262 | // Accessors for code of the runtime routines written in JavaScript. |
| 6263 | inline Code* javascript_builtin_code(Builtins::JavaScript id); |
| 6264 | inline void set_javascript_builtin_code(Builtins::JavaScript id, Code* value); |
| 6265 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6266 | // Casting. |
| 6267 | static inline JSBuiltinsObject* cast(Object* obj); |
| 6268 | |
| 6269 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6270 | #ifdef OBJECT_PRINT |
| 6271 | inline void JSBuiltinsObjectPrint() { |
| 6272 | JSBuiltinsObjectPrint(stdout); |
| 6273 | } |
| 6274 | void JSBuiltinsObjectPrint(FILE* out); |
| 6275 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6276 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6277 | void JSBuiltinsObjectVerify(); |
| 6278 | #endif |
| 6279 | |
| 6280 | // Layout description. The size of the builtins object includes |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 6281 | // room for two pointers per runtime routine written in javascript |
| 6282 | // (function and code object). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6283 | static const int kJSBuiltinsCount = Builtins::id_count; |
| 6284 | static const int kJSBuiltinsOffset = GlobalObject::kHeaderSize; |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 6285 | static const int kJSBuiltinsCodeOffset = |
| 6286 | GlobalObject::kHeaderSize + (kJSBuiltinsCount * kPointerSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6287 | static const int kSize = |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 6288 | kJSBuiltinsCodeOffset + (kJSBuiltinsCount * kPointerSize); |
| 6289 | |
| 6290 | static int OffsetOfFunctionWithId(Builtins::JavaScript id) { |
| 6291 | return kJSBuiltinsOffset + id * kPointerSize; |
| 6292 | } |
| 6293 | |
| 6294 | static int OffsetOfCodeWithId(Builtins::JavaScript id) { |
| 6295 | return kJSBuiltinsCodeOffset + id * kPointerSize; |
| 6296 | } |
| 6297 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6298 | private: |
| 6299 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSBuiltinsObject); |
| 6300 | }; |
| 6301 | |
| 6302 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6303 | // Representation for JS Wrapper objects, String, Number, Boolean, etc. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6304 | class JSValue: public JSObject { |
| 6305 | public: |
| 6306 | // [value]: the object being wrapped. |
| 6307 | DECL_ACCESSORS(value, Object) |
| 6308 | |
| 6309 | // Casting. |
| 6310 | static inline JSValue* cast(Object* obj); |
| 6311 | |
| 6312 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6313 | #ifdef OBJECT_PRINT |
| 6314 | inline void JSValuePrint() { |
| 6315 | JSValuePrint(stdout); |
| 6316 | } |
| 6317 | void JSValuePrint(FILE* out); |
| 6318 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6319 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6320 | void JSValueVerify(); |
| 6321 | #endif |
| 6322 | |
| 6323 | // Layout description. |
| 6324 | static const int kValueOffset = JSObject::kHeaderSize; |
| 6325 | static const int kSize = kValueOffset + kPointerSize; |
| 6326 | |
| 6327 | private: |
| 6328 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSValue); |
| 6329 | }; |
| 6330 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 6331 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6332 | class DateCache; |
| 6333 | |
| 6334 | // Representation for JS date objects. |
| 6335 | class JSDate: public JSObject { |
| 6336 | public: |
| 6337 | // If one component is NaN, all of them are, indicating a NaN time value. |
| 6338 | // [value]: the time value. |
| 6339 | DECL_ACCESSORS(value, Object) |
| 6340 | // [year]: caches year. Either undefined, smi, or NaN. |
| 6341 | DECL_ACCESSORS(year, Object) |
| 6342 | // [month]: caches month. Either undefined, smi, or NaN. |
| 6343 | DECL_ACCESSORS(month, Object) |
| 6344 | // [day]: caches day. Either undefined, smi, or NaN. |
| 6345 | DECL_ACCESSORS(day, Object) |
| 6346 | // [weekday]: caches day of week. Either undefined, smi, or NaN. |
| 6347 | DECL_ACCESSORS(weekday, Object) |
| 6348 | // [hour]: caches hours. Either undefined, smi, or NaN. |
| 6349 | DECL_ACCESSORS(hour, Object) |
| 6350 | // [min]: caches minutes. Either undefined, smi, or NaN. |
| 6351 | DECL_ACCESSORS(min, Object) |
| 6352 | // [sec]: caches seconds. Either undefined, smi, or NaN. |
| 6353 | DECL_ACCESSORS(sec, Object) |
| 6354 | // [cache stamp]: sample of the date cache stamp at the |
| 6355 | // moment when local fields were cached. |
| 6356 | DECL_ACCESSORS(cache_stamp, Object) |
| 6357 | |
| 6358 | // Casting. |
| 6359 | static inline JSDate* cast(Object* obj); |
| 6360 | |
| 6361 | // Returns the date field with the specified index. |
| 6362 | // See FieldIndex for the list of date fields. |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 6363 | static Object* GetField(Object* date, Smi* index); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6364 | |
| 6365 | void SetValue(Object* value, bool is_value_nan); |
| 6366 | |
| 6367 | |
| 6368 | // Dispatched behavior. |
| 6369 | #ifdef OBJECT_PRINT |
| 6370 | inline void JSDatePrint() { |
| 6371 | JSDatePrint(stdout); |
| 6372 | } |
| 6373 | void JSDatePrint(FILE* out); |
| 6374 | #endif |
| 6375 | #ifdef DEBUG |
| 6376 | void JSDateVerify(); |
| 6377 | #endif |
| 6378 | // The order is important. It must be kept in sync with date macros |
| 6379 | // in macros.py. |
| 6380 | enum FieldIndex { |
| 6381 | kDateValue, |
| 6382 | kYear, |
| 6383 | kMonth, |
| 6384 | kDay, |
| 6385 | kWeekday, |
| 6386 | kHour, |
| 6387 | kMinute, |
| 6388 | kSecond, |
| 6389 | kFirstUncachedField, |
| 6390 | kMillisecond = kFirstUncachedField, |
| 6391 | kDays, |
| 6392 | kTimeInDay, |
| 6393 | kFirstUTCField, |
| 6394 | kYearUTC = kFirstUTCField, |
| 6395 | kMonthUTC, |
| 6396 | kDayUTC, |
| 6397 | kWeekdayUTC, |
| 6398 | kHourUTC, |
| 6399 | kMinuteUTC, |
| 6400 | kSecondUTC, |
| 6401 | kMillisecondUTC, |
| 6402 | kDaysUTC, |
| 6403 | kTimeInDayUTC, |
| 6404 | kTimezoneOffset |
| 6405 | }; |
| 6406 | |
| 6407 | // Layout description. |
| 6408 | static const int kValueOffset = JSObject::kHeaderSize; |
| 6409 | static const int kYearOffset = kValueOffset + kPointerSize; |
| 6410 | static const int kMonthOffset = kYearOffset + kPointerSize; |
| 6411 | static const int kDayOffset = kMonthOffset + kPointerSize; |
| 6412 | static const int kWeekdayOffset = kDayOffset + kPointerSize; |
| 6413 | static const int kHourOffset = kWeekdayOffset + kPointerSize; |
| 6414 | static const int kMinOffset = kHourOffset + kPointerSize; |
| 6415 | static const int kSecOffset = kMinOffset + kPointerSize; |
| 6416 | static const int kCacheStampOffset = kSecOffset + kPointerSize; |
| 6417 | static const int kSize = kCacheStampOffset + kPointerSize; |
| 6418 | |
| 6419 | private: |
| 6420 | inline Object* DoGetField(FieldIndex index); |
| 6421 | |
| 6422 | Object* GetUTCField(FieldIndex index, double value, DateCache* date_cache); |
| 6423 | |
| 6424 | // Computes and caches the cacheable fields of the date. |
| 6425 | inline void SetLocalFields(int64_t local_time_ms, DateCache* date_cache); |
| 6426 | |
| 6427 | |
| 6428 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSDate); |
| 6429 | }; |
| 6430 | |
| 6431 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 6432 | // Representation of message objects used for error reporting through |
| 6433 | // the API. The messages are formatted in JavaScript so this object is |
| 6434 | // a real JavaScript object. The information used for formatting the |
| 6435 | // error messages are not directly accessible from JavaScript to |
| 6436 | // prevent leaking information to user code called during error |
| 6437 | // formatting. |
| 6438 | class JSMessageObject: public JSObject { |
| 6439 | public: |
| 6440 | // [type]: the type of error message. |
| 6441 | DECL_ACCESSORS(type, String) |
| 6442 | |
| 6443 | // [arguments]: the arguments for formatting the error message. |
| 6444 | DECL_ACCESSORS(arguments, JSArray) |
| 6445 | |
| 6446 | // [script]: the script from which the error message originated. |
| 6447 | DECL_ACCESSORS(script, Object) |
| 6448 | |
| 6449 | // [stack_trace]: the stack trace for this error message. |
| 6450 | DECL_ACCESSORS(stack_trace, Object) |
| 6451 | |
| 6452 | // [stack_frames]: an array of stack frames for this error object. |
| 6453 | DECL_ACCESSORS(stack_frames, Object) |
| 6454 | |
| 6455 | // [start_position]: the start position in the script for the error message. |
| 6456 | inline int start_position(); |
| 6457 | inline void set_start_position(int value); |
| 6458 | |
| 6459 | // [end_position]: the end position in the script for the error message. |
| 6460 | inline int end_position(); |
| 6461 | inline void set_end_position(int value); |
| 6462 | |
| 6463 | // Casting. |
| 6464 | static inline JSMessageObject* cast(Object* obj); |
| 6465 | |
| 6466 | // Dispatched behavior. |
| 6467 | #ifdef OBJECT_PRINT |
| 6468 | inline void JSMessageObjectPrint() { |
| 6469 | JSMessageObjectPrint(stdout); |
| 6470 | } |
| 6471 | void JSMessageObjectPrint(FILE* out); |
| 6472 | #endif |
| 6473 | #ifdef DEBUG |
| 6474 | void JSMessageObjectVerify(); |
| 6475 | #endif |
| 6476 | |
| 6477 | // Layout description. |
| 6478 | static const int kTypeOffset = JSObject::kHeaderSize; |
| 6479 | static const int kArgumentsOffset = kTypeOffset + kPointerSize; |
| 6480 | static const int kScriptOffset = kArgumentsOffset + kPointerSize; |
| 6481 | static const int kStackTraceOffset = kScriptOffset + kPointerSize; |
| 6482 | static const int kStackFramesOffset = kStackTraceOffset + kPointerSize; |
| 6483 | static const int kStartPositionOffset = kStackFramesOffset + kPointerSize; |
| 6484 | static const int kEndPositionOffset = kStartPositionOffset + kPointerSize; |
| 6485 | static const int kSize = kEndPositionOffset + kPointerSize; |
| 6486 | |
| 6487 | typedef FixedBodyDescriptor<HeapObject::kMapOffset, |
| 6488 | kStackFramesOffset + kPointerSize, |
| 6489 | kSize> BodyDescriptor; |
| 6490 | }; |
| 6491 | |
| 6492 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6493 | // Regular expressions |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6494 | // The regular expression holds a single reference to a FixedArray in |
| 6495 | // the kDataOffset field. |
| 6496 | // The FixedArray contains the following data: |
| 6497 | // - tag : type of regexp implementation (not compiled yet, atom or irregexp) |
| 6498 | // - reference to the original source string |
| 6499 | // - reference to the original flag string |
| 6500 | // If it is an atom regexp |
| 6501 | // - a reference to a literal string to search for |
| 6502 | // If it is an irregexp regexp: |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 6503 | // - a reference to code for ASCII inputs (bytecode or compiled), or a smi |
| 6504 | // used for tracking the last usage (used for code flushing). |
| 6505 | // - a reference to code for UC16 inputs (bytecode or compiled), or a smi |
| 6506 | // used for tracking the last usage (used for code flushing).. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6507 | // - max number of registers used by irregexp implementations. |
| 6508 | // - number of capture registers (output values) of the regexp. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6509 | class JSRegExp: public JSObject { |
| 6510 | public: |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 6511 | // Meaning of Type: |
| 6512 | // 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] | 6513 | // ATOM: A simple string to match against using an indexOf operation. |
| 6514 | // IRREGEXP: Compiled with Irregexp. |
| 6515 | // IRREGEXP_NATIVE: Compiled to native code with Irregexp. |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 6516 | enum Type { NOT_COMPILED, ATOM, IRREGEXP }; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6517 | enum Flag { NONE = 0, GLOBAL = 1, IGNORE_CASE = 2, MULTILINE = 4 }; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6518 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6519 | class Flags { |
| 6520 | public: |
| 6521 | explicit Flags(uint32_t value) : value_(value) { } |
| 6522 | bool is_global() { return (value_ & GLOBAL) != 0; } |
| 6523 | bool is_ignore_case() { return (value_ & IGNORE_CASE) != 0; } |
| 6524 | bool is_multiline() { return (value_ & MULTILINE) != 0; } |
| 6525 | uint32_t value() { return value_; } |
| 6526 | private: |
| 6527 | uint32_t value_; |
| 6528 | }; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6529 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6530 | DECL_ACCESSORS(data, Object) |
| 6531 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6532 | inline Type TypeTag(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 6533 | inline int CaptureCount(); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 6534 | inline Flags GetFlags(); |
| 6535 | inline String* Pattern(); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6536 | inline Object* DataAt(int index); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6537 | // Set implementation data after the object has been prepared. |
| 6538 | inline void SetDataAt(int index, Object* value); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 6539 | |
| 6540 | // Used during GC when flushing code or setting age. |
| 6541 | inline Object* DataAtUnchecked(int index); |
| 6542 | inline void SetDataAtUnchecked(int index, Object* value, Heap* heap); |
| 6543 | inline Type TypeTagUnchecked(); |
| 6544 | |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 6545 | static int code_index(bool is_ascii) { |
| 6546 | if (is_ascii) { |
| 6547 | return kIrregexpASCIICodeIndex; |
| 6548 | } else { |
| 6549 | return kIrregexpUC16CodeIndex; |
| 6550 | } |
| 6551 | } |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6552 | |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 6553 | static int saved_code_index(bool is_ascii) { |
| 6554 | if (is_ascii) { |
| 6555 | return kIrregexpASCIICodeSavedIndex; |
| 6556 | } else { |
| 6557 | return kIrregexpUC16CodeSavedIndex; |
| 6558 | } |
| 6559 | } |
| 6560 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6561 | static inline JSRegExp* cast(Object* obj); |
| 6562 | |
| 6563 | // Dispatched behavior. |
| 6564 | #ifdef DEBUG |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6565 | void JSRegExpVerify(); |
| 6566 | #endif |
| 6567 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6568 | static const int kDataOffset = JSObject::kHeaderSize; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 6569 | static const int kSize = kDataOffset + kPointerSize; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6570 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6571 | // Indices in the data array. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6572 | static const int kTagIndex = 0; |
| 6573 | static const int kSourceIndex = kTagIndex + 1; |
| 6574 | static const int kFlagsIndex = kSourceIndex + 1; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6575 | static const int kDataIndex = kFlagsIndex + 1; |
| 6576 | // The data fields are used in different ways depending on the |
| 6577 | // value of the tag. |
| 6578 | // Atom regexps (literal strings). |
| 6579 | static const int kAtomPatternIndex = kDataIndex; |
| 6580 | |
| 6581 | static const int kAtomDataSize = kAtomPatternIndex + 1; |
| 6582 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 6583 | // Irregexp compiled code or bytecode for ASCII. If compilation |
| 6584 | // fails, this fields hold an exception object that should be |
| 6585 | // thrown if the regexp is used again. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6586 | static const int kIrregexpASCIICodeIndex = kDataIndex; |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 6587 | // Irregexp compiled code or bytecode for UC16. If compilation |
| 6588 | // fails, this fields hold an exception object that should be |
| 6589 | // thrown if the regexp is used again. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6590 | static const int kIrregexpUC16CodeIndex = kDataIndex + 1; |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 6591 | |
| 6592 | // Saved instance of Irregexp compiled code or bytecode for ASCII that |
| 6593 | // is a potential candidate for flushing. |
| 6594 | static const int kIrregexpASCIICodeSavedIndex = kDataIndex + 2; |
| 6595 | // Saved instance of Irregexp compiled code or bytecode for UC16 that is |
| 6596 | // a potential candidate for flushing. |
| 6597 | static const int kIrregexpUC16CodeSavedIndex = kDataIndex + 3; |
| 6598 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6599 | // Maximal number of registers used by either ASCII or UC16. |
| 6600 | // Only used to check that there is enough stack space |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 6601 | static const int kIrregexpMaxRegisterCountIndex = kDataIndex + 4; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6602 | // Number of captures in the compiled regexp. |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 6603 | static const int kIrregexpCaptureCountIndex = kDataIndex + 5; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6604 | |
| 6605 | static const int kIrregexpDataSize = kIrregexpCaptureCountIndex + 1; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 6606 | |
| 6607 | // Offsets directly into the data fixed array. |
| 6608 | static const int kDataTagOffset = |
| 6609 | FixedArray::kHeaderSize + kTagIndex * kPointerSize; |
| 6610 | static const int kDataAsciiCodeOffset = |
| 6611 | FixedArray::kHeaderSize + kIrregexpASCIICodeIndex * kPointerSize; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 6612 | static const int kDataUC16CodeOffset = |
| 6613 | FixedArray::kHeaderSize + kIrregexpUC16CodeIndex * kPointerSize; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 6614 | static const int kIrregexpCaptureCountOffset = |
| 6615 | FixedArray::kHeaderSize + kIrregexpCaptureCountIndex * kPointerSize; |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 6616 | |
| 6617 | // In-object fields. |
| 6618 | static const int kSourceFieldIndex = 0; |
| 6619 | static const int kGlobalFieldIndex = 1; |
| 6620 | static const int kIgnoreCaseFieldIndex = 2; |
| 6621 | static const int kMultilineFieldIndex = 3; |
| 6622 | static const int kLastIndexFieldIndex = 4; |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 6623 | static const int kInObjectFieldCount = 5; |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 6624 | |
| 6625 | // The uninitialized value for a regexp code object. |
| 6626 | static const int kUninitializedValue = -1; |
| 6627 | |
| 6628 | // The compilation error value for the regexp code object. The real error |
| 6629 | // object is in the saved code field. |
| 6630 | static const int kCompilationErrorValue = -2; |
| 6631 | |
| 6632 | // When we store the sweep generation at which we moved the code from the |
| 6633 | // code index to the saved code index we mask it of to be in the [0:255] |
| 6634 | // range. |
| 6635 | static const int kCodeAgeMask = 0xff; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6636 | }; |
| 6637 | |
| 6638 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6639 | class CompilationCacheShape : public BaseShape<HashTableKey*> { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 6640 | public: |
| 6641 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 6642 | return key->IsMatch(value); |
| 6643 | } |
| 6644 | |
| 6645 | static inline uint32_t Hash(HashTableKey* key) { |
| 6646 | return key->Hash(); |
| 6647 | } |
| 6648 | |
| 6649 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 6650 | return key->HashForObject(object); |
| 6651 | } |
| 6652 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 6653 | MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 6654 | return key->AsObject(); |
| 6655 | } |
| 6656 | |
| 6657 | static const int kPrefixSize = 0; |
| 6658 | static const int kEntrySize = 2; |
| 6659 | }; |
| 6660 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 6661 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 6662 | class CompilationCacheTable: public HashTable<CompilationCacheShape, |
| 6663 | HashTableKey*> { |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6664 | public: |
| 6665 | // Find cached value for a string key, otherwise return null. |
| 6666 | Object* Lookup(String* src); |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 6667 | Object* LookupEval(String* src, |
| 6668 | Context* context, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 6669 | LanguageMode language_mode, |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 6670 | int scope_position); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6671 | Object* LookupRegExp(String* source, JSRegExp::Flags flags); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 6672 | MUST_USE_RESULT MaybeObject* Put(String* src, Object* value); |
| 6673 | MUST_USE_RESULT MaybeObject* PutEval(String* src, |
| 6674 | Context* context, |
| 6675 | SharedFunctionInfo* value, |
| 6676 | int scope_position); |
| 6677 | MUST_USE_RESULT MaybeObject* PutRegExp(String* src, |
| 6678 | JSRegExp::Flags flags, |
| 6679 | FixedArray* value); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6680 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6681 | // Remove given value from cache. |
| 6682 | void Remove(Object* value); |
| 6683 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6684 | static inline CompilationCacheTable* cast(Object* obj); |
| 6685 | |
| 6686 | private: |
| 6687 | DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheTable); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6688 | }; |
| 6689 | |
| 6690 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 6691 | class CodeCache: public Struct { |
| 6692 | public: |
| 6693 | DECL_ACCESSORS(default_cache, FixedArray) |
| 6694 | DECL_ACCESSORS(normal_type_cache, Object) |
| 6695 | |
| 6696 | // Add the code object to the cache. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 6697 | MUST_USE_RESULT MaybeObject* Update(String* name, Code* code); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 6698 | |
| 6699 | // Lookup code object in the cache. Returns code object if found and undefined |
| 6700 | // if not. |
| 6701 | Object* Lookup(String* name, Code::Flags flags); |
| 6702 | |
| 6703 | // Get the internal index of a code object in the cache. Returns -1 if the |
| 6704 | // code object is not in that cache. This index can be used to later call |
| 6705 | // RemoveByIndex. The cache cannot be modified between a call to GetIndex and |
| 6706 | // RemoveByIndex. |
sgjesse@chromium.org | 99a37fa | 2010-03-11 09:23:46 +0000 | [diff] [blame] | 6707 | int GetIndex(Object* name, Code* code); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 6708 | |
| 6709 | // Remove an object from the cache with the provided internal index. |
sgjesse@chromium.org | 99a37fa | 2010-03-11 09:23:46 +0000 | [diff] [blame] | 6710 | void RemoveByIndex(Object* name, Code* code, int index); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 6711 | |
| 6712 | static inline CodeCache* cast(Object* obj); |
| 6713 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6714 | #ifdef OBJECT_PRINT |
| 6715 | inline void CodeCachePrint() { |
| 6716 | CodeCachePrint(stdout); |
| 6717 | } |
| 6718 | void CodeCachePrint(FILE* out); |
| 6719 | #endif |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 6720 | #ifdef DEBUG |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 6721 | void CodeCacheVerify(); |
| 6722 | #endif |
| 6723 | |
| 6724 | static const int kDefaultCacheOffset = HeapObject::kHeaderSize; |
| 6725 | static const int kNormalTypeCacheOffset = |
| 6726 | kDefaultCacheOffset + kPointerSize; |
| 6727 | static const int kSize = kNormalTypeCacheOffset + kPointerSize; |
| 6728 | |
| 6729 | private: |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 6730 | MUST_USE_RESULT MaybeObject* UpdateDefaultCache(String* name, Code* code); |
| 6731 | MUST_USE_RESULT MaybeObject* UpdateNormalTypeCache(String* name, Code* code); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 6732 | Object* LookupDefaultCache(String* name, Code::Flags flags); |
| 6733 | Object* LookupNormalTypeCache(String* name, Code::Flags flags); |
| 6734 | |
| 6735 | // Code cache layout of the default cache. Elements are alternating name and |
| 6736 | // code objects for non normal load/store/call IC's. |
| 6737 | static const int kCodeCacheEntrySize = 2; |
| 6738 | static const int kCodeCacheEntryNameOffset = 0; |
| 6739 | static const int kCodeCacheEntryCodeOffset = 1; |
| 6740 | |
| 6741 | DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCache); |
| 6742 | }; |
| 6743 | |
| 6744 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6745 | class CodeCacheHashTableShape : public BaseShape<HashTableKey*> { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 6746 | public: |
| 6747 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 6748 | return key->IsMatch(value); |
| 6749 | } |
| 6750 | |
| 6751 | static inline uint32_t Hash(HashTableKey* key) { |
| 6752 | return key->Hash(); |
| 6753 | } |
| 6754 | |
| 6755 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 6756 | return key->HashForObject(object); |
| 6757 | } |
| 6758 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 6759 | MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 6760 | return key->AsObject(); |
| 6761 | } |
| 6762 | |
| 6763 | static const int kPrefixSize = 0; |
| 6764 | static const int kEntrySize = 2; |
| 6765 | }; |
| 6766 | |
| 6767 | |
| 6768 | class CodeCacheHashTable: public HashTable<CodeCacheHashTableShape, |
| 6769 | HashTableKey*> { |
| 6770 | public: |
| 6771 | Object* Lookup(String* name, Code::Flags flags); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 6772 | MUST_USE_RESULT MaybeObject* Put(String* name, Code* code); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 6773 | |
| 6774 | int GetIndex(String* name, Code::Flags flags); |
| 6775 | void RemoveByIndex(int index); |
| 6776 | |
| 6777 | static inline CodeCacheHashTable* cast(Object* obj); |
| 6778 | |
| 6779 | // Initial size of the fixed array backing the hash table. |
| 6780 | static const int kInitialSize = 64; |
| 6781 | |
| 6782 | private: |
| 6783 | DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCacheHashTable); |
| 6784 | }; |
| 6785 | |
| 6786 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 6787 | class PolymorphicCodeCache: public Struct { |
| 6788 | public: |
| 6789 | DECL_ACCESSORS(cache, Object) |
| 6790 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6791 | static void Update(Handle<PolymorphicCodeCache> cache, |
| 6792 | MapHandleList* maps, |
| 6793 | Code::Flags flags, |
| 6794 | Handle<Code> code); |
| 6795 | |
| 6796 | MUST_USE_RESULT MaybeObject* Update(MapHandleList* maps, |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 6797 | Code::Flags flags, |
| 6798 | Code* code); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6799 | |
| 6800 | // Returns an undefined value if the entry is not found. |
| 6801 | Handle<Object> Lookup(MapHandleList* maps, Code::Flags flags); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 6802 | |
| 6803 | static inline PolymorphicCodeCache* cast(Object* obj); |
| 6804 | |
| 6805 | #ifdef OBJECT_PRINT |
| 6806 | inline void PolymorphicCodeCachePrint() { |
| 6807 | PolymorphicCodeCachePrint(stdout); |
| 6808 | } |
| 6809 | void PolymorphicCodeCachePrint(FILE* out); |
| 6810 | #endif |
| 6811 | #ifdef DEBUG |
| 6812 | void PolymorphicCodeCacheVerify(); |
| 6813 | #endif |
| 6814 | |
| 6815 | static const int kCacheOffset = HeapObject::kHeaderSize; |
| 6816 | static const int kSize = kCacheOffset + kPointerSize; |
| 6817 | |
| 6818 | private: |
| 6819 | DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCache); |
| 6820 | }; |
| 6821 | |
| 6822 | |
| 6823 | class PolymorphicCodeCacheHashTable |
| 6824 | : public HashTable<CodeCacheHashTableShape, HashTableKey*> { |
| 6825 | public: |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6826 | Object* Lookup(MapHandleList* maps, int code_kind); |
| 6827 | |
| 6828 | MUST_USE_RESULT MaybeObject* Put(MapHandleList* maps, |
| 6829 | int code_kind, |
| 6830 | Code* code); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 6831 | |
| 6832 | static inline PolymorphicCodeCacheHashTable* cast(Object* obj); |
| 6833 | |
| 6834 | static const int kInitialSize = 64; |
| 6835 | private: |
| 6836 | DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCacheHashTable); |
| 6837 | }; |
| 6838 | |
| 6839 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 6840 | class TypeFeedbackInfo: public Struct { |
| 6841 | public: |
| 6842 | inline int ic_total_count(); |
| 6843 | inline void set_ic_total_count(int count); |
| 6844 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6845 | inline int ic_with_type_info_count(); |
| 6846 | inline void set_ic_with_type_info_count(int count); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 6847 | |
| 6848 | DECL_ACCESSORS(type_feedback_cells, TypeFeedbackCells) |
| 6849 | |
| 6850 | static inline TypeFeedbackInfo* cast(Object* obj); |
| 6851 | |
| 6852 | #ifdef OBJECT_PRINT |
| 6853 | inline void TypeFeedbackInfoPrint() { |
| 6854 | TypeFeedbackInfoPrint(stdout); |
| 6855 | } |
| 6856 | void TypeFeedbackInfoPrint(FILE* out); |
| 6857 | #endif |
| 6858 | #ifdef DEBUG |
| 6859 | void TypeFeedbackInfoVerify(); |
| 6860 | #endif |
| 6861 | |
| 6862 | static const int kIcTotalCountOffset = HeapObject::kHeaderSize; |
| 6863 | static const int kIcWithTypeinfoCountOffset = |
| 6864 | kIcTotalCountOffset + kPointerSize; |
| 6865 | static const int kTypeFeedbackCellsOffset = |
| 6866 | kIcWithTypeinfoCountOffset + kPointerSize; |
| 6867 | static const int kSize = kTypeFeedbackCellsOffset + kPointerSize; |
| 6868 | |
| 6869 | private: |
| 6870 | DISALLOW_IMPLICIT_CONSTRUCTORS(TypeFeedbackInfo); |
| 6871 | }; |
| 6872 | |
| 6873 | |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 6874 | // Representation of a slow alias as part of a non-strict arguments objects. |
| 6875 | // For fast aliases (if HasNonStrictArgumentsElements()): |
| 6876 | // - the parameter map contains an index into the context |
| 6877 | // - all attributes of the element have default values |
| 6878 | // For slow aliases (if HasDictionaryArgumentsElements()): |
| 6879 | // - the parameter map contains no fast alias mapping (i.e. the hole) |
| 6880 | // - this struct (in the slow backing store) contains an index into the context |
| 6881 | // - all attributes are available as part if the property details |
| 6882 | class AliasedArgumentsEntry: public Struct { |
| 6883 | public: |
| 6884 | inline int aliased_context_slot(); |
| 6885 | inline void set_aliased_context_slot(int count); |
| 6886 | |
| 6887 | static inline AliasedArgumentsEntry* cast(Object* obj); |
| 6888 | |
| 6889 | #ifdef OBJECT_PRINT |
| 6890 | inline void AliasedArgumentsEntryPrint() { |
| 6891 | AliasedArgumentsEntryPrint(stdout); |
| 6892 | } |
| 6893 | void AliasedArgumentsEntryPrint(FILE* out); |
| 6894 | #endif |
| 6895 | #ifdef DEBUG |
| 6896 | void AliasedArgumentsEntryVerify(); |
| 6897 | #endif |
| 6898 | |
| 6899 | static const int kAliasedContextSlot = HeapObject::kHeaderSize; |
| 6900 | static const int kSize = kAliasedContextSlot + kPointerSize; |
| 6901 | |
| 6902 | private: |
| 6903 | DISALLOW_IMPLICIT_CONSTRUCTORS(AliasedArgumentsEntry); |
| 6904 | }; |
| 6905 | |
| 6906 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6907 | enum AllowNullsFlag {ALLOW_NULLS, DISALLOW_NULLS}; |
| 6908 | enum RobustnessFlag {ROBUST_STRING_TRAVERSAL, FAST_STRING_TRAVERSAL}; |
| 6909 | |
| 6910 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6911 | class StringHasher { |
| 6912 | public: |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6913 | explicit inline StringHasher(int length, uint32_t seed); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6914 | |
| 6915 | // Returns true if the hash of this string can be computed without |
| 6916 | // looking at the contents. |
| 6917 | inline bool has_trivial_hash(); |
| 6918 | |
| 6919 | // Add a character to the hash and update the array index calculation. |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 6920 | inline void AddCharacter(uint32_t c); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6921 | |
| 6922 | // Adds a character to the hash but does not update the array index |
| 6923 | // calculation. This can only be called when it has been verified |
| 6924 | // that the input is not an array index. |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 6925 | inline void AddCharacterNoIndex(uint32_t c); |
| 6926 | |
| 6927 | // Add a character above 0xffff as a surrogate pair. These can get into |
| 6928 | // the hasher through the routines that take a UTF-8 string and make a symbol. |
| 6929 | void AddSurrogatePair(uc32 c); |
| 6930 | void AddSurrogatePairNoIndex(uc32 c); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6931 | |
| 6932 | // Returns the value to store in the hash field of a string with |
| 6933 | // the given length and contents. |
| 6934 | uint32_t GetHashField(); |
| 6935 | |
| 6936 | // Returns true if the characters seen so far make up a legal array |
| 6937 | // index. |
| 6938 | bool is_array_index() { return is_array_index_; } |
| 6939 | |
| 6940 | bool is_valid() { return is_valid_; } |
| 6941 | |
| 6942 | void invalidate() { is_valid_ = false; } |
| 6943 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 6944 | // Calculated hash value for a string consisting of 1 to |
| 6945 | // String::kMaxArrayIndexSize digits with no leading zeros (except "0"). |
| 6946 | // value is represented decimal value. |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 6947 | static uint32_t MakeArrayIndexHash(uint32_t value, int length); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 6948 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6949 | // No string is allowed to have a hash of zero. That value is reserved |
| 6950 | // for internal properties. If the hash calculation yields zero then we |
| 6951 | // use 27 instead. |
| 6952 | static const int kZeroHash = 27; |
| 6953 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6954 | private: |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6955 | uint32_t array_index() { |
| 6956 | ASSERT(is_array_index()); |
| 6957 | return array_index_; |
| 6958 | } |
| 6959 | |
| 6960 | inline uint32_t GetHash(); |
| 6961 | |
| 6962 | int length_; |
| 6963 | uint32_t raw_running_hash_; |
| 6964 | uint32_t array_index_; |
| 6965 | bool is_array_index_; |
| 6966 | bool is_first_char_; |
| 6967 | bool is_valid_; |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 6968 | friend class TwoCharHashTableKey; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6969 | }; |
| 6970 | |
| 6971 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 6972 | // Calculates string hash. |
| 6973 | template <typename schar> |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6974 | inline uint32_t HashSequentialString(const schar* chars, |
| 6975 | int length, |
| 6976 | uint32_t seed); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 6977 | |
| 6978 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 6979 | // The characteristics of a string are stored in its map. Retrieving these |
| 6980 | // few bits of information is moderately expensive, involving two memory |
| 6981 | // loads where the second is dependent on the first. To improve efficiency |
| 6982 | // the shape of the string is given its own class so that it can be retrieved |
| 6983 | // once and used for several string operations. A StringShape is small enough |
| 6984 | // 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] | 6985 | // string can potentially alter its shape. Also be aware that a GC caused by |
| 6986 | // 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] | 6987 | // shortcutting. Keeping these restrictions in mind has proven to be error- |
| 6988 | // prone and so we no longer put StringShapes in variables unless there is a |
| 6989 | // concrete performance benefit at that particular point in the code. |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 6990 | class StringShape BASE_EMBEDDED { |
| 6991 | public: |
| 6992 | inline explicit StringShape(String* s); |
| 6993 | inline explicit StringShape(Map* s); |
| 6994 | inline explicit StringShape(InstanceType t); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 6995 | inline bool IsSequential(); |
| 6996 | inline bool IsExternal(); |
| 6997 | inline bool IsCons(); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 6998 | inline bool IsSliced(); |
| 6999 | inline bool IsIndirect(); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 7000 | inline bool IsExternalAscii(); |
| 7001 | inline bool IsExternalTwoByte(); |
| 7002 | inline bool IsSequentialAscii(); |
| 7003 | inline bool IsSequentialTwoByte(); |
| 7004 | inline bool IsSymbol(); |
| 7005 | inline StringRepresentationTag representation_tag(); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 7006 | inline uint32_t encoding_tag(); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 7007 | inline uint32_t full_representation_tag(); |
| 7008 | inline uint32_t size_tag(); |
| 7009 | #ifdef DEBUG |
| 7010 | inline uint32_t type() { return type_; } |
| 7011 | inline void invalidate() { valid_ = false; } |
| 7012 | inline bool valid() { return valid_; } |
| 7013 | #else |
| 7014 | inline void invalidate() { } |
| 7015 | #endif |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 7016 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 7017 | private: |
| 7018 | uint32_t type_; |
| 7019 | #ifdef DEBUG |
| 7020 | inline void set_valid() { valid_ = true; } |
| 7021 | bool valid_; |
| 7022 | #else |
| 7023 | inline void set_valid() { } |
| 7024 | #endif |
| 7025 | }; |
| 7026 | |
| 7027 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7028 | // The String abstract class captures JavaScript string values: |
| 7029 | // |
| 7030 | // Ecma-262: |
| 7031 | // 4.3.16 String Value |
| 7032 | // A string value is a member of the type String and is a finite |
| 7033 | // ordered sequence of zero or more 16-bit unsigned integer values. |
| 7034 | // |
| 7035 | // All string values have a length field. |
| 7036 | class String: public HeapObject { |
| 7037 | public: |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 7038 | // Representation of the flat content of a String. |
| 7039 | // A non-flat string doesn't have flat content. |
| 7040 | // A flat string has content that's encoded as a sequence of either |
| 7041 | // ASCII chars or two-byte UC16. |
| 7042 | // Returned by String::GetFlatContent(). |
| 7043 | class FlatContent { |
| 7044 | public: |
| 7045 | // Returns true if the string is flat and this structure contains content. |
| 7046 | bool IsFlat() { return state_ != NON_FLAT; } |
| 7047 | // Returns true if the structure contains ASCII content. |
| 7048 | bool IsAscii() { return state_ == ASCII; } |
| 7049 | // Returns true if the structure contains two-byte content. |
| 7050 | bool IsTwoByte() { return state_ == TWO_BYTE; } |
| 7051 | |
| 7052 | // Return the ASCII content of the string. Only use if IsAscii() returns |
| 7053 | // true. |
| 7054 | Vector<const char> ToAsciiVector() { |
| 7055 | ASSERT_EQ(ASCII, state_); |
| 7056 | return Vector<const char>::cast(buffer_); |
| 7057 | } |
| 7058 | // Return the two-byte content of the string. Only use if IsTwoByte() |
| 7059 | // returns true. |
| 7060 | Vector<const uc16> ToUC16Vector() { |
| 7061 | ASSERT_EQ(TWO_BYTE, state_); |
| 7062 | return Vector<const uc16>::cast(buffer_); |
| 7063 | } |
| 7064 | |
| 7065 | private: |
| 7066 | enum State { NON_FLAT, ASCII, TWO_BYTE }; |
| 7067 | |
| 7068 | // Constructors only used by String::GetFlatContent(). |
| 7069 | explicit FlatContent(Vector<const char> chars) |
| 7070 | : buffer_(Vector<const byte>::cast(chars)), |
| 7071 | state_(ASCII) { } |
| 7072 | explicit FlatContent(Vector<const uc16> chars) |
| 7073 | : buffer_(Vector<const byte>::cast(chars)), |
| 7074 | state_(TWO_BYTE) { } |
| 7075 | FlatContent() : buffer_(), state_(NON_FLAT) { } |
| 7076 | |
| 7077 | Vector<const byte> buffer_; |
| 7078 | State state_; |
| 7079 | |
| 7080 | friend class String; |
| 7081 | }; |
| 7082 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7083 | // Get and set the length of the string. |
| 7084 | inline int length(); |
| 7085 | inline void set_length(int value); |
| 7086 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 7087 | // Get and set the hash field of the string. |
| 7088 | inline uint32_t hash_field(); |
| 7089 | inline void set_hash_field(uint32_t value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7090 | |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 7091 | // Returns whether this string has only ASCII chars, i.e. all of them can |
| 7092 | // be ASCII encoded. This might be the case even if the string is |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 7093 | // two-byte. Such strings may appear when the embedder prefers |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 7094 | // two-byte external representations even for ASCII data. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 7095 | inline bool IsAsciiRepresentation(); |
| 7096 | inline bool IsTwoByteRepresentation(); |
| 7097 | |
| 7098 | // Cons and slices have an encoding flag that may not represent the actual |
| 7099 | // encoding of the underlying string. This is taken into account here. |
| 7100 | // Requires: this->IsFlat() |
| 7101 | inline bool IsAsciiRepresentationUnderneath(); |
| 7102 | inline bool IsTwoByteRepresentationUnderneath(); |
| 7103 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 7104 | // NOTE: this should be considered only a hint. False negatives are |
| 7105 | // possible. |
| 7106 | inline bool HasOnlyAsciiChars(); |
ricow@chromium.org | aa1b616 | 2010-03-29 07:44:58 +0000 | [diff] [blame] | 7107 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7108 | // Get and set individual two byte chars in the string. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 7109 | inline void Set(int index, uint16_t value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7110 | // Get individual two byte char in the string. Repeated calls |
| 7111 | // to this method are not efficient unless the string is flat. |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 7112 | INLINE(uint16_t Get(int index)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7113 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7114 | // Try to flatten the string. Checks first inline to see if it is |
| 7115 | // necessary. Does nothing if the string is not a cons string. |
| 7116 | // Flattening allocates a sequential string with the same data as |
| 7117 | // the given string and mutates the cons string to a degenerate |
| 7118 | // form, where the first component is the new sequential string and |
| 7119 | // the second component is the empty string. If allocation fails, |
| 7120 | // this function returns a failure. If flattening succeeds, this |
| 7121 | // function returns the sequential string that is now the first |
| 7122 | // component of the cons string. |
| 7123 | // |
| 7124 | // Degenerate cons strings are handled specially by the garbage |
| 7125 | // collector (see IsShortcutCandidate). |
| 7126 | // |
| 7127 | // Use FlattenString from Handles.cc to flatten even in case an |
| 7128 | // allocation failure happens. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 7129 | inline MaybeObject* TryFlatten(PretenureFlag pretenure = NOT_TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7130 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7131 | // Convenience function. Has exactly the same behavior as |
| 7132 | // TryFlatten(), except in the case of failure returns the original |
| 7133 | // string. |
| 7134 | inline String* TryFlattenGetString(PretenureFlag pretenure = NOT_TENURED); |
| 7135 | |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 7136 | // Tries to return the content of a flat string as a structure holding either |
| 7137 | // a flat vector of char or of uc16. |
| 7138 | // If the string isn't flat, and therefore doesn't have flat content, the |
| 7139 | // returned structure will report so, and can't provide a vector of either |
| 7140 | // kind. |
| 7141 | FlatContent GetFlatContent(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7142 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 7143 | // Returns the parent of a sliced string or first part of a flat cons string. |
| 7144 | // Requires: StringShape(this).IsIndirect() && this->IsFlat() |
| 7145 | inline String* GetUnderlying(); |
| 7146 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7147 | // Mark the string as an undetectable object. It only applies to |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 7148 | // ASCII and two byte string types. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7149 | bool MarkAsUndetectable(); |
| 7150 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7151 | // Return a substring. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 7152 | MUST_USE_RESULT MaybeObject* SubString(int from, |
| 7153 | int to, |
| 7154 | PretenureFlag pretenure = NOT_TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7155 | |
| 7156 | // String equality operations. |
| 7157 | inline bool Equals(String* other); |
| 7158 | bool IsEqualTo(Vector<const char> str); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 7159 | bool IsAsciiEqualTo(Vector<const char> str); |
| 7160 | bool IsTwoByteEqualTo(Vector<const uc16> str); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7161 | |
| 7162 | // Return a UTF8 representation of the string. The string is null |
| 7163 | // terminated but may optionally contain nulls. Length is returned |
| 7164 | // in length_output if length_output is not a null pointer The string |
| 7165 | // should be nearly flat, otherwise the performance of this method may |
| 7166 | // be very slow (quadratic in the length). Setting robustness_flag to |
| 7167 | // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
| 7168 | // handles unexpected data without causing assert failures and it does not |
| 7169 | // do any heap allocations. This is useful when printing stack traces. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 7170 | SmartArrayPointer<char> ToCString(AllowNullsFlag allow_nulls, |
| 7171 | RobustnessFlag robustness_flag, |
| 7172 | int offset, |
| 7173 | int length, |
| 7174 | int* length_output = 0); |
| 7175 | SmartArrayPointer<char> ToCString( |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7176 | AllowNullsFlag allow_nulls = DISALLOW_NULLS, |
| 7177 | RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL, |
| 7178 | int* length_output = 0); |
| 7179 | |
| 7180 | // Return a 16 bit Unicode representation of the string. |
| 7181 | // The string should be nearly flat, otherwise the performance of |
| 7182 | // of this method may be very bad. Setting robustness_flag to |
| 7183 | // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
| 7184 | // handles unexpected data without causing assert failures and it does not |
| 7185 | // do any heap allocations. This is useful when printing stack traces. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 7186 | SmartArrayPointer<uc16> ToWideCString( |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 7187 | RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7188 | |
| 7189 | // Tells whether the hash code has been computed. |
| 7190 | inline bool HasHashCode(); |
| 7191 | |
| 7192 | // Returns a hash value used for the property table |
| 7193 | inline uint32_t Hash(); |
| 7194 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 7195 | static uint32_t ComputeHashField(unibrow::CharacterStream* buffer, |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 7196 | int length, |
| 7197 | uint32_t seed); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7198 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7199 | static bool ComputeArrayIndex(unibrow::CharacterStream* buffer, |
| 7200 | uint32_t* index, |
| 7201 | int length); |
| 7202 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 7203 | // Externalization. |
| 7204 | bool MakeExternal(v8::String::ExternalStringResource* resource); |
| 7205 | bool MakeExternal(v8::String::ExternalAsciiStringResource* resource); |
| 7206 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7207 | // Conversion. |
| 7208 | inline bool AsArrayIndex(uint32_t* index); |
| 7209 | |
| 7210 | // Casting. |
| 7211 | static inline String* cast(Object* obj); |
| 7212 | |
| 7213 | void PrintOn(FILE* out); |
| 7214 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7215 | // For use during stack traces. Performs rudimentary sanity check. |
| 7216 | bool LooksValid(); |
| 7217 | |
| 7218 | // Dispatched behavior. |
| 7219 | void StringShortPrint(StringStream* accumulator); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7220 | #ifdef OBJECT_PRINT |
| 7221 | inline void StringPrint() { |
| 7222 | StringPrint(stdout); |
| 7223 | } |
| 7224 | void StringPrint(FILE* out); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 7225 | |
| 7226 | char* ToAsciiArray(); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7227 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7228 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7229 | void StringVerify(); |
| 7230 | #endif |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 7231 | inline bool IsFlat(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7232 | |
| 7233 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 7234 | static const int kLengthOffset = HeapObject::kHeaderSize; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 7235 | static const int kHashFieldOffset = kLengthOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 7236 | static const int kSize = kHashFieldOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7237 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 7238 | // Maximum number of characters to consider when trying to convert a string |
| 7239 | // value into an array index. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7240 | static const int kMaxArrayIndexSize = 10; |
| 7241 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 7242 | // Max ASCII char code. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 7243 | static const int kMaxAsciiCharCode = unibrow::Utf8::kMaxOneByteChar; |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 7244 | static const unsigned kMaxAsciiCharCodeU = unibrow::Utf8::kMaxOneByteChar; |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 7245 | static const int kMaxUtf16CodeUnit = 0xffff; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 7246 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7247 | // Mask constant for checking if a string has a computed hash code |
| 7248 | // and if it is an array index. The least significant bit indicates |
| 7249 | // whether a hash code has been computed. If the hash code has been |
| 7250 | // computed the 2nd bit tells whether the string can be used as an |
| 7251 | // array index. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 7252 | static const int kHashNotComputedMask = 1; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 7253 | static const int kIsNotArrayIndexMask = 1 << 1; |
| 7254 | static const int kNofHashBitFields = 2; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7255 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 7256 | // Shift constant retrieving hash code from hash field. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 7257 | static const int kHashShift = kNofHashBitFields; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 7258 | |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 7259 | // Only these bits are relevant in the hash, since the top two are shifted |
| 7260 | // out. |
| 7261 | static const uint32_t kHashBitMask = 0xffffffffu >> kHashShift; |
| 7262 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 7263 | // Array index strings this short can keep their index in the hash |
| 7264 | // field. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 7265 | static const int kMaxCachedArrayIndexLength = 7; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 7266 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 7267 | // For strings which are array indexes the hash value has the string length |
| 7268 | // mixed into the hash, mainly to avoid a hash value of zero which would be |
| 7269 | // the case for the string '0'. 24 bits are used for the array index value. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 7270 | static const int kArrayIndexValueBits = 24; |
| 7271 | static const int kArrayIndexLengthBits = |
| 7272 | kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields; |
| 7273 | |
| 7274 | STATIC_CHECK((kArrayIndexLengthBits > 0)); |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 7275 | STATIC_CHECK(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits)); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 7276 | |
| 7277 | static const int kArrayIndexHashLengthShift = |
| 7278 | kArrayIndexValueBits + kNofHashBitFields; |
| 7279 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 7280 | static const int kArrayIndexHashMask = (1 << kArrayIndexHashLengthShift) - 1; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 7281 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 7282 | static const int kArrayIndexValueMask = |
| 7283 | ((1 << kArrayIndexValueBits) - 1) << kHashShift; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 7284 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 7285 | // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we |
| 7286 | // could use a mask to test if the length of string is less than or equal to |
| 7287 | // kMaxCachedArrayIndexLength. |
| 7288 | STATIC_CHECK(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1)); |
| 7289 | |
| 7290 | static const int kContainsCachedArrayIndexMask = |
| 7291 | (~kMaxCachedArrayIndexLength << kArrayIndexHashLengthShift) | |
| 7292 | kIsNotArrayIndexMask; |
| 7293 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 7294 | // Value of empty hash field indicating that the hash is not computed. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 7295 | static const int kEmptyHashField = |
| 7296 | kIsNotArrayIndexMask | kHashNotComputedMask; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 7297 | |
| 7298 | // Value of hash field containing computed hash equal to zero. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 7299 | static const int kZeroHash = kIsNotArrayIndexMask; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 7300 | |
| 7301 | // Maximal string length. |
| 7302 | static const int kMaxLength = (1 << (32 - 2)) - 1; |
| 7303 | |
| 7304 | // Max length for computing hash. For strings longer than this limit the |
| 7305 | // string length is used as the hash value. |
| 7306 | static const int kMaxHashCalcLength = 16383; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7307 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 7308 | // Limit for truncation in short printing. |
| 7309 | static const int kMaxShortPrintLength = 1024; |
| 7310 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7311 | // Support for regular expressions. |
| 7312 | const uc16* GetTwoByteData(); |
| 7313 | const uc16* GetTwoByteData(unsigned start); |
| 7314 | |
| 7315 | // Support for StringInputBuffer |
| 7316 | static const unibrow::byte* ReadBlock(String* input, |
| 7317 | unibrow::byte* util_buffer, |
| 7318 | unsigned capacity, |
| 7319 | unsigned* remaining, |
| 7320 | unsigned* offset); |
| 7321 | static const unibrow::byte* ReadBlock(String** input, |
| 7322 | unibrow::byte* util_buffer, |
| 7323 | unsigned capacity, |
| 7324 | unsigned* remaining, |
| 7325 | unsigned* offset); |
| 7326 | |
| 7327 | // Helper function for flattening strings. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 7328 | template <typename sinkchar> |
| 7329 | static void WriteToFlat(String* source, |
| 7330 | sinkchar* sink, |
| 7331 | int from, |
| 7332 | int to); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7333 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 7334 | static inline bool IsAscii(const char* chars, int length) { |
| 7335 | const char* limit = chars + length; |
| 7336 | #ifdef V8_HOST_CAN_READ_UNALIGNED |
| 7337 | ASSERT(kMaxAsciiCharCode == 0x7F); |
| 7338 | const uintptr_t non_ascii_mask = kUintptrAllBitsSet / 0xFF * 0x80; |
| 7339 | while (chars <= limit - sizeof(uintptr_t)) { |
| 7340 | if (*reinterpret_cast<const uintptr_t*>(chars) & non_ascii_mask) { |
| 7341 | return false; |
| 7342 | } |
| 7343 | chars += sizeof(uintptr_t); |
| 7344 | } |
| 7345 | #endif |
| 7346 | while (chars < limit) { |
| 7347 | if (static_cast<uint8_t>(*chars) > kMaxAsciiCharCodeU) return false; |
| 7348 | ++chars; |
| 7349 | } |
| 7350 | return true; |
| 7351 | } |
| 7352 | |
| 7353 | static inline bool IsAscii(const uc16* chars, int length) { |
| 7354 | const uc16* limit = chars + length; |
| 7355 | while (chars < limit) { |
| 7356 | if (*chars > kMaxAsciiCharCodeU) return false; |
| 7357 | ++chars; |
| 7358 | } |
| 7359 | return true; |
| 7360 | } |
| 7361 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7362 | protected: |
| 7363 | class ReadBlockBuffer { |
| 7364 | public: |
| 7365 | ReadBlockBuffer(unibrow::byte* util_buffer_, |
| 7366 | unsigned cursor_, |
| 7367 | unsigned capacity_, |
| 7368 | unsigned remaining_) : |
| 7369 | util_buffer(util_buffer_), |
| 7370 | cursor(cursor_), |
| 7371 | capacity(capacity_), |
| 7372 | remaining(remaining_) { |
| 7373 | } |
| 7374 | unibrow::byte* util_buffer; |
| 7375 | unsigned cursor; |
| 7376 | unsigned capacity; |
| 7377 | unsigned remaining; |
| 7378 | }; |
| 7379 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7380 | static inline const unibrow::byte* ReadBlock(String* input, |
| 7381 | ReadBlockBuffer* buffer, |
| 7382 | unsigned* offset, |
| 7383 | unsigned max_chars); |
| 7384 | static void ReadBlockIntoBuffer(String* input, |
| 7385 | ReadBlockBuffer* buffer, |
| 7386 | unsigned* offset_ptr, |
| 7387 | unsigned max_chars); |
| 7388 | |
| 7389 | private: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7390 | // Try to flatten the top level ConsString that is hiding behind this |
| 7391 | // string. This is a no-op unless the string is a ConsString. Flatten |
| 7392 | // mutates the ConsString and might return a failure. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 7393 | MUST_USE_RESULT MaybeObject* SlowTryFlatten(PretenureFlag pretenure); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7394 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 7395 | static inline bool IsHashFieldComputed(uint32_t field); |
| 7396 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7397 | // Slow case of String::Equals. This implementation works on any strings |
| 7398 | // but it is most efficient on strings that are almost flat. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 7399 | bool SlowEquals(String* other); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7400 | |
| 7401 | // Slow case of AsArrayIndex. |
| 7402 | bool SlowAsArrayIndex(uint32_t* index); |
| 7403 | |
| 7404 | // Compute and set the hash code. |
| 7405 | uint32_t ComputeAndSetHash(); |
| 7406 | |
| 7407 | DISALLOW_IMPLICIT_CONSTRUCTORS(String); |
| 7408 | }; |
| 7409 | |
| 7410 | |
| 7411 | // The SeqString abstract class captures sequential string values. |
| 7412 | class SeqString: public String { |
| 7413 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7414 | // Casting. |
| 7415 | static inline SeqString* cast(Object* obj); |
| 7416 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7417 | // Layout description. |
| 7418 | static const int kHeaderSize = String::kSize; |
| 7419 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7420 | private: |
| 7421 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString); |
| 7422 | }; |
| 7423 | |
| 7424 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 7425 | // The AsciiString class captures sequential ASCII string objects. |
| 7426 | // Each character in the AsciiString is an ASCII character. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7427 | class SeqAsciiString: public SeqString { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7428 | public: |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 7429 | static const bool kHasAsciiEncoding = true; |
| 7430 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7431 | // Dispatched behavior. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7432 | inline uint16_t SeqAsciiStringGet(int index); |
| 7433 | inline void SeqAsciiStringSet(int index, uint16_t value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7434 | |
| 7435 | // Get the address of the characters in this string. |
| 7436 | inline Address GetCharsAddress(); |
| 7437 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 7438 | inline char* GetChars(); |
| 7439 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7440 | // Casting |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7441 | static inline SeqAsciiString* cast(Object* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7442 | |
| 7443 | // Garbage collection support. This method is called by the |
| 7444 | // garbage collector to compute the actual size of an AsciiString |
| 7445 | // instance. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 7446 | inline int SeqAsciiStringSize(InstanceType instance_type); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7447 | |
| 7448 | // Computes the size for an AsciiString instance of a given length. |
| 7449 | static int SizeFor(int length) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 7450 | return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7451 | } |
| 7452 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7453 | // Maximal memory usage for a single sequential ASCII string. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7454 | static const int kMaxSize = 512 * MB - 1; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7455 | // Maximal length of a single sequential ASCII string. |
| 7456 | // Q.v. String::kMaxLength which is the maximal size of concatenated strings. |
| 7457 | static const int kMaxLength = (kMaxSize - kHeaderSize); |
| 7458 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7459 | // Support for StringInputBuffer. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7460 | inline void SeqAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 7461 | unsigned* offset, |
| 7462 | unsigned chars); |
| 7463 | inline const unibrow::byte* SeqAsciiStringReadBlock(unsigned* remaining, |
| 7464 | unsigned* offset, |
| 7465 | unsigned chars); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7466 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 7467 | #ifdef DEBUG |
| 7468 | void SeqAsciiStringVerify(); |
| 7469 | #endif |
| 7470 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7471 | private: |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7472 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqAsciiString); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7473 | }; |
| 7474 | |
| 7475 | |
| 7476 | // The TwoByteString class captures sequential unicode string objects. |
| 7477 | // Each character in the TwoByteString is a two-byte uint16_t. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7478 | class SeqTwoByteString: public SeqString { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7479 | public: |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 7480 | static const bool kHasAsciiEncoding = false; |
| 7481 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7482 | // Dispatched behavior. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7483 | inline uint16_t SeqTwoByteStringGet(int index); |
| 7484 | inline void SeqTwoByteStringSet(int index, uint16_t value); |
| 7485 | |
| 7486 | // Get the address of the characters in this string. |
| 7487 | inline Address GetCharsAddress(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7488 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 7489 | inline uc16* GetChars(); |
| 7490 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7491 | // For regexp code. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7492 | const uint16_t* SeqTwoByteStringGetData(unsigned start); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7493 | |
| 7494 | // Casting |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7495 | static inline SeqTwoByteString* cast(Object* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7496 | |
| 7497 | // Garbage collection support. This method is called by the |
| 7498 | // garbage collector to compute the actual size of a TwoByteString |
| 7499 | // instance. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 7500 | inline int SeqTwoByteStringSize(InstanceType instance_type); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7501 | |
| 7502 | // Computes the size for a TwoByteString instance of a given length. |
| 7503 | static int SizeFor(int length) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 7504 | return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7505 | } |
| 7506 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7507 | // Maximal memory usage for a single sequential two-byte string. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7508 | static const int kMaxSize = 512 * MB - 1; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7509 | // Maximal length of a single sequential two-byte string. |
| 7510 | // Q.v. String::kMaxLength which is the maximal size of concatenated strings. |
| 7511 | static const int kMaxLength = (kMaxSize - kHeaderSize) / sizeof(uint16_t); |
| 7512 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7513 | // Support for StringInputBuffer. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7514 | inline void SeqTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 7515 | unsigned* offset_ptr, |
| 7516 | unsigned chars); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7517 | |
| 7518 | private: |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7519 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqTwoByteString); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7520 | }; |
| 7521 | |
| 7522 | |
| 7523 | // The ConsString class describes string values built by using the |
| 7524 | // addition operator on strings. A ConsString is a pair where the |
| 7525 | // first and second components are pointers to other string values. |
| 7526 | // One or both components of a ConsString can be pointers to other |
| 7527 | // ConsStrings, creating a binary tree of ConsStrings where the leaves |
| 7528 | // are non-ConsString string values. The string value represented by |
| 7529 | // a ConsString can be obtained by concatenating the leaf string |
| 7530 | // values in a left-to-right depth-first traversal of the tree. |
| 7531 | class ConsString: public String { |
| 7532 | public: |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 7533 | // First string of the cons cell. |
| 7534 | inline String* first(); |
| 7535 | // Doesn't check that the result is a string, even in debug mode. This is |
| 7536 | // useful during GC where the mark bits confuse the checks. |
| 7537 | inline Object* unchecked_first(); |
| 7538 | inline void set_first(String* first, |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 7539 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7540 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 7541 | // Second string of the cons cell. |
| 7542 | inline String* second(); |
| 7543 | // Doesn't check that the result is a string, even in debug mode. This is |
| 7544 | // useful during GC where the mark bits confuse the checks. |
| 7545 | inline Object* unchecked_second(); |
| 7546 | inline void set_second(String* second, |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 7547 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7548 | |
| 7549 | // Dispatched behavior. |
| 7550 | uint16_t ConsStringGet(int index); |
| 7551 | |
| 7552 | // Casting. |
| 7553 | static inline ConsString* cast(Object* obj); |
| 7554 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7555 | // Layout description. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 7556 | static const int kFirstOffset = POINTER_SIZE_ALIGN(String::kSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7557 | static const int kSecondOffset = kFirstOffset + kPointerSize; |
| 7558 | static const int kSize = kSecondOffset + kPointerSize; |
| 7559 | |
| 7560 | // Support for StringInputBuffer. |
| 7561 | inline const unibrow::byte* ConsStringReadBlock(ReadBlockBuffer* buffer, |
| 7562 | unsigned* offset_ptr, |
| 7563 | unsigned chars); |
| 7564 | inline void ConsStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 7565 | unsigned* offset_ptr, |
| 7566 | unsigned chars); |
| 7567 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 7568 | // Minimum length for a cons string. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7569 | static const int kMinLength = 13; |
| 7570 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 7571 | typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize> |
| 7572 | BodyDescriptor; |
| 7573 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 7574 | #ifdef DEBUG |
| 7575 | void ConsStringVerify(); |
| 7576 | #endif |
| 7577 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7578 | private: |
| 7579 | DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString); |
| 7580 | }; |
| 7581 | |
| 7582 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 7583 | // The Sliced String class describes strings that are substrings of another |
| 7584 | // sequential string. The motivation is to save time and memory when creating |
| 7585 | // a substring. A Sliced String is described as a pointer to the parent, |
| 7586 | // the offset from the start of the parent string and the length. Using |
| 7587 | // a Sliced String therefore requires unpacking of the parent string and |
| 7588 | // adding the offset to the start address. A substring of a Sliced String |
| 7589 | // are not nested since the double indirection is simplified when creating |
| 7590 | // such a substring. |
| 7591 | // Currently missing features are: |
| 7592 | // - handling externalized parent strings |
| 7593 | // - external strings as parent |
| 7594 | // - truncating sliced string to enable otherwise unneeded parent to be GC'ed. |
| 7595 | class SlicedString: public String { |
| 7596 | public: |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 7597 | inline String* parent(); |
| 7598 | inline void set_parent(String* parent); |
| 7599 | inline int offset(); |
| 7600 | inline void set_offset(int offset); |
| 7601 | |
| 7602 | // Dispatched behavior. |
| 7603 | uint16_t SlicedStringGet(int index); |
| 7604 | |
| 7605 | // Casting. |
| 7606 | static inline SlicedString* cast(Object* obj); |
| 7607 | |
| 7608 | // Layout description. |
| 7609 | static const int kParentOffset = POINTER_SIZE_ALIGN(String::kSize); |
| 7610 | static const int kOffsetOffset = kParentOffset + kPointerSize; |
| 7611 | static const int kSize = kOffsetOffset + kPointerSize; |
| 7612 | |
| 7613 | // Support for StringInputBuffer |
| 7614 | inline const unibrow::byte* SlicedStringReadBlock(ReadBlockBuffer* buffer, |
| 7615 | unsigned* offset_ptr, |
| 7616 | unsigned chars); |
| 7617 | inline void SlicedStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 7618 | unsigned* offset_ptr, |
| 7619 | unsigned chars); |
| 7620 | // Minimum length for a sliced string. |
| 7621 | static const int kMinLength = 13; |
| 7622 | |
| 7623 | typedef FixedBodyDescriptor<kParentOffset, |
| 7624 | kOffsetOffset + kPointerSize, kSize> |
| 7625 | BodyDescriptor; |
| 7626 | |
| 7627 | #ifdef DEBUG |
| 7628 | void SlicedStringVerify(); |
| 7629 | #endif |
| 7630 | |
| 7631 | private: |
| 7632 | DISALLOW_IMPLICIT_CONSTRUCTORS(SlicedString); |
| 7633 | }; |
| 7634 | |
| 7635 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7636 | // The ExternalString class describes string values that are backed by |
| 7637 | // a string resource that lies outside the V8 heap. ExternalStrings |
| 7638 | // consist of the length field common to all strings, a pointer to the |
| 7639 | // external resource. It is important to ensure (externally) that the |
| 7640 | // resource is not deallocated while the ExternalString is live in the |
| 7641 | // V8 heap. |
| 7642 | // |
| 7643 | // The API expects that all ExternalStrings are created through the |
| 7644 | // API. Therefore, ExternalStrings should not be used internally. |
| 7645 | class ExternalString: public String { |
| 7646 | public: |
| 7647 | // Casting |
| 7648 | static inline ExternalString* cast(Object* obj); |
| 7649 | |
| 7650 | // Layout description. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 7651 | static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 7652 | static const int kShortSize = kResourceOffset + kPointerSize; |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 7653 | static const int kResourceDataOffset = kResourceOffset + kPointerSize; |
| 7654 | static const int kSize = kResourceDataOffset + kPointerSize; |
| 7655 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 7656 | // Return whether external string is short (data pointer is not cached). |
| 7657 | inline bool is_short(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7658 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 7659 | STATIC_CHECK(kResourceOffset == Internals::kStringResourceOffset); |
| 7660 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7661 | private: |
| 7662 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString); |
| 7663 | }; |
| 7664 | |
| 7665 | |
| 7666 | // The ExternalAsciiString class is an external string backed by an |
| 7667 | // ASCII string. |
| 7668 | class ExternalAsciiString: public ExternalString { |
| 7669 | public: |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 7670 | static const bool kHasAsciiEncoding = true; |
| 7671 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7672 | typedef v8::String::ExternalAsciiStringResource Resource; |
| 7673 | |
| 7674 | // The underlying resource. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7675 | inline const Resource* resource(); |
| 7676 | inline void set_resource(const Resource* buffer); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7677 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 7678 | // Update the pointer cache to the external character array. |
| 7679 | // The cached pointer is always valid, as the external character array does = |
| 7680 | // not move during lifetime. Deserialization is the only exception, after |
| 7681 | // which the pointer cache has to be refreshed. |
| 7682 | inline void update_data_cache(); |
| 7683 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 7684 | inline const char* GetChars(); |
| 7685 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7686 | // Dispatched behavior. |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 7687 | inline uint16_t ExternalAsciiStringGet(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7688 | |
| 7689 | // Casting. |
| 7690 | static inline ExternalAsciiString* cast(Object* obj); |
| 7691 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7692 | // Garbage collection support. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 7693 | inline void ExternalAsciiStringIterateBody(ObjectVisitor* v); |
| 7694 | |
| 7695 | template<typename StaticVisitor> |
| 7696 | inline void ExternalAsciiStringIterateBody(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7697 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7698 | // Support for StringInputBuffer. |
| 7699 | const unibrow::byte* ExternalAsciiStringReadBlock(unsigned* remaining, |
| 7700 | unsigned* offset, |
| 7701 | unsigned chars); |
| 7702 | inline void ExternalAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 7703 | unsigned* offset, |
| 7704 | unsigned chars); |
| 7705 | |
| 7706 | private: |
| 7707 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalAsciiString); |
| 7708 | }; |
| 7709 | |
| 7710 | |
| 7711 | // The ExternalTwoByteString class is an external string backed by a UTF-16 |
| 7712 | // encoded string. |
| 7713 | class ExternalTwoByteString: public ExternalString { |
| 7714 | public: |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 7715 | static const bool kHasAsciiEncoding = false; |
| 7716 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7717 | typedef v8::String::ExternalStringResource Resource; |
| 7718 | |
| 7719 | // The underlying string resource. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7720 | inline const Resource* resource(); |
| 7721 | inline void set_resource(const Resource* buffer); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7722 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 7723 | // Update the pointer cache to the external character array. |
| 7724 | // The cached pointer is always valid, as the external character array does = |
| 7725 | // not move during lifetime. Deserialization is the only exception, after |
| 7726 | // which the pointer cache has to be refreshed. |
| 7727 | inline void update_data_cache(); |
| 7728 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 7729 | inline const uint16_t* GetChars(); |
| 7730 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7731 | // Dispatched behavior. |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 7732 | inline uint16_t ExternalTwoByteStringGet(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7733 | |
| 7734 | // For regexp code. |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 7735 | inline const uint16_t* ExternalTwoByteStringGetData(unsigned start); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7736 | |
| 7737 | // Casting. |
| 7738 | static inline ExternalTwoByteString* cast(Object* obj); |
| 7739 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7740 | // Garbage collection support. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 7741 | inline void ExternalTwoByteStringIterateBody(ObjectVisitor* v); |
| 7742 | |
| 7743 | template<typename StaticVisitor> |
| 7744 | inline void ExternalTwoByteStringIterateBody(); |
| 7745 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7746 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7747 | // Support for StringInputBuffer. |
| 7748 | void ExternalTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 7749 | unsigned* offset_ptr, |
| 7750 | unsigned chars); |
| 7751 | |
| 7752 | private: |
| 7753 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalTwoByteString); |
| 7754 | }; |
| 7755 | |
| 7756 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 7757 | // Utility superclass for stack-allocated objects that must be updated |
| 7758 | // on gc. It provides two ways for the gc to update instances, either |
| 7759 | // iterating or updating after gc. |
| 7760 | class Relocatable BASE_EMBEDDED { |
| 7761 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7762 | explicit inline Relocatable(Isolate* isolate); |
| 7763 | inline virtual ~Relocatable(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 7764 | virtual void IterateInstance(ObjectVisitor* v) { } |
| 7765 | virtual void PostGarbageCollection() { } |
| 7766 | |
| 7767 | static void PostGarbageCollectionProcessing(); |
| 7768 | static int ArchiveSpacePerThread(); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7769 | static char* ArchiveState(Isolate* isolate, char* to); |
| 7770 | static char* RestoreState(Isolate* isolate, char* from); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 7771 | static void Iterate(ObjectVisitor* v); |
| 7772 | static void Iterate(ObjectVisitor* v, Relocatable* top); |
| 7773 | static char* Iterate(ObjectVisitor* v, char* t); |
| 7774 | private: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7775 | Isolate* isolate_; |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 7776 | Relocatable* prev_; |
| 7777 | }; |
| 7778 | |
| 7779 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 7780 | // A flat string reader provides random access to the contents of a |
| 7781 | // string independent of the character width of the string. The handle |
| 7782 | // must be valid as long as the reader is being used. |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 7783 | class FlatStringReader : public Relocatable { |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 7784 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7785 | FlatStringReader(Isolate* isolate, Handle<String> str); |
| 7786 | FlatStringReader(Isolate* isolate, Vector<const char> input); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 7787 | void PostGarbageCollection(); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 7788 | inline uc32 Get(int index); |
| 7789 | int length() { return length_; } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 7790 | private: |
| 7791 | String** str_; |
| 7792 | bool is_ascii_; |
| 7793 | int length_; |
| 7794 | const void* start_; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 7795 | }; |
| 7796 | |
| 7797 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7798 | // Note that StringInputBuffers are not valid across a GC! To fix this |
| 7799 | // it would have to store a String Handle instead of a String* and |
| 7800 | // AsciiStringReadBlock would have to be modified to use memcpy. |
| 7801 | // |
| 7802 | // StringInputBuffer is able to traverse any string regardless of how |
| 7803 | // deeply nested a sequence of ConsStrings it is made of. However, |
| 7804 | // performance will be better if deep strings are flattened before they |
| 7805 | // are traversed. Since flattening requires memory allocation this is |
| 7806 | // not always desirable, however (esp. in debugging situations). |
| 7807 | class StringInputBuffer: public unibrow::InputBuffer<String, String*, 1024> { |
| 7808 | public: |
| 7809 | virtual void Seek(unsigned pos); |
| 7810 | inline StringInputBuffer(): unibrow::InputBuffer<String, String*, 1024>() {} |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 7811 | explicit inline StringInputBuffer(String* backing): |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7812 | unibrow::InputBuffer<String, String*, 1024>(backing) {} |
| 7813 | }; |
| 7814 | |
| 7815 | |
| 7816 | class SafeStringInputBuffer |
| 7817 | : public unibrow::InputBuffer<String, String**, 256> { |
| 7818 | public: |
| 7819 | virtual void Seek(unsigned pos); |
| 7820 | inline SafeStringInputBuffer() |
| 7821 | : unibrow::InputBuffer<String, String**, 256>() {} |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 7822 | explicit inline SafeStringInputBuffer(String** backing) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7823 | : unibrow::InputBuffer<String, String**, 256>(backing) {} |
| 7824 | }; |
| 7825 | |
| 7826 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7827 | template <typename T> |
| 7828 | class VectorIterator { |
| 7829 | public: |
| 7830 | VectorIterator(T* d, int l) : data_(Vector<const T>(d, l)), index_(0) { } |
| 7831 | explicit VectorIterator(Vector<const T> data) : data_(data), index_(0) { } |
| 7832 | T GetNext() { return data_[index_++]; } |
| 7833 | bool has_more() { return index_ < data_.length(); } |
| 7834 | private: |
| 7835 | Vector<const T> data_; |
| 7836 | int index_; |
| 7837 | }; |
| 7838 | |
| 7839 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7840 | // The Oddball describes objects null, undefined, true, and false. |
| 7841 | class Oddball: public HeapObject { |
| 7842 | public: |
| 7843 | // [to_string]: Cached to_string computed at startup. |
| 7844 | DECL_ACCESSORS(to_string, String) |
| 7845 | |
| 7846 | // [to_number]: Cached to_number computed at startup. |
| 7847 | DECL_ACCESSORS(to_number, Object) |
| 7848 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7849 | inline byte kind(); |
| 7850 | inline void set_kind(byte kind); |
| 7851 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7852 | // Casting. |
| 7853 | static inline Oddball* cast(Object* obj); |
| 7854 | |
| 7855 | // Dispatched behavior. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7856 | #ifdef DEBUG |
| 7857 | void OddballVerify(); |
| 7858 | #endif |
| 7859 | |
| 7860 | // Initialize the fields. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 7861 | MUST_USE_RESULT MaybeObject* Initialize(const char* to_string, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7862 | Object* to_number, |
| 7863 | byte kind); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7864 | |
| 7865 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 7866 | static const int kToStringOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7867 | static const int kToNumberOffset = kToStringOffset + kPointerSize; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7868 | static const int kKindOffset = kToNumberOffset + kPointerSize; |
| 7869 | static const int kSize = kKindOffset + kPointerSize; |
| 7870 | |
| 7871 | static const byte kFalse = 0; |
| 7872 | static const byte kTrue = 1; |
| 7873 | static const byte kNotBooleanMask = ~1; |
| 7874 | static const byte kTheHole = 2; |
| 7875 | static const byte kNull = 3; |
| 7876 | static const byte kArgumentMarker = 4; |
| 7877 | static const byte kUndefined = 5; |
| 7878 | static const byte kOther = 6; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7879 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 7880 | typedef FixedBodyDescriptor<kToStringOffset, |
| 7881 | kToNumberOffset + kPointerSize, |
| 7882 | kSize> BodyDescriptor; |
| 7883 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 7884 | STATIC_CHECK(kKindOffset == Internals::kOddballKindOffset); |
| 7885 | STATIC_CHECK(kNull == Internals::kNullOddballKind); |
| 7886 | STATIC_CHECK(kUndefined == Internals::kUndefinedOddballKind); |
| 7887 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7888 | private: |
| 7889 | DISALLOW_IMPLICIT_CONSTRUCTORS(Oddball); |
| 7890 | }; |
| 7891 | |
| 7892 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7893 | class JSGlobalPropertyCell: public HeapObject { |
| 7894 | public: |
| 7895 | // [value]: value of the global property. |
| 7896 | DECL_ACCESSORS(value, Object) |
| 7897 | |
| 7898 | // Casting. |
| 7899 | static inline JSGlobalPropertyCell* cast(Object* obj); |
| 7900 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7901 | #ifdef DEBUG |
| 7902 | void JSGlobalPropertyCellVerify(); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7903 | #endif |
| 7904 | #ifdef OBJECT_PRINT |
| 7905 | inline void JSGlobalPropertyCellPrint() { |
| 7906 | JSGlobalPropertyCellPrint(stdout); |
| 7907 | } |
| 7908 | void JSGlobalPropertyCellPrint(FILE* out); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7909 | #endif |
| 7910 | |
| 7911 | // Layout description. |
| 7912 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 7913 | static const int kSize = kValueOffset + kPointerSize; |
| 7914 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 7915 | typedef FixedBodyDescriptor<kValueOffset, |
| 7916 | kValueOffset + kPointerSize, |
| 7917 | kSize> BodyDescriptor; |
| 7918 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7919 | private: |
| 7920 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalPropertyCell); |
| 7921 | }; |
| 7922 | |
| 7923 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7924 | // The JSProxy describes EcmaScript Harmony proxies |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 7925 | class JSProxy: public JSReceiver { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7926 | public: |
| 7927 | // [handler]: The handler property. |
| 7928 | DECL_ACCESSORS(handler, Object) |
| 7929 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7930 | // [hash]: The hash code property (undefined if not initialized yet). |
| 7931 | DECL_ACCESSORS(hash, Object) |
| 7932 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7933 | // Casting. |
| 7934 | static inline JSProxy* cast(Object* obj); |
| 7935 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 7936 | bool HasPropertyWithHandler(String* name); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7937 | bool HasElementWithHandler(uint32_t index); |
| 7938 | |
| 7939 | MUST_USE_RESULT MaybeObject* GetPropertyWithHandler( |
| 7940 | Object* receiver, |
| 7941 | String* name); |
| 7942 | MUST_USE_RESULT MaybeObject* GetElementWithHandler( |
| 7943 | Object* receiver, |
| 7944 | uint32_t index); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 7945 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 7946 | MUST_USE_RESULT MaybeObject* SetPropertyWithHandler( |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 7947 | JSReceiver* receiver, |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 7948 | String* name, |
| 7949 | Object* value, |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 7950 | PropertyAttributes attributes, |
| 7951 | StrictModeFlag strict_mode); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7952 | MUST_USE_RESULT MaybeObject* SetElementWithHandler( |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 7953 | JSReceiver* receiver, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7954 | uint32_t index, |
| 7955 | Object* value, |
| 7956 | StrictModeFlag strict_mode); |
| 7957 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 7958 | // If the handler defines an accessor property with a setter, invoke it. |
| 7959 | // If it defines an accessor property without a setter, or a data property |
| 7960 | // that is read-only, throw. In all these cases set '*done' to true, |
| 7961 | // otherwise set it to false. |
| 7962 | MUST_USE_RESULT MaybeObject* SetPropertyViaPrototypesWithHandler( |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 7963 | JSReceiver* receiver, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7964 | String* name, |
| 7965 | Object* value, |
| 7966 | PropertyAttributes attributes, |
| 7967 | StrictModeFlag strict_mode, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 7968 | bool* done); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 7969 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 7970 | MUST_USE_RESULT MaybeObject* DeletePropertyWithHandler( |
| 7971 | String* name, |
| 7972 | DeleteMode mode); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7973 | MUST_USE_RESULT MaybeObject* DeleteElementWithHandler( |
| 7974 | uint32_t index, |
| 7975 | DeleteMode mode); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 7976 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 7977 | MUST_USE_RESULT PropertyAttributes GetPropertyAttributeWithHandler( |
| 7978 | JSReceiver* receiver, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7979 | String* name); |
| 7980 | MUST_USE_RESULT PropertyAttributes GetElementAttributeWithHandler( |
| 7981 | JSReceiver* receiver, |
| 7982 | uint32_t index); |
| 7983 | |
| 7984 | MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 7985 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 7986 | // Turn this into an (empty) JSObject. |
| 7987 | void Fix(); |
| 7988 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 7989 | // Initializes the body after the handler slot. |
| 7990 | inline void InitializeBody(int object_size, Object* value); |
| 7991 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7992 | // Invoke a trap by name. If the trap does not exist on this's handler, |
| 7993 | // but derived_trap is non-NULL, invoke that instead. May cause GC. |
| 7994 | Handle<Object> CallTrap(const char* name, |
| 7995 | Handle<Object> derived_trap, |
| 7996 | int argc, |
| 7997 | Handle<Object> args[]); |
| 7998 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7999 | // Dispatched behavior. |
| 8000 | #ifdef OBJECT_PRINT |
| 8001 | inline void JSProxyPrint() { |
| 8002 | JSProxyPrint(stdout); |
| 8003 | } |
| 8004 | void JSProxyPrint(FILE* out); |
| 8005 | #endif |
| 8006 | #ifdef DEBUG |
| 8007 | void JSProxyVerify(); |
| 8008 | #endif |
| 8009 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 8010 | // Layout description. We add padding so that a proxy has the same |
| 8011 | // size as a virgin JSObject. This is essential for becoming a JSObject |
| 8012 | // upon freeze. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 8013 | static const int kHandlerOffset = HeapObject::kHeaderSize; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 8014 | static const int kHashOffset = kHandlerOffset + kPointerSize; |
| 8015 | static const int kPaddingOffset = kHashOffset + kPointerSize; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 8016 | static const int kSize = JSObject::kHeaderSize; |
| 8017 | static const int kHeaderSize = kPaddingOffset; |
| 8018 | static const int kPaddingSize = kSize - kPaddingOffset; |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 8019 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 8020 | STATIC_CHECK(kPaddingSize >= 0); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 8021 | |
| 8022 | typedef FixedBodyDescriptor<kHandlerOffset, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 8023 | kPaddingOffset, |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 8024 | kSize> BodyDescriptor; |
| 8025 | |
| 8026 | private: |
| 8027 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxy); |
| 8028 | }; |
| 8029 | |
| 8030 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 8031 | class JSFunctionProxy: public JSProxy { |
| 8032 | public: |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 8033 | // [call_trap]: The call trap. |
| 8034 | DECL_ACCESSORS(call_trap, Object) |
| 8035 | |
| 8036 | // [construct_trap]: The construct trap. |
| 8037 | DECL_ACCESSORS(construct_trap, Object) |
| 8038 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 8039 | // Casting. |
| 8040 | static inline JSFunctionProxy* cast(Object* obj); |
| 8041 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 8042 | // Dispatched behavior. |
| 8043 | #ifdef OBJECT_PRINT |
| 8044 | inline void JSFunctionProxyPrint() { |
| 8045 | JSFunctionProxyPrint(stdout); |
| 8046 | } |
| 8047 | void JSFunctionProxyPrint(FILE* out); |
| 8048 | #endif |
| 8049 | #ifdef DEBUG |
| 8050 | void JSFunctionProxyVerify(); |
| 8051 | #endif |
| 8052 | |
| 8053 | // Layout description. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 8054 | static const int kCallTrapOffset = JSProxy::kPaddingOffset; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 8055 | static const int kConstructTrapOffset = kCallTrapOffset + kPointerSize; |
| 8056 | static const int kPaddingOffset = kConstructTrapOffset + kPointerSize; |
| 8057 | static const int kSize = JSFunction::kSize; |
| 8058 | static const int kPaddingSize = kSize - kPaddingOffset; |
| 8059 | |
| 8060 | STATIC_CHECK(kPaddingSize >= 0); |
| 8061 | |
| 8062 | typedef FixedBodyDescriptor<kHandlerOffset, |
| 8063 | kConstructTrapOffset + kPointerSize, |
| 8064 | kSize> BodyDescriptor; |
| 8065 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 8066 | private: |
| 8067 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunctionProxy); |
| 8068 | }; |
| 8069 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 8070 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 8071 | // The JSSet describes EcmaScript Harmony sets |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 8072 | class JSSet: public JSObject { |
| 8073 | public: |
| 8074 | // [set]: the backing hash set containing keys. |
| 8075 | DECL_ACCESSORS(table, Object) |
| 8076 | |
| 8077 | // Casting. |
| 8078 | static inline JSSet* cast(Object* obj); |
| 8079 | |
| 8080 | #ifdef OBJECT_PRINT |
| 8081 | inline void JSSetPrint() { |
| 8082 | JSSetPrint(stdout); |
| 8083 | } |
| 8084 | void JSSetPrint(FILE* out); |
| 8085 | #endif |
| 8086 | #ifdef DEBUG |
| 8087 | void JSSetVerify(); |
| 8088 | #endif |
| 8089 | |
| 8090 | static const int kTableOffset = JSObject::kHeaderSize; |
| 8091 | static const int kSize = kTableOffset + kPointerSize; |
| 8092 | |
| 8093 | private: |
| 8094 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSSet); |
| 8095 | }; |
| 8096 | |
| 8097 | |
| 8098 | // The JSMap describes EcmaScript Harmony maps |
| 8099 | class JSMap: public JSObject { |
| 8100 | public: |
| 8101 | // [table]: the backing hash table mapping keys to values. |
| 8102 | DECL_ACCESSORS(table, Object) |
| 8103 | |
| 8104 | // Casting. |
| 8105 | static inline JSMap* cast(Object* obj); |
| 8106 | |
| 8107 | #ifdef OBJECT_PRINT |
| 8108 | inline void JSMapPrint() { |
| 8109 | JSMapPrint(stdout); |
| 8110 | } |
| 8111 | void JSMapPrint(FILE* out); |
| 8112 | #endif |
| 8113 | #ifdef DEBUG |
| 8114 | void JSMapVerify(); |
| 8115 | #endif |
| 8116 | |
| 8117 | static const int kTableOffset = JSObject::kHeaderSize; |
| 8118 | static const int kSize = kTableOffset + kPointerSize; |
| 8119 | |
| 8120 | private: |
| 8121 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSMap); |
| 8122 | }; |
| 8123 | |
| 8124 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 8125 | // The JSWeakMap describes EcmaScript Harmony weak maps |
| 8126 | class JSWeakMap: public JSObject { |
| 8127 | public: |
| 8128 | // [table]: the backing hash table mapping keys to values. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 8129 | DECL_ACCESSORS(table, Object) |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 8130 | |
| 8131 | // [next]: linked list of encountered weak maps during GC. |
| 8132 | DECL_ACCESSORS(next, Object) |
| 8133 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 8134 | // Casting. |
| 8135 | static inline JSWeakMap* cast(Object* obj); |
| 8136 | |
| 8137 | #ifdef OBJECT_PRINT |
| 8138 | inline void JSWeakMapPrint() { |
| 8139 | JSWeakMapPrint(stdout); |
| 8140 | } |
| 8141 | void JSWeakMapPrint(FILE* out); |
| 8142 | #endif |
| 8143 | #ifdef DEBUG |
| 8144 | void JSWeakMapVerify(); |
| 8145 | #endif |
| 8146 | |
| 8147 | static const int kTableOffset = JSObject::kHeaderSize; |
| 8148 | static const int kNextOffset = kTableOffset + kPointerSize; |
| 8149 | static const int kSize = kNextOffset + kPointerSize; |
| 8150 | |
| 8151 | private: |
| 8152 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakMap); |
| 8153 | }; |
| 8154 | |
| 8155 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 8156 | // Foreign describes objects pointing from JavaScript to C structures. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 8157 | // Since they cannot contain references to JS HeapObjects they can be |
| 8158 | // placed in old_data_space. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 8159 | class Foreign: public HeapObject { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8160 | public: |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 8161 | // [address]: field containing the address. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 8162 | inline Address foreign_address(); |
| 8163 | inline void set_foreign_address(Address value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8164 | |
| 8165 | // Casting. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 8166 | static inline Foreign* cast(Object* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8167 | |
| 8168 | // Dispatched behavior. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 8169 | inline void ForeignIterateBody(ObjectVisitor* v); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 8170 | |
| 8171 | template<typename StaticVisitor> |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 8172 | inline void ForeignIterateBody(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 8173 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8174 | #ifdef OBJECT_PRINT |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 8175 | inline void ForeignPrint() { |
| 8176 | ForeignPrint(stdout); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8177 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 8178 | void ForeignPrint(FILE* out); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8179 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8180 | #ifdef DEBUG |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 8181 | void ForeignVerify(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8182 | #endif |
| 8183 | |
| 8184 | // Layout description. |
| 8185 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 8186 | static const int kForeignAddressOffset = HeapObject::kHeaderSize; |
| 8187 | static const int kSize = kForeignAddressOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8188 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 8189 | STATIC_CHECK(kForeignAddressOffset == Internals::kForeignAddressOffset); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 8190 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8191 | private: |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 8192 | DISALLOW_IMPLICIT_CONSTRUCTORS(Foreign); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8193 | }; |
| 8194 | |
| 8195 | |
| 8196 | // The JSArray describes JavaScript Arrays |
| 8197 | // Such an array can be in one of two modes: |
| 8198 | // - fast, backing storage is a FixedArray and length <= elements.length(); |
| 8199 | // Please note: push and pop can be used to grow and shrink the array. |
| 8200 | // - slow, backing storage is a HashTable with numbers as keys. |
| 8201 | class JSArray: public JSObject { |
| 8202 | public: |
| 8203 | // [length]: The length property. |
| 8204 | DECL_ACCESSORS(length, Object) |
| 8205 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 8206 | // Overload the length setter to skip write barrier when the length |
| 8207 | // is set to a smi. This matches the set function on FixedArray. |
| 8208 | inline void set_length(Smi* length); |
| 8209 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 8210 | MUST_USE_RESULT MaybeObject* JSArrayUpdateLengthFromIndex(uint32_t index, |
| 8211 | Object* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8212 | |
| 8213 | // Initialize the array with the given capacity. The function may |
| 8214 | // fail due to out-of-memory situations, but only if the requested |
| 8215 | // capacity is non-zero. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 8216 | MUST_USE_RESULT MaybeObject* Initialize(int capacity); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8217 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 8218 | // Initializes the array to a certain length. |
| 8219 | inline bool AllowsSetElementsLength(); |
| 8220 | MUST_USE_RESULT MaybeObject* SetElementsLength(Object* length); |
| 8221 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8222 | // Set the content of the array to the content of storage. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 8223 | MUST_USE_RESULT inline MaybeObject* SetContent(FixedArrayBase* storage); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8224 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8225 | // Casting. |
| 8226 | static inline JSArray* cast(Object* obj); |
| 8227 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 8228 | // Uses handles. Ensures that the fixed array backing the JSArray has at |
| 8229 | // least the stated size. |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 8230 | inline void EnsureSize(int minimum_size_of_backing_fixed_array); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 8231 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8232 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8233 | #ifdef OBJECT_PRINT |
| 8234 | inline void JSArrayPrint() { |
| 8235 | JSArrayPrint(stdout); |
| 8236 | } |
| 8237 | void JSArrayPrint(FILE* out); |
| 8238 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8239 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8240 | void JSArrayVerify(); |
| 8241 | #endif |
| 8242 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 8243 | // Number of element slots to pre-allocate for an empty array. |
| 8244 | static const int kPreallocatedArrayElements = 4; |
| 8245 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8246 | // Layout description. |
| 8247 | static const int kLengthOffset = JSObject::kHeaderSize; |
| 8248 | static const int kSize = kLengthOffset + kPointerSize; |
| 8249 | |
| 8250 | private: |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 8251 | // Expand the fixed array backing of a fast-case JSArray to at least |
| 8252 | // the requested size. |
| 8253 | void Expand(int minimum_size_of_backing_fixed_array); |
| 8254 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8255 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSArray); |
| 8256 | }; |
| 8257 | |
| 8258 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 8259 | // JSRegExpResult is just a JSArray with a specific initial map. |
| 8260 | // This initial map adds in-object properties for "index" and "input" |
| 8261 | // properties, as assigned by RegExp.prototype.exec, which allows |
| 8262 | // faster creation of RegExp exec results. |
| 8263 | // This class just holds constants used when creating the result. |
| 8264 | // After creation the result must be treated as a JSArray in all regards. |
| 8265 | class JSRegExpResult: public JSArray { |
| 8266 | public: |
| 8267 | // Offsets of object fields. |
| 8268 | static const int kIndexOffset = JSArray::kSize; |
| 8269 | static const int kInputOffset = kIndexOffset + kPointerSize; |
| 8270 | static const int kSize = kInputOffset + kPointerSize; |
| 8271 | // Indices of in-object properties. |
| 8272 | static const int kIndexIndex = 0; |
| 8273 | static const int kInputIndex = 1; |
| 8274 | private: |
| 8275 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSRegExpResult); |
| 8276 | }; |
| 8277 | |
| 8278 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 8279 | // An accessor must have a getter, but can have no setter. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8280 | // |
| 8281 | // When setting a property, V8 searches accessors in prototypes. |
| 8282 | // If an accessor was found and it does not have a setter, |
| 8283 | // the request is ignored. |
| 8284 | // |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8285 | // If the accessor in the prototype has the READ_ONLY property attribute, then |
| 8286 | // a new value is added to the local object when the property is set. |
| 8287 | // This shadows the accessor in the prototype. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8288 | class AccessorInfo: public Struct { |
| 8289 | public: |
| 8290 | DECL_ACCESSORS(getter, Object) |
| 8291 | DECL_ACCESSORS(setter, Object) |
| 8292 | DECL_ACCESSORS(data, Object) |
| 8293 | DECL_ACCESSORS(name, Object) |
| 8294 | DECL_ACCESSORS(flag, Smi) |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 8295 | DECL_ACCESSORS(expected_receiver_type, Object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8296 | |
| 8297 | inline bool all_can_read(); |
| 8298 | inline void set_all_can_read(bool value); |
| 8299 | |
| 8300 | inline bool all_can_write(); |
| 8301 | inline void set_all_can_write(bool value); |
| 8302 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 8303 | inline bool prohibits_overwriting(); |
| 8304 | inline void set_prohibits_overwriting(bool value); |
| 8305 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8306 | inline PropertyAttributes property_attributes(); |
| 8307 | inline void set_property_attributes(PropertyAttributes attributes); |
| 8308 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 8309 | // Checks whether the given receiver is compatible with this accessor. |
| 8310 | inline bool IsCompatibleReceiver(Object* receiver); |
| 8311 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8312 | static inline AccessorInfo* cast(Object* obj); |
| 8313 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8314 | #ifdef OBJECT_PRINT |
| 8315 | inline void AccessorInfoPrint() { |
| 8316 | AccessorInfoPrint(stdout); |
| 8317 | } |
| 8318 | void AccessorInfoPrint(FILE* out); |
| 8319 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8320 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8321 | void AccessorInfoVerify(); |
| 8322 | #endif |
| 8323 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 8324 | static const int kGetterOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8325 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 8326 | static const int kDataOffset = kSetterOffset + kPointerSize; |
| 8327 | static const int kNameOffset = kDataOffset + kPointerSize; |
| 8328 | static const int kFlagOffset = kNameOffset + kPointerSize; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 8329 | static const int kExpectedReceiverTypeOffset = kFlagOffset + kPointerSize; |
| 8330 | static const int kSize = kExpectedReceiverTypeOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8331 | |
| 8332 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8333 | // Bit positions in flag. |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 8334 | static const int kAllCanReadBit = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8335 | static const int kAllCanWriteBit = 1; |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 8336 | static const int kProhibitsOverwritingBit = 2; |
| 8337 | class AttributesField: public BitField<PropertyAttributes, 3, 3> {}; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 8338 | |
| 8339 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorInfo); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8340 | }; |
| 8341 | |
| 8342 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 8343 | // Support for JavaScript accessors: A pair of a getter and a setter. Each |
| 8344 | // accessor can either be |
| 8345 | // * a pointer to a JavaScript function or proxy: a real accessor |
| 8346 | // * undefined: considered an accessor by the spec, too, strangely enough |
| 8347 | // * the hole: an accessor which has not been set |
| 8348 | // * a pointer to a map: a transition used to ensure map sharing |
| 8349 | class AccessorPair: public Struct { |
| 8350 | public: |
| 8351 | DECL_ACCESSORS(getter, Object) |
| 8352 | DECL_ACCESSORS(setter, Object) |
| 8353 | |
| 8354 | static inline AccessorPair* cast(Object* obj); |
| 8355 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame^] | 8356 | MUST_USE_RESULT MaybeObject* Copy(); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 8357 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 8358 | Object* get(AccessorComponent component) { |
| 8359 | return component == ACCESSOR_GETTER ? getter() : setter(); |
| 8360 | } |
| 8361 | |
| 8362 | void set(AccessorComponent component, Object* value) { |
| 8363 | if (component == ACCESSOR_GETTER) { |
| 8364 | set_getter(value); |
| 8365 | } else { |
| 8366 | set_setter(value); |
| 8367 | } |
| 8368 | } |
| 8369 | |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 8370 | // Note: Returns undefined instead in case of a hole. |
| 8371 | Object* GetComponent(AccessorComponent component); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 8372 | |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 8373 | // Set both components, skipping arguments which are a JavaScript null. |
| 8374 | void SetComponents(Object* getter, Object* setter) { |
| 8375 | if (!getter->IsNull()) set_getter(getter); |
| 8376 | if (!setter->IsNull()) set_setter(setter); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 8377 | } |
| 8378 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 8379 | bool ContainsAccessor() { |
| 8380 | return IsJSAccessor(getter()) || IsJSAccessor(setter()); |
| 8381 | } |
| 8382 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 8383 | #ifdef OBJECT_PRINT |
| 8384 | void AccessorPairPrint(FILE* out = stdout); |
| 8385 | #endif |
| 8386 | #ifdef DEBUG |
| 8387 | void AccessorPairVerify(); |
| 8388 | #endif |
| 8389 | |
| 8390 | static const int kGetterOffset = HeapObject::kHeaderSize; |
| 8391 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 8392 | static const int kSize = kSetterOffset + kPointerSize; |
| 8393 | |
| 8394 | private: |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 8395 | // Strangely enough, in addition to functions and harmony proxies, the spec |
| 8396 | // requires us to consider undefined as a kind of accessor, too: |
| 8397 | // var obj = {}; |
| 8398 | // Object.defineProperty(obj, "foo", {get: undefined}); |
| 8399 | // assertTrue("foo" in obj); |
| 8400 | bool IsJSAccessor(Object* obj) { |
| 8401 | return obj->IsSpecFunction() || obj->IsUndefined(); |
| 8402 | } |
| 8403 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 8404 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorPair); |
| 8405 | }; |
| 8406 | |
| 8407 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8408 | class AccessCheckInfo: public Struct { |
| 8409 | public: |
| 8410 | DECL_ACCESSORS(named_callback, Object) |
| 8411 | DECL_ACCESSORS(indexed_callback, Object) |
| 8412 | DECL_ACCESSORS(data, Object) |
| 8413 | |
| 8414 | static inline AccessCheckInfo* cast(Object* obj); |
| 8415 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8416 | #ifdef OBJECT_PRINT |
| 8417 | inline void AccessCheckInfoPrint() { |
| 8418 | AccessCheckInfoPrint(stdout); |
| 8419 | } |
| 8420 | void AccessCheckInfoPrint(FILE* out); |
| 8421 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8422 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8423 | void AccessCheckInfoVerify(); |
| 8424 | #endif |
| 8425 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 8426 | static const int kNamedCallbackOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8427 | static const int kIndexedCallbackOffset = kNamedCallbackOffset + kPointerSize; |
| 8428 | static const int kDataOffset = kIndexedCallbackOffset + kPointerSize; |
| 8429 | static const int kSize = kDataOffset + kPointerSize; |
| 8430 | |
| 8431 | private: |
| 8432 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessCheckInfo); |
| 8433 | }; |
| 8434 | |
| 8435 | |
| 8436 | class InterceptorInfo: public Struct { |
| 8437 | public: |
| 8438 | DECL_ACCESSORS(getter, Object) |
| 8439 | DECL_ACCESSORS(setter, Object) |
| 8440 | DECL_ACCESSORS(query, Object) |
| 8441 | DECL_ACCESSORS(deleter, Object) |
| 8442 | DECL_ACCESSORS(enumerator, Object) |
| 8443 | DECL_ACCESSORS(data, Object) |
| 8444 | |
| 8445 | static inline InterceptorInfo* cast(Object* obj); |
| 8446 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8447 | #ifdef OBJECT_PRINT |
| 8448 | inline void InterceptorInfoPrint() { |
| 8449 | InterceptorInfoPrint(stdout); |
| 8450 | } |
| 8451 | void InterceptorInfoPrint(FILE* out); |
| 8452 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8453 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8454 | void InterceptorInfoVerify(); |
| 8455 | #endif |
| 8456 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 8457 | static const int kGetterOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8458 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 8459 | static const int kQueryOffset = kSetterOffset + kPointerSize; |
| 8460 | static const int kDeleterOffset = kQueryOffset + kPointerSize; |
| 8461 | static const int kEnumeratorOffset = kDeleterOffset + kPointerSize; |
| 8462 | static const int kDataOffset = kEnumeratorOffset + kPointerSize; |
| 8463 | static const int kSize = kDataOffset + kPointerSize; |
| 8464 | |
| 8465 | private: |
| 8466 | DISALLOW_IMPLICIT_CONSTRUCTORS(InterceptorInfo); |
| 8467 | }; |
| 8468 | |
| 8469 | |
| 8470 | class CallHandlerInfo: public Struct { |
| 8471 | public: |
| 8472 | DECL_ACCESSORS(callback, Object) |
| 8473 | DECL_ACCESSORS(data, Object) |
| 8474 | |
| 8475 | static inline CallHandlerInfo* cast(Object* obj); |
| 8476 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8477 | #ifdef OBJECT_PRINT |
| 8478 | inline void CallHandlerInfoPrint() { |
| 8479 | CallHandlerInfoPrint(stdout); |
| 8480 | } |
| 8481 | void CallHandlerInfoPrint(FILE* out); |
| 8482 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8483 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8484 | void CallHandlerInfoVerify(); |
| 8485 | #endif |
| 8486 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 8487 | static const int kCallbackOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8488 | static const int kDataOffset = kCallbackOffset + kPointerSize; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 8489 | static const int kSize = kDataOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8490 | |
| 8491 | private: |
| 8492 | DISALLOW_IMPLICIT_CONSTRUCTORS(CallHandlerInfo); |
| 8493 | }; |
| 8494 | |
| 8495 | |
| 8496 | class TemplateInfo: public Struct { |
| 8497 | public: |
| 8498 | DECL_ACCESSORS(tag, Object) |
| 8499 | DECL_ACCESSORS(property_list, Object) |
| 8500 | |
| 8501 | #ifdef DEBUG |
| 8502 | void TemplateInfoVerify(); |
| 8503 | #endif |
| 8504 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 8505 | static const int kTagOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8506 | static const int kPropertyListOffset = kTagOffset + kPointerSize; |
| 8507 | static const int kHeaderSize = kPropertyListOffset + kPointerSize; |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 8508 | |
| 8509 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8510 | DISALLOW_IMPLICIT_CONSTRUCTORS(TemplateInfo); |
| 8511 | }; |
| 8512 | |
| 8513 | |
| 8514 | class FunctionTemplateInfo: public TemplateInfo { |
| 8515 | public: |
| 8516 | DECL_ACCESSORS(serial_number, Object) |
| 8517 | DECL_ACCESSORS(call_code, Object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8518 | DECL_ACCESSORS(property_accessors, Object) |
| 8519 | DECL_ACCESSORS(prototype_template, Object) |
| 8520 | DECL_ACCESSORS(parent_template, Object) |
| 8521 | DECL_ACCESSORS(named_property_handler, Object) |
| 8522 | DECL_ACCESSORS(indexed_property_handler, Object) |
| 8523 | DECL_ACCESSORS(instance_template, Object) |
| 8524 | DECL_ACCESSORS(class_name, Object) |
| 8525 | DECL_ACCESSORS(signature, Object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8526 | DECL_ACCESSORS(instance_call_handler, Object) |
| 8527 | DECL_ACCESSORS(access_check_info, Object) |
| 8528 | DECL_ACCESSORS(flag, Smi) |
| 8529 | |
| 8530 | // Following properties use flag bits. |
| 8531 | DECL_BOOLEAN_ACCESSORS(hidden_prototype) |
| 8532 | DECL_BOOLEAN_ACCESSORS(undetectable) |
| 8533 | // If the bit is set, object instances created by this function |
| 8534 | // requires access check. |
| 8535 | DECL_BOOLEAN_ACCESSORS(needs_access_check) |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 8536 | DECL_BOOLEAN_ACCESSORS(read_only_prototype) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8537 | |
| 8538 | static inline FunctionTemplateInfo* cast(Object* obj); |
| 8539 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8540 | #ifdef OBJECT_PRINT |
| 8541 | inline void FunctionTemplateInfoPrint() { |
| 8542 | FunctionTemplateInfoPrint(stdout); |
| 8543 | } |
| 8544 | void FunctionTemplateInfoPrint(FILE* out); |
| 8545 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8546 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8547 | void FunctionTemplateInfoVerify(); |
| 8548 | #endif |
| 8549 | |
| 8550 | static const int kSerialNumberOffset = TemplateInfo::kHeaderSize; |
| 8551 | static const int kCallCodeOffset = kSerialNumberOffset + kPointerSize; |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 8552 | static const int kPropertyAccessorsOffset = kCallCodeOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8553 | static const int kPrototypeTemplateOffset = |
| 8554 | kPropertyAccessorsOffset + kPointerSize; |
| 8555 | static const int kParentTemplateOffset = |
| 8556 | kPrototypeTemplateOffset + kPointerSize; |
| 8557 | static const int kNamedPropertyHandlerOffset = |
| 8558 | kParentTemplateOffset + kPointerSize; |
| 8559 | static const int kIndexedPropertyHandlerOffset = |
| 8560 | kNamedPropertyHandlerOffset + kPointerSize; |
| 8561 | static const int kInstanceTemplateOffset = |
| 8562 | kIndexedPropertyHandlerOffset + kPointerSize; |
| 8563 | static const int kClassNameOffset = kInstanceTemplateOffset + kPointerSize; |
| 8564 | static const int kSignatureOffset = kClassNameOffset + kPointerSize; |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 8565 | static const int kInstanceCallHandlerOffset = kSignatureOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8566 | static const int kAccessCheckInfoOffset = |
| 8567 | kInstanceCallHandlerOffset + kPointerSize; |
| 8568 | static const int kFlagOffset = kAccessCheckInfoOffset + kPointerSize; |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 8569 | static const int kSize = kFlagOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8570 | |
| 8571 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8572 | // Bit position in the flag, from least significant bit position. |
| 8573 | static const int kHiddenPrototypeBit = 0; |
| 8574 | static const int kUndetectableBit = 1; |
| 8575 | static const int kNeedsAccessCheckBit = 2; |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 8576 | static const int kReadOnlyPrototypeBit = 3; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 8577 | |
| 8578 | DISALLOW_IMPLICIT_CONSTRUCTORS(FunctionTemplateInfo); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8579 | }; |
| 8580 | |
| 8581 | |
| 8582 | class ObjectTemplateInfo: public TemplateInfo { |
| 8583 | public: |
| 8584 | DECL_ACCESSORS(constructor, Object) |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 8585 | DECL_ACCESSORS(internal_field_count, Object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8586 | |
| 8587 | static inline ObjectTemplateInfo* cast(Object* obj); |
| 8588 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8589 | #ifdef OBJECT_PRINT |
| 8590 | inline void ObjectTemplateInfoPrint() { |
| 8591 | ObjectTemplateInfoPrint(stdout); |
| 8592 | } |
| 8593 | void ObjectTemplateInfoPrint(FILE* out); |
| 8594 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8595 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8596 | void ObjectTemplateInfoVerify(); |
| 8597 | #endif |
| 8598 | |
| 8599 | static const int kConstructorOffset = TemplateInfo::kHeaderSize; |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 8600 | static const int kInternalFieldCountOffset = |
| 8601 | kConstructorOffset + kPointerSize; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 8602 | static const int kSize = kInternalFieldCountOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8603 | }; |
| 8604 | |
| 8605 | |
| 8606 | class SignatureInfo: public Struct { |
| 8607 | public: |
| 8608 | DECL_ACCESSORS(receiver, Object) |
| 8609 | DECL_ACCESSORS(args, Object) |
| 8610 | |
| 8611 | static inline SignatureInfo* cast(Object* obj); |
| 8612 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8613 | #ifdef OBJECT_PRINT |
| 8614 | inline void SignatureInfoPrint() { |
| 8615 | SignatureInfoPrint(stdout); |
| 8616 | } |
| 8617 | void SignatureInfoPrint(FILE* out); |
| 8618 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8619 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8620 | void SignatureInfoVerify(); |
| 8621 | #endif |
| 8622 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 8623 | static const int kReceiverOffset = Struct::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8624 | static const int kArgsOffset = kReceiverOffset + kPointerSize; |
| 8625 | static const int kSize = kArgsOffset + kPointerSize; |
| 8626 | |
| 8627 | private: |
| 8628 | DISALLOW_IMPLICIT_CONSTRUCTORS(SignatureInfo); |
| 8629 | }; |
| 8630 | |
| 8631 | |
| 8632 | class TypeSwitchInfo: public Struct { |
| 8633 | public: |
| 8634 | DECL_ACCESSORS(types, Object) |
| 8635 | |
| 8636 | static inline TypeSwitchInfo* cast(Object* obj); |
| 8637 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8638 | #ifdef OBJECT_PRINT |
| 8639 | inline void TypeSwitchInfoPrint() { |
| 8640 | TypeSwitchInfoPrint(stdout); |
| 8641 | } |
| 8642 | void TypeSwitchInfoPrint(FILE* out); |
| 8643 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8644 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8645 | void TypeSwitchInfoVerify(); |
| 8646 | #endif |
| 8647 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 8648 | static const int kTypesOffset = Struct::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8649 | static const int kSize = kTypesOffset + kPointerSize; |
| 8650 | }; |
| 8651 | |
| 8652 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 8653 | #ifdef ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 8654 | // The DebugInfo class holds additional information for a function being |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8655 | // debugged. |
| 8656 | class DebugInfo: public Struct { |
| 8657 | public: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 8658 | // The shared function info for the source being debugged. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8659 | DECL_ACCESSORS(shared, SharedFunctionInfo) |
| 8660 | // Code object for the original code. |
| 8661 | DECL_ACCESSORS(original_code, Code) |
| 8662 | // Code object for the patched code. This code object is the code object |
| 8663 | // currently active for the function. |
| 8664 | DECL_ACCESSORS(code, Code) |
| 8665 | // Fixed array holding status information for each active break point. |
| 8666 | DECL_ACCESSORS(break_points, FixedArray) |
| 8667 | |
| 8668 | // Check if there is a break point at a code position. |
| 8669 | bool HasBreakPoint(int code_position); |
| 8670 | // Get the break point info object for a code position. |
| 8671 | Object* GetBreakPointInfo(int code_position); |
| 8672 | // Clear a break point. |
| 8673 | static void ClearBreakPoint(Handle<DebugInfo> debug_info, |
| 8674 | int code_position, |
| 8675 | Handle<Object> break_point_object); |
| 8676 | // Set a break point. |
| 8677 | static void SetBreakPoint(Handle<DebugInfo> debug_info, int code_position, |
| 8678 | int source_position, int statement_position, |
| 8679 | Handle<Object> break_point_object); |
| 8680 | // Get the break point objects for a code position. |
| 8681 | Object* GetBreakPointObjects(int code_position); |
| 8682 | // Find the break point info holding this break point object. |
| 8683 | static Object* FindBreakPointInfo(Handle<DebugInfo> debug_info, |
| 8684 | Handle<Object> break_point_object); |
| 8685 | // Get the number of break points for this function. |
| 8686 | int GetBreakPointCount(); |
| 8687 | |
| 8688 | static inline DebugInfo* cast(Object* obj); |
| 8689 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8690 | #ifdef OBJECT_PRINT |
| 8691 | inline void DebugInfoPrint() { |
| 8692 | DebugInfoPrint(stdout); |
| 8693 | } |
| 8694 | void DebugInfoPrint(FILE* out); |
| 8695 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8696 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8697 | void DebugInfoVerify(); |
| 8698 | #endif |
| 8699 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 8700 | static const int kSharedFunctionInfoIndex = Struct::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8701 | static const int kOriginalCodeIndex = kSharedFunctionInfoIndex + kPointerSize; |
| 8702 | static const int kPatchedCodeIndex = kOriginalCodeIndex + kPointerSize; |
| 8703 | static const int kActiveBreakPointsCountIndex = |
| 8704 | kPatchedCodeIndex + kPointerSize; |
| 8705 | static const int kBreakPointsStateIndex = |
| 8706 | kActiveBreakPointsCountIndex + kPointerSize; |
| 8707 | static const int kSize = kBreakPointsStateIndex + kPointerSize; |
| 8708 | |
| 8709 | private: |
| 8710 | static const int kNoBreakPointInfo = -1; |
| 8711 | |
| 8712 | // Lookup the index in the break_points array for a code position. |
| 8713 | int GetBreakPointInfoIndex(int code_position); |
| 8714 | |
| 8715 | DISALLOW_IMPLICIT_CONSTRUCTORS(DebugInfo); |
| 8716 | }; |
| 8717 | |
| 8718 | |
| 8719 | // The BreakPointInfo class holds information for break points set in a |
| 8720 | // function. The DebugInfo object holds a BreakPointInfo object for each code |
| 8721 | // position with one or more break points. |
| 8722 | class BreakPointInfo: public Struct { |
| 8723 | public: |
| 8724 | // The position in the code for the break point. |
| 8725 | DECL_ACCESSORS(code_position, Smi) |
| 8726 | // The position in the source for the break position. |
| 8727 | DECL_ACCESSORS(source_position, Smi) |
| 8728 | // The position in the source for the last statement before this break |
| 8729 | // position. |
| 8730 | DECL_ACCESSORS(statement_position, Smi) |
| 8731 | // List of related JavaScript break points. |
| 8732 | DECL_ACCESSORS(break_point_objects, Object) |
| 8733 | |
| 8734 | // Removes a break point. |
| 8735 | static void ClearBreakPoint(Handle<BreakPointInfo> info, |
| 8736 | Handle<Object> break_point_object); |
| 8737 | // Set a break point. |
| 8738 | static void SetBreakPoint(Handle<BreakPointInfo> info, |
| 8739 | Handle<Object> break_point_object); |
| 8740 | // Check if break point info has this break point object. |
| 8741 | static bool HasBreakPointObject(Handle<BreakPointInfo> info, |
| 8742 | Handle<Object> break_point_object); |
| 8743 | // Get the number of break points for this code position. |
| 8744 | int GetBreakPointCount(); |
| 8745 | |
| 8746 | static inline BreakPointInfo* cast(Object* obj); |
| 8747 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8748 | #ifdef OBJECT_PRINT |
| 8749 | inline void BreakPointInfoPrint() { |
| 8750 | BreakPointInfoPrint(stdout); |
| 8751 | } |
| 8752 | void BreakPointInfoPrint(FILE* out); |
| 8753 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8754 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8755 | void BreakPointInfoVerify(); |
| 8756 | #endif |
| 8757 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 8758 | static const int kCodePositionIndex = Struct::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8759 | static const int kSourcePositionIndex = kCodePositionIndex + kPointerSize; |
| 8760 | static const int kStatementPositionIndex = |
| 8761 | kSourcePositionIndex + kPointerSize; |
| 8762 | static const int kBreakPointObjectsIndex = |
| 8763 | kStatementPositionIndex + kPointerSize; |
| 8764 | static const int kSize = kBreakPointObjectsIndex + kPointerSize; |
| 8765 | |
| 8766 | private: |
| 8767 | DISALLOW_IMPLICIT_CONSTRUCTORS(BreakPointInfo); |
| 8768 | }; |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 8769 | #endif // ENABLE_DEBUGGER_SUPPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8770 | |
| 8771 | |
| 8772 | #undef DECL_BOOLEAN_ACCESSORS |
| 8773 | #undef DECL_ACCESSORS |
| 8774 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 8775 | #define VISITOR_SYNCHRONIZATION_TAGS_LIST(V) \ |
| 8776 | V(kSymbolTable, "symbol_table", "(Symbols)") \ |
| 8777 | V(kExternalStringsTable, "external_strings_table", "(External strings)") \ |
| 8778 | V(kStrongRootList, "strong_root_list", "(Strong roots)") \ |
| 8779 | V(kSymbol, "symbol", "(Symbol)") \ |
| 8780 | V(kBootstrapper, "bootstrapper", "(Bootstrapper)") \ |
| 8781 | V(kTop, "top", "(Isolate)") \ |
| 8782 | V(kRelocatable, "relocatable", "(Relocatable)") \ |
| 8783 | V(kDebug, "debug", "(Debugger)") \ |
| 8784 | V(kCompilationCache, "compilationcache", "(Compilation cache)") \ |
| 8785 | V(kHandleScope, "handlescope", "(Handle scope)") \ |
| 8786 | V(kBuiltins, "builtins", "(Builtins)") \ |
| 8787 | V(kGlobalHandles, "globalhandles", "(Global handles)") \ |
| 8788 | V(kThreadManager, "threadmanager", "(Thread manager)") \ |
| 8789 | V(kExtensions, "Extensions", "(Extensions)") |
| 8790 | |
| 8791 | class VisitorSynchronization : public AllStatic { |
| 8792 | public: |
| 8793 | #define DECLARE_ENUM(enum_item, ignore1, ignore2) enum_item, |
| 8794 | enum SyncTag { |
| 8795 | VISITOR_SYNCHRONIZATION_TAGS_LIST(DECLARE_ENUM) |
| 8796 | kNumberOfSyncTags |
| 8797 | }; |
| 8798 | #undef DECLARE_ENUM |
| 8799 | |
| 8800 | static const char* const kTags[kNumberOfSyncTags]; |
| 8801 | static const char* const kTagNames[kNumberOfSyncTags]; |
| 8802 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8803 | |
| 8804 | // Abstract base class for visiting, and optionally modifying, the |
| 8805 | // pointers contained in Objects. Used in GC and serialization/deserialization. |
| 8806 | class ObjectVisitor BASE_EMBEDDED { |
| 8807 | public: |
| 8808 | virtual ~ObjectVisitor() {} |
| 8809 | |
| 8810 | // Visits a contiguous arrays of pointers in the half-open range |
| 8811 | // [start, end). Any or all of the values may be modified on return. |
| 8812 | virtual void VisitPointers(Object** start, Object** end) = 0; |
| 8813 | |
| 8814 | // To allow lazy clearing of inline caches the visitor has |
| 8815 | // a rich interface for iterating over Code objects.. |
| 8816 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8817 | // Visits a code target in the instruction stream. |
| 8818 | virtual void VisitCodeTarget(RelocInfo* rinfo); |
| 8819 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 8820 | // Visits a code entry in a JS function. |
| 8821 | virtual void VisitCodeEntry(Address entry_address); |
| 8822 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 8823 | // Visits a global property cell reference in the instruction stream. |
| 8824 | virtual void VisitGlobalPropertyCell(RelocInfo* rinfo); |
| 8825 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8826 | // Visits a runtime entry in the instruction stream. |
| 8827 | virtual void VisitRuntimeEntry(RelocInfo* rinfo) {} |
| 8828 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 8829 | // Visits the resource of an ASCII or two-byte string. |
| 8830 | virtual void VisitExternalAsciiString( |
| 8831 | v8::String::ExternalAsciiStringResource** resource) {} |
| 8832 | virtual void VisitExternalTwoByteString( |
| 8833 | v8::String::ExternalStringResource** resource) {} |
| 8834 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8835 | // Visits a debug call target in the instruction stream. |
| 8836 | virtual void VisitDebugTarget(RelocInfo* rinfo); |
| 8837 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8838 | // Handy shorthand for visiting a single pointer. |
| 8839 | virtual void VisitPointer(Object** p) { VisitPointers(p, p + 1); } |
| 8840 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 8841 | // Visit pointer embedded into a code object. |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 8842 | virtual void VisitEmbeddedPointer(RelocInfo* rinfo); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 8843 | |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 8844 | virtual void VisitSharedFunctionInfo(SharedFunctionInfo* shared) {} |
| 8845 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8846 | // Visits a contiguous arrays of external references (references to the C++ |
| 8847 | // heap) in the half-open range [start, end). Any or all of the values |
| 8848 | // may be modified on return. |
| 8849 | virtual void VisitExternalReferences(Address* start, Address* end) {} |
| 8850 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 8851 | virtual void VisitExternalReference(RelocInfo* rinfo); |
| 8852 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8853 | inline void VisitExternalReference(Address* p) { |
| 8854 | VisitExternalReferences(p, p + 1); |
| 8855 | } |
| 8856 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 8857 | // Visits a handle that has an embedder-assigned class ID. |
| 8858 | virtual void VisitEmbedderReference(Object** p, uint16_t class_id) {} |
| 8859 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8860 | // Intended for serialization/deserialization checking: insert, or |
| 8861 | // check for the presence of, a tag at this position in the stream. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 8862 | // Also used for marking up GC roots in heap snapshots. |
| 8863 | virtual void Synchronize(VisitorSynchronization::SyncTag tag) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8864 | }; |
| 8865 | |
| 8866 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 8867 | class StructBodyDescriptor : public |
| 8868 | FlexibleBodyDescriptor<HeapObject::kHeaderSize> { |
| 8869 | public: |
| 8870 | static inline int SizeOf(Map* map, HeapObject* object) { |
| 8871 | return map->instance_size(); |
| 8872 | } |
| 8873 | }; |
| 8874 | |
| 8875 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8876 | // BooleanBit is a helper class for setting and getting a bit in an |
| 8877 | // integer or Smi. |
| 8878 | class BooleanBit : public AllStatic { |
| 8879 | public: |
| 8880 | static inline bool get(Smi* smi, int bit_position) { |
| 8881 | return get(smi->value(), bit_position); |
| 8882 | } |
| 8883 | |
| 8884 | static inline bool get(int value, int bit_position) { |
| 8885 | return (value & (1 << bit_position)) != 0; |
| 8886 | } |
| 8887 | |
| 8888 | static inline Smi* set(Smi* smi, int bit_position, bool v) { |
| 8889 | return Smi::FromInt(set(smi->value(), bit_position, v)); |
| 8890 | } |
| 8891 | |
| 8892 | static inline int set(int value, int bit_position, bool v) { |
| 8893 | if (v) { |
| 8894 | value |= (1 << bit_position); |
| 8895 | } else { |
| 8896 | value &= ~(1 << bit_position); |
| 8897 | } |
| 8898 | return value; |
| 8899 | } |
| 8900 | }; |
| 8901 | |
| 8902 | } } // namespace v8::internal |
| 8903 | |
| 8904 | #endif // V8_OBJECTS_H_ |