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 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 181 | // Instance size sentinel for objects of variable size. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 182 | const int kVariableSizeSentinel = 0; |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 183 | |
| 184 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 185 | // All Maps have a field instance_type containing a InstanceType. |
| 186 | // It describes the type of the instances. |
| 187 | // |
| 188 | // As an example, a JavaScript object is a heap object and its map |
| 189 | // instance_type is JS_OBJECT_TYPE. |
| 190 | // |
| 191 | // The names of the string instance types are intended to systematically |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 192 | // mirror their encoding in the instance_type field of the map. The default |
| 193 | // encoding is considered TWO_BYTE. It is not mentioned in the name. ASCII |
| 194 | // encoding is mentioned explicitly in the name. Likewise, the default |
| 195 | // representation is considered sequential. It is not mentioned in the |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 196 | // name. The other representations (e.g. CONS, EXTERNAL) are explicitly |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 197 | // mentioned. Finally, the string is either a SYMBOL_TYPE (if it is a |
| 198 | // symbol) or a STRING_TYPE (if it is not a symbol). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 199 | // |
| 200 | // NOTE: The following things are some that depend on the string types having |
| 201 | // instance_types that are less than those of all other types: |
| 202 | // HeapObject::Size, HeapObject::IterateBody, the typeof operator, and |
| 203 | // Object::IsString. |
| 204 | // |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 205 | // NOTE: Everything following JS_VALUE_TYPE is considered a |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 206 | // JSObject for GC purposes. The first four entries here have typeof |
| 207 | // 'object', whereas JS_FUNCTION_TYPE has typeof 'function'. |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 208 | #define INSTANCE_TYPE_LIST_ALL(V) \ |
| 209 | V(SYMBOL_TYPE) \ |
| 210 | V(ASCII_SYMBOL_TYPE) \ |
| 211 | V(CONS_SYMBOL_TYPE) \ |
| 212 | V(CONS_ASCII_SYMBOL_TYPE) \ |
| 213 | V(EXTERNAL_SYMBOL_TYPE) \ |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 214 | V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 215 | V(EXTERNAL_ASCII_SYMBOL_TYPE) \ |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 216 | V(SHORT_EXTERNAL_SYMBOL_TYPE) \ |
| 217 | V(SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE) \ |
| 218 | V(SHORT_EXTERNAL_ASCII_SYMBOL_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 219 | V(STRING_TYPE) \ |
| 220 | V(ASCII_STRING_TYPE) \ |
| 221 | V(CONS_STRING_TYPE) \ |
| 222 | V(CONS_ASCII_STRING_TYPE) \ |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 223 | V(SLICED_STRING_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 224 | V(EXTERNAL_STRING_TYPE) \ |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 225 | V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 226 | V(EXTERNAL_ASCII_STRING_TYPE) \ |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 227 | V(SHORT_EXTERNAL_STRING_TYPE) \ |
| 228 | V(SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \ |
| 229 | V(SHORT_EXTERNAL_ASCII_STRING_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 230 | V(PRIVATE_EXTERNAL_ASCII_STRING_TYPE) \ |
| 231 | \ |
| 232 | V(MAP_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 233 | V(CODE_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 234 | V(ODDBALL_TYPE) \ |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 235 | V(JS_GLOBAL_PROPERTY_CELL_TYPE) \ |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 236 | \ |
| 237 | V(HEAP_NUMBER_TYPE) \ |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 238 | V(FOREIGN_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 239 | V(BYTE_ARRAY_TYPE) \ |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 240 | V(FREE_SPACE_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 241 | /* Note: the order of these external array */ \ |
| 242 | /* types is relied upon in */ \ |
| 243 | /* Object::IsExternalArray(). */ \ |
| 244 | V(EXTERNAL_BYTE_ARRAY_TYPE) \ |
| 245 | V(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE) \ |
| 246 | V(EXTERNAL_SHORT_ARRAY_TYPE) \ |
| 247 | V(EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE) \ |
| 248 | V(EXTERNAL_INT_ARRAY_TYPE) \ |
| 249 | V(EXTERNAL_UNSIGNED_INT_ARRAY_TYPE) \ |
| 250 | V(EXTERNAL_FLOAT_ARRAY_TYPE) \ |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 251 | V(EXTERNAL_PIXEL_ARRAY_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 252 | V(FILLER_TYPE) \ |
| 253 | \ |
| 254 | V(ACCESSOR_INFO_TYPE) \ |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 255 | V(ACCESSOR_PAIR_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 256 | V(ACCESS_CHECK_INFO_TYPE) \ |
| 257 | V(INTERCEPTOR_INFO_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 258 | V(CALL_HANDLER_INFO_TYPE) \ |
| 259 | V(FUNCTION_TEMPLATE_INFO_TYPE) \ |
| 260 | V(OBJECT_TEMPLATE_INFO_TYPE) \ |
| 261 | V(SIGNATURE_INFO_TYPE) \ |
| 262 | V(TYPE_SWITCH_INFO_TYPE) \ |
| 263 | V(SCRIPT_TYPE) \ |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 264 | V(CODE_CACHE_TYPE) \ |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 265 | V(POLYMORPHIC_CODE_CACHE_TYPE) \ |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 266 | V(TYPE_FEEDBACK_INFO_TYPE) \ |
| 267 | V(ALIASED_ARGUMENTS_ENTRY_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 268 | \ |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 269 | V(FIXED_ARRAY_TYPE) \ |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 270 | V(FIXED_DOUBLE_ARRAY_TYPE) \ |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 271 | V(SHARED_FUNCTION_INFO_TYPE) \ |
| 272 | \ |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 273 | V(JS_MESSAGE_OBJECT_TYPE) \ |
| 274 | \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 275 | V(JS_VALUE_TYPE) \ |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 276 | V(JS_DATE_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 277 | V(JS_OBJECT_TYPE) \ |
| 278 | V(JS_CONTEXT_EXTENSION_OBJECT_TYPE) \ |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 279 | V(JS_MODULE_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 280 | V(JS_GLOBAL_OBJECT_TYPE) \ |
| 281 | V(JS_BUILTINS_OBJECT_TYPE) \ |
| 282 | V(JS_GLOBAL_PROXY_TYPE) \ |
| 283 | V(JS_ARRAY_TYPE) \ |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 284 | V(JS_PROXY_TYPE) \ |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 285 | V(JS_WEAK_MAP_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 286 | V(JS_REGEXP_TYPE) \ |
| 287 | \ |
| 288 | V(JS_FUNCTION_TYPE) \ |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 289 | V(JS_FUNCTION_PROXY_TYPE) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 290 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 291 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 292 | #define INSTANCE_TYPE_LIST_DEBUGGER(V) \ |
| 293 | V(DEBUG_INFO_TYPE) \ |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 294 | V(BREAK_POINT_INFO_TYPE) |
| 295 | #else |
| 296 | #define INSTANCE_TYPE_LIST_DEBUGGER(V) |
| 297 | #endif |
| 298 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 299 | #define INSTANCE_TYPE_LIST(V) \ |
| 300 | INSTANCE_TYPE_LIST_ALL(V) \ |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 301 | INSTANCE_TYPE_LIST_DEBUGGER(V) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 302 | |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 303 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 304 | // Since string types are not consecutive, this macro is used to |
| 305 | // iterate over them. |
| 306 | #define STRING_TYPE_LIST(V) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 307 | V(SYMBOL_TYPE, \ |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 308 | kVariableSizeSentinel, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 309 | symbol, \ |
| 310 | Symbol) \ |
| 311 | V(ASCII_SYMBOL_TYPE, \ |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 312 | kVariableSizeSentinel, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 313 | ascii_symbol, \ |
| 314 | AsciiSymbol) \ |
| 315 | V(CONS_SYMBOL_TYPE, \ |
| 316 | ConsString::kSize, \ |
| 317 | cons_symbol, \ |
| 318 | ConsSymbol) \ |
| 319 | V(CONS_ASCII_SYMBOL_TYPE, \ |
| 320 | ConsString::kSize, \ |
| 321 | cons_ascii_symbol, \ |
| 322 | ConsAsciiSymbol) \ |
| 323 | V(EXTERNAL_SYMBOL_TYPE, \ |
| 324 | ExternalTwoByteString::kSize, \ |
| 325 | external_symbol, \ |
| 326 | ExternalSymbol) \ |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 327 | V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \ |
| 328 | ExternalTwoByteString::kSize, \ |
| 329 | external_symbol_with_ascii_data, \ |
| 330 | ExternalSymbolWithAsciiData) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 331 | V(EXTERNAL_ASCII_SYMBOL_TYPE, \ |
| 332 | ExternalAsciiString::kSize, \ |
| 333 | external_ascii_symbol, \ |
| 334 | ExternalAsciiSymbol) \ |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 335 | V(SHORT_EXTERNAL_SYMBOL_TYPE, \ |
| 336 | ExternalTwoByteString::kShortSize, \ |
| 337 | short_external_symbol, \ |
| 338 | ShortExternalSymbol) \ |
| 339 | V(SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \ |
| 340 | ExternalTwoByteString::kShortSize, \ |
| 341 | short_external_symbol_with_ascii_data, \ |
| 342 | ShortExternalSymbolWithAsciiData) \ |
| 343 | V(SHORT_EXTERNAL_ASCII_SYMBOL_TYPE, \ |
| 344 | ExternalAsciiString::kShortSize, \ |
| 345 | short_external_ascii_symbol, \ |
| 346 | ShortExternalAsciiSymbol) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 347 | V(STRING_TYPE, \ |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 348 | kVariableSizeSentinel, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 349 | string, \ |
| 350 | String) \ |
| 351 | V(ASCII_STRING_TYPE, \ |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 352 | kVariableSizeSentinel, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 353 | ascii_string, \ |
| 354 | AsciiString) \ |
| 355 | V(CONS_STRING_TYPE, \ |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 356 | ConsString::kSize, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 357 | cons_string, \ |
| 358 | ConsString) \ |
| 359 | V(CONS_ASCII_STRING_TYPE, \ |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 360 | ConsString::kSize, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 361 | cons_ascii_string, \ |
| 362 | ConsAsciiString) \ |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 363 | V(SLICED_STRING_TYPE, \ |
| 364 | SlicedString::kSize, \ |
| 365 | sliced_string, \ |
| 366 | SlicedString) \ |
| 367 | V(SLICED_ASCII_STRING_TYPE, \ |
| 368 | SlicedString::kSize, \ |
| 369 | sliced_ascii_string, \ |
| 370 | SlicedAsciiString) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 371 | V(EXTERNAL_STRING_TYPE, \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 372 | ExternalTwoByteString::kSize, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 373 | external_string, \ |
| 374 | ExternalString) \ |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 375 | V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \ |
| 376 | ExternalTwoByteString::kSize, \ |
| 377 | external_string_with_ascii_data, \ |
| 378 | ExternalStringWithAsciiData) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 379 | V(EXTERNAL_ASCII_STRING_TYPE, \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 380 | ExternalAsciiString::kSize, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 381 | external_ascii_string, \ |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 382 | ExternalAsciiString) \ |
| 383 | V(SHORT_EXTERNAL_STRING_TYPE, \ |
| 384 | ExternalTwoByteString::kShortSize, \ |
| 385 | short_external_string, \ |
| 386 | ShortExternalString) \ |
| 387 | V(SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \ |
| 388 | ExternalTwoByteString::kShortSize, \ |
| 389 | short_external_string_with_ascii_data, \ |
| 390 | ShortExternalStringWithAsciiData) \ |
| 391 | V(SHORT_EXTERNAL_ASCII_STRING_TYPE, \ |
| 392 | ExternalAsciiString::kShortSize, \ |
| 393 | short_external_ascii_string, \ |
| 394 | ShortExternalAsciiString) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 395 | |
| 396 | // A struct is a simple object a set of object-valued fields. Including an |
| 397 | // object type in this causes the compiler to generate most of the boilerplate |
| 398 | // code for the class including allocation and garbage collection routines, |
| 399 | // casts and predicates. All you need to define is the class, methods and |
| 400 | // object verification routines. Easy, no? |
| 401 | // |
| 402 | // Note that for subtle reasons related to the ordering or numerical values of |
| 403 | // type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST |
| 404 | // manually. |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 405 | #define STRUCT_LIST_ALL(V) \ |
| 406 | V(ACCESSOR_INFO, AccessorInfo, accessor_info) \ |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 407 | V(ACCESSOR_PAIR, AccessorPair, accessor_pair) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 408 | V(ACCESS_CHECK_INFO, AccessCheckInfo, access_check_info) \ |
| 409 | V(INTERCEPTOR_INFO, InterceptorInfo, interceptor_info) \ |
| 410 | V(CALL_HANDLER_INFO, CallHandlerInfo, call_handler_info) \ |
| 411 | V(FUNCTION_TEMPLATE_INFO, FunctionTemplateInfo, function_template_info) \ |
| 412 | V(OBJECT_TEMPLATE_INFO, ObjectTemplateInfo, object_template_info) \ |
| 413 | V(SIGNATURE_INFO, SignatureInfo, signature_info) \ |
| 414 | V(TYPE_SWITCH_INFO, TypeSwitchInfo, type_switch_info) \ |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 415 | V(SCRIPT, Script, script) \ |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 416 | V(CODE_CACHE, CodeCache, code_cache) \ |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 417 | V(POLYMORPHIC_CODE_CACHE, PolymorphicCodeCache, polymorphic_code_cache) \ |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 418 | V(TYPE_FEEDBACK_INFO, TypeFeedbackInfo, type_feedback_info) \ |
| 419 | V(ALIASED_ARGUMENTS_ENTRY, AliasedArgumentsEntry, aliased_arguments_entry) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 420 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 421 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 422 | #define STRUCT_LIST_DEBUGGER(V) \ |
| 423 | V(DEBUG_INFO, DebugInfo, debug_info) \ |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 424 | V(BREAK_POINT_INFO, BreakPointInfo, break_point_info) |
| 425 | #else |
| 426 | #define STRUCT_LIST_DEBUGGER(V) |
| 427 | #endif |
| 428 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 429 | #define STRUCT_LIST(V) \ |
| 430 | STRUCT_LIST_ALL(V) \ |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 431 | STRUCT_LIST_DEBUGGER(V) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 432 | |
| 433 | // We use the full 8 bits of the instance_type field to encode heap object |
| 434 | // instance types. The high-order bit (bit 7) is set if the object is not a |
| 435 | // string, and cleared if it is a string. |
| 436 | const uint32_t kIsNotStringMask = 0x80; |
| 437 | const uint32_t kStringTag = 0x0; |
| 438 | const uint32_t kNotStringTag = 0x80; |
| 439 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 440 | // Bit 6 indicates that the object is a symbol (if set) or not (if cleared). |
| 441 | // There are not enough types that the non-string types (with bit 7 set) can |
| 442 | // have bit 6 set too. |
| 443 | const uint32_t kIsSymbolMask = 0x40; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 444 | const uint32_t kNotSymbolTag = 0x0; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 445 | const uint32_t kSymbolTag = 0x40; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 446 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 447 | // If bit 7 is clear then bit 2 indicates whether the string consists of |
| 448 | // two-byte characters or one-byte characters. |
| 449 | const uint32_t kStringEncodingMask = 0x4; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 450 | const uint32_t kTwoByteStringTag = 0x0; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 451 | const uint32_t kAsciiStringTag = 0x4; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 452 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 453 | // 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] | 454 | // of the string. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 455 | const uint32_t kStringRepresentationMask = 0x03; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 456 | enum StringRepresentationTag { |
| 457 | kSeqStringTag = 0x0, |
| 458 | kConsStringTag = 0x1, |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 459 | kExternalStringTag = 0x2, |
| 460 | kSlicedStringTag = 0x3 |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 461 | }; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 462 | const uint32_t kIsIndirectStringMask = 0x1; |
| 463 | const uint32_t kIsIndirectStringTag = 0x1; |
| 464 | STATIC_ASSERT((kSeqStringTag & kIsIndirectStringMask) == 0); |
| 465 | STATIC_ASSERT((kExternalStringTag & kIsIndirectStringMask) == 0); |
| 466 | STATIC_ASSERT( |
| 467 | (kConsStringTag & kIsIndirectStringMask) == kIsIndirectStringTag); |
| 468 | STATIC_ASSERT( |
| 469 | (kSlicedStringTag & kIsIndirectStringMask) == kIsIndirectStringTag); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 470 | |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 471 | // Use this mask to distinguish between cons and slice only after making |
| 472 | // sure that the string is one of the two (an indirect string). |
| 473 | const uint32_t kSlicedNotConsMask = kSlicedStringTag & ~kConsStringTag; |
| 474 | STATIC_ASSERT(IS_POWER_OF_TWO(kSlicedNotConsMask) && kSlicedNotConsMask != 0); |
| 475 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 476 | // If bit 7 is clear, then bit 3 indicates whether this two-byte |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 477 | // string actually contains ASCII data. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 478 | const uint32_t kAsciiDataHintMask = 0x08; |
| 479 | const uint32_t kAsciiDataHintTag = 0x08; |
| 480 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 481 | // If bit 7 is clear and string representation indicates an external string, |
| 482 | // then bit 4 indicates whether the data pointer is cached. |
| 483 | const uint32_t kShortExternalStringMask = 0x10; |
| 484 | const uint32_t kShortExternalStringTag = 0x10; |
| 485 | |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 486 | |
| 487 | // A ConsString with an empty string as the right side is a candidate |
| 488 | // for being shortcut by the garbage collector unless it is a |
| 489 | // symbol. It's not common to have non-flat symbols, so we do not |
| 490 | // shortcut them thereby avoiding turning symbols into strings. See |
| 491 | // heap.cc and mark-compact.cc. |
| 492 | const uint32_t kShortcutTypeMask = |
| 493 | kIsNotStringMask | |
| 494 | kIsSymbolMask | |
| 495 | kStringRepresentationMask; |
| 496 | const uint32_t kShortcutTypeTag = kConsStringTag; |
| 497 | |
| 498 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 499 | enum InstanceType { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 500 | // String types. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 501 | SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kSeqStringTag, |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 502 | ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kSeqStringTag, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 503 | CONS_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kConsStringTag, |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 504 | CONS_ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kConsStringTag, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 505 | SHORT_EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | |
| 506 | kExternalStringTag | kShortExternalStringTag, |
| 507 | SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE = |
| 508 | kTwoByteStringTag | kSymbolTag | kExternalStringTag | |
| 509 | kAsciiDataHintTag | kShortExternalStringTag, |
| 510 | SHORT_EXTERNAL_ASCII_SYMBOL_TYPE = kAsciiStringTag | kExternalStringTag | |
| 511 | kSymbolTag | kShortExternalStringTag, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 512 | EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kExternalStringTag, |
| 513 | EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE = |
| 514 | kTwoByteStringTag | kSymbolTag | kExternalStringTag | kAsciiDataHintTag, |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 515 | EXTERNAL_ASCII_SYMBOL_TYPE = |
| 516 | kAsciiStringTag | kSymbolTag | kExternalStringTag, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 517 | STRING_TYPE = kTwoByteStringTag | kSeqStringTag, |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 518 | ASCII_STRING_TYPE = kAsciiStringTag | kSeqStringTag, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 519 | CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag, |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 520 | CONS_ASCII_STRING_TYPE = kAsciiStringTag | kConsStringTag, |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 521 | SLICED_STRING_TYPE = kTwoByteStringTag | kSlicedStringTag, |
| 522 | SLICED_ASCII_STRING_TYPE = kAsciiStringTag | kSlicedStringTag, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 523 | SHORT_EXTERNAL_STRING_TYPE = |
| 524 | kTwoByteStringTag | kExternalStringTag | kShortExternalStringTag, |
| 525 | SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE = |
| 526 | kTwoByteStringTag | kExternalStringTag | |
| 527 | kAsciiDataHintTag | kShortExternalStringTag, |
| 528 | SHORT_EXTERNAL_ASCII_STRING_TYPE = |
| 529 | kAsciiStringTag | kExternalStringTag | kShortExternalStringTag, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 530 | EXTERNAL_STRING_TYPE = kTwoByteStringTag | kExternalStringTag, |
| 531 | EXTERNAL_STRING_WITH_ASCII_DATA_TYPE = |
| 532 | kTwoByteStringTag | kExternalStringTag | kAsciiDataHintTag, |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 533 | // LAST_STRING_TYPE |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 534 | EXTERNAL_ASCII_STRING_TYPE = kAsciiStringTag | kExternalStringTag, |
| 535 | PRIVATE_EXTERNAL_ASCII_STRING_TYPE = EXTERNAL_ASCII_STRING_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 536 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 537 | // Objects allocated in their own spaces (never in new space). |
| 538 | MAP_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 539 | CODE_TYPE, |
| 540 | ODDBALL_TYPE, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 541 | JS_GLOBAL_PROPERTY_CELL_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 542 | |
| 543 | // "Data", objects that cannot contain non-map-word pointers to heap |
| 544 | // objects. |
| 545 | HEAP_NUMBER_TYPE, |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 546 | FOREIGN_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 547 | BYTE_ARRAY_TYPE, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 548 | FREE_SPACE_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 549 | EXTERNAL_BYTE_ARRAY_TYPE, // FIRST_EXTERNAL_ARRAY_TYPE |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 550 | EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE, |
| 551 | EXTERNAL_SHORT_ARRAY_TYPE, |
| 552 | EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE, |
| 553 | EXTERNAL_INT_ARRAY_TYPE, |
| 554 | EXTERNAL_UNSIGNED_INT_ARRAY_TYPE, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 555 | EXTERNAL_FLOAT_ARRAY_TYPE, |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 556 | EXTERNAL_DOUBLE_ARRAY_TYPE, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 557 | EXTERNAL_PIXEL_ARRAY_TYPE, // LAST_EXTERNAL_ARRAY_TYPE |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 558 | FIXED_DOUBLE_ARRAY_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 559 | FILLER_TYPE, // LAST_DATA_TYPE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 560 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 561 | // Structs. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 562 | ACCESSOR_INFO_TYPE, |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 563 | ACCESSOR_PAIR_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 564 | ACCESS_CHECK_INFO_TYPE, |
| 565 | INTERCEPTOR_INFO_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 566 | CALL_HANDLER_INFO_TYPE, |
| 567 | FUNCTION_TEMPLATE_INFO_TYPE, |
| 568 | OBJECT_TEMPLATE_INFO_TYPE, |
| 569 | SIGNATURE_INFO_TYPE, |
| 570 | TYPE_SWITCH_INFO_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 571 | SCRIPT_TYPE, |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 572 | CODE_CACHE_TYPE, |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 573 | POLYMORPHIC_CODE_CACHE_TYPE, |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 574 | TYPE_FEEDBACK_INFO_TYPE, |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 575 | ALIASED_ARGUMENTS_ENTRY_TYPE, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 576 | // The following two instance types are only used when ENABLE_DEBUGGER_SUPPORT |
| 577 | // is defined. However as include/v8.h contain some of the instance type |
| 578 | // constants always having them avoids them getting different numbers |
| 579 | // depending on whether ENABLE_DEBUGGER_SUPPORT is defined or not. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 580 | DEBUG_INFO_TYPE, |
| 581 | BREAK_POINT_INFO_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 582 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 583 | FIXED_ARRAY_TYPE, |
| 584 | SHARED_FUNCTION_INFO_TYPE, |
| 585 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 586 | JS_MESSAGE_OBJECT_TYPE, |
| 587 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 588 | // All the following types are subtypes of JSReceiver, which corresponds to |
| 589 | // objects in the JS sense. The first and the last type in this range are |
| 590 | // the two forms of function. This organization enables using the same |
| 591 | // compares for checking the JS_RECEIVER/SPEC_OBJECT range and the |
| 592 | // NONCALLABLE_JS_OBJECT range. |
| 593 | JS_FUNCTION_PROXY_TYPE, // FIRST_JS_RECEIVER_TYPE, FIRST_JS_PROXY_TYPE |
| 594 | JS_PROXY_TYPE, // LAST_JS_PROXY_TYPE |
| 595 | |
| 596 | JS_VALUE_TYPE, // FIRST_JS_OBJECT_TYPE |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 597 | JS_DATE_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 598 | JS_OBJECT_TYPE, |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 599 | JS_CONTEXT_EXTENSION_OBJECT_TYPE, |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 600 | JS_MODULE_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 601 | JS_GLOBAL_OBJECT_TYPE, |
| 602 | JS_BUILTINS_OBJECT_TYPE, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 603 | JS_GLOBAL_PROXY_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 604 | JS_ARRAY_TYPE, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 605 | JS_SET_TYPE, |
| 606 | JS_MAP_TYPE, |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 607 | JS_WEAK_MAP_TYPE, |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 608 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 609 | JS_REGEXP_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 610 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 611 | JS_FUNCTION_TYPE, // LAST_JS_OBJECT_TYPE, LAST_JS_RECEIVER_TYPE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 612 | |
| 613 | // Pseudo-types |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 614 | FIRST_TYPE = 0x0, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 615 | LAST_TYPE = JS_FUNCTION_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 616 | INVALID_TYPE = FIRST_TYPE - 1, |
| 617 | FIRST_NONSTRING_TYPE = MAP_TYPE, |
| 618 | // Boundaries for testing for an external array. |
| 619 | FIRST_EXTERNAL_ARRAY_TYPE = EXTERNAL_BYTE_ARRAY_TYPE, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 620 | LAST_EXTERNAL_ARRAY_TYPE = EXTERNAL_PIXEL_ARRAY_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 621 | // Boundary for promotion to old data space/old pointer space. |
| 622 | LAST_DATA_TYPE = FILLER_TYPE, |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 623 | // Boundary for objects represented as JSReceiver (i.e. JSObject or JSProxy). |
| 624 | // Note that there is no range for JSObject or JSProxy, since their subtypes |
| 625 | // are not continuous in this enum! The enum ranges instead reflect the |
| 626 | // external class names, where proxies are treated as either ordinary objects, |
| 627 | // or functions. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 628 | FIRST_JS_RECEIVER_TYPE = JS_FUNCTION_PROXY_TYPE, |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 629 | LAST_JS_RECEIVER_TYPE = LAST_TYPE, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 630 | // Boundaries for testing the types represented as JSObject |
| 631 | FIRST_JS_OBJECT_TYPE = JS_VALUE_TYPE, |
| 632 | LAST_JS_OBJECT_TYPE = LAST_TYPE, |
| 633 | // Boundaries for testing the types represented as JSProxy |
| 634 | FIRST_JS_PROXY_TYPE = JS_FUNCTION_PROXY_TYPE, |
| 635 | LAST_JS_PROXY_TYPE = JS_PROXY_TYPE, |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 636 | // Boundaries for testing whether the type is a JavaScript object. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 637 | FIRST_SPEC_OBJECT_TYPE = FIRST_JS_RECEIVER_TYPE, |
| 638 | LAST_SPEC_OBJECT_TYPE = LAST_JS_RECEIVER_TYPE, |
| 639 | // Boundaries for testing the types for which typeof is "object". |
| 640 | FIRST_NONCALLABLE_SPEC_OBJECT_TYPE = JS_PROXY_TYPE, |
| 641 | LAST_NONCALLABLE_SPEC_OBJECT_TYPE = JS_REGEXP_TYPE, |
| 642 | // Note that the types for which typeof is "function" are not continuous. |
| 643 | // Define this so that we can put assertions on discrete checks. |
| 644 | NUM_OF_CALLABLE_SPEC_OBJECT_TYPES = 2 |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 645 | }; |
| 646 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 647 | const int kExternalArrayTypeCount = |
| 648 | LAST_EXTERNAL_ARRAY_TYPE - FIRST_EXTERNAL_ARRAY_TYPE + 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 649 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 650 | STATIC_CHECK(JS_OBJECT_TYPE == Internals::kJSObjectType); |
| 651 | STATIC_CHECK(FIRST_NONSTRING_TYPE == Internals::kFirstNonstringType); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 652 | STATIC_CHECK(ODDBALL_TYPE == Internals::kOddballType); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 653 | STATIC_CHECK(FOREIGN_TYPE == Internals::kForeignType); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 654 | |
| 655 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 656 | enum CompareResult { |
| 657 | LESS = -1, |
| 658 | EQUAL = 0, |
| 659 | GREATER = 1, |
| 660 | |
| 661 | NOT_EQUAL = GREATER |
| 662 | }; |
| 663 | |
| 664 | |
| 665 | #define DECL_BOOLEAN_ACCESSORS(name) \ |
| 666 | inline bool name(); \ |
| 667 | inline void set_##name(bool value); \ |
| 668 | |
| 669 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 670 | #define DECL_ACCESSORS(name, type) \ |
| 671 | inline type* name(); \ |
| 672 | inline void set_##name(type* value, \ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 673 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 674 | |
| 675 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 676 | class AccessorPair; |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 677 | class DictionaryElementsAccessor; |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 678 | class ElementsAccessor; |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 679 | class Failure; |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 680 | class FixedArrayBase; |
| 681 | class ObjectVisitor; |
| 682 | class StringStream; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 683 | |
| 684 | struct ValueInfo : public Malloced { |
| 685 | ValueInfo() : type(FIRST_TYPE), ptr(NULL), str(NULL), number(0) { } |
| 686 | InstanceType type; |
| 687 | Object* ptr; |
| 688 | const char* str; |
| 689 | double number; |
| 690 | }; |
| 691 | |
| 692 | |
| 693 | // A template-ized version of the IsXXX functions. |
| 694 | template <class C> static inline bool Is(Object* obj); |
| 695 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 696 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 697 | class MaybeObject BASE_EMBEDDED { |
| 698 | public: |
| 699 | inline bool IsFailure(); |
| 700 | inline bool IsRetryAfterGC(); |
| 701 | inline bool IsOutOfMemory(); |
| 702 | inline bool IsException(); |
| 703 | INLINE(bool IsTheHole()); |
| 704 | inline bool ToObject(Object** obj) { |
| 705 | if (IsFailure()) return false; |
| 706 | *obj = reinterpret_cast<Object*>(this); |
| 707 | return true; |
| 708 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 709 | inline Failure* ToFailureUnchecked() { |
| 710 | ASSERT(IsFailure()); |
| 711 | return reinterpret_cast<Failure*>(this); |
| 712 | } |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 713 | inline Object* ToObjectUnchecked() { |
| 714 | ASSERT(!IsFailure()); |
| 715 | return reinterpret_cast<Object*>(this); |
| 716 | } |
| 717 | inline Object* ToObjectChecked() { |
| 718 | CHECK(!IsFailure()); |
| 719 | return reinterpret_cast<Object*>(this); |
| 720 | } |
| 721 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 722 | template<typename T> |
| 723 | inline bool To(T** obj) { |
| 724 | if (IsFailure()) return false; |
| 725 | *obj = T::cast(reinterpret_cast<Object*>(this)); |
| 726 | return true; |
| 727 | } |
| 728 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 729 | #ifdef OBJECT_PRINT |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 730 | // Prints this object with details. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 731 | inline void Print() { |
| 732 | Print(stdout); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 733 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 734 | inline void PrintLn() { |
| 735 | PrintLn(stdout); |
| 736 | } |
| 737 | void Print(FILE* out); |
| 738 | void PrintLn(FILE* out); |
| 739 | #endif |
| 740 | #ifdef DEBUG |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 741 | // Verifies the object. |
| 742 | void Verify(); |
| 743 | #endif |
| 744 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 745 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 746 | |
| 747 | #define OBJECT_TYPE_LIST(V) \ |
| 748 | V(Smi) \ |
| 749 | V(HeapObject) \ |
| 750 | V(Number) \ |
| 751 | |
| 752 | #define HEAP_OBJECT_TYPE_LIST(V) \ |
| 753 | V(HeapNumber) \ |
| 754 | V(String) \ |
| 755 | V(Symbol) \ |
| 756 | V(SeqString) \ |
| 757 | V(ExternalString) \ |
| 758 | V(ConsString) \ |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 759 | V(SlicedString) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 760 | V(ExternalTwoByteString) \ |
| 761 | V(ExternalAsciiString) \ |
| 762 | V(SeqTwoByteString) \ |
| 763 | V(SeqAsciiString) \ |
| 764 | \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 765 | V(ExternalArray) \ |
| 766 | V(ExternalByteArray) \ |
| 767 | V(ExternalUnsignedByteArray) \ |
| 768 | V(ExternalShortArray) \ |
| 769 | V(ExternalUnsignedShortArray) \ |
| 770 | V(ExternalIntArray) \ |
| 771 | V(ExternalUnsignedIntArray) \ |
| 772 | V(ExternalFloatArray) \ |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 773 | V(ExternalDoubleArray) \ |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 774 | V(ExternalPixelArray) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 775 | V(ByteArray) \ |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 776 | V(FreeSpace) \ |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 777 | V(JSReceiver) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 778 | V(JSObject) \ |
| 779 | V(JSContextExtensionObject) \ |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 780 | V(JSModule) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 781 | V(Map) \ |
| 782 | V(DescriptorArray) \ |
| 783 | V(DeoptimizationInputData) \ |
| 784 | V(DeoptimizationOutputData) \ |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 785 | V(TypeFeedbackCells) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 786 | V(FixedArray) \ |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 787 | V(FixedDoubleArray) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 788 | V(Context) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 789 | V(GlobalContext) \ |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 790 | V(ModuleContext) \ |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 791 | V(ScopeInfo) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 792 | V(JSFunction) \ |
| 793 | V(Code) \ |
| 794 | V(Oddball) \ |
| 795 | V(SharedFunctionInfo) \ |
| 796 | V(JSValue) \ |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 797 | V(JSDate) \ |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 798 | V(JSMessageObject) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 799 | V(StringWrapper) \ |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 800 | V(Foreign) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 801 | V(Boolean) \ |
| 802 | V(JSArray) \ |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 803 | V(JSProxy) \ |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 804 | V(JSFunctionProxy) \ |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 805 | V(JSSet) \ |
| 806 | V(JSMap) \ |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 807 | V(JSWeakMap) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 808 | V(JSRegExp) \ |
| 809 | V(HashTable) \ |
| 810 | V(Dictionary) \ |
| 811 | V(SymbolTable) \ |
| 812 | V(JSFunctionResultCache) \ |
| 813 | V(NormalizedMapCache) \ |
| 814 | V(CompilationCacheTable) \ |
| 815 | V(CodeCacheHashTable) \ |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 816 | V(PolymorphicCodeCacheHashTable) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 817 | V(MapCache) \ |
| 818 | V(Primitive) \ |
| 819 | V(GlobalObject) \ |
| 820 | V(JSGlobalObject) \ |
| 821 | V(JSBuiltinsObject) \ |
| 822 | V(JSGlobalProxy) \ |
| 823 | V(UndetectableObject) \ |
| 824 | V(AccessCheckNeeded) \ |
| 825 | V(JSGlobalPropertyCell) \ |
| 826 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 827 | |
| 828 | class JSReceiver; |
| 829 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 830 | // Object is the abstract superclass for all classes in the |
| 831 | // object hierarchy. |
| 832 | // Object does not use any virtual functions to avoid the |
| 833 | // allocation of the C++ vtable. |
| 834 | // Since Smi and Failure are subclasses of Object no |
| 835 | // data members can be present in Object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 836 | class Object : public MaybeObject { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 837 | public: |
| 838 | // Type testing. |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 839 | bool IsObject() { return true; } |
| 840 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 841 | #define IS_TYPE_FUNCTION_DECL(type_) inline bool Is##type_(); |
| 842 | OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
| 843 | HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
| 844 | #undef IS_TYPE_FUNCTION_DECL |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 845 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 846 | inline bool IsFixedArrayBase(); |
| 847 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 848 | // Returns true if this object is an instance of the specified |
| 849 | // function template. |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 850 | inline bool IsInstanceOf(FunctionTemplateInfo* type); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 851 | |
| 852 | inline bool IsStruct(); |
| 853 | #define DECLARE_STRUCT_PREDICATE(NAME, Name, name) inline bool Is##Name(); |
| 854 | STRUCT_LIST(DECLARE_STRUCT_PREDICATE) |
| 855 | #undef DECLARE_STRUCT_PREDICATE |
| 856 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 857 | INLINE(bool IsSpecObject()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 858 | INLINE(bool IsSpecFunction()); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 859 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 860 | // Oddball testing. |
| 861 | INLINE(bool IsUndefined()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 862 | INLINE(bool IsNull()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 863 | INLINE(bool IsTheHole()); // Shadows MaybeObject's implementation. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 864 | INLINE(bool IsTrue()); |
| 865 | INLINE(bool IsFalse()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 866 | inline bool IsArgumentsMarker(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 867 | inline bool NonFailureIsHeapObject(); |
| 868 | |
| 869 | // Filler objects (fillers and free space objects). |
| 870 | inline bool IsFiller(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 871 | |
| 872 | // Extract the number. |
| 873 | inline double Number(); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 874 | inline bool IsNaN(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 875 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 876 | // Returns true if the object is of the correct type to be used as a |
| 877 | // implementation of a JSObject's elements. |
| 878 | inline bool HasValidElements(); |
| 879 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 880 | inline bool HasSpecificClassOf(String* name); |
| 881 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 882 | MUST_USE_RESULT MaybeObject* ToObject(); // ECMA-262 9.9. |
| 883 | Object* ToBoolean(); // ECMA-262 9.2. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 884 | |
| 885 | // Convert to a JSObject if needed. |
| 886 | // global_context is used when creating wrapper object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 887 | MUST_USE_RESULT MaybeObject* ToObject(Context* global_context); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 888 | |
| 889 | // Converts this to a Smi if possible. |
| 890 | // Failure is returned otherwise. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 891 | MUST_USE_RESULT inline MaybeObject* ToSmi(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 892 | |
| 893 | void Lookup(String* name, LookupResult* result); |
| 894 | |
| 895 | // Property access. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 896 | MUST_USE_RESULT inline MaybeObject* GetProperty(String* key); |
| 897 | MUST_USE_RESULT inline MaybeObject* GetProperty( |
| 898 | String* key, |
| 899 | PropertyAttributes* attributes); |
| 900 | MUST_USE_RESULT MaybeObject* GetPropertyWithReceiver( |
| 901 | Object* receiver, |
| 902 | String* key, |
| 903 | PropertyAttributes* attributes); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 904 | |
| 905 | static Handle<Object> GetProperty(Handle<Object> object, |
| 906 | Handle<Object> receiver, |
| 907 | LookupResult* result, |
| 908 | Handle<String> key, |
| 909 | PropertyAttributes* attributes); |
| 910 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 911 | MUST_USE_RESULT MaybeObject* GetProperty(Object* receiver, |
| 912 | LookupResult* result, |
| 913 | String* key, |
| 914 | PropertyAttributes* attributes); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 915 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 916 | MUST_USE_RESULT MaybeObject* GetPropertyWithDefinedGetter(Object* receiver, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 917 | JSReceiver* getter); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 918 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 919 | static Handle<Object> GetElement(Handle<Object> object, uint32_t index); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 920 | MUST_USE_RESULT inline MaybeObject* GetElement(uint32_t index); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 921 | // For use when we know that no exception can be thrown. |
| 922 | inline Object* GetElementNoExceptionThrown(uint32_t index); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 923 | MUST_USE_RESULT MaybeObject* GetElementWithReceiver(Object* receiver, |
| 924 | uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 925 | |
| 926 | // Return the object's prototype (might be Heap::null_value()). |
| 927 | Object* GetPrototype(); |
| 928 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 929 | // Returns the permanent hash code associated with this object depending on |
| 930 | // the actual object type. Might return a failure in case no hash was |
| 931 | // created yet or GC was caused by creation. |
| 932 | MUST_USE_RESULT MaybeObject* GetHash(CreationFlag flag); |
| 933 | |
| 934 | // Checks whether this object has the same value as the given one. This |
| 935 | // function is implemented according to ES5, section 9.12 and can be used |
| 936 | // to implement the Harmony "egal" function. |
| 937 | bool SameValue(Object* other); |
| 938 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 939 | // Tries to convert an object to an array index. Returns true and sets |
| 940 | // the output parameter if it succeeds. |
| 941 | inline bool ToArrayIndex(uint32_t* index); |
| 942 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 943 | // Returns true if this is a JSValue containing a string and the index is |
| 944 | // < the length of the string. Used to implement [] on strings. |
| 945 | inline bool IsStringObjectWithCharacterAt(uint32_t index); |
| 946 | |
| 947 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 948 | // Verify a pointer is a valid object pointer. |
| 949 | static void VerifyPointer(Object* p); |
| 950 | #endif |
| 951 | |
| 952 | // Prints this object without details. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 953 | inline void ShortPrint() { |
| 954 | ShortPrint(stdout); |
| 955 | } |
| 956 | void ShortPrint(FILE* out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 957 | |
| 958 | // Prints this object without details to a message accumulator. |
| 959 | void ShortPrint(StringStream* accumulator); |
| 960 | |
| 961 | // Casting: This cast is only needed to satisfy macros in objects-inl.h. |
| 962 | static Object* cast(Object* value) { return value; } |
| 963 | |
| 964 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 965 | 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] | 966 | |
| 967 | private: |
| 968 | DISALLOW_IMPLICIT_CONSTRUCTORS(Object); |
| 969 | }; |
| 970 | |
| 971 | |
| 972 | // Smi represents integer Numbers that can be stored in 31 bits. |
| 973 | // 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] | 974 | // 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] | 975 | // For long smis it has the following format: |
| 976 | // [32 bit signed int] [31 bits zero padding] 0 |
| 977 | // Smi stands for small integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 978 | class Smi: public Object { |
| 979 | public: |
| 980 | // Returns the integer value. |
| 981 | inline int value(); |
| 982 | |
| 983 | // Convert a value to a Smi object. |
| 984 | static inline Smi* FromInt(int value); |
| 985 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 986 | static inline Smi* FromIntptr(intptr_t value); |
| 987 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 988 | // Returns whether value can be represented in a Smi. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 989 | static inline bool IsValid(intptr_t value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 990 | |
| 991 | // Casting. |
| 992 | static inline Smi* cast(Object* object); |
| 993 | |
| 994 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 995 | inline void SmiPrint() { |
| 996 | SmiPrint(stdout); |
| 997 | } |
| 998 | void SmiPrint(FILE* out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 999 | void SmiPrint(StringStream* accumulator); |
| 1000 | #ifdef DEBUG |
| 1001 | void SmiVerify(); |
| 1002 | #endif |
| 1003 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 1004 | static const int kMinValue = |
| 1005 | (static_cast<unsigned int>(-1)) << (kSmiValueSize - 1); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1006 | static const int kMaxValue = -(kMinValue + 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1007 | |
| 1008 | private: |
| 1009 | DISALLOW_IMPLICIT_CONSTRUCTORS(Smi); |
| 1010 | }; |
| 1011 | |
| 1012 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1013 | // Failure is used for reporting out of memory situations and |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1014 | // propagating exceptions through the runtime system. Failure objects |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1015 | // are transient and cannot occur as part of the object graph. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1016 | // |
| 1017 | // Failures are a single word, encoded as follows: |
| 1018 | // +-------------------------+---+--+--+ |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1019 | // |.........unused..........|sss|tt|11| |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1020 | // +-------------------------+---+--+--+ |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1021 | // 7 6 4 32 10 |
| 1022 | // |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1023 | // |
| 1024 | // The low two bits, 0-1, are the failure tag, 11. The next two bits, |
| 1025 | // 2-3, are a failure type tag 'tt' with possible values: |
| 1026 | // 00 RETRY_AFTER_GC |
| 1027 | // 01 EXCEPTION |
| 1028 | // 10 INTERNAL_ERROR |
| 1029 | // 11 OUT_OF_MEMORY_EXCEPTION |
| 1030 | // |
| 1031 | // The next three bits, 4-6, are an allocation space tag 'sss'. The |
| 1032 | // allocation space tag is 000 for all failure types except |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1033 | // RETRY_AFTER_GC. For RETRY_AFTER_GC, the possible values are the |
| 1034 | // allocation spaces (the encoding is found in globals.h). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1035 | |
| 1036 | // Failure type tag info. |
| 1037 | const int kFailureTypeTagSize = 2; |
| 1038 | const int kFailureTypeTagMask = (1 << kFailureTypeTagSize) - 1; |
| 1039 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1040 | class Failure: public MaybeObject { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1041 | public: |
| 1042 | // RuntimeStubs assumes EXCEPTION = 1 in the compiler-generated code. |
| 1043 | enum Type { |
| 1044 | RETRY_AFTER_GC = 0, |
| 1045 | EXCEPTION = 1, // Returning this marker tells the real exception |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1046 | // is in Isolate::pending_exception. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1047 | INTERNAL_ERROR = 2, |
| 1048 | OUT_OF_MEMORY_EXCEPTION = 3 |
| 1049 | }; |
| 1050 | |
| 1051 | inline Type type() const; |
| 1052 | |
| 1053 | // Returns the space that needs to be collected for RetryAfterGC failures. |
| 1054 | inline AllocationSpace allocation_space() const; |
| 1055 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1056 | inline bool IsInternalError() const; |
| 1057 | inline bool IsOutOfMemoryException() const; |
| 1058 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1059 | static inline Failure* RetryAfterGC(AllocationSpace space); |
| 1060 | static inline Failure* RetryAfterGC(); // NEW_SPACE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1061 | static inline Failure* Exception(); |
| 1062 | static inline Failure* InternalError(); |
| 1063 | static inline Failure* OutOfMemoryException(); |
| 1064 | // Casting. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1065 | static inline Failure* cast(MaybeObject* object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1066 | |
| 1067 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1068 | inline void FailurePrint() { |
| 1069 | FailurePrint(stdout); |
| 1070 | } |
| 1071 | void FailurePrint(FILE* out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1072 | void FailurePrint(StringStream* accumulator); |
| 1073 | #ifdef DEBUG |
| 1074 | void FailureVerify(); |
| 1075 | #endif |
| 1076 | |
| 1077 | private: |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1078 | inline intptr_t value() const; |
| 1079 | static inline Failure* Construct(Type type, intptr_t value = 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1080 | |
| 1081 | DISALLOW_IMPLICIT_CONSTRUCTORS(Failure); |
| 1082 | }; |
| 1083 | |
| 1084 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1085 | // 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] | 1086 | // during GC other data (e.g. mark bits, forwarding addresses) is sometimes |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1087 | // encoded in the first word. The class MapWord is an abstraction of the |
| 1088 | // value in a heap object's first word. |
| 1089 | class MapWord BASE_EMBEDDED { |
| 1090 | public: |
| 1091 | // Normal state: the map word contains a map pointer. |
| 1092 | |
| 1093 | // Create a map word from a map pointer. |
| 1094 | static inline MapWord FromMap(Map* map); |
| 1095 | |
| 1096 | // View this map word as a map pointer. |
| 1097 | inline Map* ToMap(); |
| 1098 | |
| 1099 | |
| 1100 | // Scavenge collection: the map word of live objects in the from space |
| 1101 | // contains a forwarding address (a heap object pointer in the to space). |
| 1102 | |
| 1103 | // True if this map word is a forwarding address for a scavenge |
| 1104 | // collection. Only valid during a scavenge collection (specifically, |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1105 | // 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] | 1106 | inline bool IsForwardingAddress(); |
| 1107 | |
| 1108 | // Create a map word from a forwarding address. |
| 1109 | static inline MapWord FromForwardingAddress(HeapObject* object); |
| 1110 | |
| 1111 | // View this map word as a forwarding address. |
| 1112 | inline HeapObject* ToForwardingAddress(); |
| 1113 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1114 | static inline MapWord FromRawValue(uintptr_t value) { |
| 1115 | return MapWord(value); |
| 1116 | } |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1117 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1118 | inline uintptr_t ToRawValue() { |
| 1119 | return value_; |
| 1120 | } |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1121 | |
| 1122 | private: |
| 1123 | // HeapObject calls the private constructor and directly reads the value. |
| 1124 | friend class HeapObject; |
| 1125 | |
| 1126 | explicit MapWord(uintptr_t value) : value_(value) {} |
| 1127 | |
| 1128 | uintptr_t value_; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1129 | }; |
| 1130 | |
| 1131 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1132 | // HeapObject is the superclass for all classes describing heap allocated |
| 1133 | // objects. |
| 1134 | class HeapObject: public Object { |
| 1135 | public: |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1136 | // [map]: Contains a map which contains the object's reflective |
| 1137 | // information. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1138 | inline Map* map(); |
| 1139 | inline void set_map(Map* value); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1140 | // The no-write-barrier version. This is OK if the object is white and in |
| 1141 | // new space, or if the value is an immortal immutable object, like the maps |
| 1142 | // of primitive (non-JS) objects like strings, heap numbers etc. |
| 1143 | inline void set_map_no_write_barrier(Map* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1144 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1145 | // During garbage collection, the map word of a heap object does not |
| 1146 | // necessarily contain a map pointer. |
| 1147 | inline MapWord map_word(); |
| 1148 | inline void set_map_word(MapWord map_word); |
| 1149 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1150 | // 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] | 1151 | inline Heap* GetHeap(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1152 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1153 | // Convenience method to get current isolate. This method can be |
| 1154 | // accessed only when its result is the same as |
| 1155 | // Isolate::Current(), it ASSERTs this. See also comment for GetHeap. |
| 1156 | inline Isolate* GetIsolate(); |
| 1157 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1158 | // Converts an address to a HeapObject pointer. |
| 1159 | static inline HeapObject* FromAddress(Address address); |
| 1160 | |
| 1161 | // Returns the address of this HeapObject. |
| 1162 | inline Address address(); |
| 1163 | |
| 1164 | // Iterates over pointers contained in the object (including the Map) |
| 1165 | void Iterate(ObjectVisitor* v); |
| 1166 | |
| 1167 | // Iterates over all pointers contained in the object except the |
| 1168 | // first map pointer. The object type is given in the first |
| 1169 | // parameter. This function does not access the map pointer in the |
| 1170 | // object, and so is safe to call while the map pointer is modified. |
| 1171 | void IterateBody(InstanceType type, int object_size, ObjectVisitor* v); |
| 1172 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1173 | // Returns the heap object's size in bytes |
| 1174 | inline int Size(); |
| 1175 | |
| 1176 | // Given a heap object's map pointer, returns the heap size in bytes |
| 1177 | // Useful when the map pointer field is used for other purposes. |
| 1178 | // GC internal. |
| 1179 | inline int SizeFromMap(Map* map); |
| 1180 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 1181 | // Returns the field at offset in obj, as a read/write Object* reference. |
| 1182 | // 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] | 1183 | // Does not invoke write barrier, so should only be assigned to |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 1184 | // during marking GC. |
| 1185 | static inline Object** RawField(HeapObject* obj, int offset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1186 | |
| 1187 | // Casting. |
| 1188 | static inline HeapObject* cast(Object* obj); |
| 1189 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1190 | // Return the write barrier mode for this. Callers of this function |
| 1191 | // must be able to present a reference to an AssertNoAllocation |
| 1192 | // object as a sign that they are not going to use this function |
| 1193 | // from code that allocates and thus invalidates the returned write |
| 1194 | // barrier mode. |
| 1195 | inline WriteBarrierMode GetWriteBarrierMode(const AssertNoAllocation&); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1196 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1197 | // Dispatched behavior. |
| 1198 | void HeapObjectShortPrint(StringStream* accumulator); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1199 | #ifdef OBJECT_PRINT |
| 1200 | inline void HeapObjectPrint() { |
| 1201 | HeapObjectPrint(stdout); |
| 1202 | } |
| 1203 | void HeapObjectPrint(FILE* out); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1204 | void PrintHeader(FILE* out, const char* id); |
| 1205 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1206 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1207 | #ifdef DEBUG |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1208 | void HeapObjectVerify(); |
| 1209 | inline void VerifyObjectField(int offset); |
| 1210 | inline void VerifySmiField(int offset); |
| 1211 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1212 | // Verify a pointer is a valid HeapObject pointer that points to object |
| 1213 | // areas in the heap. |
| 1214 | static void VerifyHeapPointer(Object* p); |
| 1215 | #endif |
| 1216 | |
| 1217 | // Layout description. |
| 1218 | // First field in a heap object is map. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1219 | static const int kMapOffset = Object::kHeaderSize; |
| 1220 | static const int kHeaderSize = kMapOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1221 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1222 | STATIC_CHECK(kMapOffset == Internals::kHeapObjectMapOffset); |
| 1223 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1224 | protected: |
| 1225 | // helpers for calling an ObjectVisitor to iterate over pointers in the |
| 1226 | // half-open range [start, end) specified as integer offsets |
| 1227 | inline void IteratePointers(ObjectVisitor* v, int start, int end); |
| 1228 | // as above, for the single element at "offset" |
| 1229 | inline void IteratePointer(ObjectVisitor* v, int offset); |
| 1230 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1231 | private: |
| 1232 | DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject); |
| 1233 | }; |
| 1234 | |
| 1235 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1236 | #define SLOT_ADDR(obj, offset) \ |
| 1237 | reinterpret_cast<Object**>((obj)->address() + offset) |
| 1238 | |
| 1239 | // This class describes a body of an object of a fixed size |
| 1240 | // in which all pointer fields are located in the [start_offset, end_offset) |
| 1241 | // interval. |
| 1242 | template<int start_offset, int end_offset, int size> |
| 1243 | class FixedBodyDescriptor { |
| 1244 | public: |
| 1245 | static const int kStartOffset = start_offset; |
| 1246 | static const int kEndOffset = end_offset; |
| 1247 | static const int kSize = size; |
| 1248 | |
| 1249 | static inline void IterateBody(HeapObject* obj, ObjectVisitor* v); |
| 1250 | |
| 1251 | template<typename StaticVisitor> |
| 1252 | static inline void IterateBody(HeapObject* obj) { |
| 1253 | StaticVisitor::VisitPointers(SLOT_ADDR(obj, start_offset), |
| 1254 | SLOT_ADDR(obj, end_offset)); |
| 1255 | } |
| 1256 | }; |
| 1257 | |
| 1258 | |
| 1259 | // This class describes a body of an object of a variable size |
| 1260 | // in which all pointer fields are located in the [start_offset, object_size) |
| 1261 | // interval. |
| 1262 | template<int start_offset> |
| 1263 | class FlexibleBodyDescriptor { |
| 1264 | public: |
| 1265 | static const int kStartOffset = start_offset; |
| 1266 | |
| 1267 | static inline void IterateBody(HeapObject* obj, |
| 1268 | int object_size, |
| 1269 | ObjectVisitor* v); |
| 1270 | |
| 1271 | template<typename StaticVisitor> |
| 1272 | static inline void IterateBody(HeapObject* obj, int object_size) { |
| 1273 | StaticVisitor::VisitPointers(SLOT_ADDR(obj, start_offset), |
| 1274 | SLOT_ADDR(obj, object_size)); |
| 1275 | } |
| 1276 | }; |
| 1277 | |
| 1278 | #undef SLOT_ADDR |
| 1279 | |
| 1280 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1281 | // The HeapNumber class describes heap allocated numbers that cannot be |
| 1282 | // represented in a Smi (small integer) |
| 1283 | class HeapNumber: public HeapObject { |
| 1284 | public: |
| 1285 | // [value]: number value. |
| 1286 | inline double value(); |
| 1287 | inline void set_value(double value); |
| 1288 | |
| 1289 | // Casting. |
| 1290 | static inline HeapNumber* cast(Object* obj); |
| 1291 | |
| 1292 | // Dispatched behavior. |
| 1293 | Object* HeapNumberToBoolean(); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1294 | inline void HeapNumberPrint() { |
| 1295 | HeapNumberPrint(stdout); |
| 1296 | } |
| 1297 | void HeapNumberPrint(FILE* out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1298 | void HeapNumberPrint(StringStream* accumulator); |
| 1299 | #ifdef DEBUG |
| 1300 | void HeapNumberVerify(); |
| 1301 | #endif |
| 1302 | |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 1303 | inline int get_exponent(); |
| 1304 | inline int get_sign(); |
| 1305 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1306 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1307 | static const int kValueOffset = HeapObject::kHeaderSize; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1308 | // IEEE doubles are two 32 bit words. The first is just mantissa, the second |
| 1309 | // is a mixture of sign, exponent and mantissa. Our current platforms are all |
| 1310 | // little endian apart from non-EABI arm which is little endian with big |
| 1311 | // endian floating point word ordering! |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1312 | static const int kMantissaOffset = kValueOffset; |
| 1313 | static const int kExponentOffset = kValueOffset + 4; |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1314 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1315 | static const int kSize = kValueOffset + kDoubleSize; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1316 | static const uint32_t kSignMask = 0x80000000u; |
| 1317 | static const uint32_t kExponentMask = 0x7ff00000u; |
| 1318 | static const uint32_t kMantissaMask = 0xfffffu; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1319 | static const int kMantissaBits = 52; |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1320 | static const int kExponentBits = 11; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1321 | static const int kExponentBias = 1023; |
| 1322 | static const int kExponentShift = 20; |
| 1323 | static const int kMantissaBitsInTopWord = 20; |
| 1324 | static const int kNonMantissaBitsInTopWord = 12; |
| 1325 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1326 | private: |
| 1327 | DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumber); |
| 1328 | }; |
| 1329 | |
| 1330 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1331 | enum EnsureElementsMode { |
| 1332 | DONT_ALLOW_DOUBLE_ELEMENTS, |
| 1333 | ALLOW_COPIED_DOUBLE_ELEMENTS, |
| 1334 | ALLOW_CONVERTED_DOUBLE_ELEMENTS |
| 1335 | }; |
| 1336 | |
| 1337 | |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 1338 | // Indicates whether a property should be set or (re)defined. Setting of a |
| 1339 | // property causes attributes to remain unchanged, writability to be checked |
| 1340 | // and callbacks to be called. Defining of a property causes attributes to |
| 1341 | // be updated and callbacks to be overridden. |
| 1342 | enum SetPropertyMode { |
| 1343 | SET_PROPERTY, |
| 1344 | DEFINE_PROPERTY |
| 1345 | }; |
| 1346 | |
| 1347 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1348 | // Indicator for one component of an AccessorPair. |
| 1349 | enum AccessorComponent { |
| 1350 | ACCESSOR_GETTER, |
| 1351 | ACCESSOR_SETTER |
| 1352 | }; |
| 1353 | |
| 1354 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1355 | // JSReceiver includes types on which properties can be defined, i.e., |
| 1356 | // JSObject and JSProxy. |
| 1357 | class JSReceiver: public HeapObject { |
| 1358 | public: |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1359 | enum DeleteMode { |
| 1360 | NORMAL_DELETION, |
| 1361 | STRICT_DELETION, |
| 1362 | FORCE_DELETION |
| 1363 | }; |
| 1364 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1365 | // A non-keyed store is of the form a.x = foo or a["x"] = foo whereas |
| 1366 | // a keyed store is of the form a[expression] = foo. |
| 1367 | enum StoreFromKeyed { |
| 1368 | MAY_BE_STORE_FROM_KEYED, |
| 1369 | CERTAINLY_NOT_STORE_FROM_KEYED |
| 1370 | }; |
| 1371 | |
mstarzinger@chromium.org | ccab367 | 2012-06-14 15:01:16 +0000 | [diff] [blame] | 1372 | // Internal properties (e.g. the hidden properties dictionary) might |
| 1373 | // be added even though the receiver is non-extensible. |
| 1374 | enum ExtensibilityCheck { |
| 1375 | PERFORM_EXTENSIBILITY_CHECK, |
| 1376 | OMIT_EXTENSIBILITY_CHECK |
| 1377 | }; |
| 1378 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1379 | // Casting. |
| 1380 | static inline JSReceiver* cast(Object* obj); |
| 1381 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1382 | static Handle<Object> SetProperty(Handle<JSReceiver> object, |
| 1383 | Handle<String> key, |
| 1384 | Handle<Object> value, |
| 1385 | PropertyAttributes attributes, |
| 1386 | StrictModeFlag strict_mode); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1387 | // Can cause GC. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1388 | MUST_USE_RESULT MaybeObject* SetProperty( |
| 1389 | String* key, |
| 1390 | Object* value, |
| 1391 | PropertyAttributes attributes, |
| 1392 | StrictModeFlag strict_mode, |
| 1393 | StoreFromKeyed store_from_keyed = MAY_BE_STORE_FROM_KEYED); |
| 1394 | MUST_USE_RESULT MaybeObject* SetProperty( |
| 1395 | LookupResult* result, |
| 1396 | String* key, |
| 1397 | Object* value, |
| 1398 | PropertyAttributes attributes, |
| 1399 | StrictModeFlag strict_mode, |
| 1400 | StoreFromKeyed store_from_keyed = MAY_BE_STORE_FROM_KEYED); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1401 | MUST_USE_RESULT MaybeObject* SetPropertyWithDefinedSetter(JSReceiver* setter, |
| 1402 | Object* value); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1403 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1404 | MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1405 | MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode); |
| 1406 | |
| 1407 | // Set the index'th array element. |
| 1408 | // Can cause GC, or return failure if GC is required. |
| 1409 | MUST_USE_RESULT MaybeObject* SetElement(uint32_t index, |
| 1410 | Object* value, |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 1411 | PropertyAttributes attributes, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1412 | StrictModeFlag strict_mode, |
| 1413 | bool check_prototype); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1414 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1415 | // Tests for the fast common case for property enumeration. |
| 1416 | bool IsSimpleEnum(); |
| 1417 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1418 | // Returns the class name ([[Class]] property in the specification). |
| 1419 | String* class_name(); |
| 1420 | |
| 1421 | // Returns the constructor name (the name (possibly, inferred name) of the |
| 1422 | // function that was used to instantiate the object). |
| 1423 | String* constructor_name(); |
| 1424 | |
| 1425 | inline PropertyAttributes GetPropertyAttribute(String* name); |
| 1426 | PropertyAttributes GetPropertyAttributeWithReceiver(JSReceiver* receiver, |
| 1427 | String* name); |
| 1428 | PropertyAttributes GetLocalPropertyAttribute(String* name); |
| 1429 | |
| 1430 | // Can cause a GC. |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1431 | inline bool HasProperty(String* name); |
| 1432 | inline bool HasLocalProperty(String* name); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1433 | inline bool HasElement(uint32_t index); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1434 | |
| 1435 | // Return the object's prototype (might be Heap::null_value()). |
| 1436 | inline Object* GetPrototype(); |
| 1437 | |
yangguo@chromium.org | c74d674 | 2012-06-29 15:15:45 +0000 | [diff] [blame^] | 1438 | // Return the constructor function (may be Heap::null_value()). |
| 1439 | inline Object* GetConstructor(); |
| 1440 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1441 | // Set the object's prototype (only JSReceiver and null are allowed). |
| 1442 | MUST_USE_RESULT MaybeObject* SetPrototype(Object* value, |
| 1443 | bool skip_hidden_prototypes); |
| 1444 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1445 | // 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] | 1446 | // 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] | 1447 | inline MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag); |
| 1448 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1449 | // Lookup a property. If found, the result is valid and has |
| 1450 | // detailed information. |
| 1451 | void LocalLookup(String* name, LookupResult* result); |
| 1452 | void Lookup(String* name, LookupResult* result); |
| 1453 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1454 | protected: |
| 1455 | Smi* GenerateIdentityHash(); |
| 1456 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1457 | private: |
| 1458 | PropertyAttributes GetPropertyAttribute(JSReceiver* receiver, |
| 1459 | LookupResult* result, |
| 1460 | String* name, |
| 1461 | bool continue_search); |
| 1462 | |
| 1463 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSReceiver); |
| 1464 | }; |
| 1465 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1466 | // The JSObject describes real heap allocated JavaScript objects with |
| 1467 | // properties. |
| 1468 | // Note that the map of JSObject changes during execution to enable inline |
| 1469 | // caching. |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1470 | class JSObject: public JSReceiver { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1471 | public: |
| 1472 | // [properties]: Backing storage for properties. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1473 | // 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] | 1474 | // slow case. |
| 1475 | DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1476 | inline void initialize_properties(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1477 | inline bool HasFastProperties(); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 1478 | inline StringDictionary* property_dictionary(); // Gets slow properties. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1479 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1480 | // [elements]: The elements (properties with names that are integers). |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1481 | // |
| 1482 | // Elements can be in two general modes: fast and slow. Each mode |
| 1483 | // corrensponds to a set of object representations of elements that |
| 1484 | // have something in common. |
| 1485 | // |
| 1486 | // In the fast mode elements is a FixedArray and so each element can |
| 1487 | // 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] | 1488 | // elements array can have one of three maps in this mode: |
| 1489 | // fixed_array_map, non_strict_arguments_elements_map or |
| 1490 | // fixed_cow_array_map (for copy-on-write arrays). In the latter case |
| 1491 | // the elements array may be shared by a few objects and so before |
| 1492 | // writing to any element the array must be copied. Use |
| 1493 | // EnsureWritableFastElements in this case. |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1494 | // |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1495 | // In the slow mode the elements is either a NumberDictionary, an |
| 1496 | // ExternalArray, or a FixedArray parameter map for a (non-strict) |
| 1497 | // arguments object. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1498 | DECL_ACCESSORS(elements, FixedArrayBase) |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1499 | inline void initialize_elements(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1500 | MUST_USE_RESULT inline MaybeObject* ResetElements(); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1501 | inline ElementsKind GetElementsKind(); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1502 | inline ElementsAccessor* GetElementsAccessor(); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1503 | // Returns true if an object has elements of FAST_SMI_ELEMENTS ElementsKind. |
| 1504 | inline bool HasFastSmiElements(); |
| 1505 | // Returns true if an object has elements of FAST_ELEMENTS ElementsKind. |
| 1506 | inline bool HasFastObjectElements(); |
| 1507 | // Returns true if an object has elements of FAST_ELEMENTS or |
| 1508 | // FAST_SMI_ONLY_ELEMENTS. |
| 1509 | inline bool HasFastSmiOrObjectElements(); |
| 1510 | // Returns true if an object has elements of FAST_DOUBLE_ELEMENTS |
| 1511 | // ElementsKind. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1512 | inline bool HasFastDoubleElements(); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1513 | // Returns true if an object has elements of FAST_HOLEY_*_ELEMENTS |
| 1514 | // ElementsKind. |
| 1515 | inline bool HasFastHoleyElements(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1516 | inline bool HasNonStrictArgumentsElements(); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1517 | inline bool HasDictionaryElements(); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1518 | inline bool HasExternalPixelElements(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1519 | inline bool HasExternalArrayElements(); |
| 1520 | inline bool HasExternalByteElements(); |
| 1521 | inline bool HasExternalUnsignedByteElements(); |
| 1522 | inline bool HasExternalShortElements(); |
| 1523 | inline bool HasExternalUnsignedShortElements(); |
| 1524 | inline bool HasExternalIntElements(); |
| 1525 | inline bool HasExternalUnsignedIntElements(); |
| 1526 | inline bool HasExternalFloatElements(); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 1527 | inline bool HasExternalDoubleElements(); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1528 | bool HasFastArgumentsElements(); |
| 1529 | bool HasDictionaryArgumentsElements(); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1530 | inline SeededNumberDictionary* element_dictionary(); // Gets slow elements. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1531 | |
svenpanne@chromium.org | 3c93e77 | 2012-01-02 09:26:59 +0000 | [diff] [blame] | 1532 | inline void set_map_and_elements( |
| 1533 | Map* map, |
| 1534 | FixedArrayBase* value, |
| 1535 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 1536 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1537 | // Requires: HasFastElements(). |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1538 | MUST_USE_RESULT inline MaybeObject* EnsureWritableFastElements(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1539 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 1540 | // Collects elements starting at index 0. |
| 1541 | // Undefined values are placed after non-undefined values. |
| 1542 | // Returns the number of non-undefined values. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1543 | MUST_USE_RESULT MaybeObject* PrepareElementsForSort(uint32_t limit); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 1544 | // As PrepareElementsForSort, but only on objects where elements is |
| 1545 | // a dictionary, and it will stay a dictionary. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1546 | MUST_USE_RESULT MaybeObject* PrepareSlowElementsForSort(uint32_t limit); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 1547 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1548 | MUST_USE_RESULT MaybeObject* GetPropertyWithCallback(Object* receiver, |
| 1549 | Object* structure, |
| 1550 | String* name); |
| 1551 | |
| 1552 | // Can cause GC. |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1553 | MUST_USE_RESULT MaybeObject* SetPropertyForResult(LookupResult* result, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1554 | String* key, |
| 1555 | Object* value, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1556 | PropertyAttributes attributes, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1557 | StrictModeFlag strict_mode, |
| 1558 | StoreFromKeyed store_mode); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1559 | MUST_USE_RESULT MaybeObject* SetPropertyWithFailedAccessCheck( |
| 1560 | LookupResult* result, |
| 1561 | String* name, |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1562 | Object* value, |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 1563 | bool check_prototype, |
| 1564 | StrictModeFlag strict_mode); |
| 1565 | MUST_USE_RESULT MaybeObject* SetPropertyWithCallback( |
| 1566 | Object* structure, |
| 1567 | String* name, |
| 1568 | Object* value, |
| 1569 | JSObject* holder, |
| 1570 | StrictModeFlag strict_mode); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1571 | MUST_USE_RESULT MaybeObject* SetPropertyWithInterceptor( |
| 1572 | String* name, |
| 1573 | Object* value, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1574 | PropertyAttributes attributes, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1575 | StrictModeFlag strict_mode); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1576 | MUST_USE_RESULT MaybeObject* SetPropertyPostInterceptor( |
| 1577 | String* name, |
| 1578 | Object* value, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1579 | PropertyAttributes attributes, |
mstarzinger@chromium.org | ccab367 | 2012-06-14 15:01:16 +0000 | [diff] [blame] | 1580 | StrictModeFlag strict_mode, |
| 1581 | ExtensibilityCheck extensibility_check); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1582 | |
| 1583 | static Handle<Object> SetLocalPropertyIgnoreAttributes( |
| 1584 | Handle<JSObject> object, |
| 1585 | Handle<String> key, |
| 1586 | Handle<Object> value, |
| 1587 | PropertyAttributes attributes); |
| 1588 | |
| 1589 | // Can cause GC. |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1590 | MUST_USE_RESULT MaybeObject* SetLocalPropertyIgnoreAttributes( |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1591 | String* key, |
| 1592 | Object* value, |
| 1593 | PropertyAttributes attributes); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1594 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1595 | // Retrieve a value in a normalized object given a lookup result. |
| 1596 | // Handles the special representation of JS global objects. |
| 1597 | Object* GetNormalizedProperty(LookupResult* result); |
| 1598 | |
| 1599 | // Sets the property value in a normalized object given a lookup result. |
| 1600 | // Handles the special representation of JS global objects. |
| 1601 | Object* SetNormalizedProperty(LookupResult* result, Object* value); |
| 1602 | |
| 1603 | // Sets the property value in a normalized object given (key, value, details). |
| 1604 | // Handles the special representation of JS global objects. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1605 | static Handle<Object> SetNormalizedProperty(Handle<JSObject> object, |
| 1606 | Handle<String> key, |
| 1607 | Handle<Object> value, |
| 1608 | PropertyDetails details); |
| 1609 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1610 | MUST_USE_RESULT MaybeObject* SetNormalizedProperty(String* name, |
| 1611 | Object* value, |
| 1612 | PropertyDetails details); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1613 | |
| 1614 | // Deletes the named property in a normalized object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1615 | MUST_USE_RESULT MaybeObject* DeleteNormalizedProperty(String* name, |
| 1616 | DeleteMode mode); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1617 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1618 | MUST_USE_RESULT MaybeObject* OptimizeAsPrototype(); |
| 1619 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1620 | // Retrieve interceptors. |
| 1621 | InterceptorInfo* GetNamedInterceptor(); |
| 1622 | InterceptorInfo* GetIndexedInterceptor(); |
| 1623 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1624 | // Used from JSReceiver. |
| 1625 | PropertyAttributes GetPropertyAttributePostInterceptor(JSObject* receiver, |
| 1626 | String* name, |
| 1627 | bool continue_search); |
| 1628 | PropertyAttributes GetPropertyAttributeWithInterceptor(JSObject* receiver, |
| 1629 | String* name, |
| 1630 | bool continue_search); |
| 1631 | PropertyAttributes GetPropertyAttributeWithFailedAccessCheck( |
| 1632 | Object* receiver, |
| 1633 | LookupResult* result, |
| 1634 | String* name, |
| 1635 | bool continue_search); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1636 | |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 1637 | static void DefineAccessor(Handle<JSObject> object, |
| 1638 | Handle<String> name, |
| 1639 | Handle<Object> getter, |
| 1640 | Handle<Object> setter, |
| 1641 | PropertyAttributes attributes); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1642 | MUST_USE_RESULT MaybeObject* DefineAccessor(String* name, |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 1643 | Object* getter, |
| 1644 | Object* setter, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1645 | PropertyAttributes attributes); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1646 | // Try to define a single accessor paying attention to map transitions. |
| 1647 | // Returns a JavaScript null if this was not possible and we have to use the |
| 1648 | // slow case. Note that we can fail due to allocations, too. |
| 1649 | MUST_USE_RESULT MaybeObject* DefineFastAccessor( |
| 1650 | String* name, |
| 1651 | AccessorComponent component, |
| 1652 | Object* accessor, |
| 1653 | PropertyAttributes attributes); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1654 | Object* LookupAccessor(String* name, AccessorComponent component); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1655 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1656 | MUST_USE_RESULT MaybeObject* DefineAccessor(AccessorInfo* info); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1657 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1658 | // Used from Object::GetProperty(). |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 1659 | MUST_USE_RESULT MaybeObject* GetPropertyWithFailedAccessCheck( |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1660 | Object* receiver, |
| 1661 | LookupResult* result, |
| 1662 | String* name, |
| 1663 | PropertyAttributes* attributes); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 1664 | MUST_USE_RESULT MaybeObject* GetPropertyWithInterceptor( |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1665 | JSReceiver* receiver, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1666 | String* name, |
| 1667 | PropertyAttributes* attributes); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 1668 | MUST_USE_RESULT MaybeObject* GetPropertyPostInterceptor( |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1669 | JSReceiver* receiver, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1670 | String* name, |
| 1671 | PropertyAttributes* attributes); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 1672 | MUST_USE_RESULT MaybeObject* GetLocalPropertyPostInterceptor( |
| 1673 | JSReceiver* receiver, |
| 1674 | String* name, |
| 1675 | PropertyAttributes* attributes); |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 1676 | |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 1677 | // Returns true if this is an instance of an api function and has |
| 1678 | // been modified since it was created. May give false positives. |
| 1679 | bool IsDirty(); |
| 1680 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1681 | // If the receiver is a JSGlobalProxy this method will return its prototype, |
| 1682 | // otherwise the result is the receiver itself. |
| 1683 | inline Object* BypassGlobalProxy(); |
| 1684 | |
| 1685 | // Accessors for hidden properties object. |
| 1686 | // |
| 1687 | // Hidden properties are not local properties of the object itself. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1688 | // 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] | 1689 | // property with a special name Heap::hidden_symbol(). But if the |
| 1690 | // 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] | 1691 | // of its prototype, and if it's a detached proxy, then you can't have |
| 1692 | // hidden properties. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1693 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1694 | // 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] | 1695 | // undefined if called on a detached proxy. |
| 1696 | static Handle<Object> SetHiddenProperty(Handle<JSObject> obj, |
| 1697 | Handle<String> key, |
| 1698 | Handle<Object> value); |
| 1699 | // Returns a failure if a GC is required. |
jkummerow@chromium.org | ab7dad4 | 2012-02-07 12:07:34 +0000 | [diff] [blame] | 1700 | MUST_USE_RESULT MaybeObject* SetHiddenProperty(String* key, Object* value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1701 | // Gets the value of a hidden property with the given key. Returns undefined |
| 1702 | // if the property doesn't exist (or if called on a detached proxy), |
| 1703 | // otherwise returns the value set for the key. |
| 1704 | Object* GetHiddenProperty(String* key); |
| 1705 | // Deletes a hidden property. Deleting a non-existing property is |
| 1706 | // considered successful. |
| 1707 | void DeleteHiddenProperty(String* key); |
| 1708 | // Returns true if the object has a property with the hidden symbol as name. |
| 1709 | bool HasHiddenProperties(); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1710 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1711 | static int GetIdentityHash(Handle<JSObject> obj); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1712 | MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag); |
| 1713 | MUST_USE_RESULT MaybeObject* SetIdentityHash(Object* hash, CreationFlag flag); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1714 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1715 | static Handle<Object> DeleteProperty(Handle<JSObject> obj, |
| 1716 | Handle<String> name); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1717 | MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1718 | |
| 1719 | static Handle<Object> DeleteElement(Handle<JSObject> obj, uint32_t index); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1720 | MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1721 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1722 | inline void ValidateElements(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1723 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1724 | // Makes sure that this object can contain HeapObject as elements. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 1725 | MUST_USE_RESULT inline MaybeObject* EnsureCanContainHeapObjectElements(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1726 | |
| 1727 | // Makes sure that this object can contain the specified elements. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 1728 | MUST_USE_RESULT inline MaybeObject* EnsureCanContainElements( |
| 1729 | Object** elements, |
| 1730 | uint32_t count, |
| 1731 | EnsureElementsMode mode); |
| 1732 | MUST_USE_RESULT inline MaybeObject* EnsureCanContainElements( |
| 1733 | FixedArrayBase* elements, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1734 | uint32_t length, |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 1735 | EnsureElementsMode mode); |
| 1736 | MUST_USE_RESULT MaybeObject* EnsureCanContainElements( |
| 1737 | Arguments* arguments, |
| 1738 | uint32_t first_arg, |
| 1739 | uint32_t arg_count, |
| 1740 | EnsureElementsMode mode); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1741 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1742 | // Do we want to keep the elements in fast case when increasing the |
| 1743 | // capacity? |
| 1744 | bool ShouldConvertToSlowElements(int new_capacity); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1745 | // Returns true if the backing storage for the slow-case elements of |
| 1746 | // this object takes up nearly as much space as a fast-case backing |
| 1747 | // storage would. In that case the JSObject should have fast |
| 1748 | // elements. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1749 | bool ShouldConvertToFastElements(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1750 | // 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] | 1751 | // represented in a FixedDoubleArray and has at least one value that can only |
| 1752 | // be represented as a double and not a Smi. |
| 1753 | bool ShouldConvertToFastDoubleElements(bool* has_smi_only_elements); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1754 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1755 | // Tells whether the index'th element is present. |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1756 | bool HasElementWithReceiver(JSReceiver* receiver, uint32_t index); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1757 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1758 | // Computes the new capacity when expanding the elements of a JSObject. |
| 1759 | static int NewElementsCapacity(int old_capacity) { |
| 1760 | // (old_capacity + 50%) + 16 |
| 1761 | return old_capacity + (old_capacity >> 1) + 16; |
| 1762 | } |
| 1763 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1764 | // Tells whether the index'th element is present and how it is stored. |
| 1765 | enum LocalElementType { |
| 1766 | // There is no element with given index. |
| 1767 | UNDEFINED_ELEMENT, |
| 1768 | |
| 1769 | // Element with given index is handled by interceptor. |
| 1770 | INTERCEPTED_ELEMENT, |
| 1771 | |
| 1772 | // Element with given index is character in string. |
| 1773 | STRING_CHARACTER_ELEMENT, |
| 1774 | |
| 1775 | // Element with given index is stored in fast backing store. |
| 1776 | FAST_ELEMENT, |
| 1777 | |
| 1778 | // Element with given index is stored in slow backing store. |
| 1779 | DICTIONARY_ELEMENT |
| 1780 | }; |
| 1781 | |
| 1782 | LocalElementType HasLocalElement(uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1783 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1784 | bool HasElementWithInterceptor(JSReceiver* receiver, uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1785 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1786 | MUST_USE_RESULT MaybeObject* SetFastElement(uint32_t index, |
| 1787 | Object* value, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1788 | StrictModeFlag strict_mode, |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1789 | bool check_prototype); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1790 | |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 1791 | MUST_USE_RESULT MaybeObject* SetDictionaryElement( |
| 1792 | uint32_t index, |
| 1793 | Object* value, |
| 1794 | PropertyAttributes attributes, |
| 1795 | StrictModeFlag strict_mode, |
| 1796 | bool check_prototype, |
| 1797 | SetPropertyMode set_mode = SET_PROPERTY); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1798 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1799 | MUST_USE_RESULT MaybeObject* SetFastDoubleElement( |
| 1800 | uint32_t index, |
| 1801 | Object* value, |
| 1802 | StrictModeFlag strict_mode, |
| 1803 | bool check_prototype = true); |
| 1804 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1805 | static Handle<Object> SetOwnElement(Handle<JSObject> object, |
| 1806 | uint32_t index, |
| 1807 | Handle<Object> value, |
| 1808 | StrictModeFlag strict_mode); |
| 1809 | |
| 1810 | // 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] | 1811 | static MUST_USE_RESULT Handle<Object> SetElement( |
| 1812 | Handle<JSObject> object, |
| 1813 | uint32_t index, |
| 1814 | Handle<Object> value, |
| 1815 | PropertyAttributes attr, |
| 1816 | StrictModeFlag strict_mode, |
| 1817 | SetPropertyMode set_mode = SET_PROPERTY); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1818 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1819 | // A Failure object is returned if GC is needed. |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 1820 | MUST_USE_RESULT MaybeObject* SetElement( |
| 1821 | uint32_t index, |
| 1822 | Object* value, |
| 1823 | PropertyAttributes attributes, |
| 1824 | StrictModeFlag strict_mode, |
| 1825 | bool check_prototype = true, |
| 1826 | SetPropertyMode set_mode = SET_PROPERTY); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1827 | |
| 1828 | // Returns the index'th element. |
| 1829 | // The undefined object if index is out of bounds. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 1830 | MUST_USE_RESULT MaybeObject* GetElementWithInterceptor(Object* receiver, |
| 1831 | uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1832 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1833 | enum SetFastElementsCapacitySmiMode { |
| 1834 | kAllowSmiElements, |
| 1835 | kForceSmiElements, |
| 1836 | kDontAllowSmiElements |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1837 | }; |
| 1838 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1839 | // Replace the elements' backing store with fast elements of the given |
| 1840 | // capacity. Update the length for JSArrays. Returns the new backing |
| 1841 | // store. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1842 | MUST_USE_RESULT MaybeObject* SetFastElementsCapacityAndLength( |
| 1843 | int capacity, |
| 1844 | int length, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1845 | SetFastElementsCapacitySmiMode smi_mode); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1846 | MUST_USE_RESULT MaybeObject* SetFastDoubleElementsCapacityAndLength( |
| 1847 | int capacity, |
| 1848 | int length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1849 | |
| 1850 | // Lookup interceptors are used for handling properties controlled by host |
| 1851 | // objects. |
| 1852 | inline bool HasNamedInterceptor(); |
| 1853 | inline bool HasIndexedInterceptor(); |
| 1854 | |
| 1855 | // Support functions for v8 api (needed for correct interceptor behavior). |
| 1856 | bool HasRealNamedProperty(String* key); |
| 1857 | bool HasRealElementProperty(uint32_t index); |
| 1858 | bool HasRealNamedCallbackProperty(String* key); |
| 1859 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1860 | // Get the header size for a JSObject. Used to compute the index of |
| 1861 | // internal fields as well as the number of internal fields. |
| 1862 | inline int GetHeaderSize(); |
| 1863 | |
| 1864 | inline int GetInternalFieldCount(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1865 | inline int GetInternalFieldOffset(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1866 | inline Object* GetInternalField(int index); |
| 1867 | inline void SetInternalField(int index, Object* value); |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1868 | inline void SetInternalField(int index, Smi* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1869 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1870 | // The following lookup functions skip interceptors. |
| 1871 | void LocalLookupRealNamedProperty(String* name, LookupResult* result); |
| 1872 | void LookupRealNamedProperty(String* name, LookupResult* result); |
| 1873 | void LookupRealNamedPropertyInPrototypes(String* name, LookupResult* result); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1874 | MUST_USE_RESULT MaybeObject* SetElementWithCallbackSetterInPrototypes( |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 1875 | uint32_t index, Object* value, bool* found, StrictModeFlag strict_mode); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 1876 | void LookupCallback(String* name, LookupResult* result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1877 | |
| 1878 | // Returns the number of properties on this object filtering out properties |
| 1879 | // with the specified attributes (ignoring interceptors). |
jkummerow@chromium.org | ab7dad4 | 2012-02-07 12:07:34 +0000 | [diff] [blame] | 1880 | int NumberOfLocalProperties(PropertyAttributes filter = NONE); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 1881 | // Fill in details for properties into storage starting at the specified |
| 1882 | // index. |
| 1883 | void GetLocalPropertyNames(FixedArray* storage, int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1884 | |
| 1885 | // Returns the number of properties on this object filtering out properties |
| 1886 | // with the specified attributes (ignoring interceptors). |
| 1887 | int NumberOfLocalElements(PropertyAttributes filter); |
| 1888 | // Returns the number of enumerable elements (ignoring interceptors). |
| 1889 | int NumberOfEnumElements(); |
| 1890 | // Returns the number of elements on this object filtering out elements |
| 1891 | // with the specified attributes (ignoring interceptors). |
| 1892 | int GetLocalElementKeys(FixedArray* storage, PropertyAttributes filter); |
| 1893 | // Count and fill in the enumerable elements into storage. |
| 1894 | // (storage->length() == NumberOfEnumElements()). |
| 1895 | // If storage is NULL, will count the elements without adding |
| 1896 | // them to any storage. |
| 1897 | // Returns the number of enumerable elements. |
| 1898 | int GetEnumElementKeys(FixedArray* storage); |
| 1899 | |
| 1900 | // Add a property to a fast-case object using a map transition to |
| 1901 | // new_map. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1902 | MUST_USE_RESULT MaybeObject* AddFastPropertyUsingMap(Map* new_map, |
| 1903 | String* name, |
| 1904 | Object* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1905 | |
| 1906 | // 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] | 1907 | // This leaves a CONSTANT_TRANSITION in the old map, and |
| 1908 | // if it is called on a second object with this map, a |
| 1909 | // normal property is added instead, with a map transition. |
| 1910 | // This avoids the creation of many maps with the same constant |
| 1911 | // function, all orphaned. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1912 | MUST_USE_RESULT MaybeObject* AddConstantFunctionProperty( |
| 1913 | String* name, |
| 1914 | JSFunction* function, |
| 1915 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1916 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1917 | MUST_USE_RESULT MaybeObject* ReplaceSlowProperty( |
| 1918 | String* name, |
| 1919 | Object* value, |
| 1920 | PropertyAttributes attributes); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1921 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1922 | // Returns a new map with all transitions dropped from the object's current |
| 1923 | // map and the ElementsKind set. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1924 | static Handle<Map> GetElementsTransitionMap(Handle<JSObject> object, |
| 1925 | ElementsKind to_kind); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1926 | inline MUST_USE_RESULT MaybeObject* GetElementsTransitionMap( |
| 1927 | Isolate* isolate, |
| 1928 | ElementsKind elements_kind); |
| 1929 | MUST_USE_RESULT MaybeObject* GetElementsTransitionMapSlow( |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1930 | ElementsKind elements_kind); |
| 1931 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1932 | static Handle<Object> TransitionElementsKind(Handle<JSObject> object, |
| 1933 | ElementsKind to_kind); |
| 1934 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1935 | MUST_USE_RESULT MaybeObject* TransitionElementsKind(ElementsKind to_kind); |
| 1936 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1937 | // Converts a descriptor of any other type to a real field, |
| 1938 | // backed by the properties array. Descriptors of visible |
| 1939 | // types, such as CONSTANT_FUNCTION, keep their enumeration order. |
| 1940 | // Converts the descriptor on the original object's map to a |
| 1941 | // map transition, and the the new field is on the object's new map. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1942 | MUST_USE_RESULT MaybeObject* ConvertDescriptorToFieldAndMapTransition( |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1943 | String* name, |
| 1944 | Object* new_value, |
| 1945 | PropertyAttributes attributes); |
| 1946 | |
| 1947 | // Converts a descriptor of any other type to a real field, |
| 1948 | // backed by the properties array. Descriptors of visible |
| 1949 | // types, such as CONSTANT_FUNCTION, keep their enumeration order. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1950 | MUST_USE_RESULT MaybeObject* ConvertDescriptorToField( |
| 1951 | String* name, |
| 1952 | Object* new_value, |
| 1953 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1954 | |
| 1955 | // Add a property to a fast-case object. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1956 | MUST_USE_RESULT MaybeObject* AddFastProperty( |
| 1957 | String* name, |
| 1958 | Object* value, |
| 1959 | PropertyAttributes attributes, |
| 1960 | StoreFromKeyed store_mode = MAY_BE_STORE_FROM_KEYED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1961 | |
| 1962 | // Add a property to a slow-case object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1963 | MUST_USE_RESULT MaybeObject* AddSlowProperty(String* name, |
| 1964 | Object* value, |
| 1965 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1966 | |
| 1967 | // Add a property to an object. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1968 | MUST_USE_RESULT MaybeObject* AddProperty( |
| 1969 | String* name, |
| 1970 | Object* value, |
| 1971 | PropertyAttributes attributes, |
| 1972 | StrictModeFlag strict_mode, |
mstarzinger@chromium.org | ccab367 | 2012-06-14 15:01:16 +0000 | [diff] [blame] | 1973 | StoreFromKeyed store_mode = MAY_BE_STORE_FROM_KEYED, |
| 1974 | ExtensibilityCheck extensibility_check = PERFORM_EXTENSIBILITY_CHECK); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1975 | |
| 1976 | // Convert the object to use the canonical dictionary |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1977 | // representation. If the object is expected to have additional properties |
| 1978 | // added this number can be indicated to have the backing store allocated to |
| 1979 | // an initial capacity for holding these properties. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1980 | static void NormalizeProperties(Handle<JSObject> object, |
| 1981 | PropertyNormalizationMode mode, |
| 1982 | int expected_additional_properties); |
| 1983 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1984 | MUST_USE_RESULT MaybeObject* NormalizeProperties( |
| 1985 | PropertyNormalizationMode mode, |
| 1986 | int expected_additional_properties); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1987 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1988 | // Convert and update the elements backing store to be a |
| 1989 | // SeededNumberDictionary dictionary. Returns the backing after conversion. |
| 1990 | static Handle<SeededNumberDictionary> NormalizeElements( |
| 1991 | Handle<JSObject> object); |
| 1992 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1993 | MUST_USE_RESULT MaybeObject* NormalizeElements(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1994 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1995 | static void UpdateMapCodeCache(Handle<JSObject> object, |
| 1996 | Handle<String> name, |
| 1997 | Handle<Code> code); |
| 1998 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1999 | MUST_USE_RESULT MaybeObject* UpdateMapCodeCache(String* name, Code* code); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2000 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2001 | // Transform slow named properties to fast variants. |
| 2002 | // Returns failure if allocation failed. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2003 | static void TransformToFastProperties(Handle<JSObject> object, |
| 2004 | int unused_property_fields); |
| 2005 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2006 | MUST_USE_RESULT MaybeObject* TransformToFastProperties( |
| 2007 | int unused_property_fields); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2008 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2009 | // Access fast-case object properties at index. |
| 2010 | inline Object* FastPropertyAt(int index); |
| 2011 | inline Object* FastPropertyAtPut(int index, Object* value); |
| 2012 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2013 | // Access to in object properties. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2014 | inline int GetInObjectPropertyOffset(int index); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2015 | inline Object* InObjectPropertyAt(int index); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2016 | inline Object* InObjectPropertyAtPut(int index, |
| 2017 | Object* value, |
| 2018 | WriteBarrierMode mode |
| 2019 | = UPDATE_WRITE_BARRIER); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2020 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2021 | // Initializes the body after properties slot, properties slot is |
| 2022 | // initialized by set_properties. Fill the pre-allocated fields with |
| 2023 | // pre_allocated_value and the rest with filler_value. |
| 2024 | // Note: this call does not update write barrier, the caller is responsible |
| 2025 | // to ensure that |filler_value| can be collected without WB here. |
| 2026 | inline void InitializeBody(Map* map, |
| 2027 | Object* pre_allocated_value, |
| 2028 | Object* filler_value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2029 | |
| 2030 | // Check whether this object references another object |
| 2031 | bool ReferencesObject(Object* obj); |
| 2032 | |
| 2033 | // Casting. |
| 2034 | static inline JSObject* cast(Object* obj); |
| 2035 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2036 | // Disalow further properties to be added to the object. |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2037 | static Handle<Object> PreventExtensions(Handle<JSObject> object); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2038 | MUST_USE_RESULT MaybeObject* PreventExtensions(); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2039 | |
| 2040 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2041 | // Dispatched behavior. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2042 | void JSObjectShortPrint(StringStream* accumulator); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2043 | #ifdef OBJECT_PRINT |
| 2044 | inline void JSObjectPrint() { |
| 2045 | JSObjectPrint(stdout); |
| 2046 | } |
| 2047 | void JSObjectPrint(FILE* out); |
| 2048 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2049 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2050 | void JSObjectVerify(); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2051 | #endif |
| 2052 | #ifdef OBJECT_PRINT |
| 2053 | inline void PrintProperties() { |
| 2054 | PrintProperties(stdout); |
| 2055 | } |
| 2056 | void PrintProperties(FILE* out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2057 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2058 | inline void PrintElements() { |
| 2059 | PrintElements(stdout); |
| 2060 | } |
| 2061 | void PrintElements(FILE* out); |
| 2062 | #endif |
| 2063 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2064 | void PrintElementsTransition( |
| 2065 | FILE* file, ElementsKind from_kind, FixedArrayBase* from_elements, |
| 2066 | ElementsKind to_kind, FixedArrayBase* to_elements); |
| 2067 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2068 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2069 | // Structure for collecting spill information about JSObjects. |
| 2070 | class SpillInformation { |
| 2071 | public: |
| 2072 | void Clear(); |
| 2073 | void Print(); |
| 2074 | int number_of_objects_; |
| 2075 | int number_of_objects_with_fast_properties_; |
| 2076 | int number_of_objects_with_fast_elements_; |
| 2077 | int number_of_fast_used_fields_; |
| 2078 | int number_of_fast_unused_fields_; |
| 2079 | int number_of_slow_used_properties_; |
| 2080 | int number_of_slow_unused_properties_; |
| 2081 | int number_of_fast_used_elements_; |
| 2082 | int number_of_fast_unused_elements_; |
| 2083 | int number_of_slow_used_elements_; |
| 2084 | int number_of_slow_unused_elements_; |
| 2085 | }; |
| 2086 | |
| 2087 | void IncrementSpillStatistics(SpillInformation* info); |
| 2088 | #endif |
| 2089 | Object* SlowReverseLookup(Object* value); |
| 2090 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2091 | // Maximal number of fast properties for the JSObject. Used to |
| 2092 | // restrict the number of map transitions to avoid an explosion in |
| 2093 | // the number of maps for objects used as dictionaries. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2094 | inline bool TooManyFastProperties(int properties, StoreFromKeyed store_mode); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2095 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2096 | // Maximal number of elements (numbered 0 .. kMaxElementCount - 1). |
| 2097 | // Also maximal value of JSArray's length property. |
| 2098 | static const uint32_t kMaxElementCount = 0xffffffffu; |
| 2099 | |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 2100 | // Constants for heuristics controlling conversion of fast elements |
| 2101 | // to slow elements. |
| 2102 | |
| 2103 | // Maximal gap that can be introduced by adding an element beyond |
| 2104 | // the current elements length. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2105 | static const uint32_t kMaxGap = 1024; |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 2106 | |
| 2107 | // Maximal length of fast elements array that won't be checked for |
| 2108 | // being dense enough on expansion. |
| 2109 | static const int kMaxUncheckedFastElementsLength = 5000; |
| 2110 | |
| 2111 | // Same as above but for old arrays. This limit is more strict. We |
| 2112 | // don't want to be wasteful with long lived objects. |
| 2113 | static const int kMaxUncheckedOldFastElementsLength = 500; |
| 2114 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2115 | static const int kInitialMaxFastElementArray = 100000; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2116 | static const int kFastPropertiesSoftLimit = 12; |
| 2117 | static const int kMaxFastProperties = 64; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2118 | static const int kMaxInstanceSize = 255 * kPointerSize; |
| 2119 | // When extending the backing storage for property values, we increase |
| 2120 | // its size by more than the 1 entry necessary, so sequentially adding fields |
| 2121 | // to the same object requires fewer allocations and copies. |
| 2122 | static const int kFieldsAdded = 3; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2123 | |
| 2124 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2125 | static const int kPropertiesOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2126 | static const int kElementsOffset = kPropertiesOffset + kPointerSize; |
| 2127 | static const int kHeaderSize = kElementsOffset + kPointerSize; |
| 2128 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 2129 | STATIC_CHECK(kHeaderSize == Internals::kJSObjectHeaderSize); |
| 2130 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2131 | class BodyDescriptor : public FlexibleBodyDescriptor<kPropertiesOffset> { |
| 2132 | public: |
| 2133 | static inline int SizeOf(Map* map, HeapObject* object); |
| 2134 | }; |
| 2135 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2136 | private: |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2137 | friend class DictionaryElementsAccessor; |
| 2138 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2139 | MUST_USE_RESULT MaybeObject* GetElementWithCallback(Object* receiver, |
| 2140 | Object* structure, |
| 2141 | uint32_t index, |
| 2142 | Object* holder); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2143 | MUST_USE_RESULT MaybeObject* SetElementWithCallback( |
| 2144 | Object* structure, |
| 2145 | uint32_t index, |
| 2146 | Object* value, |
| 2147 | JSObject* holder, |
| 2148 | StrictModeFlag strict_mode); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2149 | MUST_USE_RESULT MaybeObject* SetElementWithInterceptor( |
| 2150 | uint32_t index, |
| 2151 | Object* value, |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 2152 | PropertyAttributes attributes, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2153 | StrictModeFlag strict_mode, |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 2154 | bool check_prototype, |
| 2155 | SetPropertyMode set_mode); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 2156 | MUST_USE_RESULT MaybeObject* SetElementWithoutInterceptor( |
| 2157 | uint32_t index, |
| 2158 | Object* value, |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 2159 | PropertyAttributes attributes, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2160 | StrictModeFlag strict_mode, |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 2161 | bool check_prototype, |
| 2162 | SetPropertyMode set_mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2163 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2164 | // Searches the prototype chain for property 'name'. If it is found and |
| 2165 | // has a setter, invoke it and set '*done' to true. If it is found and is |
| 2166 | // read-only, reject and set '*done' to true. Otherwise, set '*done' to |
| 2167 | // false. Can cause GC and can return a failure result with '*done==true'. |
| 2168 | MUST_USE_RESULT MaybeObject* SetPropertyViaPrototypes( |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2169 | String* name, |
| 2170 | Object* value, |
| 2171 | PropertyAttributes attributes, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2172 | StrictModeFlag strict_mode, |
| 2173 | bool* done); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2174 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2175 | MUST_USE_RESULT MaybeObject* DeletePropertyPostInterceptor(String* name, |
| 2176 | DeleteMode mode); |
| 2177 | MUST_USE_RESULT MaybeObject* DeletePropertyWithInterceptor(String* name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2178 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2179 | MUST_USE_RESULT MaybeObject* DeleteElementWithInterceptor(uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2180 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2181 | MUST_USE_RESULT MaybeObject* DeleteFastElement(uint32_t index); |
| 2182 | MUST_USE_RESULT MaybeObject* DeleteDictionaryElement(uint32_t index, |
| 2183 | DeleteMode mode); |
| 2184 | |
| 2185 | bool ReferencesObjectFromElements(FixedArray* elements, |
| 2186 | ElementsKind kind, |
| 2187 | Object* object); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2188 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2189 | // Returns true if most of the elements backing storage is used. |
| 2190 | bool HasDenseElements(); |
| 2191 | |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 2192 | // Gets the current elements capacity and the number of used elements. |
| 2193 | void GetElementsCapacityAndUsage(int* capacity, int* used); |
| 2194 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2195 | bool CanSetCallback(String* name); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2196 | MUST_USE_RESULT MaybeObject* SetElementCallback( |
| 2197 | uint32_t index, |
| 2198 | Object* structure, |
| 2199 | PropertyAttributes attributes); |
| 2200 | MUST_USE_RESULT MaybeObject* SetPropertyCallback( |
| 2201 | String* name, |
| 2202 | Object* structure, |
| 2203 | PropertyAttributes attributes); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 2204 | MUST_USE_RESULT MaybeObject* DefineElementAccessor( |
| 2205 | uint32_t index, |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 2206 | Object* getter, |
| 2207 | Object* setter, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2208 | PropertyAttributes attributes); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 2209 | MUST_USE_RESULT MaybeObject* CreateAccessorPairFor(String* name); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 2210 | MUST_USE_RESULT MaybeObject* DefinePropertyAccessor( |
| 2211 | String* name, |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 2212 | Object* getter, |
| 2213 | Object* setter, |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 2214 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2215 | void LookupInDescriptor(String* name, LookupResult* result); |
| 2216 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2217 | // Returns the hidden properties backing store object, currently |
| 2218 | // a StringDictionary, stored on this object. |
| 2219 | // If no hidden properties object has been put on this object, |
| 2220 | // return undefined, unless create_if_absent is true, in which case |
| 2221 | // a new dictionary is created, added to this object, and returned. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2222 | MUST_USE_RESULT MaybeObject* GetHiddenPropertiesDictionary( |
| 2223 | bool create_if_absent); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2224 | // Updates the existing hidden properties dictionary. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2225 | MUST_USE_RESULT MaybeObject* SetHiddenPropertiesDictionary( |
| 2226 | StringDictionary* dictionary); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2227 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2228 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject); |
| 2229 | }; |
| 2230 | |
| 2231 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2232 | // Common superclass for FixedArrays that allow implementations to share |
| 2233 | // common accessors and some code paths. |
| 2234 | class FixedArrayBase: public HeapObject { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2235 | public: |
| 2236 | // [length]: length of the array. |
| 2237 | inline int length(); |
| 2238 | inline void set_length(int value); |
| 2239 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2240 | inline static FixedArrayBase* cast(Object* object); |
| 2241 | |
| 2242 | // Layout description. |
| 2243 | // Length is smi tagged when it is stored. |
| 2244 | static const int kLengthOffset = HeapObject::kHeaderSize; |
| 2245 | static const int kHeaderSize = kLengthOffset + kPointerSize; |
| 2246 | }; |
| 2247 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 2248 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 2249 | class FixedDoubleArray; |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2250 | |
| 2251 | // FixedArray describes fixed-sized arrays with element type Object*. |
| 2252 | class FixedArray: public FixedArrayBase { |
| 2253 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2254 | // Setter and getter for elements. |
| 2255 | inline Object* get(int index); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2256 | // Setter that uses write barrier. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2257 | inline void set(int index, Object* value); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2258 | inline bool is_the_hole(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2259 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2260 | // Setter that doesn't need write barrier). |
| 2261 | inline void set(int index, Smi* value); |
| 2262 | // Setter with explicit barrier mode. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2263 | inline void set(int index, Object* value, WriteBarrierMode mode); |
| 2264 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2265 | // Setters for frequently used oddballs located in old space. |
| 2266 | inline void set_undefined(int index); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2267 | // TODO(isolates): duplicate. |
| 2268 | inline void set_undefined(Heap* heap, int index); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2269 | inline void set_null(int index); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2270 | // TODO(isolates): duplicate. |
| 2271 | inline void set_null(Heap* heap, int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2272 | inline void set_the_hole(int index); |
| 2273 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 2274 | // Setters with less debug checks for the GC to use. |
| 2275 | inline void set_unchecked(int index, Smi* value); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2276 | inline void set_null_unchecked(Heap* heap, int index); |
| 2277 | inline void set_unchecked(Heap* heap, int index, Object* value, |
| 2278 | WriteBarrierMode mode); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 2279 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2280 | // Gives access to raw memory which stores the array's data. |
| 2281 | inline Object** data_start(); |
| 2282 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2283 | inline Object** GetFirstElementAddress(); |
| 2284 | inline bool ContainsOnlySmisOrHoles(); |
| 2285 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2286 | // Copy operations. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2287 | MUST_USE_RESULT inline MaybeObject* Copy(); |
| 2288 | MUST_USE_RESULT MaybeObject* CopySize(int new_length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2289 | |
| 2290 | // Add the elements of a JSArray to this FixedArray. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2291 | MUST_USE_RESULT MaybeObject* AddKeysFromJSArray(JSArray* array); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2292 | |
| 2293 | // Compute the union of this and other. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2294 | MUST_USE_RESULT MaybeObject* UnionOfKeys(FixedArray* other); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2295 | |
| 2296 | // Copy a sub array from the receiver to dest. |
| 2297 | void CopyTo(int pos, FixedArray* dest, int dest_pos, int len); |
| 2298 | |
| 2299 | // Garbage collection support. |
| 2300 | static int SizeFor(int length) { return kHeaderSize + length * kPointerSize; } |
| 2301 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2302 | // Code Generation support. |
| 2303 | static int OffsetOfElementAt(int index) { return SizeFor(index); } |
| 2304 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2305 | // Casting. |
| 2306 | static inline FixedArray* cast(Object* obj); |
| 2307 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2308 | // Maximal allowed size, in bytes, of a single FixedArray. |
| 2309 | // Prevents overflowing size computations, as well as extreme memory |
| 2310 | // consumption. |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 2311 | static const int kMaxSize = 128 * MB * kPointerSize; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2312 | // Maximally allowed length of a FixedArray. |
| 2313 | static const int kMaxLength = (kMaxSize - kHeaderSize) / kPointerSize; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2314 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2315 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2316 | #ifdef OBJECT_PRINT |
| 2317 | inline void FixedArrayPrint() { |
| 2318 | FixedArrayPrint(stdout); |
| 2319 | } |
| 2320 | void FixedArrayPrint(FILE* out); |
| 2321 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2322 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2323 | void FixedArrayVerify(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2324 | // Checks if two FixedArrays have identical contents. |
| 2325 | bool IsEqualTo(FixedArray* other); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2326 | #endif |
| 2327 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2328 | // Swap two elements in a pair of arrays. If this array and the |
| 2329 | // numbers array are the same object, the elements are only swapped |
| 2330 | // once. |
| 2331 | void SwapPairs(FixedArray* numbers, int i, int j); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2332 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2333 | // Sort prefix of this array and the numbers array as pairs wrt. the |
| 2334 | // numbers. If the numbers array and the this array are the same |
| 2335 | // object, the prefix of this array is sorted. |
| 2336 | void SortPairs(FixedArray* numbers, uint32_t len); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2337 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2338 | class BodyDescriptor : public FlexibleBodyDescriptor<kHeaderSize> { |
| 2339 | public: |
| 2340 | static inline int SizeOf(Map* map, HeapObject* object) { |
| 2341 | return SizeFor(reinterpret_cast<FixedArray*>(object)->length()); |
| 2342 | } |
| 2343 | }; |
| 2344 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2345 | protected: |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2346 | // Set operation on FixedArray without using write barriers. Can |
| 2347 | // only be used for storing old space objects or smis. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2348 | static inline void NoWriteBarrierSet(FixedArray* array, |
| 2349 | int index, |
| 2350 | Object* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2351 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2352 | // Set operation on FixedArray without incremental write barrier. Can |
| 2353 | // only be used if the object is guaranteed to be white (whiteness witness |
| 2354 | // is present). |
| 2355 | static inline void NoIncrementalWriteBarrierSet(FixedArray* array, |
| 2356 | int index, |
| 2357 | Object* value); |
| 2358 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2359 | private: |
| 2360 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedArray); |
| 2361 | }; |
| 2362 | |
| 2363 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2364 | // FixedDoubleArray describes fixed-sized arrays with element type double. |
| 2365 | class FixedDoubleArray: public FixedArrayBase { |
| 2366 | public: |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2367 | // Setter and getter for elements. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2368 | inline double get_scalar(int index); |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 2369 | inline int64_t get_representation(int index); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2370 | MUST_USE_RESULT inline MaybeObject* get(int index); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2371 | inline void set(int index, double value); |
| 2372 | inline void set_the_hole(int index); |
| 2373 | |
| 2374 | // Checking for the hole. |
| 2375 | inline bool is_the_hole(int index); |
| 2376 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2377 | // Copy operations |
| 2378 | MUST_USE_RESULT inline MaybeObject* Copy(); |
| 2379 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2380 | // Garbage collection support. |
| 2381 | inline static int SizeFor(int length) { |
| 2382 | return kHeaderSize + length * kDoubleSize; |
| 2383 | } |
| 2384 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 2385 | // Code Generation support. |
| 2386 | static int OffsetOfElementAt(int index) { return SizeFor(index); } |
| 2387 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2388 | inline static bool is_the_hole_nan(double value); |
| 2389 | inline static double hole_nan_as_double(); |
| 2390 | inline static double canonical_not_the_hole_nan_as_double(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2391 | |
| 2392 | // Casting. |
| 2393 | static inline FixedDoubleArray* cast(Object* obj); |
| 2394 | |
| 2395 | // Maximal allowed size, in bytes, of a single FixedDoubleArray. |
| 2396 | // Prevents overflowing size computations, as well as extreme memory |
| 2397 | // consumption. |
| 2398 | static const int kMaxSize = 512 * MB; |
| 2399 | // Maximally allowed length of a FixedArray. |
| 2400 | static const int kMaxLength = (kMaxSize - kHeaderSize) / kDoubleSize; |
| 2401 | |
| 2402 | // Dispatched behavior. |
| 2403 | #ifdef OBJECT_PRINT |
| 2404 | inline void FixedDoubleArrayPrint() { |
| 2405 | FixedDoubleArrayPrint(stdout); |
| 2406 | } |
| 2407 | void FixedDoubleArrayPrint(FILE* out); |
| 2408 | #endif |
| 2409 | |
| 2410 | #ifdef DEBUG |
| 2411 | void FixedDoubleArrayVerify(); |
| 2412 | #endif |
| 2413 | |
| 2414 | private: |
| 2415 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedDoubleArray); |
| 2416 | }; |
| 2417 | |
| 2418 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2419 | class IncrementalMarking; |
| 2420 | |
| 2421 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2422 | // DescriptorArrays are fixed arrays used to hold instance descriptors. |
| 2423 | // The format of the these objects is: |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2424 | // TODO(1399): It should be possible to make room for bit_field3 in the map |
| 2425 | // without overloading the instance descriptors field in the map |
| 2426 | // (and storing it in the DescriptorArray when the map has one). |
| 2427 | // [0]: storage for bit_field3 for Map owning this object (Smi) |
| 2428 | // [1]: point to a fixed array with (value, detail) pairs. |
| 2429 | // [2]: next enumeration index (Smi), or pointer to small fixed array: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2430 | // [0]: next enumeration index (Smi) |
| 2431 | // [1]: pointer to fixed array with enum cache |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2432 | // [3]: first key |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2433 | // [length() - 1]: last key |
| 2434 | // |
| 2435 | class DescriptorArray: public FixedArray { |
| 2436 | public: |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2437 | // Returns true for both shared empty_descriptor_array and for smis, which the |
| 2438 | // map uses to encode additional bit fields when the descriptor array is not |
| 2439 | // yet used. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2440 | inline bool IsEmpty(); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2441 | inline bool MayContainTransitions(); |
| 2442 | |
| 2443 | DECL_ACCESSORS(elements_transition_map, Map) |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 2444 | inline void ClearElementsTransition(); |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 2445 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2446 | // Returns the number of descriptors in the array. |
| 2447 | int number_of_descriptors() { |
verwaest@chromium.org | 5091559 | 2012-06-18 12:15:44 +0000 | [diff] [blame] | 2448 | ASSERT(length() >= kFirstIndex || IsEmpty()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2449 | int len = length(); |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2450 | return len <= kFirstIndex ? 0 : (len - kFirstIndex) / kDescriptorSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2451 | } |
| 2452 | |
| 2453 | int NextEnumerationIndex() { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2454 | if (IsEmpty()) return PropertyDetails::kInitialIndex; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2455 | Object* obj = get(kEnumerationIndexIndex); |
| 2456 | if (obj->IsSmi()) { |
| 2457 | return Smi::cast(obj)->value(); |
| 2458 | } else { |
| 2459 | Object* index = FixedArray::cast(obj)->get(kEnumCacheBridgeEnumIndex); |
| 2460 | return Smi::cast(index)->value(); |
| 2461 | } |
| 2462 | } |
| 2463 | |
| 2464 | // Set next enumeration index and flush any enum cache. |
| 2465 | void SetNextEnumerationIndex(int value) { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2466 | if (!IsEmpty()) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2467 | set(kEnumerationIndexIndex, Smi::FromInt(value)); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2468 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2469 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2470 | bool HasEnumCache() { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2471 | return !IsEmpty() && !get(kEnumerationIndexIndex)->IsSmi(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2472 | } |
| 2473 | |
| 2474 | Object* GetEnumCache() { |
| 2475 | ASSERT(HasEnumCache()); |
| 2476 | FixedArray* bridge = FixedArray::cast(get(kEnumerationIndexIndex)); |
| 2477 | return bridge->get(kEnumCacheBridgeCacheIndex); |
| 2478 | } |
| 2479 | |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2480 | Object** GetEnumCacheSlot() { |
| 2481 | ASSERT(HasEnumCache()); |
| 2482 | return HeapObject::RawField(reinterpret_cast<HeapObject*>(this), |
| 2483 | kEnumerationIndexOffset); |
| 2484 | } |
| 2485 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2486 | Object** GetTransitionsSlot() { |
| 2487 | ASSERT(elements_transition_map() != NULL); |
| 2488 | return HeapObject::RawField(reinterpret_cast<HeapObject*>(this), |
| 2489 | kTransitionsOffset); |
| 2490 | } |
| 2491 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2492 | // TODO(1399): It should be possible to make room for bit_field3 in the map |
| 2493 | // without overloading the instance descriptors field in the map |
| 2494 | // (and storing it in the DescriptorArray when the map has one). |
| 2495 | inline int bit_field3_storage(); |
| 2496 | inline void set_bit_field3_storage(int value); |
| 2497 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2498 | // Initialize or change the enum cache, |
| 2499 | // using the supplied storage for the small "bridge". |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 2500 | void SetEnumCache(FixedArray* bridge_storage, |
| 2501 | FixedArray* new_cache, |
| 2502 | Object* new_index_cache); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2503 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2504 | // Accessors for fetching instance descriptor at descriptor number. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2505 | inline String* GetKey(int descriptor_number); |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2506 | inline Object** GetKeySlot(int descriptor_number); |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 2507 | inline void SetKeyUnchecked(Heap* heap, int descriptor_number, String* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2508 | inline Object* GetValue(int descriptor_number); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 2509 | inline Object** GetValueSlot(int descriptor_number); |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 2510 | inline void SetNullValueUnchecked(Heap* heap, int descriptor_number); |
| 2511 | inline void SetValueUnchecked(Heap* heap, |
| 2512 | int descriptor_number, |
| 2513 | Object* value); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 2514 | inline PropertyDetails GetDetails(int descriptor_number); |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2515 | inline void SetDetailsUnchecked(int descriptor_number, Smi* value); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2516 | inline PropertyType GetType(int descriptor_number); |
| 2517 | inline int GetFieldIndex(int descriptor_number); |
| 2518 | inline JSFunction* GetConstantFunction(int descriptor_number); |
| 2519 | inline Object* GetCallbacksObject(int descriptor_number); |
| 2520 | inline AccessorDescriptor* GetCallbacks(int descriptor_number); |
| 2521 | inline bool IsProperty(int descriptor_number); |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 2522 | inline bool IsTransitionOnly(int descriptor_number); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2523 | |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 2524 | // WhitenessWitness is used to prove that a specific descriptor array is white |
| 2525 | // (unmarked), so incremental write barriers can be skipped because the |
| 2526 | // marking invariant cannot be broken and slots pointing into evacuation |
| 2527 | // candidates will be discovered when the object is scanned. A witness is |
| 2528 | // always stack-allocated right after creating a descriptor array. By |
| 2529 | // allocating a witness, incremental marking is globally disabled. The witness |
| 2530 | // is then passed along wherever needed to statically prove that the |
| 2531 | // descriptor array is known to be white. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2532 | class WhitenessWitness { |
| 2533 | public: |
| 2534 | inline explicit WhitenessWitness(DescriptorArray* array); |
| 2535 | inline ~WhitenessWitness(); |
| 2536 | |
| 2537 | private: |
| 2538 | IncrementalMarking* marking_; |
| 2539 | }; |
| 2540 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2541 | // Accessor for complete descriptor. |
| 2542 | inline void Get(int descriptor_number, Descriptor* desc); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2543 | inline void Set(int descriptor_number, |
| 2544 | Descriptor* desc, |
| 2545 | const WhitenessWitness&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2546 | |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 2547 | // Transfer a complete descriptor from the src descriptor array to the dst |
| 2548 | // one, dropping map transitions in CALLBACKS. |
| 2549 | static void CopyFrom(Handle<DescriptorArray> dst, |
| 2550 | int dst_index, |
| 2551 | Handle<DescriptorArray> src, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2552 | int src_index, |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 2553 | const WhitenessWitness& witness); |
| 2554 | |
| 2555 | // Transfer a complete descriptor from the src descriptor array to this |
| 2556 | // descriptor array, dropping map transitions in CALLBACKS. |
| 2557 | MUST_USE_RESULT MaybeObject* CopyFrom(int dst_index, |
| 2558 | DescriptorArray* src, |
| 2559 | int src_index, |
| 2560 | const WhitenessWitness&); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2561 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2562 | // Copy the descriptor array, insert a new descriptor and optionally |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2563 | // remove map transitions. If the descriptor is already present, it is |
| 2564 | // replaced. If a replaced descriptor is a real property (not a transition |
| 2565 | // or null), its enumeration index is kept as is. |
| 2566 | // If adding a real property, map transitions must be removed. If adding |
| 2567 | // a transition, they must not be removed. All null descriptors are removed. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2568 | MUST_USE_RESULT MaybeObject* CopyInsert(Descriptor* descriptor, |
| 2569 | TransitionFlag transition_flag); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2570 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2571 | // Indicates whether the search function should expect a sorted or an unsorted |
| 2572 | // descriptor array as input. |
| 2573 | enum SharedMode { |
| 2574 | MAY_BE_SHARED, |
| 2575 | CANNOT_BE_SHARED |
| 2576 | }; |
| 2577 | |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 2578 | // Return a copy of the array with all transitions and null descriptors |
| 2579 | // removed. Return a Failure object in case of an allocation failure. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2580 | MUST_USE_RESULT MaybeObject* RemoveTransitions(SharedMode shared_mode); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2581 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2582 | // Sort the instance descriptors by the hash codes of their keys. |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 2583 | // Does not check for duplicates. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2584 | void SortUnchecked(const WhitenessWitness&); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 2585 | |
| 2586 | // Sort the instance descriptors by the hash codes of their keys. |
| 2587 | // Checks the result for duplicates. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2588 | void Sort(const WhitenessWitness&); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2589 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2590 | // Search the instance descriptors for given name. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2591 | INLINE(int Search(String* name)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2592 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2593 | // As the above, but uses DescriptorLookupCache and updates it when |
| 2594 | // necessary. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2595 | INLINE(int SearchWithCache(String* name)); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2596 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2597 | // Tells whether the name is present int the array. |
| 2598 | bool Contains(String* name) { return kNotFound != Search(name); } |
| 2599 | |
| 2600 | // Perform a binary search in the instance descriptors represented |
| 2601 | // by this fixed array. low and high are descriptor indices. If there |
| 2602 | // are three instance descriptors in this array it should be called |
| 2603 | // with low=0 and high=2. |
| 2604 | int BinarySearch(String* name, int low, int high); |
| 2605 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2606 | // Perform a linear search in the instance descriptors represented |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2607 | // by this fixed array. len is the number of descriptor indices that are |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2608 | // valid. |
| 2609 | int LinearSearch(SearchMode mode, String* name, int len); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2610 | |
| 2611 | // Allocates a DescriptorArray, but returns the singleton |
| 2612 | // empty descriptor array object if number_of_descriptors is 0. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2613 | MUST_USE_RESULT static MaybeObject* Allocate(int number_of_descriptors, |
| 2614 | SharedMode shared_mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2615 | |
| 2616 | // Casting. |
| 2617 | static inline DescriptorArray* cast(Object* obj); |
| 2618 | |
| 2619 | // Constant for denoting key was not found. |
| 2620 | static const int kNotFound = -1; |
| 2621 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2622 | static const int kBitField3StorageIndex = 0; |
verwaest@chromium.org | 5091559 | 2012-06-18 12:15:44 +0000 | [diff] [blame] | 2623 | static const int kEnumerationIndexIndex = 1; |
| 2624 | static const int kTransitionsIndex = 2; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2625 | static const int kFirstIndex = 3; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2626 | |
| 2627 | // The length of the "bridge" to the enum cache. |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 2628 | static const int kEnumCacheBridgeLength = 3; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2629 | static const int kEnumCacheBridgeEnumIndex = 0; |
| 2630 | static const int kEnumCacheBridgeCacheIndex = 1; |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 2631 | static const int kEnumCacheBridgeIndicesCacheIndex = 2; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2632 | |
| 2633 | // Layout description. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2634 | static const int kBitField3StorageOffset = FixedArray::kHeaderSize; |
verwaest@chromium.org | 5091559 | 2012-06-18 12:15:44 +0000 | [diff] [blame] | 2635 | static const int kEnumerationIndexOffset = |
| 2636 | kBitField3StorageOffset + kPointerSize; |
| 2637 | static const int kTransitionsOffset = kEnumerationIndexOffset + kPointerSize; |
| 2638 | static const int kFirstOffset = kTransitionsOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2639 | |
| 2640 | // Layout description for the bridge array. |
| 2641 | static const int kEnumCacheBridgeEnumOffset = FixedArray::kHeaderSize; |
| 2642 | static const int kEnumCacheBridgeCacheOffset = |
| 2643 | kEnumCacheBridgeEnumOffset + kPointerSize; |
| 2644 | |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2645 | // Layout of descriptor. |
| 2646 | static const int kDescriptorKey = 0; |
| 2647 | static const int kDescriptorDetails = 1; |
| 2648 | static const int kDescriptorValue = 2; |
| 2649 | static const int kDescriptorSize = 3; |
| 2650 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2651 | #ifdef OBJECT_PRINT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2652 | // Print all the descriptors. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2653 | inline void PrintDescriptors() { |
| 2654 | PrintDescriptors(stdout); |
| 2655 | } |
| 2656 | void PrintDescriptors(FILE* out); |
| 2657 | #endif |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 2658 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2659 | #ifdef DEBUG |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 2660 | // Is the descriptor array sorted and without duplicates? |
| 2661 | bool IsSortedNoDuplicates(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2662 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 2663 | // Is the descriptor array consistent with the back pointers in targets? |
| 2664 | bool IsConsistentWithBackPointers(Map* current_map); |
| 2665 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2666 | // Are two DescriptorArrays equal? |
| 2667 | bool IsEqualTo(DescriptorArray* other); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2668 | #endif |
| 2669 | |
| 2670 | // The maximum number of descriptors we want in a descriptor array (should |
| 2671 | // fit in a page). |
| 2672 | static const int kMaxNumberOfDescriptors = 1024 + 512; |
| 2673 | |
| 2674 | private: |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2675 | // An entry in a DescriptorArray, represented as an (array, index) pair. |
| 2676 | class Entry { |
| 2677 | public: |
| 2678 | inline explicit Entry(DescriptorArray* descs, int index) : |
| 2679 | descs_(descs), index_(index) { } |
| 2680 | |
| 2681 | inline PropertyType type() { return descs_->GetType(index_); } |
| 2682 | inline Object* GetCallbackObject() { return descs_->GetValue(index_); } |
| 2683 | |
| 2684 | private: |
| 2685 | DescriptorArray* descs_; |
| 2686 | int index_; |
| 2687 | }; |
| 2688 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2689 | // Conversion from descriptor number to array indices. |
| 2690 | static int ToKeyIndex(int descriptor_number) { |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2691 | return kFirstIndex + |
| 2692 | (descriptor_number * kDescriptorSize) + |
| 2693 | kDescriptorKey; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2694 | } |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 2695 | |
| 2696 | static int ToDetailsIndex(int descriptor_number) { |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2697 | return kFirstIndex + |
| 2698 | (descriptor_number * kDescriptorSize) + |
| 2699 | kDescriptorDetails; |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 2700 | } |
| 2701 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2702 | static int ToValueIndex(int descriptor_number) { |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2703 | return kFirstIndex + |
| 2704 | (descriptor_number * kDescriptorSize) + |
| 2705 | kDescriptorValue; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2706 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2707 | |
| 2708 | // Swap operation on FixedArray without using write barriers. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2709 | static inline void NoIncrementalWriteBarrierSwap( |
| 2710 | FixedArray* array, int first, int second); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2711 | |
| 2712 | // Swap descriptor first and second. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2713 | inline void NoIncrementalWriteBarrierSwapDescriptors( |
| 2714 | int first, int second); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2715 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2716 | DISALLOW_IMPLICIT_CONSTRUCTORS(DescriptorArray); |
| 2717 | }; |
| 2718 | |
| 2719 | |
| 2720 | // HashTable is a subclass of FixedArray that implements a hash table |
| 2721 | // that uses open addressing and quadratic probing. |
| 2722 | // |
| 2723 | // In order for the quadratic probing to work, elements that have not |
| 2724 | // yet been used and elements that have been deleted are |
| 2725 | // distinguished. Probing continues when deleted elements are |
| 2726 | // encountered and stops when unused elements are encountered. |
| 2727 | // |
| 2728 | // - Elements with key == undefined have not been used yet. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2729 | // - Elements with key == the_hole have been deleted. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2730 | // |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2731 | // The hash table class is parameterized with a Shape and a Key. |
| 2732 | // Shape must be a class with the following interface: |
| 2733 | // class ExampleShape { |
| 2734 | // public: |
| 2735 | // // Tells whether key matches other. |
| 2736 | // static bool IsMatch(Key key, Object* other); |
| 2737 | // // Returns the hash value for key. |
| 2738 | // static uint32_t Hash(Key key); |
| 2739 | // // Returns the hash value for object. |
| 2740 | // static uint32_t HashForObject(Key key, Object* object); |
| 2741 | // // Convert key to an object. |
| 2742 | // static inline Object* AsObject(Key key); |
| 2743 | // // The prefix size indicates number of elements in the beginning |
| 2744 | // // of the backing storage. |
| 2745 | // static const int kPrefixSize = ..; |
| 2746 | // // The Element size indicates number of elements per entry. |
| 2747 | // static const int kEntrySize = ..; |
| 2748 | // }; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2749 | // The prefix size indicates an amount of memory in the |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2750 | // beginning of the backing storage that can be used for non-element |
| 2751 | // information by subclasses. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2752 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2753 | template<typename Key> |
| 2754 | class BaseShape { |
| 2755 | public: |
| 2756 | static const bool UsesSeed = false; |
| 2757 | static uint32_t Hash(Key key) { return 0; } |
| 2758 | static uint32_t SeededHash(Key key, uint32_t seed) { |
| 2759 | ASSERT(UsesSeed); |
| 2760 | return Hash(key); |
| 2761 | } |
| 2762 | static uint32_t HashForObject(Key key, Object* object) { return 0; } |
| 2763 | static uint32_t SeededHashForObject(Key key, uint32_t seed, Object* object) { |
| 2764 | ASSERT(UsesSeed); |
| 2765 | return HashForObject(key, object); |
| 2766 | } |
| 2767 | }; |
| 2768 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2769 | template<typename Shape, typename Key> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2770 | class HashTable: public FixedArray { |
| 2771 | public: |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2772 | // Wrapper methods |
| 2773 | inline uint32_t Hash(Key key) { |
| 2774 | if (Shape::UsesSeed) { |
| 2775 | return Shape::SeededHash(key, |
| 2776 | GetHeap()->HashSeed()); |
| 2777 | } else { |
| 2778 | return Shape::Hash(key); |
| 2779 | } |
| 2780 | } |
| 2781 | |
| 2782 | inline uint32_t HashForObject(Key key, Object* object) { |
| 2783 | if (Shape::UsesSeed) { |
| 2784 | return Shape::SeededHashForObject(key, |
| 2785 | GetHeap()->HashSeed(), object); |
| 2786 | } else { |
| 2787 | return Shape::HashForObject(key, object); |
| 2788 | } |
| 2789 | } |
| 2790 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2791 | // Returns the number of elements in the hash table. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2792 | int NumberOfElements() { |
| 2793 | return Smi::cast(get(kNumberOfElementsIndex))->value(); |
| 2794 | } |
| 2795 | |
kasperl@chromium.org | edf0cd1 | 2010-01-05 13:29:12 +0000 | [diff] [blame] | 2796 | // Returns the number of deleted elements in the hash table. |
| 2797 | int NumberOfDeletedElements() { |
| 2798 | return Smi::cast(get(kNumberOfDeletedElementsIndex))->value(); |
| 2799 | } |
| 2800 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2801 | // Returns the capacity of the hash table. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2802 | int Capacity() { |
| 2803 | return Smi::cast(get(kCapacityIndex))->value(); |
| 2804 | } |
| 2805 | |
| 2806 | // 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] | 2807 | // hash table. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2808 | void ElementAdded() { SetNumberOfElements(NumberOfElements() + 1); } |
| 2809 | |
| 2810 | // 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] | 2811 | // a hash table. |
kasperl@chromium.org | edf0cd1 | 2010-01-05 13:29:12 +0000 | [diff] [blame] | 2812 | void ElementRemoved() { |
| 2813 | SetNumberOfElements(NumberOfElements() - 1); |
| 2814 | SetNumberOfDeletedElements(NumberOfDeletedElements() + 1); |
| 2815 | } |
| 2816 | void ElementsRemoved(int n) { |
| 2817 | SetNumberOfElements(NumberOfElements() - n); |
| 2818 | SetNumberOfDeletedElements(NumberOfDeletedElements() + n); |
| 2819 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2820 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2821 | // Returns a new HashTable object. Might return Failure. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2822 | MUST_USE_RESULT static MaybeObject* Allocate( |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2823 | int at_least_space_for, |
| 2824 | PretenureFlag pretenure = NOT_TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2825 | |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 2826 | // Computes the required capacity for a table holding the given |
| 2827 | // number of elements. May be more than HashTable::kMaxCapacity. |
| 2828 | static int ComputeCapacity(int at_least_space_for); |
| 2829 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2830 | // Returns the key at entry. |
| 2831 | Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } |
| 2832 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2833 | // 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] | 2834 | // as keys and can be used to indicate missing or deleted elements. |
| 2835 | bool IsKey(Object* k) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2836 | return !k->IsTheHole() && !k->IsUndefined(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2837 | } |
| 2838 | |
| 2839 | // Garbage collection support. |
| 2840 | void IteratePrefix(ObjectVisitor* visitor); |
| 2841 | void IterateElements(ObjectVisitor* visitor); |
| 2842 | |
| 2843 | // Casting. |
| 2844 | static inline HashTable* cast(Object* obj); |
| 2845 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2846 | // Compute the probe offset (quadratic probing). |
| 2847 | INLINE(static uint32_t GetProbeOffset(uint32_t n)) { |
| 2848 | return (n + n * n) >> 1; |
| 2849 | } |
| 2850 | |
| 2851 | static const int kNumberOfElementsIndex = 0; |
kasperl@chromium.org | edf0cd1 | 2010-01-05 13:29:12 +0000 | [diff] [blame] | 2852 | static const int kNumberOfDeletedElementsIndex = 1; |
| 2853 | static const int kCapacityIndex = 2; |
| 2854 | static const int kPrefixStartIndex = 3; |
| 2855 | static const int kElementsStartIndex = |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2856 | kPrefixStartIndex + Shape::kPrefixSize; |
kasperl@chromium.org | edf0cd1 | 2010-01-05 13:29:12 +0000 | [diff] [blame] | 2857 | static const int kEntrySize = Shape::kEntrySize; |
| 2858 | static const int kElementsStartOffset = |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2859 | kHeaderSize + kElementsStartIndex * kPointerSize; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2860 | static const int kCapacityOffset = |
| 2861 | kHeaderSize + kCapacityIndex * kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2862 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2863 | // Constant used for denoting a absent entry. |
| 2864 | static const int kNotFound = -1; |
| 2865 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2866 | // Maximal capacity of HashTable. Based on maximal length of underlying |
| 2867 | // FixedArray. Staying below kMaxCapacity also ensures that EntryToIndex |
| 2868 | // cannot overflow. |
| 2869 | static const int kMaxCapacity = |
| 2870 | (FixedArray::kMaxLength - kElementsStartOffset) / kEntrySize; |
| 2871 | |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2872 | // Find entry for key otherwise return kNotFound. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2873 | inline int FindEntry(Key key); |
| 2874 | int FindEntry(Isolate* isolate, Key key); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2875 | |
| 2876 | protected: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2877 | // Find the entry at which to insert element with the given key that |
| 2878 | // has the given hash value. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2879 | uint32_t FindInsertionEntry(uint32_t hash); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2880 | |
| 2881 | // Returns the index for an entry (of the key) |
| 2882 | static inline int EntryToIndex(int entry) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2883 | return (entry * kEntrySize) + kElementsStartIndex; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2884 | } |
| 2885 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2886 | // Update the number of elements in the hash table. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2887 | void SetNumberOfElements(int nof) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2888 | set(kNumberOfElementsIndex, Smi::FromInt(nof)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2889 | } |
| 2890 | |
kasperl@chromium.org | edf0cd1 | 2010-01-05 13:29:12 +0000 | [diff] [blame] | 2891 | // Update the number of deleted elements in the hash table. |
| 2892 | void SetNumberOfDeletedElements(int nod) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2893 | set(kNumberOfDeletedElementsIndex, Smi::FromInt(nod)); |
kasperl@chromium.org | edf0cd1 | 2010-01-05 13:29:12 +0000 | [diff] [blame] | 2894 | } |
| 2895 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2896 | // Sets the capacity of the hash table. |
| 2897 | void SetCapacity(int capacity) { |
| 2898 | // To scale a computed hash code to fit within the hash table, we |
| 2899 | // use bit-wise AND with a mask, so the capacity must be positive |
| 2900 | // and non-zero. |
| 2901 | ASSERT(capacity > 0); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2902 | ASSERT(capacity <= kMaxCapacity); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2903 | set(kCapacityIndex, Smi::FromInt(capacity)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2904 | } |
| 2905 | |
| 2906 | |
| 2907 | // Returns probe entry. |
| 2908 | static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size) { |
| 2909 | ASSERT(IsPowerOf2(size)); |
| 2910 | return (hash + GetProbeOffset(number)) & (size - 1); |
| 2911 | } |
| 2912 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2913 | static uint32_t FirstProbe(uint32_t hash, uint32_t size) { |
| 2914 | return hash & (size - 1); |
| 2915 | } |
| 2916 | |
| 2917 | static uint32_t NextProbe(uint32_t last, uint32_t number, uint32_t size) { |
| 2918 | return (last + number) & (size - 1); |
| 2919 | } |
| 2920 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 2921 | // Rehashes this hash-table into the new table. |
| 2922 | MUST_USE_RESULT MaybeObject* Rehash(HashTable* new_table, Key key); |
| 2923 | |
| 2924 | // Attempt to shrink hash table after removal of key. |
| 2925 | MUST_USE_RESULT MaybeObject* Shrink(Key key); |
| 2926 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2927 | // Ensure enough space for n additional elements. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2928 | MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2929 | }; |
| 2930 | |
| 2931 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2932 | // HashTableKey is an abstract superclass for virtual key behavior. |
| 2933 | class HashTableKey { |
| 2934 | public: |
| 2935 | // Returns whether the other object matches this key. |
| 2936 | virtual bool IsMatch(Object* other) = 0; |
| 2937 | // Returns the hash value for this key. |
| 2938 | virtual uint32_t Hash() = 0; |
| 2939 | // Returns the hash value for object. |
| 2940 | virtual uint32_t HashForObject(Object* key) = 0; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2941 | // Returns the key object for storing into the hash table. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2942 | // If allocations fails a failure object is returned. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2943 | MUST_USE_RESULT virtual MaybeObject* AsObject() = 0; |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2944 | // Required. |
| 2945 | virtual ~HashTableKey() {} |
| 2946 | }; |
| 2947 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2948 | |
| 2949 | class SymbolTableShape : public BaseShape<HashTableKey*> { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2950 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2951 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2952 | return key->IsMatch(value); |
| 2953 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2954 | static inline uint32_t Hash(HashTableKey* key) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2955 | return key->Hash(); |
| 2956 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2957 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2958 | return key->HashForObject(object); |
| 2959 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2960 | MUST_USE_RESULT static inline MaybeObject* AsObject(HashTableKey* key) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2961 | return key->AsObject(); |
| 2962 | } |
| 2963 | |
| 2964 | static const int kPrefixSize = 0; |
| 2965 | static const int kEntrySize = 1; |
| 2966 | }; |
| 2967 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2968 | class SeqAsciiString; |
| 2969 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2970 | // SymbolTable. |
| 2971 | // |
| 2972 | // No special elements in the prefix and the element size is 1 |
| 2973 | // because only the symbol itself (the key) needs to be stored. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2974 | class SymbolTable: public HashTable<SymbolTableShape, HashTableKey*> { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2975 | public: |
| 2976 | // Find symbol in the symbol table. If it is not there yet, it is |
| 2977 | // added. The return value is the symbol table which might have |
| 2978 | // been enlarged. If the return value is not a failure, the symbol |
| 2979 | // pointer *s is set to the symbol found. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2980 | MUST_USE_RESULT MaybeObject* LookupSymbol(Vector<const char> str, Object** s); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 2981 | MUST_USE_RESULT MaybeObject* LookupAsciiSymbol(Vector<const char> str, |
| 2982 | Object** s); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2983 | MUST_USE_RESULT MaybeObject* LookupSubStringAsciiSymbol( |
| 2984 | Handle<SeqAsciiString> str, |
| 2985 | int from, |
| 2986 | int length, |
| 2987 | Object** s); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 2988 | MUST_USE_RESULT MaybeObject* LookupTwoByteSymbol(Vector<const uc16> str, |
| 2989 | Object** s); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2990 | MUST_USE_RESULT MaybeObject* LookupString(String* key, Object** s); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2991 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2992 | // Looks up a symbol that is equal to the given string and returns |
| 2993 | // true if it is found, assigning the symbol to the given output |
| 2994 | // parameter. |
| 2995 | bool LookupSymbolIfExists(String* str, String** symbol); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 2996 | bool LookupTwoCharsSymbolIfExists(uint32_t c1, uint32_t c2, String** symbol); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2997 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2998 | // Casting. |
| 2999 | static inline SymbolTable* cast(Object* obj); |
| 3000 | |
| 3001 | private: |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3002 | MUST_USE_RESULT MaybeObject* LookupKey(HashTableKey* key, Object** s); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3003 | |
| 3004 | DISALLOW_IMPLICIT_CONSTRUCTORS(SymbolTable); |
| 3005 | }; |
| 3006 | |
| 3007 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3008 | class MapCacheShape : public BaseShape<HashTableKey*> { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3009 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3010 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3011 | return key->IsMatch(value); |
| 3012 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3013 | static inline uint32_t Hash(HashTableKey* key) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3014 | return key->Hash(); |
| 3015 | } |
| 3016 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3017 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3018 | return key->HashForObject(object); |
| 3019 | } |
| 3020 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3021 | MUST_USE_RESULT static inline MaybeObject* AsObject(HashTableKey* key) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3022 | return key->AsObject(); |
| 3023 | } |
| 3024 | |
| 3025 | static const int kPrefixSize = 0; |
| 3026 | static const int kEntrySize = 2; |
| 3027 | }; |
| 3028 | |
| 3029 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 3030 | // MapCache. |
| 3031 | // |
| 3032 | // Maps keys that are a fixed array of symbols to a map. |
| 3033 | // Used for canonicalize maps for object literals. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3034 | class MapCache: public HashTable<MapCacheShape, HashTableKey*> { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 3035 | public: |
| 3036 | // Find cached value for a string key, otherwise return null. |
| 3037 | Object* Lookup(FixedArray* key); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3038 | MUST_USE_RESULT MaybeObject* Put(FixedArray* key, Map* value); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 3039 | static inline MapCache* cast(Object* obj); |
| 3040 | |
| 3041 | private: |
| 3042 | DISALLOW_IMPLICIT_CONSTRUCTORS(MapCache); |
| 3043 | }; |
| 3044 | |
| 3045 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3046 | template <typename Shape, typename Key> |
| 3047 | class Dictionary: public HashTable<Shape, Key> { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3048 | public: |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3049 | static inline Dictionary<Shape, Key>* cast(Object* obj) { |
| 3050 | return reinterpret_cast<Dictionary<Shape, Key>*>(obj); |
| 3051 | } |
| 3052 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3053 | // Returns the value at entry. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 3054 | Object* ValueAt(int entry) { |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3055 | return this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 1); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 3056 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3057 | |
| 3058 | // Set the value for entry. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3059 | void ValueAtPut(int entry, Object* value) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 3060 | this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 1, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3061 | } |
| 3062 | |
| 3063 | // Returns the property details for the property at entry. |
| 3064 | PropertyDetails DetailsAt(int entry) { |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 3065 | 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] | 3066 | return PropertyDetails( |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 3067 | Smi::cast(this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 2))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3068 | } |
| 3069 | |
| 3070 | // Set the details for entry. |
| 3071 | void DetailsAtPut(int entry, PropertyDetails value) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 3072 | this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 2, value.AsSmi()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3073 | } |
| 3074 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3075 | // Sorting support |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3076 | void CopyValuesTo(FixedArray* elements); |
| 3077 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3078 | // Delete a property from the dictionary. |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 3079 | Object* DeleteProperty(int entry, JSObject::DeleteMode mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3080 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 3081 | // Attempt to shrink the dictionary after deletion of key. |
| 3082 | MUST_USE_RESULT MaybeObject* Shrink(Key key); |
| 3083 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3084 | // Returns the number of elements in the dictionary filtering out properties |
| 3085 | // with the specified attributes. |
| 3086 | int NumberOfElementsFilterAttributes(PropertyAttributes filter); |
| 3087 | |
| 3088 | // Returns the number of enumerable elements in the dictionary. |
| 3089 | int NumberOfEnumElements(); |
| 3090 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 3091 | enum SortMode { UNSORTED, SORTED }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3092 | // Copies keys to preallocated fixed array. |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 3093 | void CopyKeysTo(FixedArray* storage, |
| 3094 | PropertyAttributes filter, |
| 3095 | SortMode sort_mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3096 | // Fill in details for properties into storage. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3097 | void CopyKeysTo(FixedArray* storage, int index, SortMode sort_mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3098 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3099 | // Accessors for next enumeration index. |
| 3100 | void SetNextEnumerationIndex(int index) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3101 | this->set(kNextEnumerationIndexIndex, Smi::FromInt(index)); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3102 | } |
| 3103 | |
| 3104 | int NextEnumerationIndex() { |
| 3105 | return Smi::cast(FixedArray::get(kNextEnumerationIndexIndex))->value(); |
| 3106 | } |
| 3107 | |
| 3108 | // Returns a new array for dictionary usage. Might return Failure. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3109 | MUST_USE_RESULT static MaybeObject* Allocate(int at_least_space_for); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3110 | |
| 3111 | // Ensure enough space for n additional elements. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3112 | MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3113 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3114 | #ifdef OBJECT_PRINT |
| 3115 | inline void Print() { |
| 3116 | Print(stdout); |
| 3117 | } |
| 3118 | void Print(FILE* out); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3119 | #endif |
| 3120 | // Returns the key (slow). |
| 3121 | Object* SlowReverseLookup(Object* value); |
| 3122 | |
| 3123 | // Sets the entry to (key, value) pair. |
| 3124 | inline void SetEntry(int entry, |
| 3125 | Object* key, |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 3126 | Object* value); |
| 3127 | inline void SetEntry(int entry, |
| 3128 | Object* key, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3129 | Object* value, |
| 3130 | PropertyDetails details); |
| 3131 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3132 | MUST_USE_RESULT MaybeObject* Add(Key key, |
| 3133 | Object* value, |
| 3134 | PropertyDetails details); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3135 | |
| 3136 | protected: |
| 3137 | // Generic at put operation. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3138 | MUST_USE_RESULT MaybeObject* AtPut(Key key, Object* value); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3139 | |
| 3140 | // Add entry to dictionary. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3141 | MUST_USE_RESULT MaybeObject* AddEntry(Key key, |
| 3142 | Object* value, |
| 3143 | PropertyDetails details, |
| 3144 | uint32_t hash); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3145 | |
| 3146 | // Generate new enumeration indices to avoid enumeration index overflow. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3147 | MUST_USE_RESULT MaybeObject* GenerateNewEnumerationIndices(); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3148 | static const int kMaxNumberKeyIndex = |
| 3149 | HashTable<Shape, Key>::kPrefixStartIndex; |
| 3150 | static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1; |
| 3151 | }; |
| 3152 | |
| 3153 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3154 | class StringDictionaryShape : public BaseShape<String*> { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3155 | public: |
| 3156 | static inline bool IsMatch(String* key, Object* other); |
| 3157 | static inline uint32_t Hash(String* key); |
| 3158 | static inline uint32_t HashForObject(String* key, Object* object); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3159 | MUST_USE_RESULT static inline MaybeObject* AsObject(String* key); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3160 | static const int kPrefixSize = 2; |
| 3161 | static const int kEntrySize = 3; |
| 3162 | static const bool kIsEnumerable = true; |
| 3163 | }; |
| 3164 | |
| 3165 | |
| 3166 | class StringDictionary: public Dictionary<StringDictionaryShape, String*> { |
| 3167 | public: |
| 3168 | static inline StringDictionary* cast(Object* obj) { |
| 3169 | ASSERT(obj->IsDictionary()); |
| 3170 | return reinterpret_cast<StringDictionary*>(obj); |
| 3171 | } |
| 3172 | |
| 3173 | // Copies enumerable keys to preallocated fixed array. |
| 3174 | void CopyEnumKeysTo(FixedArray* storage, FixedArray* sort_array); |
| 3175 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3176 | // For transforming properties of a JSObject. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3177 | MUST_USE_RESULT MaybeObject* TransformPropertiesToFastFor( |
| 3178 | JSObject* obj, |
| 3179 | int unused_property_fields); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 3180 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3181 | // Find entry for key, otherwise return kNotFound. Optimized version of |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 3182 | // HashTable::FindEntry. |
| 3183 | int FindEntry(String* key); |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 3184 | |
| 3185 | bool ContainsTransition(int entry); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3186 | }; |
| 3187 | |
| 3188 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3189 | class NumberDictionaryShape : public BaseShape<uint32_t> { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3190 | public: |
| 3191 | static inline bool IsMatch(uint32_t key, Object* other); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3192 | MUST_USE_RESULT static inline MaybeObject* AsObject(uint32_t key); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3193 | static const int kEntrySize = 3; |
| 3194 | static const bool kIsEnumerable = false; |
| 3195 | }; |
| 3196 | |
| 3197 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3198 | class SeededNumberDictionaryShape : public NumberDictionaryShape { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3199 | public: |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3200 | static const bool UsesSeed = true; |
| 3201 | static const int kPrefixSize = 2; |
| 3202 | |
| 3203 | static inline uint32_t SeededHash(uint32_t key, uint32_t seed); |
| 3204 | static inline uint32_t SeededHashForObject(uint32_t key, |
| 3205 | uint32_t seed, |
| 3206 | Object* object); |
| 3207 | }; |
| 3208 | |
| 3209 | |
| 3210 | class UnseededNumberDictionaryShape : public NumberDictionaryShape { |
| 3211 | public: |
| 3212 | static const int kPrefixSize = 0; |
| 3213 | |
| 3214 | static inline uint32_t Hash(uint32_t key); |
| 3215 | static inline uint32_t HashForObject(uint32_t key, Object* object); |
| 3216 | }; |
| 3217 | |
| 3218 | |
| 3219 | class SeededNumberDictionary |
| 3220 | : public Dictionary<SeededNumberDictionaryShape, uint32_t> { |
| 3221 | public: |
| 3222 | static SeededNumberDictionary* cast(Object* obj) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3223 | ASSERT(obj->IsDictionary()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3224 | return reinterpret_cast<SeededNumberDictionary*>(obj); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3225 | } |
| 3226 | |
| 3227 | // Type specific at put (default NONE attributes is used when adding). |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3228 | MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value); |
| 3229 | MUST_USE_RESULT MaybeObject* AddNumberEntry(uint32_t key, |
| 3230 | Object* value, |
| 3231 | PropertyDetails details); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3232 | |
| 3233 | // 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] | 3234 | // Return the updated dictionary. |
| 3235 | MUST_USE_RESULT static Handle<SeededNumberDictionary> Set( |
| 3236 | Handle<SeededNumberDictionary> dictionary, |
| 3237 | uint32_t index, |
| 3238 | Handle<Object> value, |
| 3239 | PropertyDetails details); |
| 3240 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3241 | MUST_USE_RESULT MaybeObject* Set(uint32_t key, |
| 3242 | Object* value, |
| 3243 | PropertyDetails details); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 3244 | |
| 3245 | void UpdateMaxNumberKey(uint32_t key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3246 | |
| 3247 | // If slow elements are required we will never go back to fast-case |
| 3248 | // for the elements kept in this dictionary. We require slow |
| 3249 | // 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] | 3250 | // kRequiresSlowElementsLimit or set_requires_slow_elements() has been called |
| 3251 | // when defining a getter or setter with a number key. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3252 | inline bool requires_slow_elements(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3253 | inline void set_requires_slow_elements(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3254 | |
| 3255 | // Get the value of the max number key that has been added to this |
| 3256 | // dictionary. max_number_key can only be called if |
| 3257 | // requires_slow_elements returns false. |
| 3258 | inline uint32_t max_number_key(); |
| 3259 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3260 | // Bit masks. |
| 3261 | static const int kRequiresSlowElementsMask = 1; |
| 3262 | static const int kRequiresSlowElementsTagSize = 1; |
| 3263 | static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3264 | }; |
| 3265 | |
| 3266 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3267 | class UnseededNumberDictionary |
| 3268 | : public Dictionary<UnseededNumberDictionaryShape, uint32_t> { |
| 3269 | public: |
| 3270 | static UnseededNumberDictionary* cast(Object* obj) { |
| 3271 | ASSERT(obj->IsDictionary()); |
| 3272 | return reinterpret_cast<UnseededNumberDictionary*>(obj); |
| 3273 | } |
| 3274 | |
| 3275 | // Type specific at put (default NONE attributes is used when adding). |
| 3276 | MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value); |
| 3277 | MUST_USE_RESULT MaybeObject* AddNumberEntry(uint32_t key, Object* value); |
| 3278 | |
| 3279 | // Set an existing entry or add a new one if needed. |
| 3280 | // Return the updated dictionary. |
| 3281 | MUST_USE_RESULT static Handle<UnseededNumberDictionary> Set( |
| 3282 | Handle<UnseededNumberDictionary> dictionary, |
| 3283 | uint32_t index, |
| 3284 | Handle<Object> value); |
| 3285 | |
| 3286 | MUST_USE_RESULT MaybeObject* Set(uint32_t key, Object* value); |
| 3287 | }; |
| 3288 | |
| 3289 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3290 | template <int entrysize> |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3291 | class ObjectHashTableShape : public BaseShape<Object*> { |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 3292 | public: |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3293 | static inline bool IsMatch(Object* key, Object* other); |
| 3294 | static inline uint32_t Hash(Object* key); |
| 3295 | static inline uint32_t HashForObject(Object* key, Object* object); |
| 3296 | MUST_USE_RESULT static inline MaybeObject* AsObject(Object* key); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 3297 | static const int kPrefixSize = 0; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3298 | static const int kEntrySize = entrysize; |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 3299 | }; |
| 3300 | |
| 3301 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3302 | // ObjectHashSet holds keys that are arbitrary objects by using the identity |
| 3303 | // hash of the key for hashing purposes. |
| 3304 | class ObjectHashSet: public HashTable<ObjectHashTableShape<1>, Object*> { |
| 3305 | public: |
| 3306 | static inline ObjectHashSet* cast(Object* obj) { |
| 3307 | ASSERT(obj->IsHashTable()); |
| 3308 | return reinterpret_cast<ObjectHashSet*>(obj); |
| 3309 | } |
| 3310 | |
| 3311 | // Looks up whether the given key is part of this hash set. |
| 3312 | bool Contains(Object* key); |
| 3313 | |
| 3314 | // Adds the given key to this hash set. |
| 3315 | MUST_USE_RESULT MaybeObject* Add(Object* key); |
| 3316 | |
| 3317 | // Removes the given key from this hash set. |
| 3318 | MUST_USE_RESULT MaybeObject* Remove(Object* key); |
| 3319 | }; |
| 3320 | |
| 3321 | |
| 3322 | // ObjectHashTable maps keys that are arbitrary objects to object values by |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 3323 | // using the identity hash of the key for hashing purposes. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3324 | class ObjectHashTable: public HashTable<ObjectHashTableShape<2>, Object*> { |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 3325 | public: |
| 3326 | static inline ObjectHashTable* cast(Object* obj) { |
| 3327 | ASSERT(obj->IsHashTable()); |
| 3328 | return reinterpret_cast<ObjectHashTable*>(obj); |
| 3329 | } |
| 3330 | |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3331 | // 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] | 3332 | // returned in case the key is not present. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3333 | Object* Lookup(Object* key); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 3334 | |
| 3335 | // 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] | 3336 | // 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] | 3337 | MUST_USE_RESULT MaybeObject* Put(Object* key, Object* value); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 3338 | |
| 3339 | private: |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3340 | friend class MarkCompactCollector; |
| 3341 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3342 | void AddEntry(int entry, Object* key, Object* value); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3343 | void RemoveEntry(int entry); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3344 | |
| 3345 | // Returns the index to the value of an entry. |
| 3346 | static inline int EntryToValueIndex(int entry) { |
| 3347 | return EntryToIndex(entry) + 1; |
| 3348 | } |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 3349 | }; |
| 3350 | |
| 3351 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 3352 | // JSFunctionResultCache caches results of some JSFunction invocation. |
| 3353 | // It is a fixed array with fixed structure: |
| 3354 | // [0]: factory function |
| 3355 | // [1]: finger index |
| 3356 | // [2]: current cache size |
| 3357 | // [3]: dummy field. |
| 3358 | // The rest of array are key/value pairs. |
| 3359 | class JSFunctionResultCache: public FixedArray { |
| 3360 | public: |
| 3361 | static const int kFactoryIndex = 0; |
| 3362 | static const int kFingerIndex = kFactoryIndex + 1; |
| 3363 | static const int kCacheSizeIndex = kFingerIndex + 1; |
| 3364 | static const int kDummyIndex = kCacheSizeIndex + 1; |
| 3365 | static const int kEntriesIndex = kDummyIndex + 1; |
antonm@chromium.org | 397e23c | 2010-04-21 12:00:05 +0000 | [diff] [blame] | 3366 | |
| 3367 | static const int kEntrySize = 2; // key + value |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3368 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3369 | static const int kFactoryOffset = kHeaderSize; |
| 3370 | static const int kFingerOffset = kFactoryOffset + kPointerSize; |
| 3371 | static const int kCacheSizeOffset = kFingerOffset + kPointerSize; |
| 3372 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3373 | inline void MakeZeroSize(); |
| 3374 | inline void Clear(); |
| 3375 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3376 | inline int size(); |
| 3377 | inline void set_size(int size); |
| 3378 | inline int finger_index(); |
| 3379 | inline void set_finger_index(int finger_index); |
| 3380 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3381 | // Casting |
| 3382 | static inline JSFunctionResultCache* cast(Object* obj); |
| 3383 | |
| 3384 | #ifdef DEBUG |
| 3385 | void JSFunctionResultCacheVerify(); |
| 3386 | #endif |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 3387 | }; |
| 3388 | |
| 3389 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3390 | // ScopeInfo represents information about different scopes of a source |
| 3391 | // program and the allocation of the scope's variables. Scope information |
| 3392 | // is stored in a compressed form in ScopeInfo objects and is used |
| 3393 | // at runtime (stack dumps, deoptimization, etc.). |
| 3394 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3395 | // This object provides quick access to scope info details for runtime |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3396 | // routines. |
| 3397 | class ScopeInfo : public FixedArray { |
| 3398 | public: |
| 3399 | static inline ScopeInfo* cast(Object* object); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3400 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3401 | // Return the type of this scope. |
| 3402 | ScopeType Type(); |
| 3403 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3404 | // Does this scope call eval? |
| 3405 | bool CallsEval(); |
| 3406 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3407 | // Return the language mode of this scope. |
| 3408 | LanguageMode language_mode(); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3409 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3410 | // Does this scope make a non-strict eval call? |
| 3411 | bool CallsNonStrictEval() { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3412 | return CallsEval() && (language_mode() == CLASSIC_MODE); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3413 | } |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3414 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3415 | // Return the total number of locals allocated on the stack and in the |
| 3416 | // context. This includes the parameters that are allocated in the context. |
| 3417 | int LocalCount(); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3418 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3419 | // Return the number of stack slots for code. This number consists of two |
| 3420 | // parts: |
| 3421 | // 1. One stack slot per stack allocated local. |
| 3422 | // 2. One stack slot for the function name if it is stack allocated. |
| 3423 | int StackSlotCount(); |
| 3424 | |
| 3425 | // Return the number of context slots for code if a context is allocated. This |
| 3426 | // number consists of three parts: |
| 3427 | // 1. Size of fixed header for every context: Context::MIN_CONTEXT_SLOTS |
| 3428 | // 2. One context slot per context allocated local. |
| 3429 | // 3. One context slot for the function name if it is context allocated. |
| 3430 | // Parameters allocated in the context count as context allocated locals. If |
| 3431 | // no contexts are allocated for this scope ContextLength returns 0. |
| 3432 | int ContextLength(); |
| 3433 | |
| 3434 | // Is this scope the scope of a named function expression? |
| 3435 | bool HasFunctionName(); |
| 3436 | |
| 3437 | // Return if this has context allocated locals. |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3438 | bool HasHeapAllocatedLocals(); |
| 3439 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3440 | // Return if contexts are allocated for this scope. |
| 3441 | bool HasContext(); |
| 3442 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3443 | // Return the function_name if present. |
| 3444 | String* FunctionName(); |
| 3445 | |
| 3446 | // Return the name of the given parameter. |
| 3447 | String* ParameterName(int var); |
| 3448 | |
| 3449 | // Return the name of the given local. |
| 3450 | String* LocalName(int var); |
| 3451 | |
| 3452 | // Return the name of the given stack local. |
| 3453 | String* StackLocalName(int var); |
| 3454 | |
| 3455 | // Return the name of the given context local. |
| 3456 | String* ContextLocalName(int var); |
| 3457 | |
| 3458 | // Return the mode of the given context local. |
| 3459 | VariableMode ContextLocalMode(int var); |
| 3460 | |
| 3461 | // Return the initialization flag of the given context local. |
| 3462 | InitializationFlag ContextLocalInitFlag(int var); |
| 3463 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3464 | // Lookup support for serialized scope info. Returns the |
| 3465 | // the stack slot index for a given slot name if the slot is |
| 3466 | // present; otherwise returns a value < 0. The name must be a symbol |
| 3467 | // (canonicalized). |
| 3468 | int StackSlotIndex(String* name); |
| 3469 | |
| 3470 | // Lookup support for serialized scope info. Returns the |
| 3471 | // context slot index for a given slot name if the slot is present; otherwise |
| 3472 | // returns a value < 0. The name must be a symbol (canonicalized). |
| 3473 | // If the slot is present and mode != NULL, sets *mode to the corresponding |
| 3474 | // mode for that variable. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3475 | int ContextSlotIndex(String* name, |
| 3476 | VariableMode* mode, |
| 3477 | InitializationFlag* init_flag); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3478 | |
| 3479 | // Lookup support for serialized scope info. Returns the |
| 3480 | // parameter index for a given parameter name if the parameter is present; |
| 3481 | // otherwise returns a value < 0. The name must be a symbol (canonicalized). |
| 3482 | int ParameterIndex(String* name); |
| 3483 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 3484 | // Lookup support for serialized scope info. Returns the function context |
| 3485 | // 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] | 3486 | // function expressions, only), otherwise returns a value < 0. The name |
| 3487 | // must be a symbol (canonicalized). |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3488 | int FunctionContextSlotIndex(String* name, VariableMode* mode); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3489 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3490 | static Handle<ScopeInfo> Create(Scope* scope, Zone* zone); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3491 | |
| 3492 | // Serializes empty scope info. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3493 | static ScopeInfo* Empty(); |
| 3494 | |
| 3495 | #ifdef DEBUG |
| 3496 | void Print(); |
| 3497 | #endif |
| 3498 | |
| 3499 | // The layout of the static part of a ScopeInfo is as follows. Each entry is |
| 3500 | // numeric and occupies one array slot. |
| 3501 | // 1. A set of properties of the scope |
| 3502 | // 2. The number of parameters. This only applies to function scopes. For |
| 3503 | // non-function scopes this is 0. |
| 3504 | // 3. The number of non-parameter variables allocated on the stack. |
| 3505 | // 4. The number of non-parameter and parameter variables allocated in the |
| 3506 | // context. |
| 3507 | #define FOR_EACH_NUMERIC_FIELD(V) \ |
| 3508 | V(Flags) \ |
| 3509 | V(ParameterCount) \ |
| 3510 | V(StackLocalCount) \ |
| 3511 | V(ContextLocalCount) |
| 3512 | |
| 3513 | #define FIELD_ACCESSORS(name) \ |
| 3514 | void Set##name(int value) { \ |
| 3515 | set(k##name, Smi::FromInt(value)); \ |
| 3516 | } \ |
| 3517 | int name() { \ |
| 3518 | if (length() > 0) { \ |
| 3519 | return Smi::cast(get(k##name))->value(); \ |
| 3520 | } else { \ |
| 3521 | return 0; \ |
| 3522 | } \ |
| 3523 | } |
| 3524 | FOR_EACH_NUMERIC_FIELD(FIELD_ACCESSORS) |
| 3525 | #undef FIELD_ACCESSORS |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3526 | |
| 3527 | private: |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3528 | enum { |
| 3529 | #define DECL_INDEX(name) k##name, |
| 3530 | FOR_EACH_NUMERIC_FIELD(DECL_INDEX) |
| 3531 | #undef DECL_INDEX |
| 3532 | #undef FOR_EACH_NUMERIC_FIELD |
| 3533 | kVariablePartIndex |
| 3534 | }; |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3535 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3536 | // The layout of the variable part of a ScopeInfo is as follows: |
| 3537 | // 1. ParameterEntries: |
| 3538 | // This part stores the names of the parameters for function scopes. One |
| 3539 | // slot is used per parameter, so in total this part occupies |
| 3540 | // ParameterCount() slots in the array. For other scopes than function |
| 3541 | // scopes ParameterCount() is 0. |
| 3542 | // 2. StackLocalEntries: |
| 3543 | // Contains the names of local variables that are allocated on the stack, |
| 3544 | // in increasing order of the stack slot index. One slot is used per stack |
| 3545 | // local, so in total this part occupies StackLocalCount() slots in the |
| 3546 | // array. |
| 3547 | // 3. ContextLocalNameEntries: |
| 3548 | // Contains the names of local variables and parameters that are allocated |
| 3549 | // in the context. They are stored in increasing order of the context slot |
| 3550 | // index starting with Context::MIN_CONTEXT_SLOTS. One slot is used per |
| 3551 | // context local, so in total this part occupies ContextLocalCount() slots |
| 3552 | // in the array. |
| 3553 | // 4. ContextLocalInfoEntries: |
| 3554 | // Contains the variable modes and initialization flags corresponding to |
| 3555 | // the context locals in ContextLocalNameEntries. One slot is used per |
| 3556 | // context local, so in total this part occupies ContextLocalCount() |
| 3557 | // slots in the array. |
| 3558 | // 5. FunctionNameEntryIndex: |
| 3559 | // If the scope belongs to a named function expression this part contains |
| 3560 | // information about the function variable. It always occupies two array |
| 3561 | // slots: a. The name of the function variable. |
| 3562 | // b. The context or stack slot index for the variable. |
| 3563 | int ParameterEntriesIndex(); |
| 3564 | int StackLocalEntriesIndex(); |
| 3565 | int ContextLocalNameEntriesIndex(); |
| 3566 | int ContextLocalInfoEntriesIndex(); |
| 3567 | int FunctionNameEntryIndex(); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3568 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3569 | // Location of the function variable for named function expressions. |
| 3570 | enum FunctionVariableInfo { |
| 3571 | NONE, // No function name present. |
| 3572 | STACK, // Function |
| 3573 | CONTEXT, |
| 3574 | UNUSED |
| 3575 | }; |
| 3576 | |
| 3577 | // Properties of scopes. |
| 3578 | class TypeField: public BitField<ScopeType, 0, 3> {}; |
| 3579 | class CallsEvalField: public BitField<bool, 3, 1> {}; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3580 | class LanguageModeField: public BitField<LanguageMode, 4, 2> {}; |
| 3581 | class FunctionVariableField: public BitField<FunctionVariableInfo, 6, 2> {}; |
| 3582 | class FunctionVariableMode: public BitField<VariableMode, 8, 3> {}; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3583 | |
| 3584 | // BitFields representing the encoded information for context locals in the |
| 3585 | // ContextLocalInfoEntries part. |
| 3586 | class ContextLocalMode: public BitField<VariableMode, 0, 3> {}; |
| 3587 | class ContextLocalInitFlag: public BitField<InitializationFlag, 3, 1> {}; |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 3588 | }; |
| 3589 | |
| 3590 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3591 | // The cache for maps used by normalized (dictionary mode) objects. |
| 3592 | // Such maps do not have property descriptors, so a typical program |
| 3593 | // needs very limited number of distinct normalized maps. |
| 3594 | class NormalizedMapCache: public FixedArray { |
| 3595 | public: |
| 3596 | static const int kEntries = 64; |
| 3597 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3598 | MUST_USE_RESULT MaybeObject* Get(JSObject* object, |
| 3599 | PropertyNormalizationMode mode); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3600 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3601 | void Clear(); |
| 3602 | |
| 3603 | // Casting |
| 3604 | static inline NormalizedMapCache* cast(Object* obj); |
| 3605 | |
| 3606 | #ifdef DEBUG |
| 3607 | void NormalizedMapCacheVerify(); |
| 3608 | #endif |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3609 | }; |
| 3610 | |
| 3611 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3612 | // ByteArray represents fixed sized byte arrays. Used for the relocation info |
| 3613 | // that is attached to code objects. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3614 | class ByteArray: public FixedArrayBase { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3615 | public: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3616 | inline int Size() { return RoundUp(length() + kHeaderSize, kPointerSize); } |
| 3617 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3618 | // Setter and getter. |
| 3619 | inline byte get(int index); |
| 3620 | inline void set(int index, byte value); |
| 3621 | |
| 3622 | // Treat contents as an int array. |
| 3623 | inline int get_int(int index); |
| 3624 | |
| 3625 | static int SizeFor(int length) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3626 | return OBJECT_POINTER_ALIGN(kHeaderSize + length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3627 | } |
| 3628 | // We use byte arrays for free blocks in the heap. Given a desired size in |
| 3629 | // bytes that is a multiple of the word size and big enough to hold a byte |
| 3630 | // array, this function returns the number of elements a byte array should |
| 3631 | // have. |
| 3632 | static int LengthFor(int size_in_bytes) { |
| 3633 | ASSERT(IsAligned(size_in_bytes, kPointerSize)); |
| 3634 | ASSERT(size_in_bytes >= kHeaderSize); |
| 3635 | return size_in_bytes - kHeaderSize; |
| 3636 | } |
| 3637 | |
| 3638 | // Returns data start address. |
| 3639 | inline Address GetDataStartAddress(); |
| 3640 | |
| 3641 | // Returns a pointer to the ByteArray object for a given data start address. |
| 3642 | static inline ByteArray* FromDataStartAddress(Address address); |
| 3643 | |
| 3644 | // Casting. |
| 3645 | static inline ByteArray* cast(Object* obj); |
| 3646 | |
| 3647 | // Dispatched behavior. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3648 | inline int ByteArraySize() { |
| 3649 | return SizeFor(this->length()); |
| 3650 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3651 | #ifdef OBJECT_PRINT |
| 3652 | inline void ByteArrayPrint() { |
| 3653 | ByteArrayPrint(stdout); |
| 3654 | } |
| 3655 | void ByteArrayPrint(FILE* out); |
| 3656 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3657 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3658 | void ByteArrayVerify(); |
| 3659 | #endif |
| 3660 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3661 | // Layout description. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3662 | static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 3663 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3664 | // Maximal memory consumption for a single ByteArray. |
| 3665 | static const int kMaxSize = 512 * MB; |
| 3666 | // Maximal length of a single ByteArray. |
| 3667 | static const int kMaxLength = kMaxSize - kHeaderSize; |
| 3668 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3669 | private: |
| 3670 | DISALLOW_IMPLICIT_CONSTRUCTORS(ByteArray); |
| 3671 | }; |
| 3672 | |
| 3673 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3674 | // FreeSpace represents fixed sized areas of the heap that are not currently in |
| 3675 | // use. Used by the heap and GC. |
| 3676 | class FreeSpace: public HeapObject { |
| 3677 | public: |
| 3678 | // [size]: size of the free space including the header. |
| 3679 | inline int size(); |
| 3680 | inline void set_size(int value); |
| 3681 | |
| 3682 | inline int Size() { return size(); } |
| 3683 | |
| 3684 | // Casting. |
| 3685 | static inline FreeSpace* cast(Object* obj); |
| 3686 | |
| 3687 | #ifdef OBJECT_PRINT |
| 3688 | inline void FreeSpacePrint() { |
| 3689 | FreeSpacePrint(stdout); |
| 3690 | } |
| 3691 | void FreeSpacePrint(FILE* out); |
| 3692 | #endif |
| 3693 | #ifdef DEBUG |
| 3694 | void FreeSpaceVerify(); |
| 3695 | #endif |
| 3696 | |
| 3697 | // Layout description. |
| 3698 | // Size is smi tagged when it is stored. |
| 3699 | static const int kSizeOffset = HeapObject::kHeaderSize; |
| 3700 | static const int kHeaderSize = kSizeOffset + kPointerSize; |
| 3701 | |
| 3702 | static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); |
| 3703 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3704 | private: |
| 3705 | DISALLOW_IMPLICIT_CONSTRUCTORS(FreeSpace); |
| 3706 | }; |
| 3707 | |
| 3708 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3709 | // An ExternalArray represents a fixed-size array of primitive values |
| 3710 | // which live outside the JavaScript heap. Its subclasses are used to |
| 3711 | // implement the CanvasArray types being defined in the WebGL |
| 3712 | // specification. As of this writing the first public draft is not yet |
| 3713 | // available, but Khronos members can access the draft at: |
| 3714 | // https://cvs.khronos.org/svn/repos/3dweb/trunk/doc/spec/WebGL-spec.html |
| 3715 | // |
| 3716 | // The semantics of these arrays differ from CanvasPixelArray. |
| 3717 | // Out-of-range values passed to the setter are converted via a C |
| 3718 | // cast, not clamping. Out-of-range indices cause exceptions to be |
| 3719 | // raised rather than being silently ignored. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3720 | class ExternalArray: public FixedArrayBase { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3721 | public: |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3722 | inline bool is_the_hole(int index) { return false; } |
| 3723 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3724 | // [external_pointer]: The pointer to the external memory area backing this |
| 3725 | // external array. |
| 3726 | DECL_ACCESSORS(external_pointer, void) // Pointer to the data store. |
| 3727 | |
| 3728 | // Casting. |
| 3729 | static inline ExternalArray* cast(Object* obj); |
| 3730 | |
| 3731 | // Maximal acceptable length for an external array. |
| 3732 | static const int kMaxLength = 0x3fffffff; |
| 3733 | |
| 3734 | // ExternalArray headers are not quadword aligned. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3735 | static const int kExternalPointerOffset = |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 3736 | POINTER_SIZE_ALIGN(FixedArrayBase::kLengthOffset + kPointerSize); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3737 | static const int kHeaderSize = kExternalPointerOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3738 | static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3739 | |
| 3740 | private: |
| 3741 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalArray); |
| 3742 | }; |
| 3743 | |
| 3744 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3745 | // A ExternalPixelArray represents a fixed-size byte array with special |
| 3746 | // semantics used for implementing the CanvasPixelArray object. Please see the |
| 3747 | // specification at: |
| 3748 | |
| 3749 | // http://www.whatwg.org/specs/web-apps/current-work/ |
| 3750 | // multipage/the-canvas-element.html#canvaspixelarray |
| 3751 | // In particular, write access clamps the value written to 0 or 255 if the |
| 3752 | // value written is outside this range. |
| 3753 | class ExternalPixelArray: public ExternalArray { |
| 3754 | public: |
| 3755 | inline uint8_t* external_pixel_pointer(); |
| 3756 | |
| 3757 | // Setter and getter. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3758 | inline uint8_t get_scalar(int index); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3759 | MUST_USE_RESULT inline MaybeObject* get(int index); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3760 | inline void set(int index, uint8_t value); |
| 3761 | |
| 3762 | // This accessor applies the correct conversion from Smi, HeapNumber and |
| 3763 | // undefined and clamps the converted value between 0 and 255. |
| 3764 | Object* SetValue(uint32_t index, Object* value); |
| 3765 | |
| 3766 | // Casting. |
| 3767 | static inline ExternalPixelArray* cast(Object* obj); |
| 3768 | |
| 3769 | #ifdef OBJECT_PRINT |
| 3770 | inline void ExternalPixelArrayPrint() { |
| 3771 | ExternalPixelArrayPrint(stdout); |
| 3772 | } |
| 3773 | void ExternalPixelArrayPrint(FILE* out); |
| 3774 | #endif |
| 3775 | #ifdef DEBUG |
| 3776 | void ExternalPixelArrayVerify(); |
| 3777 | #endif // DEBUG |
| 3778 | |
| 3779 | private: |
| 3780 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalPixelArray); |
| 3781 | }; |
| 3782 | |
| 3783 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3784 | class ExternalByteArray: public ExternalArray { |
| 3785 | public: |
| 3786 | // Setter and getter. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3787 | inline int8_t get_scalar(int index); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3788 | MUST_USE_RESULT inline MaybeObject* get(int index); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3789 | inline void set(int index, int8_t value); |
| 3790 | |
| 3791 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3792 | // and undefined. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3793 | MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3794 | |
| 3795 | // Casting. |
| 3796 | static inline ExternalByteArray* cast(Object* obj); |
| 3797 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3798 | #ifdef OBJECT_PRINT |
| 3799 | inline void ExternalByteArrayPrint() { |
| 3800 | ExternalByteArrayPrint(stdout); |
| 3801 | } |
| 3802 | void ExternalByteArrayPrint(FILE* out); |
| 3803 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3804 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3805 | void ExternalByteArrayVerify(); |
| 3806 | #endif // DEBUG |
| 3807 | |
| 3808 | private: |
| 3809 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalByteArray); |
| 3810 | }; |
| 3811 | |
| 3812 | |
| 3813 | class ExternalUnsignedByteArray: public ExternalArray { |
| 3814 | public: |
| 3815 | // Setter and getter. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3816 | inline uint8_t get_scalar(int index); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3817 | MUST_USE_RESULT inline MaybeObject* get(int index); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3818 | inline void set(int index, uint8_t value); |
| 3819 | |
| 3820 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3821 | // and undefined. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3822 | MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3823 | |
| 3824 | // Casting. |
| 3825 | static inline ExternalUnsignedByteArray* cast(Object* obj); |
| 3826 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3827 | #ifdef OBJECT_PRINT |
| 3828 | inline void ExternalUnsignedByteArrayPrint() { |
| 3829 | ExternalUnsignedByteArrayPrint(stdout); |
| 3830 | } |
| 3831 | void ExternalUnsignedByteArrayPrint(FILE* out); |
| 3832 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3833 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3834 | void ExternalUnsignedByteArrayVerify(); |
| 3835 | #endif // DEBUG |
| 3836 | |
| 3837 | private: |
| 3838 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedByteArray); |
| 3839 | }; |
| 3840 | |
| 3841 | |
| 3842 | class ExternalShortArray: public ExternalArray { |
| 3843 | public: |
| 3844 | // Setter and getter. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3845 | inline int16_t get_scalar(int index); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3846 | MUST_USE_RESULT inline MaybeObject* get(int index); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3847 | inline void set(int index, int16_t value); |
| 3848 | |
| 3849 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3850 | // and undefined. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3851 | MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3852 | |
| 3853 | // Casting. |
| 3854 | static inline ExternalShortArray* cast(Object* obj); |
| 3855 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3856 | #ifdef OBJECT_PRINT |
| 3857 | inline void ExternalShortArrayPrint() { |
| 3858 | ExternalShortArrayPrint(stdout); |
| 3859 | } |
| 3860 | void ExternalShortArrayPrint(FILE* out); |
| 3861 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3862 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3863 | void ExternalShortArrayVerify(); |
| 3864 | #endif // DEBUG |
| 3865 | |
| 3866 | private: |
| 3867 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalShortArray); |
| 3868 | }; |
| 3869 | |
| 3870 | |
| 3871 | class ExternalUnsignedShortArray: public ExternalArray { |
| 3872 | public: |
| 3873 | // Setter and getter. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3874 | inline uint16_t get_scalar(int index); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3875 | MUST_USE_RESULT inline MaybeObject* get(int index); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3876 | inline void set(int index, uint16_t value); |
| 3877 | |
| 3878 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3879 | // and undefined. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3880 | MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3881 | |
| 3882 | // Casting. |
| 3883 | static inline ExternalUnsignedShortArray* cast(Object* obj); |
| 3884 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3885 | #ifdef OBJECT_PRINT |
| 3886 | inline void ExternalUnsignedShortArrayPrint() { |
| 3887 | ExternalUnsignedShortArrayPrint(stdout); |
| 3888 | } |
| 3889 | void ExternalUnsignedShortArrayPrint(FILE* out); |
| 3890 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3891 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3892 | void ExternalUnsignedShortArrayVerify(); |
| 3893 | #endif // DEBUG |
| 3894 | |
| 3895 | private: |
| 3896 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedShortArray); |
| 3897 | }; |
| 3898 | |
| 3899 | |
| 3900 | class ExternalIntArray: public ExternalArray { |
| 3901 | public: |
| 3902 | // Setter and getter. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3903 | inline int32_t get_scalar(int index); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3904 | MUST_USE_RESULT inline MaybeObject* get(int index); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3905 | inline void set(int index, int32_t value); |
| 3906 | |
| 3907 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3908 | // and undefined. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3909 | MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3910 | |
| 3911 | // Casting. |
| 3912 | static inline ExternalIntArray* cast(Object* obj); |
| 3913 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3914 | #ifdef OBJECT_PRINT |
| 3915 | inline void ExternalIntArrayPrint() { |
| 3916 | ExternalIntArrayPrint(stdout); |
| 3917 | } |
| 3918 | void ExternalIntArrayPrint(FILE* out); |
| 3919 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3920 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3921 | void ExternalIntArrayVerify(); |
| 3922 | #endif // DEBUG |
| 3923 | |
| 3924 | private: |
| 3925 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalIntArray); |
| 3926 | }; |
| 3927 | |
| 3928 | |
| 3929 | class ExternalUnsignedIntArray: public ExternalArray { |
| 3930 | public: |
| 3931 | // Setter and getter. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3932 | inline uint32_t get_scalar(int index); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3933 | MUST_USE_RESULT inline MaybeObject* get(int index); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3934 | inline void set(int index, uint32_t value); |
| 3935 | |
| 3936 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3937 | // and undefined. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3938 | MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3939 | |
| 3940 | // Casting. |
| 3941 | static inline ExternalUnsignedIntArray* cast(Object* obj); |
| 3942 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3943 | #ifdef OBJECT_PRINT |
| 3944 | inline void ExternalUnsignedIntArrayPrint() { |
| 3945 | ExternalUnsignedIntArrayPrint(stdout); |
| 3946 | } |
| 3947 | void ExternalUnsignedIntArrayPrint(FILE* out); |
| 3948 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3949 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3950 | void ExternalUnsignedIntArrayVerify(); |
| 3951 | #endif // DEBUG |
| 3952 | |
| 3953 | private: |
| 3954 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedIntArray); |
| 3955 | }; |
| 3956 | |
| 3957 | |
| 3958 | class ExternalFloatArray: public ExternalArray { |
| 3959 | public: |
| 3960 | // Setter and getter. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3961 | inline float get_scalar(int index); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3962 | MUST_USE_RESULT inline MaybeObject* get(int index); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3963 | inline void set(int index, float value); |
| 3964 | |
| 3965 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3966 | // and undefined. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3967 | MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3968 | |
| 3969 | // Casting. |
| 3970 | static inline ExternalFloatArray* cast(Object* obj); |
| 3971 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3972 | #ifdef OBJECT_PRINT |
| 3973 | inline void ExternalFloatArrayPrint() { |
| 3974 | ExternalFloatArrayPrint(stdout); |
| 3975 | } |
| 3976 | void ExternalFloatArrayPrint(FILE* out); |
| 3977 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3978 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3979 | void ExternalFloatArrayVerify(); |
| 3980 | #endif // DEBUG |
| 3981 | |
| 3982 | private: |
| 3983 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalFloatArray); |
| 3984 | }; |
| 3985 | |
| 3986 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 3987 | class ExternalDoubleArray: public ExternalArray { |
| 3988 | public: |
| 3989 | // Setter and getter. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3990 | inline double get_scalar(int index); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3991 | MUST_USE_RESULT inline MaybeObject* get(int index); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 3992 | inline void set(int index, double value); |
| 3993 | |
| 3994 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3995 | // and undefined. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 3996 | MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 3997 | |
| 3998 | // Casting. |
| 3999 | static inline ExternalDoubleArray* cast(Object* obj); |
| 4000 | |
| 4001 | #ifdef OBJECT_PRINT |
| 4002 | inline void ExternalDoubleArrayPrint() { |
| 4003 | ExternalDoubleArrayPrint(stdout); |
| 4004 | } |
| 4005 | void ExternalDoubleArrayPrint(FILE* out); |
| 4006 | #endif // OBJECT_PRINT |
| 4007 | #ifdef DEBUG |
| 4008 | void ExternalDoubleArrayVerify(); |
| 4009 | #endif // DEBUG |
| 4010 | |
| 4011 | private: |
| 4012 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalDoubleArray); |
| 4013 | }; |
| 4014 | |
| 4015 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4016 | // DeoptimizationInputData is a fixed array used to hold the deoptimization |
| 4017 | // data for code generated by the Hydrogen/Lithium compiler. It also |
| 4018 | // contains information about functions that were inlined. If N different |
| 4019 | // functions were inlined then first N elements of the literal array will |
| 4020 | // contain these functions. |
| 4021 | // |
| 4022 | // It can be empty. |
| 4023 | class DeoptimizationInputData: public FixedArray { |
| 4024 | public: |
| 4025 | // Layout description. Indices in the array. |
| 4026 | static const int kTranslationByteArrayIndex = 0; |
| 4027 | static const int kInlinedFunctionCountIndex = 1; |
| 4028 | static const int kLiteralArrayIndex = 2; |
| 4029 | static const int kOsrAstIdIndex = 3; |
| 4030 | static const int kOsrPcOffsetIndex = 4; |
| 4031 | static const int kFirstDeoptEntryIndex = 5; |
| 4032 | |
| 4033 | // Offsets of deopt entry elements relative to the start of the entry. |
| 4034 | static const int kAstIdOffset = 0; |
| 4035 | static const int kTranslationIndexOffset = 1; |
| 4036 | static const int kArgumentsStackHeightOffset = 2; |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 4037 | static const int kPcOffset = 3; |
| 4038 | static const int kDeoptEntrySize = 4; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4039 | |
| 4040 | // Simple element accessors. |
| 4041 | #define DEFINE_ELEMENT_ACCESSORS(name, type) \ |
| 4042 | type* name() { \ |
| 4043 | return type::cast(get(k##name##Index)); \ |
| 4044 | } \ |
| 4045 | void Set##name(type* value) { \ |
| 4046 | set(k##name##Index, value); \ |
| 4047 | } |
| 4048 | |
| 4049 | DEFINE_ELEMENT_ACCESSORS(TranslationByteArray, ByteArray) |
| 4050 | DEFINE_ELEMENT_ACCESSORS(InlinedFunctionCount, Smi) |
| 4051 | DEFINE_ELEMENT_ACCESSORS(LiteralArray, FixedArray) |
| 4052 | DEFINE_ELEMENT_ACCESSORS(OsrAstId, Smi) |
| 4053 | DEFINE_ELEMENT_ACCESSORS(OsrPcOffset, Smi) |
| 4054 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4055 | #undef DEFINE_ELEMENT_ACCESSORS |
| 4056 | |
| 4057 | // Accessors for elements of the ith deoptimization entry. |
| 4058 | #define DEFINE_ENTRY_ACCESSORS(name, type) \ |
| 4059 | type* name(int i) { \ |
| 4060 | return type::cast(get(IndexForEntry(i) + k##name##Offset)); \ |
| 4061 | } \ |
| 4062 | void Set##name(int i, type* value) { \ |
| 4063 | set(IndexForEntry(i) + k##name##Offset, value); \ |
| 4064 | } |
| 4065 | |
| 4066 | DEFINE_ENTRY_ACCESSORS(AstId, Smi) |
| 4067 | DEFINE_ENTRY_ACCESSORS(TranslationIndex, Smi) |
| 4068 | DEFINE_ENTRY_ACCESSORS(ArgumentsStackHeight, Smi) |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 4069 | DEFINE_ENTRY_ACCESSORS(Pc, Smi) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4070 | |
| 4071 | #undef DEFINE_ENTRY_ACCESSORS |
| 4072 | |
| 4073 | int DeoptCount() { |
| 4074 | return (length() - kFirstDeoptEntryIndex) / kDeoptEntrySize; |
| 4075 | } |
| 4076 | |
| 4077 | // Allocates a DeoptimizationInputData. |
| 4078 | MUST_USE_RESULT static MaybeObject* Allocate(int deopt_entry_count, |
| 4079 | PretenureFlag pretenure); |
| 4080 | |
| 4081 | // Casting. |
| 4082 | static inline DeoptimizationInputData* cast(Object* obj); |
| 4083 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4084 | #ifdef ENABLE_DISASSEMBLER |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4085 | void DeoptimizationInputDataPrint(FILE* out); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4086 | #endif |
| 4087 | |
| 4088 | private: |
| 4089 | static int IndexForEntry(int i) { |
| 4090 | return kFirstDeoptEntryIndex + (i * kDeoptEntrySize); |
| 4091 | } |
| 4092 | |
| 4093 | static int LengthFor(int entry_count) { |
| 4094 | return IndexForEntry(entry_count); |
| 4095 | } |
| 4096 | }; |
| 4097 | |
| 4098 | |
| 4099 | // DeoptimizationOutputData is a fixed array used to hold the deoptimization |
| 4100 | // data for code generated by the full compiler. |
| 4101 | // The format of the these objects is |
| 4102 | // [i * 2]: Ast ID for ith deoptimization. |
| 4103 | // [i * 2 + 1]: PC and state of ith deoptimization |
| 4104 | class DeoptimizationOutputData: public FixedArray { |
| 4105 | public: |
| 4106 | int DeoptPoints() { return length() / 2; } |
| 4107 | Smi* AstId(int index) { return Smi::cast(get(index * 2)); } |
| 4108 | void SetAstId(int index, Smi* id) { set(index * 2, id); } |
| 4109 | Smi* PcAndState(int index) { return Smi::cast(get(1 + index * 2)); } |
| 4110 | void SetPcAndState(int index, Smi* offset) { set(1 + index * 2, offset); } |
| 4111 | |
| 4112 | static int LengthOfFixedArray(int deopt_points) { |
| 4113 | return deopt_points * 2; |
| 4114 | } |
| 4115 | |
| 4116 | // Allocates a DeoptimizationOutputData. |
| 4117 | MUST_USE_RESULT static MaybeObject* Allocate(int number_of_deopt_points, |
| 4118 | PretenureFlag pretenure); |
| 4119 | |
| 4120 | // Casting. |
| 4121 | static inline DeoptimizationOutputData* cast(Object* obj); |
| 4122 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4123 | #if defined(OBJECT_PRINT) || defined(ENABLE_DISASSEMBLER) |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4124 | void DeoptimizationOutputDataPrint(FILE* out); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4125 | #endif |
| 4126 | }; |
| 4127 | |
| 4128 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4129 | // Forward declaration. |
| 4130 | class JSGlobalPropertyCell; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4131 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4132 | // TypeFeedbackCells is a fixed array used to hold the association between |
| 4133 | // cache cells and AST ids for code generated by the full compiler. |
| 4134 | // The format of the these objects is |
| 4135 | // [i * 2]: Global property cell of ith cache cell. |
| 4136 | // [i * 2 + 1]: Ast ID for ith cache cell. |
| 4137 | class TypeFeedbackCells: public FixedArray { |
| 4138 | public: |
| 4139 | int CellCount() { return length() / 2; } |
| 4140 | static int LengthOfFixedArray(int cell_count) { return cell_count * 2; } |
| 4141 | |
| 4142 | // Accessors for AST ids associated with cache values. |
| 4143 | inline Smi* AstId(int index); |
| 4144 | inline void SetAstId(int index, Smi* id); |
| 4145 | |
| 4146 | // Accessors for global property cells holding the cache values. |
| 4147 | inline JSGlobalPropertyCell* Cell(int index); |
| 4148 | inline void SetCell(int index, JSGlobalPropertyCell* cell); |
| 4149 | |
| 4150 | // The object that indicates an uninitialized cache. |
| 4151 | static inline Handle<Object> UninitializedSentinel(Isolate* isolate); |
| 4152 | |
| 4153 | // The object that indicates a megamorphic state. |
| 4154 | static inline Handle<Object> MegamorphicSentinel(Isolate* isolate); |
| 4155 | |
| 4156 | // A raw version of the uninitialized sentinel that's safe to read during |
| 4157 | // garbage collection (e.g., for patching the cache). |
| 4158 | static inline Object* RawUninitializedSentinel(Heap* heap); |
| 4159 | |
| 4160 | // Casting. |
| 4161 | static inline TypeFeedbackCells* cast(Object* obj); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 4162 | |
| 4163 | static const int kForInFastCaseMarker = 0; |
| 4164 | static const int kForInSlowCaseMarker = 1; |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4165 | }; |
| 4166 | |
| 4167 | |
| 4168 | // Forward declaration. |
| 4169 | class SafepointEntry; |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 4170 | class TypeFeedbackInfo; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4171 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4172 | // Code describes objects with on-the-fly generated machine code. |
| 4173 | class Code: public HeapObject { |
| 4174 | public: |
| 4175 | // Opaque data type for encapsulating code flags like kind, inline |
| 4176 | // cache state, and arguments count. |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 4177 | // FLAGS_MIN_VALUE and FLAGS_MAX_VALUE are specified to ensure that |
| 4178 | // enumeration type has correct value range (see Issue 830 for more details). |
| 4179 | enum Flags { |
| 4180 | FLAGS_MIN_VALUE = kMinInt, |
| 4181 | FLAGS_MAX_VALUE = kMaxInt |
| 4182 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4183 | |
| 4184 | enum Kind { |
| 4185 | FUNCTION, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4186 | OPTIMIZED_FUNCTION, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4187 | STUB, |
| 4188 | BUILTIN, |
| 4189 | LOAD_IC, |
| 4190 | KEYED_LOAD_IC, |
| 4191 | CALL_IC, |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 4192 | KEYED_CALL_IC, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4193 | STORE_IC, |
| 4194 | KEYED_STORE_IC, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4195 | UNARY_OP_IC, |
| 4196 | BINARY_OP_IC, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4197 | COMPARE_IC, |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 4198 | TO_BOOLEAN_IC, |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4199 | // No more than 16 kinds. The value currently encoded in four bits in |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 4200 | // Flags. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4201 | |
| 4202 | // Pseudo-kinds. |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 4203 | REGEXP = BUILTIN, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4204 | FIRST_IC_KIND = LOAD_IC, |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 4205 | LAST_IC_KIND = TO_BOOLEAN_IC |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4206 | }; |
| 4207 | |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 4208 | // Types of stubs. |
| 4209 | enum StubType { |
| 4210 | NORMAL, |
| 4211 | FIELD, |
| 4212 | CONSTANT_FUNCTION, |
| 4213 | CALLBACKS, |
| 4214 | INTERCEPTOR, |
| 4215 | MAP_TRANSITION, |
| 4216 | NONEXISTENT |
| 4217 | }; |
| 4218 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4219 | enum { |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 4220 | NUMBER_OF_KINDS = LAST_IC_KIND + 1 |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4221 | }; |
| 4222 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 4223 | typedef int ExtraICState; |
| 4224 | |
| 4225 | static const ExtraICState kNoExtraICState = 0; |
| 4226 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 4227 | #ifdef ENABLE_DISASSEMBLER |
| 4228 | // Printing |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4229 | static const char* Kind2String(Kind kind); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4230 | static const char* ICState2String(InlineCacheState state); |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 4231 | static const char* StubType2String(StubType type); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4232 | static void PrintExtraICState(FILE* out, Kind kind, ExtraICState extra); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4233 | inline void Disassemble(const char* name) { |
| 4234 | Disassemble(name, stdout); |
| 4235 | } |
| 4236 | void Disassemble(const char* name, FILE* out); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 4237 | #endif // ENABLE_DISASSEMBLER |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4238 | |
| 4239 | // [instruction_size]: Size of the native instructions |
| 4240 | inline int instruction_size(); |
| 4241 | inline void set_instruction_size(int value); |
| 4242 | |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4243 | // [relocation_info]: Code relocation information |
| 4244 | DECL_ACCESSORS(relocation_info, ByteArray) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4245 | void InvalidateRelocation(); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4246 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4247 | // [handler_table]: Fixed array containing offsets of exception handlers. |
| 4248 | DECL_ACCESSORS(handler_table, FixedArray) |
| 4249 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4250 | // [deoptimization_data]: Array containing data for deopt. |
| 4251 | DECL_ACCESSORS(deoptimization_data, FixedArray) |
| 4252 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 4253 | // [type_feedback_info]: Struct containing type feedback information. |
| 4254 | // Will contain either a TypeFeedbackInfo object, or undefined. |
| 4255 | DECL_ACCESSORS(type_feedback_info, Object) |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4256 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 4257 | // [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] | 4258 | // field does not have to be traced during garbage collection since |
| 4259 | // it is only used by the garbage collector itself. |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 4260 | DECL_ACCESSORS(gc_metadata, Object) |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4261 | |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 4262 | // [ic_age]: Inline caching age: the value of the Heap::global_ic_age |
| 4263 | // at the moment when this object was created. |
| 4264 | inline void set_ic_age(int count); |
| 4265 | inline int ic_age(); |
| 4266 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4267 | // Unchecked accessors to be used during GC. |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4268 | inline ByteArray* unchecked_relocation_info(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4269 | inline FixedArray* unchecked_deoptimization_data(); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4270 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4271 | inline int relocation_size(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4272 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4273 | // [flags]: Various code flags. |
| 4274 | inline Flags flags(); |
| 4275 | inline void set_flags(Flags flags); |
| 4276 | |
| 4277 | // [flags]: Access to specific code flags. |
| 4278 | inline Kind kind(); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4279 | inline InlineCacheState ic_state(); // Only valid for IC stubs. |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 4280 | inline ExtraICState extra_ic_state(); // Only valid for IC stubs. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 4281 | inline StubType type(); // Only valid for monomorphic IC stubs. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4282 | inline int arguments_count(); // Only valid for call IC stubs. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4283 | |
| 4284 | // Testers for IC stub kinds. |
| 4285 | inline bool is_inline_cache_stub(); |
| 4286 | inline bool is_load_stub() { return kind() == LOAD_IC; } |
| 4287 | inline bool is_keyed_load_stub() { return kind() == KEYED_LOAD_IC; } |
| 4288 | inline bool is_store_stub() { return kind() == STORE_IC; } |
| 4289 | inline bool is_keyed_store_stub() { return kind() == KEYED_STORE_IC; } |
| 4290 | inline bool is_call_stub() { return kind() == CALL_IC; } |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 4291 | inline bool is_keyed_call_stub() { return kind() == KEYED_CALL_IC; } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 4292 | inline bool is_unary_op_stub() { return kind() == UNARY_OP_IC; } |
| 4293 | inline bool is_binary_op_stub() { return kind() == BINARY_OP_IC; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4294 | inline bool is_compare_ic_stub() { return kind() == COMPARE_IC; } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 4295 | 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] | 4296 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4297 | // [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] | 4298 | inline int major_key(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4299 | inline void set_major_key(int value); |
| 4300 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4301 | // For stubs, tells whether they should always exist, so that they can be |
| 4302 | // called from other stubs. |
| 4303 | inline bool is_pregenerated(); |
| 4304 | inline void set_is_pregenerated(bool value); |
| 4305 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4306 | // [optimizable]: For FUNCTION kind, tells if it is optimizable. |
| 4307 | inline bool optimizable(); |
| 4308 | inline void set_optimizable(bool value); |
| 4309 | |
| 4310 | // [has_deoptimization_support]: For FUNCTION kind, tells if it has |
| 4311 | // deoptimization support. |
| 4312 | inline bool has_deoptimization_support(); |
| 4313 | inline void set_has_deoptimization_support(bool value); |
| 4314 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4315 | // [has_debug_break_slots]: For FUNCTION kind, tells if it has |
| 4316 | // been compiled with debug break slots. |
| 4317 | inline bool has_debug_break_slots(); |
| 4318 | inline void set_has_debug_break_slots(bool value); |
| 4319 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4320 | // [compiled_with_optimizing]: For FUNCTION kind, tells if it has |
| 4321 | // been compiled with IsOptimizing set to true. |
| 4322 | inline bool is_compiled_optimizable(); |
| 4323 | inline void set_compiled_optimizable(bool value); |
| 4324 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4325 | // [allow_osr_at_loop_nesting_level]: For FUNCTION kind, tells for |
| 4326 | // how long the function has been marked for OSR and therefore which |
| 4327 | // level of loop nesting we are willing to do on-stack replacement |
| 4328 | // for. |
| 4329 | inline void set_allow_osr_at_loop_nesting_level(int level); |
| 4330 | inline int allow_osr_at_loop_nesting_level(); |
| 4331 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 4332 | // [profiler_ticks]: For FUNCTION kind, tells for how many profiler ticks |
| 4333 | // the code object was seen on the stack with no IC patching going on. |
| 4334 | inline int profiler_ticks(); |
| 4335 | inline void set_profiler_ticks(int ticks); |
| 4336 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4337 | // [stack_slots]: For kind OPTIMIZED_FUNCTION, the number of stack slots |
| 4338 | // reserved in the code prologue. |
| 4339 | inline unsigned stack_slots(); |
| 4340 | inline void set_stack_slots(unsigned slots); |
| 4341 | |
| 4342 | // [safepoint_table_start]: For kind OPTIMIZED_CODE, the offset in |
| 4343 | // the instruction stream where the safepoint table starts. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4344 | inline unsigned safepoint_table_offset(); |
| 4345 | inline void set_safepoint_table_offset(unsigned offset); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4346 | |
| 4347 | // [stack_check_table_start]: For kind FUNCTION, the offset in the |
| 4348 | // instruction stream where the stack check table starts. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4349 | inline unsigned stack_check_table_offset(); |
| 4350 | inline void set_stack_check_table_offset(unsigned offset); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4351 | |
| 4352 | // [check type]: For kind CALL_IC, tells how to check if the |
| 4353 | // receiver is valid for the given call. |
| 4354 | inline CheckType check_type(); |
| 4355 | inline void set_check_type(CheckType value); |
| 4356 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 4357 | // [type-recording unary op type]: For kind UNARY_OP_IC. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4358 | inline byte unary_op_type(); |
| 4359 | inline void set_unary_op_type(byte value); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 4360 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 4361 | // [type-recording binary op type]: For kind BINARY_OP_IC. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4362 | inline byte binary_op_type(); |
| 4363 | inline void set_binary_op_type(byte value); |
| 4364 | inline byte binary_op_result_type(); |
| 4365 | inline void set_binary_op_result_type(byte value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4366 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 4367 | // [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] | 4368 | inline byte compare_state(); |
| 4369 | inline void set_compare_state(byte value); |
| 4370 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 4371 | // [compare_operation]: For kind COMPARE_IC tells what compare operation the |
| 4372 | // stub was generated for. |
| 4373 | inline byte compare_operation(); |
| 4374 | inline void set_compare_operation(byte value); |
| 4375 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 4376 | // [to_boolean_foo]: For kind TO_BOOLEAN_IC tells what state the stub is in. |
| 4377 | inline byte to_boolean_state(); |
| 4378 | inline void set_to_boolean_state(byte value); |
| 4379 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4380 | // [has_function_cache]: For kind STUB tells whether there is a function |
| 4381 | // cache is passed to the stub. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4382 | inline bool has_function_cache(); |
| 4383 | inline void set_has_function_cache(bool flag); |
| 4384 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4385 | bool allowed_in_shared_map_code_cache(); |
| 4386 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4387 | // Get the safepoint entry for the given pc. |
| 4388 | SafepointEntry GetSafepointEntry(Address pc); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4389 | |
| 4390 | // Mark this code object as not having a stack check table. Assumes kind |
| 4391 | // is FUNCTION. |
| 4392 | void SetNoStackCheckTable(); |
| 4393 | |
| 4394 | // Find the first map in an IC stub. |
| 4395 | Map* FindFirstMap(); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4396 | |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4397 | class ExtraICStateStrictMode: public BitField<StrictModeFlag, 0, 1> {}; |
| 4398 | class ExtraICStateKeyedAccessGrowMode: |
| 4399 | public BitField<KeyedAccessGrowMode, 1, 1> {}; // NOLINT |
| 4400 | |
| 4401 | static const int kExtraICStateGrowModeShift = 1; |
| 4402 | |
| 4403 | static inline StrictModeFlag GetStrictMode(ExtraICState extra_ic_state) { |
| 4404 | return ExtraICStateStrictMode::decode(extra_ic_state); |
| 4405 | } |
| 4406 | |
| 4407 | static inline KeyedAccessGrowMode GetKeyedAccessGrowMode( |
| 4408 | ExtraICState extra_ic_state) { |
| 4409 | return ExtraICStateKeyedAccessGrowMode::decode(extra_ic_state); |
| 4410 | } |
| 4411 | |
| 4412 | static inline ExtraICState ComputeExtraICState( |
| 4413 | KeyedAccessGrowMode grow_mode, |
| 4414 | StrictModeFlag strict_mode) { |
| 4415 | return ExtraICStateKeyedAccessGrowMode::encode(grow_mode) | |
| 4416 | ExtraICStateStrictMode::encode(strict_mode); |
| 4417 | } |
| 4418 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4419 | // Flags operations. |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 4420 | static inline Flags ComputeFlags( |
| 4421 | Kind kind, |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 4422 | InlineCacheState ic_state = UNINITIALIZED, |
| 4423 | ExtraICState extra_ic_state = kNoExtraICState, |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 4424 | StubType type = NORMAL, |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 4425 | int argc = -1, |
| 4426 | InlineCacheHolderFlag holder = OWN_MAP); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4427 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4428 | static inline Flags ComputeMonomorphicFlags( |
| 4429 | Kind kind, |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 4430 | StubType type, |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 4431 | ExtraICState extra_ic_state = kNoExtraICState, |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4432 | InlineCacheHolderFlag holder = OWN_MAP, |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4433 | int argc = -1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4434 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4435 | static inline InlineCacheState ExtractICStateFromFlags(Flags flags); |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 4436 | static inline StubType ExtractTypeFromFlags(Flags flags); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4437 | static inline Kind ExtractKindFromFlags(Flags flags); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4438 | static inline InlineCacheHolderFlag ExtractCacheHolderFromFlags(Flags flags); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4439 | static inline ExtraICState ExtractExtraICStateFromFlags(Flags flags); |
| 4440 | static inline int ExtractArgumentsCountFromFlags(Flags flags); |
| 4441 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4442 | static inline Flags RemoveTypeFromFlags(Flags flags); |
| 4443 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 4444 | // Convert a target address into a code object. |
| 4445 | static inline Code* GetCodeFromTargetAddress(Address address); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4446 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 4447 | // Convert an entry address into an object. |
| 4448 | static inline Object* GetObjectFromEntryAddress(Address location_of_address); |
| 4449 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4450 | // Returns the address of the first instruction. |
| 4451 | inline byte* instruction_start(); |
| 4452 | |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4453 | // Returns the address right after the last instruction. |
| 4454 | inline byte* instruction_end(); |
| 4455 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4456 | // Returns the size of the instructions, padding, and relocation information. |
| 4457 | inline int body_size(); |
| 4458 | |
| 4459 | // Returns the address of the first relocation info (read backwards!). |
| 4460 | inline byte* relocation_start(); |
| 4461 | |
| 4462 | // Code entry point. |
| 4463 | inline byte* entry(); |
| 4464 | |
| 4465 | // Returns true if pc is inside this object's instructions. |
| 4466 | inline bool contains(byte* pc); |
| 4467 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4468 | // Relocate the code by delta bytes. Called to signal that this code |
| 4469 | // object has been moved by delta bytes. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4470 | void Relocate(intptr_t delta); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4471 | |
| 4472 | // Migrate code described by desc. |
| 4473 | void CopyFrom(const CodeDesc& desc); |
| 4474 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4475 | // Returns the object size for a given body (used for allocation). |
| 4476 | static int SizeFor(int body_size) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4477 | ASSERT_SIZE_TAG_ALIGNED(body_size); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4478 | return RoundUp(kHeaderSize + body_size, kCodeAlignment); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4479 | } |
| 4480 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4481 | // Calculate the size of the code object to report for log events. This takes |
| 4482 | // the layout of the code object into account. |
| 4483 | int ExecutableSize() { |
| 4484 | // 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] | 4485 | ASSERT_EQ(static_cast<int>(instruction_start() - address()), |
| 4486 | Code::kHeaderSize); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4487 | return instruction_size() + Code::kHeaderSize; |
| 4488 | } |
| 4489 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4490 | // Locating source position. |
| 4491 | int SourcePosition(Address pc); |
| 4492 | int SourceStatementPosition(Address pc); |
| 4493 | |
| 4494 | // Casting. |
| 4495 | static inline Code* cast(Object* obj); |
| 4496 | |
| 4497 | // Dispatched behavior. |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4498 | int CodeSize() { return SizeFor(body_size()); } |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4499 | inline void CodeIterateBody(ObjectVisitor* v); |
| 4500 | |
| 4501 | template<typename StaticVisitor> |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4502 | inline void CodeIterateBody(Heap* heap); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4503 | #ifdef OBJECT_PRINT |
| 4504 | inline void CodePrint() { |
| 4505 | CodePrint(stdout); |
| 4506 | } |
| 4507 | void CodePrint(FILE* out); |
| 4508 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4509 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4510 | void CodeVerify(); |
| 4511 | #endif |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 4512 | void ClearInlineCaches(); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 4513 | void ClearTypeFeedbackCells(Heap* heap); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4514 | |
| 4515 | // Max loop nesting marker used to postpose OSR. We don't take loop |
| 4516 | // nesting that is deeper than 5 levels into account. |
| 4517 | static const int kMaxLoopNestingMarker = 6; |
| 4518 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4519 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 4520 | static const int kInstructionSizeOffset = HeapObject::kHeaderSize; |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4521 | static const int kRelocationInfoOffset = kInstructionSizeOffset + kIntSize; |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4522 | static const int kHandlerTableOffset = kRelocationInfoOffset + kPointerSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4523 | static const int kDeoptimizationDataOffset = |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4524 | kHandlerTableOffset + kPointerSize; |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 4525 | static const int kTypeFeedbackInfoOffset = |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4526 | kDeoptimizationDataOffset + kPointerSize; |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 4527 | static const int kGCMetadataOffset = kTypeFeedbackInfoOffset + kPointerSize; |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 4528 | static const int kICAgeOffset = |
| 4529 | kGCMetadataOffset + kPointerSize; |
| 4530 | static const int kFlagsOffset = kICAgeOffset + kIntSize; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4531 | static const int kKindSpecificFlagsOffset = kFlagsOffset + kIntSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4532 | static const int kKindSpecificFlagsSize = 2 * kIntSize; |
| 4533 | |
| 4534 | static const int kHeaderPaddingStart = kKindSpecificFlagsOffset + |
| 4535 | kKindSpecificFlagsSize; |
| 4536 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4537 | // Add padding to align the instruction start following right after |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 4538 | // the Code object header. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4539 | static const int kHeaderSize = |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4540 | (kHeaderPaddingStart + kCodeAlignmentMask) & ~kCodeAlignmentMask; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4541 | |
| 4542 | // Byte offsets within kKindSpecificFlagsOffset. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4543 | static const int kStubMajorKeyOffset = kKindSpecificFlagsOffset; |
| 4544 | static const int kOptimizableOffset = kKindSpecificFlagsOffset; |
| 4545 | static const int kStackSlotsOffset = kKindSpecificFlagsOffset; |
| 4546 | static const int kCheckTypeOffset = kKindSpecificFlagsOffset; |
| 4547 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 4548 | static const int kUnaryOpTypeOffset = kStubMajorKeyOffset + 1; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4549 | static const int kBinaryOpTypeOffset = kStubMajorKeyOffset + 1; |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 4550 | static const int kCompareStateOffset = kStubMajorKeyOffset + 1; |
| 4551 | static const int kToBooleanTypeOffset = kStubMajorKeyOffset + 1; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4552 | static const int kHasFunctionCacheOffset = kStubMajorKeyOffset + 1; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4553 | |
| 4554 | static const int kFullCodeFlags = kOptimizableOffset + 1; |
| 4555 | class FullCodeFlagsHasDeoptimizationSupportField: |
| 4556 | public BitField<bool, 0, 1> {}; // NOLINT |
| 4557 | class FullCodeFlagsHasDebugBreakSlotsField: public BitField<bool, 1, 1> {}; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4558 | class FullCodeFlagsIsCompiledOptimizable: public BitField<bool, 2, 1> {}; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4559 | |
| 4560 | static const int kBinaryOpReturnTypeOffset = kBinaryOpTypeOffset + 1; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4561 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 4562 | static const int kCompareOperationOffset = kCompareStateOffset + 1; |
| 4563 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4564 | static const int kAllowOSRAtLoopNestingLevelOffset = kFullCodeFlags + 1; |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 4565 | static const int kProfilerTicksOffset = kAllowOSRAtLoopNestingLevelOffset + 1; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4566 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4567 | static const int kSafepointTableOffsetOffset = kStackSlotsOffset + kIntSize; |
| 4568 | static const int kStackCheckTableOffsetOffset = kStackSlotsOffset + kIntSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4569 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4570 | // Flags layout. BitField<type, shift, size>. |
| 4571 | class ICStateField: public BitField<InlineCacheState, 0, 3> {}; |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 4572 | class TypeField: public BitField<StubType, 3, 3> {}; |
| 4573 | class CacheHolderField: public BitField<InlineCacheHolderFlag, 6, 1> {}; |
| 4574 | class KindField: public BitField<Kind, 7, 4> {}; |
| 4575 | class ExtraICStateField: public BitField<ExtraICState, 11, 2> {}; |
| 4576 | class IsPregeneratedField: public BitField<bool, 13, 1> {}; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4577 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4578 | // Signed field cannot be encoded using the BitField class. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 4579 | static const int kArgumentsCountShift = 14; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4580 | static const int kArgumentsCountMask = ~((1 << kArgumentsCountShift) - 1); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4581 | |
jkummerow@chromium.org | 1145ef8 | 2012-02-02 16:21:15 +0000 | [diff] [blame] | 4582 | // This constant should be encodable in an ARM instruction. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4583 | static const int kFlagsNotUsedInLookup = |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4584 | TypeField::kMask | CacheHolderField::kMask; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4585 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4586 | private: |
| 4587 | DISALLOW_IMPLICIT_CONSTRUCTORS(Code); |
| 4588 | }; |
| 4589 | |
| 4590 | |
| 4591 | // All heap objects have a Map that describes their structure. |
| 4592 | // A Map contains information about: |
| 4593 | // - Size information about the object |
| 4594 | // - How to iterate over an object (for garbage collection) |
| 4595 | class Map: public HeapObject { |
| 4596 | public: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4597 | // Instance size. |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 4598 | // Size in bytes or kVariableSizeSentinel if instances do not have |
| 4599 | // a fixed size. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4600 | inline int instance_size(); |
| 4601 | inline void set_instance_size(int value); |
| 4602 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4603 | // Count of properties allocated in the object. |
| 4604 | inline int inobject_properties(); |
| 4605 | inline void set_inobject_properties(int value); |
| 4606 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4607 | // Count of property fields pre-allocated in the object when first allocated. |
| 4608 | inline int pre_allocated_property_fields(); |
| 4609 | inline void set_pre_allocated_property_fields(int value); |
| 4610 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4611 | // Instance type. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4612 | inline InstanceType instance_type(); |
| 4613 | inline void set_instance_type(InstanceType value); |
| 4614 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4615 | // Tells how many unused property fields are available in the |
| 4616 | // instance (only used for JSObject in fast mode). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4617 | inline int unused_property_fields(); |
| 4618 | inline void set_unused_property_fields(int value); |
| 4619 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4620 | // Bit field. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4621 | inline byte bit_field(); |
| 4622 | inline void set_bit_field(byte value); |
| 4623 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 4624 | // Bit field 2. |
| 4625 | inline byte bit_field2(); |
| 4626 | inline void set_bit_field2(byte value); |
| 4627 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4628 | // Bit field 3. |
| 4629 | // TODO(1399): It should be possible to make room for bit_field3 in the map |
| 4630 | // without overloading the instance descriptors field (and storing it in the |
| 4631 | // DescriptorArray when the map has one). |
| 4632 | inline int bit_field3(); |
| 4633 | inline void set_bit_field3(int value); |
| 4634 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4635 | // Tells whether the object in the prototype property will be used |
| 4636 | // for instances created from this function. If the prototype |
| 4637 | // property is set to a value that is not a JSObject, the prototype |
| 4638 | // property will not be used to create instances of the function. |
| 4639 | // See ECMA-262, 13.2.2. |
| 4640 | inline void set_non_instance_prototype(bool value); |
| 4641 | inline bool has_non_instance_prototype(); |
| 4642 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 4643 | // Tells whether function has special prototype property. If not, prototype |
| 4644 | // property will not be created when accessed (will return undefined), |
| 4645 | // and construction from this function will not be allowed. |
| 4646 | inline void set_function_with_prototype(bool value); |
| 4647 | inline bool function_with_prototype(); |
| 4648 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4649 | // Tells whether the instance with this map should be ignored by the |
| 4650 | // __proto__ accessor. |
| 4651 | inline void set_is_hidden_prototype() { |
| 4652 | set_bit_field(bit_field() | (1 << kIsHiddenPrototype)); |
| 4653 | } |
| 4654 | |
| 4655 | inline bool is_hidden_prototype() { |
| 4656 | return ((1 << kIsHiddenPrototype) & bit_field()) != 0; |
| 4657 | } |
| 4658 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 4659 | // Records and queries whether the instance has a named interceptor. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4660 | inline void set_has_named_interceptor() { |
| 4661 | set_bit_field(bit_field() | (1 << kHasNamedInterceptor)); |
| 4662 | } |
| 4663 | |
| 4664 | inline bool has_named_interceptor() { |
| 4665 | return ((1 << kHasNamedInterceptor) & bit_field()) != 0; |
| 4666 | } |
| 4667 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 4668 | // Records and queries whether the instance has an indexed interceptor. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4669 | inline void set_has_indexed_interceptor() { |
| 4670 | set_bit_field(bit_field() | (1 << kHasIndexedInterceptor)); |
| 4671 | } |
| 4672 | |
| 4673 | inline bool has_indexed_interceptor() { |
| 4674 | return ((1 << kHasIndexedInterceptor) & bit_field()) != 0; |
| 4675 | } |
| 4676 | |
| 4677 | // Tells whether the instance is undetectable. |
| 4678 | // An undetectable object is a special class of JSObject: 'typeof' operator |
| 4679 | // returns undefined, ToBoolean returns false. Otherwise it behaves like |
| 4680 | // a normal JS object. It is useful for implementing undetectable |
| 4681 | // document.all in Firefox & Safari. |
| 4682 | // See https://bugzilla.mozilla.org/show_bug.cgi?id=248549. |
| 4683 | inline void set_is_undetectable() { |
| 4684 | set_bit_field(bit_field() | (1 << kIsUndetectable)); |
| 4685 | } |
| 4686 | |
| 4687 | inline bool is_undetectable() { |
| 4688 | return ((1 << kIsUndetectable) & bit_field()) != 0; |
| 4689 | } |
| 4690 | |
| 4691 | // Tells whether the instance has a call-as-function handler. |
| 4692 | inline void set_has_instance_call_handler() { |
| 4693 | set_bit_field(bit_field() | (1 << kHasInstanceCallHandler)); |
| 4694 | } |
| 4695 | |
| 4696 | inline bool has_instance_call_handler() { |
| 4697 | return ((1 << kHasInstanceCallHandler) & bit_field()) != 0; |
| 4698 | } |
| 4699 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4700 | inline void set_is_extensible(bool value); |
| 4701 | inline bool is_extensible(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4702 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4703 | inline void set_elements_kind(ElementsKind elements_kind) { |
| 4704 | ASSERT(elements_kind < kElementsKindCount); |
| 4705 | ASSERT(kElementsKindCount <= (1 << kElementsKindBitCount)); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4706 | set_bit_field2((bit_field2() & ~kElementsKindMask) | |
| 4707 | (elements_kind << kElementsKindShift)); |
| 4708 | ASSERT(this->elements_kind() == elements_kind); |
| 4709 | } |
| 4710 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4711 | inline ElementsKind elements_kind() { |
| 4712 | return static_cast<ElementsKind>( |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4713 | (bit_field2() & kElementsKindMask) >> kElementsKindShift); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 4714 | } |
| 4715 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4716 | // Tells whether the instance has fast elements that are only Smis. |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4717 | inline bool has_fast_smi_elements() { |
| 4718 | return IsFastSmiElementsKind(elements_kind()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4719 | } |
| 4720 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4721 | // Tells whether the instance has fast elements. |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4722 | inline bool has_fast_object_elements() { |
| 4723 | return IsFastObjectElementsKind(elements_kind()); |
| 4724 | } |
| 4725 | |
| 4726 | inline bool has_fast_smi_or_object_elements() { |
| 4727 | return IsFastSmiOrObjectElementsKind(elements_kind()); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4728 | } |
| 4729 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4730 | inline bool has_fast_double_elements() { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4731 | return IsFastDoubleElementsKind(elements_kind()); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4732 | } |
| 4733 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4734 | inline bool has_non_strict_arguments_elements() { |
| 4735 | return elements_kind() == NON_STRICT_ARGUMENTS_ELEMENTS; |
| 4736 | } |
| 4737 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4738 | inline bool has_external_array_elements() { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4739 | return IsExternalArrayElementsKind(elements_kind()); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4740 | } |
| 4741 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4742 | inline bool has_dictionary_elements() { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4743 | return IsDictionaryElementsKind(elements_kind()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4744 | } |
| 4745 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4746 | inline bool has_slow_elements_kind() { |
| 4747 | return elements_kind() == DICTIONARY_ELEMENTS |
| 4748 | || elements_kind() == NON_STRICT_ARGUMENTS_ELEMENTS; |
| 4749 | } |
| 4750 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4751 | static bool IsValidElementsTransition(ElementsKind from_kind, |
| 4752 | ElementsKind to_kind); |
| 4753 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4754 | inline Map* elements_transition_map(); |
| 4755 | inline void set_elements_transition_map(Map* transitioned_map); |
| 4756 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4757 | // Tells whether the map is attached to SharedFunctionInfo |
| 4758 | // (for inobject slack tracking). |
| 4759 | inline void set_attached_to_shared_function_info(bool value); |
| 4760 | |
| 4761 | inline bool attached_to_shared_function_info(); |
| 4762 | |
| 4763 | // Tells whether the map is shared between objects that may have different |
| 4764 | // behavior. If true, the map should never be modified, instead a clone |
| 4765 | // should be created and modified. |
| 4766 | inline void set_is_shared(bool value); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4767 | inline bool is_shared(); |
| 4768 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4769 | // Tells whether the instance needs security checks when accessing its |
| 4770 | // properties. |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 4771 | inline void set_is_access_check_needed(bool access_check_needed); |
| 4772 | inline bool is_access_check_needed(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4773 | |
| 4774 | // [prototype]: implicit prototype object. |
| 4775 | DECL_ACCESSORS(prototype, Object) |
| 4776 | |
| 4777 | // [constructor]: points back to the function responsible for this map. |
| 4778 | DECL_ACCESSORS(constructor, Object) |
| 4779 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4780 | inline JSFunction* unchecked_constructor(); |
| 4781 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4782 | // Should only be called by the code that initializes map to set initial valid |
| 4783 | // value of the instance descriptor member. |
| 4784 | inline void init_instance_descriptors(); |
| 4785 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4786 | // [instance descriptors]: describes the object. |
| 4787 | DECL_ACCESSORS(instance_descriptors, DescriptorArray) |
| 4788 | |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 4789 | // Should only be called to clear a descriptor array that was only used to |
| 4790 | // store transitions and does not contain any live transitions anymore. |
| 4791 | inline void ClearDescriptorArray(); |
| 4792 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4793 | // Sets the instance descriptor array for the map to be an empty descriptor |
| 4794 | // array. |
| 4795 | inline void clear_instance_descriptors(); |
| 4796 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4797 | // [stub cache]: contains stubs compiled for this map. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4798 | DECL_ACCESSORS(code_cache, Object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4799 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 4800 | // [back pointer]: points back to the parent map from which a transition |
| 4801 | // leads to this map. The field overlaps with prototype transitions and the |
| 4802 | // back pointer will be moved into the prototype transitions array if |
| 4803 | // required. |
| 4804 | inline Object* GetBackPointer(); |
| 4805 | inline void SetBackPointer(Object* value, |
| 4806 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 4807 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 4808 | // [prototype transitions]: cache of prototype transitions. |
| 4809 | // Prototype transition is a transition that happens |
| 4810 | // when we change object's prototype to a new one. |
| 4811 | // Cache format: |
| 4812 | // 0: finger - index of the first free cell in the cache |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 4813 | // 1: back pointer that overlaps with prototype transitions field. |
| 4814 | // 2 + 2 * i: prototype |
| 4815 | // 3 + 2 * i: target map |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 4816 | DECL_ACCESSORS(prototype_transitions, FixedArray) |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4817 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 4818 | inline void init_prototype_transitions(Object* undefined); |
| 4819 | inline HeapObject* unchecked_prototype_transitions(); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 4820 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 4821 | static const int kProtoTransitionHeaderSize = 2; |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4822 | static const int kProtoTransitionNumberOfEntriesOffset = 0; |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 4823 | static const int kProtoTransitionBackPointerOffset = 1; |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4824 | static const int kProtoTransitionElementsPerEntry = 2; |
| 4825 | static const int kProtoTransitionPrototypeOffset = 0; |
| 4826 | static const int kProtoTransitionMapOffset = 1; |
| 4827 | |
| 4828 | inline int NumberOfProtoTransitions() { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4829 | FixedArray* cache = prototype_transitions(); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4830 | if (cache->length() == 0) return 0; |
| 4831 | return |
| 4832 | Smi::cast(cache->get(kProtoTransitionNumberOfEntriesOffset))->value(); |
| 4833 | } |
| 4834 | |
| 4835 | inline void SetNumberOfProtoTransitions(int value) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4836 | FixedArray* cache = prototype_transitions(); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4837 | ASSERT(cache->length() != 0); |
| 4838 | cache->set_unchecked(kProtoTransitionNumberOfEntriesOffset, |
| 4839 | Smi::FromInt(value)); |
| 4840 | } |
| 4841 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4842 | // Lookup in the map's instance descriptors and fill out the result |
| 4843 | // with the given holder if the name is found. The holder may be |
| 4844 | // NULL when this function is used from the compiler. |
| 4845 | void LookupInDescriptors(JSObject* holder, |
| 4846 | String* name, |
| 4847 | LookupResult* result); |
| 4848 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4849 | MUST_USE_RESULT MaybeObject* CopyDropDescriptors(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4850 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4851 | MUST_USE_RESULT MaybeObject* CopyNormalized(PropertyNormalizationMode mode, |
| 4852 | NormalizedMapSharingMode sharing); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4853 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 4854 | // Returns a copy of the map, with all transitions dropped from the |
| 4855 | // instance descriptors. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4856 | MUST_USE_RESULT MaybeObject* CopyDropTransitions( |
| 4857 | DescriptorArray::SharedMode shared_mode); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 4858 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4859 | // Returns the property index for name (only valid for FAST MODE). |
| 4860 | int PropertyIndexFor(String* name); |
| 4861 | |
| 4862 | // Returns the next free property index (only valid for FAST MODE). |
| 4863 | int NextFreePropertyIndex(); |
| 4864 | |
jkummerow@chromium.org | ab7dad4 | 2012-02-07 12:07:34 +0000 | [diff] [blame] | 4865 | // Returns the number of properties described in instance_descriptors |
| 4866 | // filtering out properties with the specified attributes. |
| 4867 | int NumberOfDescribedProperties(PropertyAttributes filter = NONE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4868 | |
| 4869 | // Casting. |
| 4870 | static inline Map* cast(Object* obj); |
| 4871 | |
| 4872 | // Locate an accessor in the instance descriptor. |
| 4873 | AccessorDescriptor* FindAccessor(String* name); |
| 4874 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4875 | // Code cache operations. |
| 4876 | |
| 4877 | // Clears the code cache. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4878 | inline void ClearCodeCache(Heap* heap); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4879 | |
| 4880 | // Update code cache. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4881 | static void UpdateCodeCache(Handle<Map> map, |
| 4882 | Handle<String> name, |
| 4883 | Handle<Code> code); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4884 | MUST_USE_RESULT MaybeObject* UpdateCodeCache(String* name, Code* code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4885 | |
| 4886 | // Returns the found code or undefined if absent. |
| 4887 | Object* FindInCodeCache(String* name, Code::Flags flags); |
| 4888 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4889 | // Returns the non-negative index of the code object if it is in the |
| 4890 | // cache and -1 otherwise. |
sgjesse@chromium.org | 99a37fa | 2010-03-11 09:23:46 +0000 | [diff] [blame] | 4891 | int IndexInCodeCache(Object* name, Code* code); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4892 | |
| 4893 | // 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] | 4894 | void RemoveFromCodeCache(String* name, Code* code, int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4895 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 4896 | // Set all map transitions from this map to dead maps to null. Also clear |
| 4897 | // back pointers in transition targets so that we do not process this map |
| 4898 | // again while following back pointers. |
| 4899 | void ClearNonLiveTransitions(Heap* heap); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4900 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 4901 | // Computes a hash value for this map, to be used in HashTables and such. |
| 4902 | int Hash(); |
| 4903 | |
| 4904 | // Compares this map to another to see if they describe equivalent objects. |
| 4905 | // If |mode| is set to CLEAR_INOBJECT_PROPERTIES, |other| is treated as if |
| 4906 | // it had exactly zero inobject properties. |
| 4907 | // The "shared" flags of both this map and |other| are ignored. |
| 4908 | bool EquivalentToForNormalization(Map* other, PropertyNormalizationMode mode); |
| 4909 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 4910 | // Returns the map that this map transitions to if its elements_kind |
| 4911 | // is changed to |elements_kind|, or NULL if no such map is cached yet. |
| 4912 | // |safe_to_add_transitions| is set to false if adding transitions is not |
| 4913 | // allowed. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4914 | Map* LookupElementsTransitionMap(ElementsKind elements_kind); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 4915 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4916 | // Adds a new transitions for changing the elements kind to |elements_kind|. |
| 4917 | MUST_USE_RESULT MaybeObject* CreateNextElementsTransition( |
| 4918 | ElementsKind elements_kind); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 4919 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4920 | // Returns the transitioned map for this map with the most generic |
| 4921 | // elements_kind that's found in |candidates|, or null handle if no match is |
| 4922 | // found at all. |
| 4923 | Handle<Map> FindTransitionedMap(MapHandleList* candidates); |
| 4924 | Map* FindTransitionedMap(MapList* candidates); |
| 4925 | |
yangguo@chromium.org | 5f0b8ea | 2012-05-16 12:37:04 +0000 | [diff] [blame] | 4926 | // Zaps the contents of backing data structures in debug mode. Note that the |
| 4927 | // heap verifier (i.e. VerifyMarkingVisitor) relies on zapping of objects |
| 4928 | // holding weak references when incremental marking is used, because it also |
| 4929 | // iterates over objects that are otherwise unreachable. |
| 4930 | #ifdef DEBUG |
| 4931 | void ZapInstanceDescriptors(); |
| 4932 | void ZapPrototypeTransitions(); |
| 4933 | #endif |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4934 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4935 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4936 | #ifdef OBJECT_PRINT |
| 4937 | inline void MapPrint() { |
| 4938 | MapPrint(stdout); |
| 4939 | } |
| 4940 | void MapPrint(FILE* out); |
| 4941 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4942 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4943 | void MapVerify(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4944 | void SharedMapVerify(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4945 | #endif |
| 4946 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4947 | inline int visitor_id(); |
| 4948 | inline void set_visitor_id(int visitor_id); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4949 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4950 | typedef void (*TraverseCallback)(Map* map, void* data); |
| 4951 | |
| 4952 | void TraverseTransitionTree(TraverseCallback callback, void* data); |
| 4953 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4954 | // When you set the prototype of an object using the __proto__ accessor you |
| 4955 | // need a new map for the object (the prototype is stored in the map). In |
| 4956 | // order not to multiply maps unnecessarily we store these as transitions in |
| 4957 | // the original map. That way we can transition to the same map if the same |
| 4958 | // prototype is set, rather than creating a new map every time. The |
| 4959 | // 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] | 4960 | // and the values are the maps the are transitioned to. |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 4961 | static const int kMaxCachedPrototypeTransitions = 256; |
| 4962 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4963 | Map* GetPrototypeTransition(Object* prototype); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 4964 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 4965 | MUST_USE_RESULT MaybeObject* PutPrototypeTransition(Object* prototype, |
| 4966 | Map* map); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 4967 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4968 | static const int kMaxPreAllocatedPropertyFields = 255; |
| 4969 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4970 | // Layout description. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4971 | static const int kInstanceSizesOffset = HeapObject::kHeaderSize; |
| 4972 | static const int kInstanceAttributesOffset = kInstanceSizesOffset + kIntSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4973 | static const int kPrototypeOffset = kInstanceAttributesOffset + kIntSize; |
| 4974 | static const int kConstructorOffset = kPrototypeOffset + kPointerSize; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4975 | // Storage for instance descriptors is overloaded to also contain additional |
| 4976 | // map flags when unused (bit_field3). When the map has instance descriptors, |
| 4977 | // the flags are transferred to the instance descriptor array and accessed |
| 4978 | // through an extra indirection. |
| 4979 | // TODO(1399): It should be possible to make room for bit_field3 in the map |
| 4980 | // without overloading the instance descriptors field, but the map is |
| 4981 | // currently perfectly aligned to 32 bytes and extending it at all would |
| 4982 | // double its size. After the increment GC work lands, this size restriction |
| 4983 | // could be loosened and bit_field3 moved directly back in the map. |
| 4984 | static const int kInstanceDescriptorsOrBitField3Offset = |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4985 | kConstructorOffset + kPointerSize; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4986 | static const int kCodeCacheOffset = |
| 4987 | kInstanceDescriptorsOrBitField3Offset + kPointerSize; |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 4988 | static const int kPrototypeTransitionsOrBackPointerOffset = |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 4989 | kCodeCacheOffset + kPointerSize; |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 4990 | static const int kPadStart = |
| 4991 | kPrototypeTransitionsOrBackPointerOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4992 | static const int kSize = MAP_POINTER_ALIGN(kPadStart); |
| 4993 | |
| 4994 | // Layout of pointer fields. Heap iteration code relies on them |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4995 | // being continuously allocated. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4996 | static const int kPointerFieldsBeginOffset = Map::kPrototypeOffset; |
| 4997 | static const int kPointerFieldsEndOffset = |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 4998 | kPrototypeTransitionsOrBackPointerOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4999 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5000 | // Byte offsets within kInstanceSizesOffset. |
| 5001 | static const int kInstanceSizeOffset = kInstanceSizesOffset + 0; |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 5002 | static const int kInObjectPropertiesByte = 1; |
| 5003 | static const int kInObjectPropertiesOffset = |
| 5004 | kInstanceSizesOffset + kInObjectPropertiesByte; |
| 5005 | static const int kPreAllocatedPropertyFieldsByte = 2; |
| 5006 | static const int kPreAllocatedPropertyFieldsOffset = |
| 5007 | kInstanceSizesOffset + kPreAllocatedPropertyFieldsByte; |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 5008 | static const int kVisitorIdByte = 3; |
| 5009 | static const int kVisitorIdOffset = kInstanceSizesOffset + kVisitorIdByte; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5010 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5011 | // Byte offsets within kInstanceAttributesOffset attributes. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5012 | static const int kInstanceTypeOffset = kInstanceAttributesOffset + 0; |
| 5013 | static const int kUnusedPropertyFieldsOffset = kInstanceAttributesOffset + 1; |
| 5014 | static const int kBitFieldOffset = kInstanceAttributesOffset + 2; |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 5015 | static const int kBitField2Offset = kInstanceAttributesOffset + 3; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5016 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5017 | STATIC_CHECK(kInstanceTypeOffset == Internals::kMapInstanceTypeOffset); |
| 5018 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5019 | // Bit positions for bit field. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5020 | 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] | 5021 | static const int kHasNonInstancePrototype = 1; |
| 5022 | static const int kIsHiddenPrototype = 2; |
| 5023 | static const int kHasNamedInterceptor = 3; |
| 5024 | static const int kHasIndexedInterceptor = 4; |
| 5025 | static const int kIsUndetectable = 5; |
| 5026 | static const int kHasInstanceCallHandler = 6; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5027 | static const int kIsAccessCheckNeeded = 7; |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 5028 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 5029 | // Bit positions for bit field 2 |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 5030 | static const int kIsExtensible = 0; |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 5031 | static const int kStringWrapperSafeForDefaultValueOf = 1; |
| 5032 | static const int kAttachedToSharedFunctionInfo = 2; |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 5033 | // 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] | 5034 | // storing ElementKind. |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 5035 | static const int kElementsKindShift = 3; |
| 5036 | static const int kElementsKindBitCount = 5; |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 5037 | |
| 5038 | // Derived values from bit field 2 |
| 5039 | static const int kElementsKindMask = (-1 << kElementsKindShift) & |
| 5040 | ((1 << (kElementsKindShift + kElementsKindBitCount)) - 1); |
| 5041 | static const int8_t kMaximumBitField2FastElementValue = static_cast<int8_t>( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5042 | (FAST_ELEMENTS + 1) << Map::kElementsKindShift) - 1; |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 5043 | static const int8_t kMaximumBitField2FastSmiElementValue = |
| 5044 | static_cast<int8_t>((FAST_SMI_ELEMENTS + 1) << |
| 5045 | Map::kElementsKindShift) - 1; |
| 5046 | static const int8_t kMaximumBitField2FastHoleyElementValue = |
| 5047 | static_cast<int8_t>((FAST_HOLEY_ELEMENTS + 1) << |
| 5048 | Map::kElementsKindShift) - 1; |
| 5049 | static const int8_t kMaximumBitField2FastHoleySmiElementValue = |
| 5050 | static_cast<int8_t>((FAST_HOLEY_SMI_ELEMENTS + 1) << |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5051 | Map::kElementsKindShift) - 1; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 5052 | |
| 5053 | // Bit positions for bit field 3 |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 5054 | static const int kIsShared = 0; |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 5055 | static const int kFunctionWithPrototype = 1; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5056 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 5057 | typedef FixedBodyDescriptor<kPointerFieldsBeginOffset, |
| 5058 | kPointerFieldsEndOffset, |
| 5059 | kSize> BodyDescriptor; |
| 5060 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5061 | private: |
| 5062 | DISALLOW_IMPLICIT_CONSTRUCTORS(Map); |
| 5063 | }; |
| 5064 | |
| 5065 | |
| 5066 | // An abstract superclass, a marker class really, for simple structure classes. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5067 | // 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] | 5068 | // identified in the type system. |
| 5069 | class Struct: public HeapObject { |
| 5070 | public: |
| 5071 | inline void InitializeBody(int object_size); |
| 5072 | static inline Struct* cast(Object* that); |
| 5073 | }; |
| 5074 | |
| 5075 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5076 | // Script describes a script which has been added to the VM. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5077 | class Script: public Struct { |
| 5078 | public: |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 5079 | // Script types. |
| 5080 | enum Type { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 5081 | TYPE_NATIVE = 0, |
| 5082 | TYPE_EXTENSION = 1, |
| 5083 | TYPE_NORMAL = 2 |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 5084 | }; |
| 5085 | |
| 5086 | // Script compilation types. |
| 5087 | enum CompilationType { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 5088 | COMPILATION_TYPE_HOST = 0, |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 5089 | COMPILATION_TYPE_EVAL = 1 |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 5090 | }; |
| 5091 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 5092 | // Script compilation state. |
| 5093 | enum CompilationState { |
| 5094 | COMPILATION_STATE_INITIAL = 0, |
| 5095 | COMPILATION_STATE_COMPILED = 1 |
| 5096 | }; |
| 5097 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5098 | // [source]: the script source. |
| 5099 | DECL_ACCESSORS(source, Object) |
| 5100 | |
| 5101 | // [name]: the script name. |
| 5102 | DECL_ACCESSORS(name, Object) |
| 5103 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5104 | // [id]: the script id. |
| 5105 | DECL_ACCESSORS(id, Object) |
| 5106 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5107 | // [line_offset]: script line offset in resource from where it was extracted. |
| 5108 | DECL_ACCESSORS(line_offset, Smi) |
| 5109 | |
| 5110 | // [column_offset]: script column offset in resource from where it was |
| 5111 | // extracted. |
| 5112 | DECL_ACCESSORS(column_offset, Smi) |
| 5113 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5114 | // [data]: additional data associated with this script. |
| 5115 | DECL_ACCESSORS(data, Object) |
| 5116 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 5117 | // [context_data]: context data for the context this script was compiled in. |
| 5118 | DECL_ACCESSORS(context_data, Object) |
| 5119 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5120 | // [wrapper]: the wrapper cache. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5121 | DECL_ACCESSORS(wrapper, Foreign) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5122 | |
| 5123 | // [type]: the script type. |
| 5124 | DECL_ACCESSORS(type, Smi) |
| 5125 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 5126 | // [compilation]: how the the script was compiled. |
| 5127 | DECL_ACCESSORS(compilation_type, Smi) |
| 5128 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 5129 | // [is_compiled]: determines whether the script has already been compiled. |
| 5130 | DECL_ACCESSORS(compilation_state, Smi) |
| 5131 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 5132 | // [line_ends]: FixedArray of line ends positions. |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 5133 | DECL_ACCESSORS(line_ends, Object) |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 5134 | |
sgjesse@chromium.org | 9818059 | 2009-12-02 08:17:28 +0000 | [diff] [blame] | 5135 | // [eval_from_shared]: for eval scripts the shared funcion info for the |
| 5136 | // function from which eval was called. |
| 5137 | DECL_ACCESSORS(eval_from_shared, Object) |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 5138 | |
| 5139 | // [eval_from_instructions_offset]: the instruction offset in the code for the |
| 5140 | // function from which eval was called where eval was called. |
| 5141 | DECL_ACCESSORS(eval_from_instructions_offset, Smi) |
| 5142 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5143 | static inline Script* cast(Object* obj); |
| 5144 | |
sgjesse@chromium.org | 152a0b0 | 2009-10-07 13:50:16 +0000 | [diff] [blame] | 5145 | // If script source is an external string, check that the underlying |
| 5146 | // resource is accessible. Otherwise, always return true. |
| 5147 | inline bool HasValidSource(); |
| 5148 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5149 | #ifdef OBJECT_PRINT |
| 5150 | inline void ScriptPrint() { |
| 5151 | ScriptPrint(stdout); |
| 5152 | } |
| 5153 | void ScriptPrint(FILE* out); |
| 5154 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5155 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5156 | void ScriptVerify(); |
| 5157 | #endif |
| 5158 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5159 | static const int kSourceOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5160 | static const int kNameOffset = kSourceOffset + kPointerSize; |
| 5161 | static const int kLineOffsetOffset = kNameOffset + kPointerSize; |
| 5162 | static const int kColumnOffsetOffset = kLineOffsetOffset + kPointerSize; |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 5163 | static const int kDataOffset = kColumnOffsetOffset + kPointerSize; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 5164 | static const int kContextOffset = kDataOffset + kPointerSize; |
| 5165 | static const int kWrapperOffset = kContextOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5166 | static const int kTypeOffset = kWrapperOffset + kPointerSize; |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 5167 | static const int kCompilationTypeOffset = kTypeOffset + kPointerSize; |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 5168 | static const int kCompilationStateOffset = |
| 5169 | kCompilationTypeOffset + kPointerSize; |
| 5170 | static const int kLineEndsOffset = kCompilationStateOffset + kPointerSize; |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 5171 | static const int kIdOffset = kLineEndsOffset + kPointerSize; |
sgjesse@chromium.org | 9818059 | 2009-12-02 08:17:28 +0000 | [diff] [blame] | 5172 | static const int kEvalFromSharedOffset = kIdOffset + kPointerSize; |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 5173 | static const int kEvalFrominstructionsOffsetOffset = |
sgjesse@chromium.org | 9818059 | 2009-12-02 08:17:28 +0000 | [diff] [blame] | 5174 | kEvalFromSharedOffset + kPointerSize; |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 5175 | static const int kSize = kEvalFrominstructionsOffsetOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5176 | |
| 5177 | private: |
| 5178 | DISALLOW_IMPLICIT_CONSTRUCTORS(Script); |
| 5179 | }; |
| 5180 | |
| 5181 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5182 | // List of builtin functions we want to identify to improve code |
| 5183 | // generation. |
| 5184 | // |
| 5185 | // Each entry has a name of a global object property holding an object |
| 5186 | // optionally followed by ".prototype", a name of a builtin function |
| 5187 | // on the object (the one the id is set for), and a label. |
| 5188 | // |
| 5189 | // Installation of ids for the selected builtin functions is handled |
| 5190 | // by the bootstrapper. |
| 5191 | // |
| 5192 | // NOTE: Order is important: math functions should be at the end of |
| 5193 | // the list and MathFloor should be the first math function. |
| 5194 | #define FUNCTIONS_WITH_ID_LIST(V) \ |
| 5195 | V(Array.prototype, push, ArrayPush) \ |
| 5196 | V(Array.prototype, pop, ArrayPop) \ |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 5197 | V(Function.prototype, apply, FunctionApply) \ |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5198 | V(String.prototype, charCodeAt, StringCharCodeAt) \ |
| 5199 | V(String.prototype, charAt, StringCharAt) \ |
| 5200 | V(String, fromCharCode, StringFromCharCode) \ |
| 5201 | V(Math, floor, MathFloor) \ |
| 5202 | V(Math, round, MathRound) \ |
| 5203 | V(Math, ceil, MathCeil) \ |
| 5204 | V(Math, abs, MathAbs) \ |
| 5205 | V(Math, log, MathLog) \ |
| 5206 | V(Math, sin, MathSin) \ |
| 5207 | V(Math, cos, MathCos) \ |
| 5208 | V(Math, tan, MathTan) \ |
| 5209 | V(Math, asin, MathASin) \ |
| 5210 | V(Math, acos, MathACos) \ |
| 5211 | V(Math, atan, MathATan) \ |
| 5212 | V(Math, exp, MathExp) \ |
| 5213 | V(Math, sqrt, MathSqrt) \ |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5214 | V(Math, pow, MathPow) \ |
| 5215 | V(Math, random, MathRandom) \ |
| 5216 | V(Math, max, MathMax) \ |
| 5217 | V(Math, min, MathMin) |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5218 | |
| 5219 | |
| 5220 | enum BuiltinFunctionId { |
| 5221 | #define DECLARE_FUNCTION_ID(ignored1, ignore2, name) \ |
| 5222 | k##name, |
| 5223 | FUNCTIONS_WITH_ID_LIST(DECLARE_FUNCTION_ID) |
| 5224 | #undef DECLARE_FUNCTION_ID |
| 5225 | // Fake id for a special case of Math.pow. Note, it continues the |
| 5226 | // list of math functions. |
| 5227 | kMathPowHalf, |
| 5228 | kFirstMathFunctionId = kMathFloor |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5229 | }; |
| 5230 | |
| 5231 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5232 | // SharedFunctionInfo describes the JSFunction information that can be |
| 5233 | // shared by multiple instances of the function. |
| 5234 | class SharedFunctionInfo: public HeapObject { |
| 5235 | public: |
| 5236 | // [name]: Function name. |
| 5237 | DECL_ACCESSORS(name, Object) |
| 5238 | |
| 5239 | // [code]: Function code. |
| 5240 | DECL_ACCESSORS(code, Code) |
| 5241 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 5242 | // [optimized_code_map]: Map from global context to optimized code |
| 5243 | // and a shared literals array or Smi 0 if none. |
| 5244 | DECL_ACCESSORS(optimized_code_map, Object) |
| 5245 | |
| 5246 | // Returns index i of the entry with the specified context. At position |
| 5247 | // i - 1 is the context, position i the code, and i + 1 the literals array. |
| 5248 | // Returns -1 when no matching entry is found. |
| 5249 | int SearchOptimizedCodeMap(Context* global_context); |
| 5250 | |
ulan@chromium.org | d9e468a | 2012-06-25 09:47:40 +0000 | [diff] [blame] | 5251 | // Installs optimized code from the code map on the given closure. The |
| 5252 | // index has to be consistent with a search result as defined above. |
| 5253 | void InstallFromOptimizedCodeMap(JSFunction* function, int index); |
| 5254 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 5255 | // Clear optimized code map. |
| 5256 | void ClearOptimizedCodeMap(); |
| 5257 | |
| 5258 | // Add a new entry to the optimized code map. |
| 5259 | static void AddToOptimizedCodeMap(Handle<SharedFunctionInfo> shared, |
| 5260 | Handle<Context> global_context, |
| 5261 | Handle<Code> code, |
| 5262 | Handle<FixedArray> literals); |
| 5263 | static const int kEntryLength = 3; |
| 5264 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 5265 | // [scope_info]: Scope info. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5266 | DECL_ACCESSORS(scope_info, ScopeInfo) |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 5267 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 5268 | // [construct stub]: Code stub for constructing instances of this function. |
| 5269 | DECL_ACCESSORS(construct_stub, Code) |
| 5270 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 5271 | inline Code* unchecked_code(); |
| 5272 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5273 | // Returns if this function has been compiled to native code yet. |
| 5274 | inline bool is_compiled(); |
| 5275 | |
| 5276 | // [length]: The function length - usually the number of declared parameters. |
| 5277 | // Use up to 2^30 parameters. |
| 5278 | inline int length(); |
| 5279 | inline void set_length(int value); |
| 5280 | |
| 5281 | // [formal parameter count]: The declared number of parameters. |
| 5282 | inline int formal_parameter_count(); |
| 5283 | inline void set_formal_parameter_count(int value); |
| 5284 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 5285 | // Set the formal parameter count so the function code will be |
| 5286 | // called without using argument adaptor frames. |
| 5287 | inline void DontAdaptArguments(); |
| 5288 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5289 | // [expected_nof_properties]: Expected number of properties for the function. |
| 5290 | inline int expected_nof_properties(); |
| 5291 | inline void set_expected_nof_properties(int value); |
| 5292 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 5293 | // Inobject slack tracking is the way to reclaim unused inobject space. |
| 5294 | // |
| 5295 | // The instance size is initially determined by adding some slack to |
| 5296 | // expected_nof_properties (to allow for a few extra properties added |
| 5297 | // after the constructor). There is no guarantee that the extra space |
| 5298 | // will not be wasted. |
| 5299 | // |
| 5300 | // Here is the algorithm to reclaim the unused inobject space: |
| 5301 | // - Detect the first constructor call for this SharedFunctionInfo. |
| 5302 | // When it happens enter the "in progress" state: remember the |
| 5303 | // constructor's initial_map and install a special construct stub that |
| 5304 | // counts constructor calls. |
| 5305 | // - While the tracking is in progress create objects filled with |
| 5306 | // one_pointer_filler_map instead of undefined_value. This way they can be |
| 5307 | // resized quickly and safely. |
| 5308 | // - Once enough (kGenerousAllocationCount) objects have been created |
| 5309 | // compute the 'slack' (traverse the map transition tree starting from the |
| 5310 | // initial_map and find the lowest value of unused_property_fields). |
| 5311 | // - Traverse the transition tree again and decrease the instance size |
| 5312 | // of every map. Existing objects will resize automatically (they are |
| 5313 | // filled with one_pointer_filler_map). All further allocations will |
| 5314 | // use the adjusted instance size. |
| 5315 | // - Decrease expected_nof_properties so that an allocations made from |
| 5316 | // another context will use the adjusted instance size too. |
| 5317 | // - Exit "in progress" state by clearing the reference to the initial_map |
| 5318 | // and setting the regular construct stub (generic or inline). |
| 5319 | // |
| 5320 | // The above is the main event sequence. Some special cases are possible |
| 5321 | // while the tracking is in progress: |
| 5322 | // |
| 5323 | // - GC occurs. |
| 5324 | // Check if the initial_map is referenced by any live objects (except this |
| 5325 | // SharedFunctionInfo). If it is, continue tracking as usual. |
| 5326 | // If it is not, clear the reference and reset the tracking state. The |
| 5327 | // tracking will be initiated again on the next constructor call. |
| 5328 | // |
| 5329 | // - The constructor is called from another context. |
| 5330 | // Immediately complete the tracking, perform all the necessary changes |
| 5331 | // to maps. This is necessary because there is no efficient way to track |
| 5332 | // multiple initial_maps. |
| 5333 | // Proceed to create an object in the current context (with the adjusted |
| 5334 | // size). |
| 5335 | // |
| 5336 | // - A different constructor function sharing the same SharedFunctionInfo is |
| 5337 | // called in the same context. This could be another closure in the same |
| 5338 | // context, or the first function could have been disposed. |
| 5339 | // This is handled the same way as the previous case. |
| 5340 | // |
| 5341 | // Important: inobject slack tracking is not attempted during the snapshot |
| 5342 | // creation. |
| 5343 | |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 5344 | static const int kGenerousAllocationCount = 8; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 5345 | |
| 5346 | // [construction_count]: Counter for constructor calls made during |
| 5347 | // the tracking phase. |
| 5348 | inline int construction_count(); |
| 5349 | inline void set_construction_count(int value); |
| 5350 | |
| 5351 | // [initial_map]: initial map of the first function called as a constructor. |
| 5352 | // Saved for the duration of the tracking phase. |
| 5353 | // This is a weak link (GC resets it to undefined_value if no other live |
| 5354 | // object reference this map). |
| 5355 | DECL_ACCESSORS(initial_map, Object) |
| 5356 | |
| 5357 | // True if the initial_map is not undefined and the countdown stub is |
| 5358 | // installed. |
| 5359 | inline bool IsInobjectSlackTrackingInProgress(); |
| 5360 | |
| 5361 | // Starts the tracking. |
| 5362 | // Stores the initial map and installs the countdown stub. |
| 5363 | // IsInobjectSlackTrackingInProgress is normally true after this call, |
| 5364 | // except when tracking have not been started (e.g. the map has no unused |
| 5365 | // properties or the snapshot is being built). |
| 5366 | void StartInobjectSlackTracking(Map* map); |
| 5367 | |
| 5368 | // Completes the tracking. |
| 5369 | // IsInobjectSlackTrackingInProgress is false after this call. |
| 5370 | void CompleteInobjectSlackTracking(); |
| 5371 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 5372 | // Invoked before pointers in SharedFunctionInfo are being marked. |
| 5373 | // Also clears the optimized code map. |
| 5374 | inline void BeforeVisitingPointers(); |
| 5375 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 5376 | // Clears the initial_map before the GC marking phase to ensure the reference |
| 5377 | // is weak. IsInobjectSlackTrackingInProgress is false after this call. |
| 5378 | void DetachInitialMap(); |
| 5379 | |
| 5380 | // Restores the link to the initial map after the GC marking phase. |
| 5381 | // IsInobjectSlackTrackingInProgress is true after this call. |
| 5382 | void AttachInitialMap(Map* map); |
| 5383 | |
| 5384 | // False if there are definitely no live objects created from this function. |
| 5385 | // True if live objects _may_ exist (existence not guaranteed). |
| 5386 | // May go back from true to false after GC. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5387 | DECL_BOOLEAN_ACCESSORS(live_objects_may_exist) |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 5388 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5389 | // [instance class name]: class name for instances. |
| 5390 | DECL_ACCESSORS(instance_class_name, Object) |
| 5391 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 5392 | // [function data]: This field holds some additional data for function. |
| 5393 | // Currently it either has FunctionTemplateInfo to make benefit the API |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5394 | // or Smi identifying a builtin function. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5395 | // In the long run we don't want all functions to have this field but |
| 5396 | // we can fix that when we have a better model for storing hidden data |
| 5397 | // on objects. |
| 5398 | DECL_ACCESSORS(function_data, Object) |
| 5399 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 5400 | inline bool IsApiFunction(); |
| 5401 | inline FunctionTemplateInfo* get_api_func_data(); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5402 | inline bool HasBuiltinFunctionId(); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5403 | inline BuiltinFunctionId builtin_function_id(); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 5404 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5405 | // [script info]: Script from which the function originates. |
| 5406 | DECL_ACCESSORS(script, Object) |
| 5407 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 5408 | // [num_literals]: Number of literals used by this function. |
| 5409 | inline int num_literals(); |
| 5410 | inline void set_num_literals(int value); |
| 5411 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5412 | // [start_position_and_type]: Field used to store both the source code |
| 5413 | // position, whether or not the function is a function expression, |
| 5414 | // and whether or not the function is a toplevel function. The two |
| 5415 | // least significants bit indicates whether the function is an |
| 5416 | // expression and the rest contains the source code position. |
| 5417 | inline int start_position_and_type(); |
| 5418 | inline void set_start_position_and_type(int value); |
| 5419 | |
| 5420 | // [debug info]: Debug information. |
| 5421 | DECL_ACCESSORS(debug_info, Object) |
| 5422 | |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 5423 | // [inferred name]: Name inferred from variable or property |
| 5424 | // assignment of this function. Used to facilitate debugging and |
| 5425 | // profiling of JavaScript code written in OO style, where almost |
| 5426 | // all functions are anonymous but are assigned to object |
| 5427 | // properties. |
| 5428 | DECL_ACCESSORS(inferred_name, String) |
| 5429 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 5430 | // The function's name if it is non-empty, otherwise the inferred name. |
| 5431 | String* DebugName(); |
| 5432 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5433 | // Position of the 'function' token in the script source. |
| 5434 | inline int function_token_position(); |
| 5435 | inline void set_function_token_position(int function_token_position); |
| 5436 | |
| 5437 | // Position of this function in the script source. |
| 5438 | inline int start_position(); |
| 5439 | inline void set_start_position(int start_position); |
| 5440 | |
| 5441 | // End position of this function in the script source. |
| 5442 | inline int end_position(); |
| 5443 | inline void set_end_position(int end_position); |
| 5444 | |
| 5445 | // Is this function a function expression in the source code. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 5446 | DECL_BOOLEAN_ACCESSORS(is_expression) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5447 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 5448 | // Is this function a top-level function (scripts, evals). |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 5449 | DECL_BOOLEAN_ACCESSORS(is_toplevel) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5450 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5451 | // Bit field containing various information collected by the compiler to |
| 5452 | // drive optimization. |
| 5453 | inline int compiler_hints(); |
| 5454 | inline void set_compiler_hints(int value); |
| 5455 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5456 | inline int ast_node_count(); |
| 5457 | inline void set_ast_node_count(int count); |
| 5458 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5459 | // A counter used to determine when to stress the deoptimizer with a |
| 5460 | // deopt. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5461 | inline int stress_deopt_counter(); |
| 5462 | inline void set_stress_deopt_counter(int counter); |
svenpanne@chromium.org | b1df11d | 2012-02-08 10:26:21 +0000 | [diff] [blame] | 5463 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 5464 | inline int profiler_ticks(); |
| 5465 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5466 | // Inline cache age is used to infer whether the function survived a context |
| 5467 | // disposal or not. In the former case we reset the opt_count. |
| 5468 | inline int ic_age(); |
| 5469 | inline void set_ic_age(int age); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5470 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5471 | // Add information on assignments of the form this.x = ...; |
| 5472 | void SetThisPropertyAssignmentsInfo( |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5473 | bool has_only_simple_this_property_assignments, |
| 5474 | FixedArray* this_property_assignments); |
| 5475 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5476 | // Clear information on assignments of the form this.x = ...; |
| 5477 | void ClearThisPropertyAssignmentsInfo(); |
| 5478 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5479 | // Indicate that this function only consists of assignments of the form |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5480 | // this.x = y; where y is either a constant or refers to an argument. |
| 5481 | inline bool has_only_simple_this_property_assignments(); |
| 5482 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 5483 | // Indicates if this function can be lazy compiled. |
| 5484 | // This is used to determine if we can safely flush code from a function |
| 5485 | // 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] | 5486 | DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation) |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 5487 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 5488 | // Indicates if this function can be lazy compiled without a context. |
| 5489 | // This is used to determine if we can force compilation without reaching |
| 5490 | // the function through program execution but through other means (e.g. heap |
| 5491 | // iteration by the debugger). |
| 5492 | DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation_without_context) |
| 5493 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 5494 | // Indicates how many full GCs this function has survived with assigned |
| 5495 | // code object. Used to determine when it is relatively safe to flush |
| 5496 | // this code object and replace it with lazy compilation stub. |
| 5497 | // Age is reset when GC notices that the code object is referenced |
| 5498 | // from the stack or compilation cache. |
| 5499 | inline int code_age(); |
| 5500 | inline void set_code_age(int age); |
| 5501 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5502 | // Indicates whether optimizations have been disabled for this |
| 5503 | // shared function info. If a function is repeatedly optimized or if |
| 5504 | // we cannot optimize the function we disable optimization to avoid |
| 5505 | // spending time attempting to optimize it again. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5506 | DECL_BOOLEAN_ACCESSORS(optimization_disabled) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5507 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5508 | // Indicates the language mode of the function's code as defined by the |
| 5509 | // current harmony drafts for the next ES language standard. Possible |
| 5510 | // values are: |
| 5511 | // 1. CLASSIC_MODE - Unrestricted syntax and semantics, same as in ES5. |
| 5512 | // 2. STRICT_MODE - Restricted syntax and semantics, same as in ES5. |
| 5513 | // 3. EXTENDED_MODE - Only available under the harmony flag, not part of ES5. |
| 5514 | inline LanguageMode language_mode(); |
| 5515 | inline void set_language_mode(LanguageMode language_mode); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5516 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5517 | // Indicates whether the language mode of this function is CLASSIC_MODE. |
| 5518 | inline bool is_classic_mode(); |
| 5519 | |
| 5520 | // Indicates whether the language mode of this function is EXTENDED_MODE. |
| 5521 | inline bool is_extended_mode(); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5522 | |
| 5523 | // False if the function definitely does not allocate an arguments object. |
| 5524 | DECL_BOOLEAN_ACCESSORS(uses_arguments) |
| 5525 | |
| 5526 | // True if the function has any duplicated parameter names. |
| 5527 | DECL_BOOLEAN_ACCESSORS(has_duplicate_parameters) |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 5528 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 5529 | // Indicates whether the function is a native function. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 5530 | // These needs special treatment in .call and .apply since |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 5531 | // null passed as the receiver should not be translated to the |
| 5532 | // global object. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 5533 | DECL_BOOLEAN_ACCESSORS(native) |
| 5534 | |
| 5535 | // Indicates that the function was created by the Function function. |
| 5536 | // Though it's anonymous, toString should treat it as if it had the name |
| 5537 | // "anonymous". We don't set the name itself so that the system does not |
| 5538 | // see a binding for it. |
| 5539 | DECL_BOOLEAN_ACCESSORS(name_should_print_as_anonymous) |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 5540 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5541 | // Indicates whether the function is a bound function created using |
| 5542 | // the bind function. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 5543 | DECL_BOOLEAN_ACCESSORS(bound) |
| 5544 | |
| 5545 | // Indicates that the function is anonymous (the name field can be set |
| 5546 | // through the API, which does not change this flag). |
| 5547 | DECL_BOOLEAN_ACCESSORS(is_anonymous) |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5548 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 5549 | // Is this a function or top-level/eval code. |
| 5550 | DECL_BOOLEAN_ACCESSORS(is_function) |
| 5551 | |
| 5552 | // Indicates that the function cannot be optimized. |
| 5553 | DECL_BOOLEAN_ACCESSORS(dont_optimize) |
svenpanne@chromium.org | b1df11d | 2012-02-08 10:26:21 +0000 | [diff] [blame] | 5554 | |
| 5555 | // Indicates that the function cannot be inlined. |
| 5556 | DECL_BOOLEAN_ACCESSORS(dont_inline) |
| 5557 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5558 | // Indicates whether or not the code in the shared function support |
| 5559 | // deoptimization. |
| 5560 | inline bool has_deoptimization_support(); |
| 5561 | |
| 5562 | // Enable deoptimization support through recompiled code. |
| 5563 | void EnableDeoptimizationSupport(Code* recompiled); |
| 5564 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5565 | // Disable (further) attempted optimization of all functions sharing this |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 5566 | // shared function info. |
| 5567 | void DisableOptimization(); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5568 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5569 | // Lookup the bailout ID and ASSERT that it exists in the non-optimized |
| 5570 | // code, returns whether it asserted (i.e., always true if assertions are |
| 5571 | // disabled). |
| 5572 | bool VerifyBailoutId(int id); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 5573 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5574 | // Check whether a inlined constructor can be generated with the given |
| 5575 | // prototype. |
| 5576 | bool CanGenerateInlineConstructor(Object* prototype); |
| 5577 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 5578 | // Prevents further attempts to generate inline constructors. |
| 5579 | // To be called if generation failed for any reason. |
| 5580 | void ForbidInlineConstructor(); |
| 5581 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5582 | // For functions which only contains this property assignments this provides |
| 5583 | // access to the names for the properties assigned. |
| 5584 | DECL_ACCESSORS(this_property_assignments, Object) |
| 5585 | inline int this_property_assignments_count(); |
| 5586 | inline void set_this_property_assignments_count(int value); |
| 5587 | String* GetThisPropertyAssignmentName(int index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 5588 | bool IsThisPropertyAssignmentArgument(int index); |
| 5589 | int GetThisPropertyAssignmentArgument(int index); |
| 5590 | Object* GetThisPropertyAssignmentConstant(int index); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5591 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5592 | // [source code]: Source code for the function. |
| 5593 | bool HasSourceCode(); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 5594 | Handle<Object> GetSourceCode(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5595 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5596 | // Number of times the function was optimized. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5597 | inline int opt_count(); |
| 5598 | inline void set_opt_count(int opt_count); |
| 5599 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5600 | // Number of times the function was deoptimized. |
| 5601 | inline void set_deopt_count(int value); |
| 5602 | inline int deopt_count(); |
| 5603 | inline void increment_deopt_count(); |
| 5604 | |
| 5605 | // Number of time we tried to re-enable optimization after it |
| 5606 | // was disabled due to high number of deoptimizations. |
| 5607 | inline void set_opt_reenable_tries(int value); |
| 5608 | inline int opt_reenable_tries(); |
| 5609 | |
| 5610 | inline void TryReenableOptimization(); |
| 5611 | |
| 5612 | // Stores deopt_count, opt_reenable_tries and ic_age as bit-fields. |
| 5613 | inline void set_counters(int value); |
| 5614 | inline int counters(); |
| 5615 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5616 | // Source size of this function. |
| 5617 | int SourceSize(); |
| 5618 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5619 | // Calculate the instance size. |
| 5620 | int CalculateInstanceSize(); |
| 5621 | |
| 5622 | // Calculate the number of in-object properties. |
| 5623 | int CalculateInObjectProperties(); |
| 5624 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5625 | // Dispatched behavior. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5626 | // Set max_length to -1 for unlimited length. |
| 5627 | void SourceCodePrint(StringStream* accumulator, int max_length); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5628 | #ifdef OBJECT_PRINT |
| 5629 | inline void SharedFunctionInfoPrint() { |
| 5630 | SharedFunctionInfoPrint(stdout); |
| 5631 | } |
| 5632 | void SharedFunctionInfoPrint(FILE* out); |
| 5633 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5634 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5635 | void SharedFunctionInfoVerify(); |
| 5636 | #endif |
| 5637 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5638 | void ResetForNewContext(int new_ic_age); |
| 5639 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 5640 | // Helper to compile the shared code. Returns true on success, false on |
| 5641 | // failure (e.g., stack overflow during compilation). This is only used by |
| 5642 | // 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] | 5643 | static bool CompileLazy(Handle<SharedFunctionInfo> shared, |
| 5644 | ClearExceptionFlag flag); |
| 5645 | |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 5646 | void SharedFunctionInfoIterateBody(ObjectVisitor* v); |
| 5647 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5648 | // Casting. |
| 5649 | static inline SharedFunctionInfo* cast(Object* obj); |
| 5650 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 5651 | // Constants. |
| 5652 | static const int kDontAdaptArgumentsSentinel = -1; |
| 5653 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5654 | // Layout description. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5655 | // Pointer fields. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5656 | static const int kNameOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5657 | static const int kCodeOffset = kNameOffset + kPointerSize; |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 5658 | static const int kOptimizedCodeMapOffset = kCodeOffset + kPointerSize; |
| 5659 | static const int kScopeInfoOffset = kOptimizedCodeMapOffset + kPointerSize; |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 5660 | static const int kConstructStubOffset = kScopeInfoOffset + kPointerSize; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5661 | static const int kInstanceClassNameOffset = |
| 5662 | kConstructStubOffset + kPointerSize; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 5663 | static const int kFunctionDataOffset = |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5664 | kInstanceClassNameOffset + kPointerSize; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 5665 | static const int kScriptOffset = kFunctionDataOffset + kPointerSize; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5666 | static const int kDebugInfoOffset = kScriptOffset + kPointerSize; |
| 5667 | static const int kInferredNameOffset = kDebugInfoOffset + kPointerSize; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 5668 | static const int kInitialMapOffset = |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5669 | kInferredNameOffset + kPointerSize; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 5670 | static const int kThisPropertyAssignmentsOffset = |
| 5671 | kInitialMapOffset + kPointerSize; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5672 | // ast_node_count is a Smi field. It could be grouped with another Smi field |
| 5673 | // into a PSEUDO_SMI_ACCESSORS pair (on x64), if one becomes available. |
| 5674 | static const int kAstNodeCountOffset = |
| 5675 | kThisPropertyAssignmentsOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5676 | #if V8_HOST_ARCH_32_BIT |
| 5677 | // Smi fields. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5678 | static const int kLengthOffset = |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5679 | kAstNodeCountOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5680 | static const int kFormalParameterCountOffset = kLengthOffset + kPointerSize; |
| 5681 | static const int kExpectedNofPropertiesOffset = |
| 5682 | kFormalParameterCountOffset + kPointerSize; |
| 5683 | static const int kNumLiteralsOffset = |
| 5684 | kExpectedNofPropertiesOffset + kPointerSize; |
| 5685 | static const int kStartPositionAndTypeOffset = |
| 5686 | kNumLiteralsOffset + kPointerSize; |
| 5687 | static const int kEndPositionOffset = |
| 5688 | kStartPositionAndTypeOffset + kPointerSize; |
| 5689 | static const int kFunctionTokenPositionOffset = |
| 5690 | kEndPositionOffset + kPointerSize; |
| 5691 | static const int kCompilerHintsOffset = |
| 5692 | kFunctionTokenPositionOffset + kPointerSize; |
| 5693 | static const int kThisPropertyAssignmentsCountOffset = |
| 5694 | kCompilerHintsOffset + kPointerSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5695 | static const int kOptCountOffset = |
| 5696 | kThisPropertyAssignmentsCountOffset + kPointerSize; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5697 | static const int kCountersOffset = kOptCountOffset + kPointerSize; |
| 5698 | static const int kStressDeoptCounterOffset = kCountersOffset + kPointerSize; |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 5699 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5700 | // Total size. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5701 | static const int kSize = kStressDeoptCounterOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5702 | #else |
| 5703 | // The only reason to use smi fields instead of int fields |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 5704 | // is to allow iteration without maps decoding during |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5705 | // garbage collections. |
| 5706 | // To avoid wasting space on 64-bit architectures we use |
| 5707 | // the following trick: we group integer fields into pairs |
| 5708 | // First integer in each pair is shifted left by 1. |
| 5709 | // By doing this we guarantee that LSB of each kPointerSize aligned |
| 5710 | // word is not set and thus this word cannot be treated as pointer |
| 5711 | // to HeapObject during old space traversal. |
| 5712 | static const int kLengthOffset = |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5713 | kAstNodeCountOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5714 | static const int kFormalParameterCountOffset = |
| 5715 | kLengthOffset + kIntSize; |
| 5716 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5717 | static const int kExpectedNofPropertiesOffset = |
| 5718 | kFormalParameterCountOffset + kIntSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5719 | static const int kNumLiteralsOffset = |
| 5720 | kExpectedNofPropertiesOffset + kIntSize; |
| 5721 | |
| 5722 | static const int kEndPositionOffset = |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 5723 | kNumLiteralsOffset + kIntSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5724 | static const int kStartPositionAndTypeOffset = |
| 5725 | kEndPositionOffset + kIntSize; |
| 5726 | |
| 5727 | static const int kFunctionTokenPositionOffset = |
| 5728 | kStartPositionAndTypeOffset + kIntSize; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5729 | static const int kCompilerHintsOffset = |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5730 | kFunctionTokenPositionOffset + kIntSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5731 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5732 | static const int kThisPropertyAssignmentsCountOffset = |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5733 | kCompilerHintsOffset + kIntSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5734 | static const int kOptCountOffset = |
| 5735 | kThisPropertyAssignmentsCountOffset + kIntSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5736 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5737 | static const int kCountersOffset = kOptCountOffset + kIntSize; |
| 5738 | static const int kStressDeoptCounterOffset = kCountersOffset + kIntSize; |
svenpanne@chromium.org | b1df11d | 2012-02-08 10:26:21 +0000 | [diff] [blame] | 5739 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5740 | // Total size. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5741 | static const int kSize = kStressDeoptCounterOffset + kIntSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5742 | |
| 5743 | #endif |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 5744 | |
| 5745 | // The construction counter for inobject slack tracking is stored in the |
| 5746 | // most significant byte of compiler_hints which is otherwise unused. |
| 5747 | // Its offset depends on the endian-ness of the architecture. |
| 5748 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 5749 | static const int kConstructionCountOffset = kCompilerHintsOffset + 3; |
| 5750 | #elif __BYTE_ORDER == __BIG_ENDIAN |
| 5751 | static const int kConstructionCountOffset = kCompilerHintsOffset + 0; |
| 5752 | #else |
| 5753 | #error Unknown byte ordering |
| 5754 | #endif |
| 5755 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 5756 | static const int kAlignedSize = POINTER_SIZE_ALIGN(kSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5757 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 5758 | typedef FixedBodyDescriptor<kNameOffset, |
| 5759 | kThisPropertyAssignmentsOffset + kPointerSize, |
| 5760 | kSize> BodyDescriptor; |
| 5761 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5762 | // Bit positions in start_position_and_type. |
| 5763 | // The source code start position is in the 30 most significant bits of |
| 5764 | // the start_position_and_type field. |
| 5765 | static const int kIsExpressionBit = 0; |
| 5766 | static const int kIsTopLevelBit = 1; |
| 5767 | static const int kStartPositionShift = 2; |
| 5768 | static const int kStartPositionMask = ~((1 << kStartPositionShift) - 1); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5769 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5770 | // Bit positions in compiler_hints. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5771 | static const int kCodeAgeSize = 3; |
| 5772 | static const int kCodeAgeMask = (1 << kCodeAgeSize) - 1; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5773 | |
| 5774 | enum CompilerHints { |
| 5775 | kHasOnlySimpleThisPropertyAssignments, |
| 5776 | kAllowLazyCompilation, |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 5777 | kAllowLazyCompilationWithoutContext, |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5778 | kLiveObjectsMayExist, |
| 5779 | kCodeAgeShift, |
| 5780 | kOptimizationDisabled = kCodeAgeShift + kCodeAgeSize, |
| 5781 | kStrictModeFunction, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5782 | kExtendedModeFunction, |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5783 | kUsesArguments, |
| 5784 | kHasDuplicateParameters, |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 5785 | kNative, |
| 5786 | kBoundFunction, |
| 5787 | kIsAnonymous, |
| 5788 | kNameShouldPrintAsAnonymous, |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 5789 | kIsFunction, |
| 5790 | kDontOptimize, |
svenpanne@chromium.org | b1df11d | 2012-02-08 10:26:21 +0000 | [diff] [blame] | 5791 | kDontInline, |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 5792 | kCompilerHintsCount // Pseudo entry |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5793 | }; |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 5794 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 5795 | class DeoptCountBits: public BitField<int, 0, 4> {}; |
| 5796 | class OptReenableTriesBits: public BitField<int, 4, 18> {}; |
| 5797 | class ICAgeBits: public BitField<int, 22, 8> {}; |
| 5798 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 5799 | private: |
| 5800 | #if V8_HOST_ARCH_32_BIT |
| 5801 | // On 32 bit platforms, compiler hints is a smi. |
| 5802 | static const int kCompilerHintsSmiTagSize = kSmiTagSize; |
| 5803 | static const int kCompilerHintsSize = kPointerSize; |
| 5804 | #else |
| 5805 | // On 64 bit platforms, compiler hints is not a smi, see comment above. |
| 5806 | static const int kCompilerHintsSmiTagSize = 0; |
| 5807 | static const int kCompilerHintsSize = kIntSize; |
| 5808 | #endif |
| 5809 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 5810 | STATIC_ASSERT(SharedFunctionInfo::kCompilerHintsCount <= |
| 5811 | SharedFunctionInfo::kCompilerHintsSize * kBitsPerByte); |
| 5812 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 5813 | public: |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 5814 | // Constants for optimizing codegen for strict mode function and |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 5815 | // native tests. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5816 | // Allows to use byte-width instructions. |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 5817 | static const int kStrictModeBitWithinByte = |
| 5818 | (kStrictModeFunction + kCompilerHintsSmiTagSize) % kBitsPerByte; |
| 5819 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5820 | static const int kExtendedModeBitWithinByte = |
| 5821 | (kExtendedModeFunction + kCompilerHintsSmiTagSize) % kBitsPerByte; |
| 5822 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 5823 | static const int kNativeBitWithinByte = |
| 5824 | (kNative + kCompilerHintsSmiTagSize) % kBitsPerByte; |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 5825 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 5826 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 5827 | static const int kStrictModeByteOffset = kCompilerHintsOffset + |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 5828 | (kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5829 | static const int kExtendedModeByteOffset = kCompilerHintsOffset + |
| 5830 | (kExtendedModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 5831 | static const int kNativeByteOffset = kCompilerHintsOffset + |
| 5832 | (kNative + kCompilerHintsSmiTagSize) / kBitsPerByte; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 5833 | #elif __BYTE_ORDER == __BIG_ENDIAN |
| 5834 | static const int kStrictModeByteOffset = kCompilerHintsOffset + |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 5835 | (kCompilerHintsSize - 1) - |
| 5836 | ((kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 5837 | static const int kExtendedModeByteOffset = kCompilerHintsOffset + |
| 5838 | (kCompilerHintsSize - 1) - |
| 5839 | ((kExtendedModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 5840 | static const int kNativeByteOffset = kCompilerHintsOffset + |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 5841 | (kCompilerHintsSize - 1) - |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 5842 | ((kNative + kCompilerHintsSmiTagSize) / kBitsPerByte); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 5843 | #else |
| 5844 | #error Unknown byte ordering |
| 5845 | #endif |
| 5846 | |
| 5847 | private: |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5848 | DISALLOW_IMPLICIT_CONSTRUCTORS(SharedFunctionInfo); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5849 | }; |
| 5850 | |
| 5851 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 5852 | // Representation for module instance objects. |
| 5853 | class JSModule: public JSObject { |
| 5854 | public: |
| 5855 | // [context]: the context holding the module's locals, or undefined if none. |
| 5856 | DECL_ACCESSORS(context, Object) |
| 5857 | |
| 5858 | // Casting. |
| 5859 | static inline JSModule* cast(Object* obj); |
| 5860 | |
| 5861 | // Dispatched behavior. |
| 5862 | #ifdef OBJECT_PRINT |
| 5863 | inline void JSModulePrint() { |
| 5864 | JSModulePrint(stdout); |
| 5865 | } |
| 5866 | void JSModulePrint(FILE* out); |
| 5867 | #endif |
| 5868 | #ifdef DEBUG |
| 5869 | void JSModuleVerify(); |
| 5870 | #endif |
| 5871 | |
| 5872 | // Layout description. |
| 5873 | static const int kContextOffset = JSObject::kHeaderSize; |
| 5874 | static const int kSize = kContextOffset + kPointerSize; |
| 5875 | |
| 5876 | private: |
| 5877 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSModule); |
| 5878 | }; |
| 5879 | |
| 5880 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5881 | // JSFunction describes JavaScript functions. |
| 5882 | class JSFunction: public JSObject { |
| 5883 | public: |
| 5884 | // [prototype_or_initial_map]: |
| 5885 | DECL_ACCESSORS(prototype_or_initial_map, Object) |
| 5886 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 5887 | // [shared]: The information about the function that |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5888 | // can be shared by instances. |
| 5889 | DECL_ACCESSORS(shared, SharedFunctionInfo) |
| 5890 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 5891 | inline SharedFunctionInfo* unchecked_shared(); |
| 5892 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5893 | // [context]: The context for this function. |
| 5894 | inline Context* context(); |
| 5895 | inline Object* unchecked_context(); |
| 5896 | inline void set_context(Object* context); |
| 5897 | |
| 5898 | // [code]: The generated code object for this function. Executed |
| 5899 | // when the function is invoked, e.g. foo() or new foo(). See |
| 5900 | // [[Call]] and [[Construct]] description in ECMA-262, section |
| 5901 | // 8.6.2, page 27. |
| 5902 | inline Code* code(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5903 | inline void set_code(Code* code); |
| 5904 | inline void ReplaceCode(Code* code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5905 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 5906 | inline Code* unchecked_code(); |
| 5907 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 5908 | // Tells whether this function is builtin. |
| 5909 | inline bool IsBuiltin(); |
| 5910 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5911 | // Tells whether or not the function needs arguments adaption. |
| 5912 | inline bool NeedsArgumentsAdaption(); |
| 5913 | |
| 5914 | // Tells whether or not this function has been optimized. |
| 5915 | inline bool IsOptimized(); |
| 5916 | |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 5917 | // Tells whether or not this function can be optimized. |
| 5918 | inline bool IsOptimizable(); |
| 5919 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5920 | // Mark this function for lazy recompilation. The function will be |
| 5921 | // recompiled the next time it is executed. |
| 5922 | void MarkForLazyRecompilation(); |
| 5923 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5924 | // Helpers to compile this function. Returns true on success, false on |
| 5925 | // failure (e.g., stack overflow during compilation). |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 5926 | static bool EnsureCompiled(Handle<JSFunction> function, |
| 5927 | ClearExceptionFlag flag); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5928 | static bool CompileLazy(Handle<JSFunction> function, |
| 5929 | ClearExceptionFlag flag); |
| 5930 | static bool CompileOptimized(Handle<JSFunction> function, |
| 5931 | int osr_ast_id, |
| 5932 | ClearExceptionFlag flag); |
| 5933 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5934 | // Tells whether or not the function is already marked for lazy |
| 5935 | // recompilation. |
| 5936 | inline bool IsMarkedForLazyRecompilation(); |
| 5937 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5938 | // Check whether or not this function is inlineable. |
| 5939 | bool IsInlineable(); |
| 5940 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5941 | // [literals_or_bindings]: Fixed array holding either |
| 5942 | // 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] | 5943 | // |
| 5944 | // If the function contains object, regexp or array literals, the |
| 5945 | // literals array prefix contains the object, regexp, and array |
| 5946 | // function to be used when creating these literals. This is |
| 5947 | // necessary so that we do not dynamically lookup the object, regexp |
| 5948 | // or array functions. Performing a dynamic lookup, we might end up |
| 5949 | // using the functions from a new context that we should not have |
| 5950 | // access to. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5951 | // |
| 5952 | // On bound functions, the array is a (copy-on-write) fixed-array containing |
| 5953 | // the function that was bound, bound this-value and any bound |
| 5954 | // arguments. Bound functions never contain literals. |
| 5955 | DECL_ACCESSORS(literals_or_bindings, FixedArray) |
| 5956 | |
| 5957 | inline FixedArray* literals(); |
| 5958 | inline void set_literals(FixedArray* literals); |
| 5959 | |
| 5960 | inline FixedArray* function_bindings(); |
| 5961 | inline void set_function_bindings(FixedArray* bindings); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5962 | |
| 5963 | // The initial map for an object created by this constructor. |
| 5964 | inline Map* initial_map(); |
| 5965 | inline void set_initial_map(Map* value); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 5966 | MUST_USE_RESULT inline MaybeObject* set_initial_map_and_cache_transitions( |
| 5967 | Map* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5968 | inline bool has_initial_map(); |
| 5969 | |
| 5970 | // Get and set the prototype property on a JSFunction. If the |
| 5971 | // function has an initial map the prototype is set on the initial |
| 5972 | // map. Otherwise, the prototype is put in the initial map field |
| 5973 | // until an initial map is needed. |
| 5974 | inline bool has_prototype(); |
| 5975 | inline bool has_instance_prototype(); |
| 5976 | inline Object* prototype(); |
| 5977 | inline Object* instance_prototype(); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 5978 | MUST_USE_RESULT MaybeObject* SetInstancePrototype(Object* value); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5979 | MUST_USE_RESULT MaybeObject* SetPrototype(Object* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5980 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 5981 | // After prototype is removed, it will not be created when accessed, and |
| 5982 | // [[Construct]] from this function will not be allowed. |
| 5983 | Object* RemovePrototype(); |
| 5984 | inline bool should_have_prototype(); |
| 5985 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5986 | // Accessor for this function's initial map's [[class]] |
| 5987 | // property. This is primarily used by ECMA native functions. This |
| 5988 | // method sets the class_name field of this function's initial map |
| 5989 | // to a given value. It creates an initial map if this function does |
| 5990 | // not have one. Note that this method does not copy the initial map |
| 5991 | // if it has one already, but simply replaces it with the new value. |
| 5992 | // Instances created afterwards will have a map whose [[class]] is |
| 5993 | // set to 'value', but there is no guarantees on instances created |
| 5994 | // before. |
| 5995 | Object* SetInstanceClassName(String* name); |
| 5996 | |
| 5997 | // Returns if this function has been compiled to native code yet. |
| 5998 | inline bool is_compiled(); |
| 5999 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6000 | // [next_function_link]: Field for linking functions. This list is treated as |
| 6001 | // a weak list by the GC. |
| 6002 | DECL_ACCESSORS(next_function_link, Object) |
| 6003 | |
| 6004 | // Prints the name of the function using PrintF. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6005 | inline void PrintName() { |
| 6006 | PrintName(stdout); |
| 6007 | } |
| 6008 | void PrintName(FILE* out); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6009 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6010 | // Casting. |
| 6011 | static inline JSFunction* cast(Object* obj); |
| 6012 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 6013 | // Iterates the objects, including code objects indirectly referenced |
| 6014 | // through pointers to the first instruction in the code object. |
| 6015 | void JSFunctionIterateBody(int object_size, ObjectVisitor* v); |
| 6016 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6017 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6018 | #ifdef OBJECT_PRINT |
| 6019 | inline void JSFunctionPrint() { |
| 6020 | JSFunctionPrint(stdout); |
| 6021 | } |
| 6022 | void JSFunctionPrint(FILE* out); |
| 6023 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6024 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6025 | void JSFunctionVerify(); |
| 6026 | #endif |
| 6027 | |
| 6028 | // Returns the number of allocated literals. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6029 | inline int NumberOfLiterals(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6030 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6031 | // Retrieve the global context from a function's literal array. |
| 6032 | static Context* GlobalContextFromLiterals(FixedArray* literals); |
| 6033 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6034 | // Layout descriptors. The last property (from kNonWeakFieldsEndOffset to |
| 6035 | // kSize) is weak and has special handling during garbage collection. |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 6036 | static const int kCodeEntryOffset = JSObject::kHeaderSize; |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 6037 | static const int kPrototypeOrInitialMapOffset = |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 6038 | kCodeEntryOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6039 | static const int kSharedFunctionInfoOffset = |
| 6040 | kPrototypeOrInitialMapOffset + kPointerSize; |
| 6041 | static const int kContextOffset = kSharedFunctionInfoOffset + kPointerSize; |
| 6042 | static const int kLiteralsOffset = kContextOffset + kPointerSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6043 | static const int kNonWeakFieldsEndOffset = kLiteralsOffset + kPointerSize; |
| 6044 | static const int kNextFunctionLinkOffset = kNonWeakFieldsEndOffset; |
| 6045 | static const int kSize = kNextFunctionLinkOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6046 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 6047 | // Layout of the literals array. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6048 | static const int kLiteralsPrefixSize = 1; |
| 6049 | static const int kLiteralGlobalContextIndex = 0; |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 6050 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6051 | // Layout of the bound-function binding array. |
| 6052 | static const int kBoundFunctionIndex = 0; |
| 6053 | static const int kBoundThisIndex = 1; |
| 6054 | static const int kBoundArgumentsStartIndex = 2; |
| 6055 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6056 | private: |
| 6057 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunction); |
| 6058 | }; |
| 6059 | |
| 6060 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 6061 | // JSGlobalProxy's prototype must be a JSGlobalObject or null, |
| 6062 | // and the prototype is hidden. JSGlobalProxy always delegates |
| 6063 | // property accesses to its prototype if the prototype is not null. |
| 6064 | // |
| 6065 | // A JSGlobalProxy can be reinitialized which will preserve its identity. |
| 6066 | // |
| 6067 | // Accessing a JSGlobalProxy requires security check. |
| 6068 | |
| 6069 | class JSGlobalProxy : public JSObject { |
| 6070 | public: |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6071 | // [context]: the owner global context of this global proxy object. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 6072 | // It is null value if this object is not used by any context. |
| 6073 | DECL_ACCESSORS(context, Object) |
| 6074 | |
| 6075 | // Casting. |
| 6076 | static inline JSGlobalProxy* cast(Object* obj); |
| 6077 | |
| 6078 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6079 | #ifdef OBJECT_PRINT |
| 6080 | inline void JSGlobalProxyPrint() { |
| 6081 | JSGlobalProxyPrint(stdout); |
| 6082 | } |
| 6083 | void JSGlobalProxyPrint(FILE* out); |
| 6084 | #endif |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 6085 | #ifdef DEBUG |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 6086 | void JSGlobalProxyVerify(); |
| 6087 | #endif |
| 6088 | |
| 6089 | // Layout description. |
| 6090 | static const int kContextOffset = JSObject::kHeaderSize; |
| 6091 | static const int kSize = kContextOffset + kPointerSize; |
| 6092 | |
| 6093 | private: |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 6094 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalProxy); |
| 6095 | }; |
| 6096 | |
| 6097 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6098 | // Forward declaration. |
| 6099 | class JSBuiltinsObject; |
| 6100 | |
| 6101 | // Common super class for JavaScript global objects and the special |
| 6102 | // builtins global objects. |
| 6103 | class GlobalObject: public JSObject { |
| 6104 | public: |
| 6105 | // [builtins]: the object holding the runtime routines written in JS. |
| 6106 | DECL_ACCESSORS(builtins, JSBuiltinsObject) |
| 6107 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 6108 | // [global context]: the global context corresponding to this global object. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6109 | DECL_ACCESSORS(global_context, Context) |
| 6110 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 6111 | // [global receiver]: the global receiver object of the context |
| 6112 | DECL_ACCESSORS(global_receiver, JSObject) |
| 6113 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6114 | // Retrieve the property cell used to store a property. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6115 | JSGlobalPropertyCell* GetPropertyCell(LookupResult* result); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6116 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 6117 | // This is like GetProperty, but is used when you know the lookup won't fail |
| 6118 | // by throwing an exception. This is for the debug and builtins global |
| 6119 | // objects, where it is known which properties can be expected to be present |
| 6120 | // on the object. |
| 6121 | Object* GetPropertyNoExceptionThrown(String* key) { |
| 6122 | Object* answer = GetProperty(key)->ToObjectUnchecked(); |
| 6123 | return answer; |
| 6124 | } |
| 6125 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 6126 | // 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] | 6127 | static Handle<JSGlobalPropertyCell> EnsurePropertyCell( |
| 6128 | Handle<GlobalObject> global, |
| 6129 | Handle<String> name); |
| 6130 | // TODO(kmillikin): This function can be eliminated once the stub cache is |
| 6131 | // full handlified (and the static helper can be written directly). |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 6132 | MUST_USE_RESULT MaybeObject* EnsurePropertyCell(String* name); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 6133 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 6134 | // Casting. |
| 6135 | static inline GlobalObject* cast(Object* obj); |
| 6136 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6137 | // Layout description. |
| 6138 | static const int kBuiltinsOffset = JSObject::kHeaderSize; |
| 6139 | static const int kGlobalContextOffset = kBuiltinsOffset + kPointerSize; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 6140 | static const int kGlobalReceiverOffset = kGlobalContextOffset + kPointerSize; |
| 6141 | static const int kHeaderSize = kGlobalReceiverOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6142 | |
| 6143 | private: |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 6144 | DISALLOW_IMPLICIT_CONSTRUCTORS(GlobalObject); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6145 | }; |
| 6146 | |
| 6147 | |
| 6148 | // JavaScript global object. |
| 6149 | class JSGlobalObject: public GlobalObject { |
| 6150 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6151 | // Casting. |
| 6152 | static inline JSGlobalObject* cast(Object* obj); |
| 6153 | |
| 6154 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6155 | #ifdef OBJECT_PRINT |
| 6156 | inline void JSGlobalObjectPrint() { |
| 6157 | JSGlobalObjectPrint(stdout); |
| 6158 | } |
| 6159 | void JSGlobalObjectPrint(FILE* out); |
| 6160 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6161 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6162 | void JSGlobalObjectVerify(); |
| 6163 | #endif |
| 6164 | |
| 6165 | // Layout description. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 6166 | static const int kSize = GlobalObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6167 | |
| 6168 | private: |
| 6169 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalObject); |
| 6170 | }; |
| 6171 | |
| 6172 | |
| 6173 | // Builtins global object which holds the runtime routines written in |
| 6174 | // JavaScript. |
| 6175 | class JSBuiltinsObject: public GlobalObject { |
| 6176 | public: |
| 6177 | // Accessors for the runtime routines written in JavaScript. |
| 6178 | inline Object* javascript_builtin(Builtins::JavaScript id); |
| 6179 | inline void set_javascript_builtin(Builtins::JavaScript id, Object* value); |
| 6180 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 6181 | // Accessors for code of the runtime routines written in JavaScript. |
| 6182 | inline Code* javascript_builtin_code(Builtins::JavaScript id); |
| 6183 | inline void set_javascript_builtin_code(Builtins::JavaScript id, Code* value); |
| 6184 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6185 | // Casting. |
| 6186 | static inline JSBuiltinsObject* cast(Object* obj); |
| 6187 | |
| 6188 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6189 | #ifdef OBJECT_PRINT |
| 6190 | inline void JSBuiltinsObjectPrint() { |
| 6191 | JSBuiltinsObjectPrint(stdout); |
| 6192 | } |
| 6193 | void JSBuiltinsObjectPrint(FILE* out); |
| 6194 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6195 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6196 | void JSBuiltinsObjectVerify(); |
| 6197 | #endif |
| 6198 | |
| 6199 | // Layout description. The size of the builtins object includes |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 6200 | // room for two pointers per runtime routine written in javascript |
| 6201 | // (function and code object). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6202 | static const int kJSBuiltinsCount = Builtins::id_count; |
| 6203 | static const int kJSBuiltinsOffset = GlobalObject::kHeaderSize; |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 6204 | static const int kJSBuiltinsCodeOffset = |
| 6205 | GlobalObject::kHeaderSize + (kJSBuiltinsCount * kPointerSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6206 | static const int kSize = |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 6207 | kJSBuiltinsCodeOffset + (kJSBuiltinsCount * kPointerSize); |
| 6208 | |
| 6209 | static int OffsetOfFunctionWithId(Builtins::JavaScript id) { |
| 6210 | return kJSBuiltinsOffset + id * kPointerSize; |
| 6211 | } |
| 6212 | |
| 6213 | static int OffsetOfCodeWithId(Builtins::JavaScript id) { |
| 6214 | return kJSBuiltinsCodeOffset + id * kPointerSize; |
| 6215 | } |
| 6216 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6217 | private: |
| 6218 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSBuiltinsObject); |
| 6219 | }; |
| 6220 | |
| 6221 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6222 | // Representation for JS Wrapper objects, String, Number, Boolean, etc. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6223 | class JSValue: public JSObject { |
| 6224 | public: |
| 6225 | // [value]: the object being wrapped. |
| 6226 | DECL_ACCESSORS(value, Object) |
| 6227 | |
| 6228 | // Casting. |
| 6229 | static inline JSValue* cast(Object* obj); |
| 6230 | |
| 6231 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6232 | #ifdef OBJECT_PRINT |
| 6233 | inline void JSValuePrint() { |
| 6234 | JSValuePrint(stdout); |
| 6235 | } |
| 6236 | void JSValuePrint(FILE* out); |
| 6237 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6238 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6239 | void JSValueVerify(); |
| 6240 | #endif |
| 6241 | |
| 6242 | // Layout description. |
| 6243 | static const int kValueOffset = JSObject::kHeaderSize; |
| 6244 | static const int kSize = kValueOffset + kPointerSize; |
| 6245 | |
| 6246 | private: |
| 6247 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSValue); |
| 6248 | }; |
| 6249 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 6250 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6251 | class DateCache; |
| 6252 | |
| 6253 | // Representation for JS date objects. |
| 6254 | class JSDate: public JSObject { |
| 6255 | public: |
| 6256 | // If one component is NaN, all of them are, indicating a NaN time value. |
| 6257 | // [value]: the time value. |
| 6258 | DECL_ACCESSORS(value, Object) |
| 6259 | // [year]: caches year. Either undefined, smi, or NaN. |
| 6260 | DECL_ACCESSORS(year, Object) |
| 6261 | // [month]: caches month. Either undefined, smi, or NaN. |
| 6262 | DECL_ACCESSORS(month, Object) |
| 6263 | // [day]: caches day. Either undefined, smi, or NaN. |
| 6264 | DECL_ACCESSORS(day, Object) |
| 6265 | // [weekday]: caches day of week. Either undefined, smi, or NaN. |
| 6266 | DECL_ACCESSORS(weekday, Object) |
| 6267 | // [hour]: caches hours. Either undefined, smi, or NaN. |
| 6268 | DECL_ACCESSORS(hour, Object) |
| 6269 | // [min]: caches minutes. Either undefined, smi, or NaN. |
| 6270 | DECL_ACCESSORS(min, Object) |
| 6271 | // [sec]: caches seconds. Either undefined, smi, or NaN. |
| 6272 | DECL_ACCESSORS(sec, Object) |
| 6273 | // [cache stamp]: sample of the date cache stamp at the |
| 6274 | // moment when local fields were cached. |
| 6275 | DECL_ACCESSORS(cache_stamp, Object) |
| 6276 | |
| 6277 | // Casting. |
| 6278 | static inline JSDate* cast(Object* obj); |
| 6279 | |
| 6280 | // Returns the date field with the specified index. |
| 6281 | // See FieldIndex for the list of date fields. |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 6282 | static Object* GetField(Object* date, Smi* index); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6283 | |
| 6284 | void SetValue(Object* value, bool is_value_nan); |
| 6285 | |
| 6286 | |
| 6287 | // Dispatched behavior. |
| 6288 | #ifdef OBJECT_PRINT |
| 6289 | inline void JSDatePrint() { |
| 6290 | JSDatePrint(stdout); |
| 6291 | } |
| 6292 | void JSDatePrint(FILE* out); |
| 6293 | #endif |
| 6294 | #ifdef DEBUG |
| 6295 | void JSDateVerify(); |
| 6296 | #endif |
| 6297 | // The order is important. It must be kept in sync with date macros |
| 6298 | // in macros.py. |
| 6299 | enum FieldIndex { |
| 6300 | kDateValue, |
| 6301 | kYear, |
| 6302 | kMonth, |
| 6303 | kDay, |
| 6304 | kWeekday, |
| 6305 | kHour, |
| 6306 | kMinute, |
| 6307 | kSecond, |
| 6308 | kFirstUncachedField, |
| 6309 | kMillisecond = kFirstUncachedField, |
| 6310 | kDays, |
| 6311 | kTimeInDay, |
| 6312 | kFirstUTCField, |
| 6313 | kYearUTC = kFirstUTCField, |
| 6314 | kMonthUTC, |
| 6315 | kDayUTC, |
| 6316 | kWeekdayUTC, |
| 6317 | kHourUTC, |
| 6318 | kMinuteUTC, |
| 6319 | kSecondUTC, |
| 6320 | kMillisecondUTC, |
| 6321 | kDaysUTC, |
| 6322 | kTimeInDayUTC, |
| 6323 | kTimezoneOffset |
| 6324 | }; |
| 6325 | |
| 6326 | // Layout description. |
| 6327 | static const int kValueOffset = JSObject::kHeaderSize; |
| 6328 | static const int kYearOffset = kValueOffset + kPointerSize; |
| 6329 | static const int kMonthOffset = kYearOffset + kPointerSize; |
| 6330 | static const int kDayOffset = kMonthOffset + kPointerSize; |
| 6331 | static const int kWeekdayOffset = kDayOffset + kPointerSize; |
| 6332 | static const int kHourOffset = kWeekdayOffset + kPointerSize; |
| 6333 | static const int kMinOffset = kHourOffset + kPointerSize; |
| 6334 | static const int kSecOffset = kMinOffset + kPointerSize; |
| 6335 | static const int kCacheStampOffset = kSecOffset + kPointerSize; |
| 6336 | static const int kSize = kCacheStampOffset + kPointerSize; |
| 6337 | |
| 6338 | private: |
| 6339 | inline Object* DoGetField(FieldIndex index); |
| 6340 | |
| 6341 | Object* GetUTCField(FieldIndex index, double value, DateCache* date_cache); |
| 6342 | |
| 6343 | // Computes and caches the cacheable fields of the date. |
| 6344 | inline void SetLocalFields(int64_t local_time_ms, DateCache* date_cache); |
| 6345 | |
| 6346 | |
| 6347 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSDate); |
| 6348 | }; |
| 6349 | |
| 6350 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 6351 | // Representation of message objects used for error reporting through |
| 6352 | // the API. The messages are formatted in JavaScript so this object is |
| 6353 | // a real JavaScript object. The information used for formatting the |
| 6354 | // error messages are not directly accessible from JavaScript to |
| 6355 | // prevent leaking information to user code called during error |
| 6356 | // formatting. |
| 6357 | class JSMessageObject: public JSObject { |
| 6358 | public: |
| 6359 | // [type]: the type of error message. |
| 6360 | DECL_ACCESSORS(type, String) |
| 6361 | |
| 6362 | // [arguments]: the arguments for formatting the error message. |
| 6363 | DECL_ACCESSORS(arguments, JSArray) |
| 6364 | |
| 6365 | // [script]: the script from which the error message originated. |
| 6366 | DECL_ACCESSORS(script, Object) |
| 6367 | |
| 6368 | // [stack_trace]: the stack trace for this error message. |
| 6369 | DECL_ACCESSORS(stack_trace, Object) |
| 6370 | |
| 6371 | // [stack_frames]: an array of stack frames for this error object. |
| 6372 | DECL_ACCESSORS(stack_frames, Object) |
| 6373 | |
| 6374 | // [start_position]: the start position in the script for the error message. |
| 6375 | inline int start_position(); |
| 6376 | inline void set_start_position(int value); |
| 6377 | |
| 6378 | // [end_position]: the end position in the script for the error message. |
| 6379 | inline int end_position(); |
| 6380 | inline void set_end_position(int value); |
| 6381 | |
| 6382 | // Casting. |
| 6383 | static inline JSMessageObject* cast(Object* obj); |
| 6384 | |
| 6385 | // Dispatched behavior. |
| 6386 | #ifdef OBJECT_PRINT |
| 6387 | inline void JSMessageObjectPrint() { |
| 6388 | JSMessageObjectPrint(stdout); |
| 6389 | } |
| 6390 | void JSMessageObjectPrint(FILE* out); |
| 6391 | #endif |
| 6392 | #ifdef DEBUG |
| 6393 | void JSMessageObjectVerify(); |
| 6394 | #endif |
| 6395 | |
| 6396 | // Layout description. |
| 6397 | static const int kTypeOffset = JSObject::kHeaderSize; |
| 6398 | static const int kArgumentsOffset = kTypeOffset + kPointerSize; |
| 6399 | static const int kScriptOffset = kArgumentsOffset + kPointerSize; |
| 6400 | static const int kStackTraceOffset = kScriptOffset + kPointerSize; |
| 6401 | static const int kStackFramesOffset = kStackTraceOffset + kPointerSize; |
| 6402 | static const int kStartPositionOffset = kStackFramesOffset + kPointerSize; |
| 6403 | static const int kEndPositionOffset = kStartPositionOffset + kPointerSize; |
| 6404 | static const int kSize = kEndPositionOffset + kPointerSize; |
| 6405 | |
| 6406 | typedef FixedBodyDescriptor<HeapObject::kMapOffset, |
| 6407 | kStackFramesOffset + kPointerSize, |
| 6408 | kSize> BodyDescriptor; |
| 6409 | }; |
| 6410 | |
| 6411 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6412 | // Regular expressions |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6413 | // The regular expression holds a single reference to a FixedArray in |
| 6414 | // the kDataOffset field. |
| 6415 | // The FixedArray contains the following data: |
| 6416 | // - tag : type of regexp implementation (not compiled yet, atom or irregexp) |
| 6417 | // - reference to the original source string |
| 6418 | // - reference to the original flag string |
| 6419 | // If it is an atom regexp |
| 6420 | // - a reference to a literal string to search for |
| 6421 | // If it is an irregexp regexp: |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 6422 | // - a reference to code for ASCII inputs (bytecode or compiled), or a smi |
| 6423 | // used for tracking the last usage (used for code flushing). |
| 6424 | // - a reference to code for UC16 inputs (bytecode or compiled), or a smi |
| 6425 | // used for tracking the last usage (used for code flushing).. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6426 | // - max number of registers used by irregexp implementations. |
| 6427 | // - number of capture registers (output values) of the regexp. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6428 | class JSRegExp: public JSObject { |
| 6429 | public: |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 6430 | // Meaning of Type: |
| 6431 | // 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] | 6432 | // ATOM: A simple string to match against using an indexOf operation. |
| 6433 | // IRREGEXP: Compiled with Irregexp. |
| 6434 | // IRREGEXP_NATIVE: Compiled to native code with Irregexp. |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 6435 | enum Type { NOT_COMPILED, ATOM, IRREGEXP }; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6436 | enum Flag { NONE = 0, GLOBAL = 1, IGNORE_CASE = 2, MULTILINE = 4 }; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6437 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6438 | class Flags { |
| 6439 | public: |
| 6440 | explicit Flags(uint32_t value) : value_(value) { } |
| 6441 | bool is_global() { return (value_ & GLOBAL) != 0; } |
| 6442 | bool is_ignore_case() { return (value_ & IGNORE_CASE) != 0; } |
| 6443 | bool is_multiline() { return (value_ & MULTILINE) != 0; } |
| 6444 | uint32_t value() { return value_; } |
| 6445 | private: |
| 6446 | uint32_t value_; |
| 6447 | }; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6448 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6449 | DECL_ACCESSORS(data, Object) |
| 6450 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6451 | inline Type TypeTag(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 6452 | inline int CaptureCount(); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 6453 | inline Flags GetFlags(); |
| 6454 | inline String* Pattern(); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6455 | inline Object* DataAt(int index); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6456 | // Set implementation data after the object has been prepared. |
| 6457 | inline void SetDataAt(int index, Object* value); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 6458 | |
| 6459 | // Used during GC when flushing code or setting age. |
| 6460 | inline Object* DataAtUnchecked(int index); |
| 6461 | inline void SetDataAtUnchecked(int index, Object* value, Heap* heap); |
| 6462 | inline Type TypeTagUnchecked(); |
| 6463 | |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 6464 | static int code_index(bool is_ascii) { |
| 6465 | if (is_ascii) { |
| 6466 | return kIrregexpASCIICodeIndex; |
| 6467 | } else { |
| 6468 | return kIrregexpUC16CodeIndex; |
| 6469 | } |
| 6470 | } |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6471 | |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 6472 | static int saved_code_index(bool is_ascii) { |
| 6473 | if (is_ascii) { |
| 6474 | return kIrregexpASCIICodeSavedIndex; |
| 6475 | } else { |
| 6476 | return kIrregexpUC16CodeSavedIndex; |
| 6477 | } |
| 6478 | } |
| 6479 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6480 | static inline JSRegExp* cast(Object* obj); |
| 6481 | |
| 6482 | // Dispatched behavior. |
| 6483 | #ifdef DEBUG |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6484 | void JSRegExpVerify(); |
| 6485 | #endif |
| 6486 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6487 | static const int kDataOffset = JSObject::kHeaderSize; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 6488 | static const int kSize = kDataOffset + kPointerSize; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6489 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6490 | // Indices in the data array. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6491 | static const int kTagIndex = 0; |
| 6492 | static const int kSourceIndex = kTagIndex + 1; |
| 6493 | static const int kFlagsIndex = kSourceIndex + 1; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6494 | static const int kDataIndex = kFlagsIndex + 1; |
| 6495 | // The data fields are used in different ways depending on the |
| 6496 | // value of the tag. |
| 6497 | // Atom regexps (literal strings). |
| 6498 | static const int kAtomPatternIndex = kDataIndex; |
| 6499 | |
| 6500 | static const int kAtomDataSize = kAtomPatternIndex + 1; |
| 6501 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 6502 | // Irregexp compiled code or bytecode for ASCII. If compilation |
| 6503 | // fails, this fields hold an exception object that should be |
| 6504 | // thrown if the regexp is used again. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6505 | static const int kIrregexpASCIICodeIndex = kDataIndex; |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 6506 | // Irregexp compiled code or bytecode for UC16. If compilation |
| 6507 | // fails, this fields hold an exception object that should be |
| 6508 | // thrown if the regexp is used again. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6509 | static const int kIrregexpUC16CodeIndex = kDataIndex + 1; |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 6510 | |
| 6511 | // Saved instance of Irregexp compiled code or bytecode for ASCII that |
| 6512 | // is a potential candidate for flushing. |
| 6513 | static const int kIrregexpASCIICodeSavedIndex = kDataIndex + 2; |
| 6514 | // Saved instance of Irregexp compiled code or bytecode for UC16 that is |
| 6515 | // a potential candidate for flushing. |
| 6516 | static const int kIrregexpUC16CodeSavedIndex = kDataIndex + 3; |
| 6517 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6518 | // Maximal number of registers used by either ASCII or UC16. |
| 6519 | // Only used to check that there is enough stack space |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 6520 | static const int kIrregexpMaxRegisterCountIndex = kDataIndex + 4; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6521 | // Number of captures in the compiled regexp. |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 6522 | static const int kIrregexpCaptureCountIndex = kDataIndex + 5; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6523 | |
| 6524 | static const int kIrregexpDataSize = kIrregexpCaptureCountIndex + 1; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 6525 | |
| 6526 | // Offsets directly into the data fixed array. |
| 6527 | static const int kDataTagOffset = |
| 6528 | FixedArray::kHeaderSize + kTagIndex * kPointerSize; |
| 6529 | static const int kDataAsciiCodeOffset = |
| 6530 | FixedArray::kHeaderSize + kIrregexpASCIICodeIndex * kPointerSize; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 6531 | static const int kDataUC16CodeOffset = |
| 6532 | FixedArray::kHeaderSize + kIrregexpUC16CodeIndex * kPointerSize; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 6533 | static const int kIrregexpCaptureCountOffset = |
| 6534 | FixedArray::kHeaderSize + kIrregexpCaptureCountIndex * kPointerSize; |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 6535 | |
| 6536 | // In-object fields. |
| 6537 | static const int kSourceFieldIndex = 0; |
| 6538 | static const int kGlobalFieldIndex = 1; |
| 6539 | static const int kIgnoreCaseFieldIndex = 2; |
| 6540 | static const int kMultilineFieldIndex = 3; |
| 6541 | static const int kLastIndexFieldIndex = 4; |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 6542 | static const int kInObjectFieldCount = 5; |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 6543 | |
| 6544 | // The uninitialized value for a regexp code object. |
| 6545 | static const int kUninitializedValue = -1; |
| 6546 | |
| 6547 | // The compilation error value for the regexp code object. The real error |
| 6548 | // object is in the saved code field. |
| 6549 | static const int kCompilationErrorValue = -2; |
| 6550 | |
| 6551 | // When we store the sweep generation at which we moved the code from the |
| 6552 | // code index to the saved code index we mask it of to be in the [0:255] |
| 6553 | // range. |
| 6554 | static const int kCodeAgeMask = 0xff; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6555 | }; |
| 6556 | |
| 6557 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6558 | class CompilationCacheShape : public BaseShape<HashTableKey*> { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 6559 | public: |
| 6560 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 6561 | return key->IsMatch(value); |
| 6562 | } |
| 6563 | |
| 6564 | static inline uint32_t Hash(HashTableKey* key) { |
| 6565 | return key->Hash(); |
| 6566 | } |
| 6567 | |
| 6568 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 6569 | return key->HashForObject(object); |
| 6570 | } |
| 6571 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 6572 | MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 6573 | return key->AsObject(); |
| 6574 | } |
| 6575 | |
| 6576 | static const int kPrefixSize = 0; |
| 6577 | static const int kEntrySize = 2; |
| 6578 | }; |
| 6579 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 6580 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 6581 | class CompilationCacheTable: public HashTable<CompilationCacheShape, |
| 6582 | HashTableKey*> { |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6583 | public: |
| 6584 | // Find cached value for a string key, otherwise return null. |
| 6585 | Object* Lookup(String* src); |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 6586 | Object* LookupEval(String* src, |
| 6587 | Context* context, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 6588 | LanguageMode language_mode, |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 6589 | int scope_position); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6590 | Object* LookupRegExp(String* source, JSRegExp::Flags flags); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 6591 | MUST_USE_RESULT MaybeObject* Put(String* src, Object* value); |
| 6592 | MUST_USE_RESULT MaybeObject* PutEval(String* src, |
| 6593 | Context* context, |
| 6594 | SharedFunctionInfo* value, |
| 6595 | int scope_position); |
| 6596 | MUST_USE_RESULT MaybeObject* PutRegExp(String* src, |
| 6597 | JSRegExp::Flags flags, |
| 6598 | FixedArray* value); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6599 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6600 | // Remove given value from cache. |
| 6601 | void Remove(Object* value); |
| 6602 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6603 | static inline CompilationCacheTable* cast(Object* obj); |
| 6604 | |
| 6605 | private: |
| 6606 | DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheTable); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6607 | }; |
| 6608 | |
| 6609 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 6610 | class CodeCache: public Struct { |
| 6611 | public: |
| 6612 | DECL_ACCESSORS(default_cache, FixedArray) |
| 6613 | DECL_ACCESSORS(normal_type_cache, Object) |
| 6614 | |
| 6615 | // Add the code object to the cache. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 6616 | MUST_USE_RESULT MaybeObject* Update(String* name, Code* code); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 6617 | |
| 6618 | // Lookup code object in the cache. Returns code object if found and undefined |
| 6619 | // if not. |
| 6620 | Object* Lookup(String* name, Code::Flags flags); |
| 6621 | |
| 6622 | // Get the internal index of a code object in the cache. Returns -1 if the |
| 6623 | // code object is not in that cache. This index can be used to later call |
| 6624 | // RemoveByIndex. The cache cannot be modified between a call to GetIndex and |
| 6625 | // RemoveByIndex. |
sgjesse@chromium.org | 99a37fa | 2010-03-11 09:23:46 +0000 | [diff] [blame] | 6626 | int GetIndex(Object* name, Code* code); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 6627 | |
| 6628 | // Remove an object from the cache with the provided internal index. |
sgjesse@chromium.org | 99a37fa | 2010-03-11 09:23:46 +0000 | [diff] [blame] | 6629 | void RemoveByIndex(Object* name, Code* code, int index); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 6630 | |
| 6631 | static inline CodeCache* cast(Object* obj); |
| 6632 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6633 | #ifdef OBJECT_PRINT |
| 6634 | inline void CodeCachePrint() { |
| 6635 | CodeCachePrint(stdout); |
| 6636 | } |
| 6637 | void CodeCachePrint(FILE* out); |
| 6638 | #endif |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 6639 | #ifdef DEBUG |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 6640 | void CodeCacheVerify(); |
| 6641 | #endif |
| 6642 | |
| 6643 | static const int kDefaultCacheOffset = HeapObject::kHeaderSize; |
| 6644 | static const int kNormalTypeCacheOffset = |
| 6645 | kDefaultCacheOffset + kPointerSize; |
| 6646 | static const int kSize = kNormalTypeCacheOffset + kPointerSize; |
| 6647 | |
| 6648 | private: |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 6649 | MUST_USE_RESULT MaybeObject* UpdateDefaultCache(String* name, Code* code); |
| 6650 | MUST_USE_RESULT MaybeObject* UpdateNormalTypeCache(String* name, Code* code); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 6651 | Object* LookupDefaultCache(String* name, Code::Flags flags); |
| 6652 | Object* LookupNormalTypeCache(String* name, Code::Flags flags); |
| 6653 | |
| 6654 | // Code cache layout of the default cache. Elements are alternating name and |
| 6655 | // code objects for non normal load/store/call IC's. |
| 6656 | static const int kCodeCacheEntrySize = 2; |
| 6657 | static const int kCodeCacheEntryNameOffset = 0; |
| 6658 | static const int kCodeCacheEntryCodeOffset = 1; |
| 6659 | |
| 6660 | DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCache); |
| 6661 | }; |
| 6662 | |
| 6663 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6664 | class CodeCacheHashTableShape : public BaseShape<HashTableKey*> { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 6665 | public: |
| 6666 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 6667 | return key->IsMatch(value); |
| 6668 | } |
| 6669 | |
| 6670 | static inline uint32_t Hash(HashTableKey* key) { |
| 6671 | return key->Hash(); |
| 6672 | } |
| 6673 | |
| 6674 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 6675 | return key->HashForObject(object); |
| 6676 | } |
| 6677 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 6678 | MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 6679 | return key->AsObject(); |
| 6680 | } |
| 6681 | |
| 6682 | static const int kPrefixSize = 0; |
| 6683 | static const int kEntrySize = 2; |
| 6684 | }; |
| 6685 | |
| 6686 | |
| 6687 | class CodeCacheHashTable: public HashTable<CodeCacheHashTableShape, |
| 6688 | HashTableKey*> { |
| 6689 | public: |
| 6690 | Object* Lookup(String* name, Code::Flags flags); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 6691 | MUST_USE_RESULT MaybeObject* Put(String* name, Code* code); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 6692 | |
| 6693 | int GetIndex(String* name, Code::Flags flags); |
| 6694 | void RemoveByIndex(int index); |
| 6695 | |
| 6696 | static inline CodeCacheHashTable* cast(Object* obj); |
| 6697 | |
| 6698 | // Initial size of the fixed array backing the hash table. |
| 6699 | static const int kInitialSize = 64; |
| 6700 | |
| 6701 | private: |
| 6702 | DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCacheHashTable); |
| 6703 | }; |
| 6704 | |
| 6705 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 6706 | class PolymorphicCodeCache: public Struct { |
| 6707 | public: |
| 6708 | DECL_ACCESSORS(cache, Object) |
| 6709 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6710 | static void Update(Handle<PolymorphicCodeCache> cache, |
| 6711 | MapHandleList* maps, |
| 6712 | Code::Flags flags, |
| 6713 | Handle<Code> code); |
| 6714 | |
| 6715 | MUST_USE_RESULT MaybeObject* Update(MapHandleList* maps, |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 6716 | Code::Flags flags, |
| 6717 | Code* code); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6718 | |
| 6719 | // Returns an undefined value if the entry is not found. |
| 6720 | Handle<Object> Lookup(MapHandleList* maps, Code::Flags flags); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 6721 | |
| 6722 | static inline PolymorphicCodeCache* cast(Object* obj); |
| 6723 | |
| 6724 | #ifdef OBJECT_PRINT |
| 6725 | inline void PolymorphicCodeCachePrint() { |
| 6726 | PolymorphicCodeCachePrint(stdout); |
| 6727 | } |
| 6728 | void PolymorphicCodeCachePrint(FILE* out); |
| 6729 | #endif |
| 6730 | #ifdef DEBUG |
| 6731 | void PolymorphicCodeCacheVerify(); |
| 6732 | #endif |
| 6733 | |
| 6734 | static const int kCacheOffset = HeapObject::kHeaderSize; |
| 6735 | static const int kSize = kCacheOffset + kPointerSize; |
| 6736 | |
| 6737 | private: |
| 6738 | DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCache); |
| 6739 | }; |
| 6740 | |
| 6741 | |
| 6742 | class PolymorphicCodeCacheHashTable |
| 6743 | : public HashTable<CodeCacheHashTableShape, HashTableKey*> { |
| 6744 | public: |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6745 | Object* Lookup(MapHandleList* maps, int code_kind); |
| 6746 | |
| 6747 | MUST_USE_RESULT MaybeObject* Put(MapHandleList* maps, |
| 6748 | int code_kind, |
| 6749 | Code* code); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 6750 | |
| 6751 | static inline PolymorphicCodeCacheHashTable* cast(Object* obj); |
| 6752 | |
| 6753 | static const int kInitialSize = 64; |
| 6754 | private: |
| 6755 | DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCacheHashTable); |
| 6756 | }; |
| 6757 | |
| 6758 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 6759 | class TypeFeedbackInfo: public Struct { |
| 6760 | public: |
| 6761 | inline int ic_total_count(); |
| 6762 | inline void set_ic_total_count(int count); |
| 6763 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6764 | inline int ic_with_type_info_count(); |
| 6765 | inline void set_ic_with_type_info_count(int count); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 6766 | |
| 6767 | DECL_ACCESSORS(type_feedback_cells, TypeFeedbackCells) |
| 6768 | |
| 6769 | static inline TypeFeedbackInfo* cast(Object* obj); |
| 6770 | |
| 6771 | #ifdef OBJECT_PRINT |
| 6772 | inline void TypeFeedbackInfoPrint() { |
| 6773 | TypeFeedbackInfoPrint(stdout); |
| 6774 | } |
| 6775 | void TypeFeedbackInfoPrint(FILE* out); |
| 6776 | #endif |
| 6777 | #ifdef DEBUG |
| 6778 | void TypeFeedbackInfoVerify(); |
| 6779 | #endif |
| 6780 | |
| 6781 | static const int kIcTotalCountOffset = HeapObject::kHeaderSize; |
| 6782 | static const int kIcWithTypeinfoCountOffset = |
| 6783 | kIcTotalCountOffset + kPointerSize; |
| 6784 | static const int kTypeFeedbackCellsOffset = |
| 6785 | kIcWithTypeinfoCountOffset + kPointerSize; |
| 6786 | static const int kSize = kTypeFeedbackCellsOffset + kPointerSize; |
| 6787 | |
| 6788 | private: |
| 6789 | DISALLOW_IMPLICIT_CONSTRUCTORS(TypeFeedbackInfo); |
| 6790 | }; |
| 6791 | |
| 6792 | |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 6793 | // Representation of a slow alias as part of a non-strict arguments objects. |
| 6794 | // For fast aliases (if HasNonStrictArgumentsElements()): |
| 6795 | // - the parameter map contains an index into the context |
| 6796 | // - all attributes of the element have default values |
| 6797 | // For slow aliases (if HasDictionaryArgumentsElements()): |
| 6798 | // - the parameter map contains no fast alias mapping (i.e. the hole) |
| 6799 | // - this struct (in the slow backing store) contains an index into the context |
| 6800 | // - all attributes are available as part if the property details |
| 6801 | class AliasedArgumentsEntry: public Struct { |
| 6802 | public: |
| 6803 | inline int aliased_context_slot(); |
| 6804 | inline void set_aliased_context_slot(int count); |
| 6805 | |
| 6806 | static inline AliasedArgumentsEntry* cast(Object* obj); |
| 6807 | |
| 6808 | #ifdef OBJECT_PRINT |
| 6809 | inline void AliasedArgumentsEntryPrint() { |
| 6810 | AliasedArgumentsEntryPrint(stdout); |
| 6811 | } |
| 6812 | void AliasedArgumentsEntryPrint(FILE* out); |
| 6813 | #endif |
| 6814 | #ifdef DEBUG |
| 6815 | void AliasedArgumentsEntryVerify(); |
| 6816 | #endif |
| 6817 | |
| 6818 | static const int kAliasedContextSlot = HeapObject::kHeaderSize; |
| 6819 | static const int kSize = kAliasedContextSlot + kPointerSize; |
| 6820 | |
| 6821 | private: |
| 6822 | DISALLOW_IMPLICIT_CONSTRUCTORS(AliasedArgumentsEntry); |
| 6823 | }; |
| 6824 | |
| 6825 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6826 | enum AllowNullsFlag {ALLOW_NULLS, DISALLOW_NULLS}; |
| 6827 | enum RobustnessFlag {ROBUST_STRING_TRAVERSAL, FAST_STRING_TRAVERSAL}; |
| 6828 | |
| 6829 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6830 | class StringHasher { |
| 6831 | public: |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6832 | explicit inline StringHasher(int length, uint32_t seed); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6833 | |
| 6834 | // Returns true if the hash of this string can be computed without |
| 6835 | // looking at the contents. |
| 6836 | inline bool has_trivial_hash(); |
| 6837 | |
| 6838 | // 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] | 6839 | inline void AddCharacter(uint32_t c); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6840 | |
| 6841 | // Adds a character to the hash but does not update the array index |
| 6842 | // calculation. This can only be called when it has been verified |
| 6843 | // that the input is not an array index. |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 6844 | inline void AddCharacterNoIndex(uint32_t c); |
| 6845 | |
| 6846 | // Add a character above 0xffff as a surrogate pair. These can get into |
| 6847 | // the hasher through the routines that take a UTF-8 string and make a symbol. |
| 6848 | void AddSurrogatePair(uc32 c); |
| 6849 | void AddSurrogatePairNoIndex(uc32 c); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6850 | |
| 6851 | // Returns the value to store in the hash field of a string with |
| 6852 | // the given length and contents. |
| 6853 | uint32_t GetHashField(); |
| 6854 | |
| 6855 | // Returns true if the characters seen so far make up a legal array |
| 6856 | // index. |
| 6857 | bool is_array_index() { return is_array_index_; } |
| 6858 | |
| 6859 | bool is_valid() { return is_valid_; } |
| 6860 | |
| 6861 | void invalidate() { is_valid_ = false; } |
| 6862 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 6863 | // Calculated hash value for a string consisting of 1 to |
| 6864 | // String::kMaxArrayIndexSize digits with no leading zeros (except "0"). |
| 6865 | // value is represented decimal value. |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 6866 | static uint32_t MakeArrayIndexHash(uint32_t value, int length); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 6867 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6868 | // No string is allowed to have a hash of zero. That value is reserved |
| 6869 | // for internal properties. If the hash calculation yields zero then we |
| 6870 | // use 27 instead. |
| 6871 | static const int kZeroHash = 27; |
| 6872 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6873 | private: |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6874 | uint32_t array_index() { |
| 6875 | ASSERT(is_array_index()); |
| 6876 | return array_index_; |
| 6877 | } |
| 6878 | |
| 6879 | inline uint32_t GetHash(); |
| 6880 | |
| 6881 | int length_; |
| 6882 | uint32_t raw_running_hash_; |
| 6883 | uint32_t array_index_; |
| 6884 | bool is_array_index_; |
| 6885 | bool is_first_char_; |
| 6886 | bool is_valid_; |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 6887 | friend class TwoCharHashTableKey; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6888 | }; |
| 6889 | |
| 6890 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 6891 | // Calculates string hash. |
| 6892 | template <typename schar> |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6893 | inline uint32_t HashSequentialString(const schar* chars, |
| 6894 | int length, |
| 6895 | uint32_t seed); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 6896 | |
| 6897 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 6898 | // The characteristics of a string are stored in its map. Retrieving these |
| 6899 | // few bits of information is moderately expensive, involving two memory |
| 6900 | // loads where the second is dependent on the first. To improve efficiency |
| 6901 | // the shape of the string is given its own class so that it can be retrieved |
| 6902 | // once and used for several string operations. A StringShape is small enough |
| 6903 | // 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] | 6904 | // string can potentially alter its shape. Also be aware that a GC caused by |
| 6905 | // 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] | 6906 | // shortcutting. Keeping these restrictions in mind has proven to be error- |
| 6907 | // prone and so we no longer put StringShapes in variables unless there is a |
| 6908 | // concrete performance benefit at that particular point in the code. |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 6909 | class StringShape BASE_EMBEDDED { |
| 6910 | public: |
| 6911 | inline explicit StringShape(String* s); |
| 6912 | inline explicit StringShape(Map* s); |
| 6913 | inline explicit StringShape(InstanceType t); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 6914 | inline bool IsSequential(); |
| 6915 | inline bool IsExternal(); |
| 6916 | inline bool IsCons(); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 6917 | inline bool IsSliced(); |
| 6918 | inline bool IsIndirect(); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 6919 | inline bool IsExternalAscii(); |
| 6920 | inline bool IsExternalTwoByte(); |
| 6921 | inline bool IsSequentialAscii(); |
| 6922 | inline bool IsSequentialTwoByte(); |
| 6923 | inline bool IsSymbol(); |
| 6924 | inline StringRepresentationTag representation_tag(); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 6925 | inline uint32_t encoding_tag(); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 6926 | inline uint32_t full_representation_tag(); |
| 6927 | inline uint32_t size_tag(); |
| 6928 | #ifdef DEBUG |
| 6929 | inline uint32_t type() { return type_; } |
| 6930 | inline void invalidate() { valid_ = false; } |
| 6931 | inline bool valid() { return valid_; } |
| 6932 | #else |
| 6933 | inline void invalidate() { } |
| 6934 | #endif |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 6935 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 6936 | private: |
| 6937 | uint32_t type_; |
| 6938 | #ifdef DEBUG |
| 6939 | inline void set_valid() { valid_ = true; } |
| 6940 | bool valid_; |
| 6941 | #else |
| 6942 | inline void set_valid() { } |
| 6943 | #endif |
| 6944 | }; |
| 6945 | |
| 6946 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6947 | // The String abstract class captures JavaScript string values: |
| 6948 | // |
| 6949 | // Ecma-262: |
| 6950 | // 4.3.16 String Value |
| 6951 | // A string value is a member of the type String and is a finite |
| 6952 | // ordered sequence of zero or more 16-bit unsigned integer values. |
| 6953 | // |
| 6954 | // All string values have a length field. |
| 6955 | class String: public HeapObject { |
| 6956 | public: |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 6957 | // Representation of the flat content of a String. |
| 6958 | // A non-flat string doesn't have flat content. |
| 6959 | // A flat string has content that's encoded as a sequence of either |
| 6960 | // ASCII chars or two-byte UC16. |
| 6961 | // Returned by String::GetFlatContent(). |
| 6962 | class FlatContent { |
| 6963 | public: |
| 6964 | // Returns true if the string is flat and this structure contains content. |
| 6965 | bool IsFlat() { return state_ != NON_FLAT; } |
| 6966 | // Returns true if the structure contains ASCII content. |
| 6967 | bool IsAscii() { return state_ == ASCII; } |
| 6968 | // Returns true if the structure contains two-byte content. |
| 6969 | bool IsTwoByte() { return state_ == TWO_BYTE; } |
| 6970 | |
| 6971 | // Return the ASCII content of the string. Only use if IsAscii() returns |
| 6972 | // true. |
| 6973 | Vector<const char> ToAsciiVector() { |
| 6974 | ASSERT_EQ(ASCII, state_); |
| 6975 | return Vector<const char>::cast(buffer_); |
| 6976 | } |
| 6977 | // Return the two-byte content of the string. Only use if IsTwoByte() |
| 6978 | // returns true. |
| 6979 | Vector<const uc16> ToUC16Vector() { |
| 6980 | ASSERT_EQ(TWO_BYTE, state_); |
| 6981 | return Vector<const uc16>::cast(buffer_); |
| 6982 | } |
| 6983 | |
| 6984 | private: |
| 6985 | enum State { NON_FLAT, ASCII, TWO_BYTE }; |
| 6986 | |
| 6987 | // Constructors only used by String::GetFlatContent(). |
| 6988 | explicit FlatContent(Vector<const char> chars) |
| 6989 | : buffer_(Vector<const byte>::cast(chars)), |
| 6990 | state_(ASCII) { } |
| 6991 | explicit FlatContent(Vector<const uc16> chars) |
| 6992 | : buffer_(Vector<const byte>::cast(chars)), |
| 6993 | state_(TWO_BYTE) { } |
| 6994 | FlatContent() : buffer_(), state_(NON_FLAT) { } |
| 6995 | |
| 6996 | Vector<const byte> buffer_; |
| 6997 | State state_; |
| 6998 | |
| 6999 | friend class String; |
| 7000 | }; |
| 7001 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7002 | // Get and set the length of the string. |
| 7003 | inline int length(); |
| 7004 | inline void set_length(int value); |
| 7005 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 7006 | // Get and set the hash field of the string. |
| 7007 | inline uint32_t hash_field(); |
| 7008 | inline void set_hash_field(uint32_t value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7009 | |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 7010 | // Returns whether this string has only ASCII chars, i.e. all of them can |
| 7011 | // 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] | 7012 | // two-byte. Such strings may appear when the embedder prefers |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 7013 | // two-byte external representations even for ASCII data. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 7014 | inline bool IsAsciiRepresentation(); |
| 7015 | inline bool IsTwoByteRepresentation(); |
| 7016 | |
| 7017 | // Cons and slices have an encoding flag that may not represent the actual |
| 7018 | // encoding of the underlying string. This is taken into account here. |
| 7019 | // Requires: this->IsFlat() |
| 7020 | inline bool IsAsciiRepresentationUnderneath(); |
| 7021 | inline bool IsTwoByteRepresentationUnderneath(); |
| 7022 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 7023 | // NOTE: this should be considered only a hint. False negatives are |
| 7024 | // possible. |
| 7025 | inline bool HasOnlyAsciiChars(); |
ricow@chromium.org | aa1b616 | 2010-03-29 07:44:58 +0000 | [diff] [blame] | 7026 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7027 | // Get and set individual two byte chars in the string. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 7028 | inline void Set(int index, uint16_t value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7029 | // Get individual two byte char in the string. Repeated calls |
| 7030 | // to this method are not efficient unless the string is flat. |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 7031 | INLINE(uint16_t Get(int index)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7032 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7033 | // Try to flatten the string. Checks first inline to see if it is |
| 7034 | // necessary. Does nothing if the string is not a cons string. |
| 7035 | // Flattening allocates a sequential string with the same data as |
| 7036 | // the given string and mutates the cons string to a degenerate |
| 7037 | // form, where the first component is the new sequential string and |
| 7038 | // the second component is the empty string. If allocation fails, |
| 7039 | // this function returns a failure. If flattening succeeds, this |
| 7040 | // function returns the sequential string that is now the first |
| 7041 | // component of the cons string. |
| 7042 | // |
| 7043 | // Degenerate cons strings are handled specially by the garbage |
| 7044 | // collector (see IsShortcutCandidate). |
| 7045 | // |
| 7046 | // Use FlattenString from Handles.cc to flatten even in case an |
| 7047 | // allocation failure happens. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 7048 | inline MaybeObject* TryFlatten(PretenureFlag pretenure = NOT_TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7049 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7050 | // Convenience function. Has exactly the same behavior as |
| 7051 | // TryFlatten(), except in the case of failure returns the original |
| 7052 | // string. |
| 7053 | inline String* TryFlattenGetString(PretenureFlag pretenure = NOT_TENURED); |
| 7054 | |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 7055 | // Tries to return the content of a flat string as a structure holding either |
| 7056 | // a flat vector of char or of uc16. |
| 7057 | // If the string isn't flat, and therefore doesn't have flat content, the |
| 7058 | // returned structure will report so, and can't provide a vector of either |
| 7059 | // kind. |
| 7060 | FlatContent GetFlatContent(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7061 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 7062 | // Returns the parent of a sliced string or first part of a flat cons string. |
| 7063 | // Requires: StringShape(this).IsIndirect() && this->IsFlat() |
| 7064 | inline String* GetUnderlying(); |
| 7065 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7066 | // Mark the string as an undetectable object. It only applies to |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 7067 | // ASCII and two byte string types. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7068 | bool MarkAsUndetectable(); |
| 7069 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7070 | // Return a substring. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 7071 | MUST_USE_RESULT MaybeObject* SubString(int from, |
| 7072 | int to, |
| 7073 | PretenureFlag pretenure = NOT_TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7074 | |
| 7075 | // String equality operations. |
| 7076 | inline bool Equals(String* other); |
| 7077 | bool IsEqualTo(Vector<const char> str); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 7078 | bool IsAsciiEqualTo(Vector<const char> str); |
| 7079 | bool IsTwoByteEqualTo(Vector<const uc16> str); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7080 | |
| 7081 | // Return a UTF8 representation of the string. The string is null |
| 7082 | // terminated but may optionally contain nulls. Length is returned |
| 7083 | // in length_output if length_output is not a null pointer The string |
| 7084 | // should be nearly flat, otherwise the performance of this method may |
| 7085 | // be very slow (quadratic in the length). Setting robustness_flag to |
| 7086 | // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
| 7087 | // handles unexpected data without causing assert failures and it does not |
| 7088 | // do any heap allocations. This is useful when printing stack traces. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 7089 | SmartArrayPointer<char> ToCString(AllowNullsFlag allow_nulls, |
| 7090 | RobustnessFlag robustness_flag, |
| 7091 | int offset, |
| 7092 | int length, |
| 7093 | int* length_output = 0); |
| 7094 | SmartArrayPointer<char> ToCString( |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7095 | AllowNullsFlag allow_nulls = DISALLOW_NULLS, |
| 7096 | RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL, |
| 7097 | int* length_output = 0); |
| 7098 | |
| 7099 | // Return a 16 bit Unicode representation of the string. |
| 7100 | // The string should be nearly flat, otherwise the performance of |
| 7101 | // of this method may be very bad. Setting robustness_flag to |
| 7102 | // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
| 7103 | // handles unexpected data without causing assert failures and it does not |
| 7104 | // do any heap allocations. This is useful when printing stack traces. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 7105 | SmartArrayPointer<uc16> ToWideCString( |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 7106 | RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7107 | |
| 7108 | // Tells whether the hash code has been computed. |
| 7109 | inline bool HasHashCode(); |
| 7110 | |
| 7111 | // Returns a hash value used for the property table |
| 7112 | inline uint32_t Hash(); |
| 7113 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 7114 | static uint32_t ComputeHashField(unibrow::CharacterStream* buffer, |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 7115 | int length, |
| 7116 | uint32_t seed); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7117 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7118 | static bool ComputeArrayIndex(unibrow::CharacterStream* buffer, |
| 7119 | uint32_t* index, |
| 7120 | int length); |
| 7121 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 7122 | // Externalization. |
| 7123 | bool MakeExternal(v8::String::ExternalStringResource* resource); |
| 7124 | bool MakeExternal(v8::String::ExternalAsciiStringResource* resource); |
| 7125 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7126 | // Conversion. |
| 7127 | inline bool AsArrayIndex(uint32_t* index); |
| 7128 | |
| 7129 | // Casting. |
| 7130 | static inline String* cast(Object* obj); |
| 7131 | |
| 7132 | void PrintOn(FILE* out); |
| 7133 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7134 | // For use during stack traces. Performs rudimentary sanity check. |
| 7135 | bool LooksValid(); |
| 7136 | |
| 7137 | // Dispatched behavior. |
| 7138 | void StringShortPrint(StringStream* accumulator); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7139 | #ifdef OBJECT_PRINT |
| 7140 | inline void StringPrint() { |
| 7141 | StringPrint(stdout); |
| 7142 | } |
| 7143 | void StringPrint(FILE* out); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 7144 | |
| 7145 | char* ToAsciiArray(); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7146 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7147 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7148 | void StringVerify(); |
| 7149 | #endif |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 7150 | inline bool IsFlat(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7151 | |
| 7152 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 7153 | static const int kLengthOffset = HeapObject::kHeaderSize; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 7154 | static const int kHashFieldOffset = kLengthOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 7155 | static const int kSize = kHashFieldOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7156 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 7157 | // Maximum number of characters to consider when trying to convert a string |
| 7158 | // value into an array index. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7159 | static const int kMaxArrayIndexSize = 10; |
| 7160 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 7161 | // Max ASCII char code. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 7162 | static const int kMaxAsciiCharCode = unibrow::Utf8::kMaxOneByteChar; |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 7163 | static const unsigned kMaxAsciiCharCodeU = unibrow::Utf8::kMaxOneByteChar; |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 7164 | static const int kMaxUtf16CodeUnit = 0xffff; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 7165 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7166 | // Mask constant for checking if a string has a computed hash code |
| 7167 | // and if it is an array index. The least significant bit indicates |
| 7168 | // whether a hash code has been computed. If the hash code has been |
| 7169 | // computed the 2nd bit tells whether the string can be used as an |
| 7170 | // array index. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 7171 | static const int kHashNotComputedMask = 1; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 7172 | static const int kIsNotArrayIndexMask = 1 << 1; |
| 7173 | static const int kNofHashBitFields = 2; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7174 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 7175 | // Shift constant retrieving hash code from hash field. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 7176 | static const int kHashShift = kNofHashBitFields; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 7177 | |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 7178 | // Only these bits are relevant in the hash, since the top two are shifted |
| 7179 | // out. |
| 7180 | static const uint32_t kHashBitMask = 0xffffffffu >> kHashShift; |
| 7181 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 7182 | // Array index strings this short can keep their index in the hash |
| 7183 | // field. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 7184 | static const int kMaxCachedArrayIndexLength = 7; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 7185 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 7186 | // For strings which are array indexes the hash value has the string length |
| 7187 | // mixed into the hash, mainly to avoid a hash value of zero which would be |
| 7188 | // 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] | 7189 | static const int kArrayIndexValueBits = 24; |
| 7190 | static const int kArrayIndexLengthBits = |
| 7191 | kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields; |
| 7192 | |
| 7193 | STATIC_CHECK((kArrayIndexLengthBits > 0)); |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 7194 | STATIC_CHECK(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits)); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 7195 | |
| 7196 | static const int kArrayIndexHashLengthShift = |
| 7197 | kArrayIndexValueBits + kNofHashBitFields; |
| 7198 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 7199 | static const int kArrayIndexHashMask = (1 << kArrayIndexHashLengthShift) - 1; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 7200 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 7201 | static const int kArrayIndexValueMask = |
| 7202 | ((1 << kArrayIndexValueBits) - 1) << kHashShift; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 7203 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 7204 | // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we |
| 7205 | // could use a mask to test if the length of string is less than or equal to |
| 7206 | // kMaxCachedArrayIndexLength. |
| 7207 | STATIC_CHECK(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1)); |
| 7208 | |
| 7209 | static const int kContainsCachedArrayIndexMask = |
| 7210 | (~kMaxCachedArrayIndexLength << kArrayIndexHashLengthShift) | |
| 7211 | kIsNotArrayIndexMask; |
| 7212 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 7213 | // 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] | 7214 | static const int kEmptyHashField = |
| 7215 | kIsNotArrayIndexMask | kHashNotComputedMask; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 7216 | |
| 7217 | // Value of hash field containing computed hash equal to zero. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 7218 | static const int kZeroHash = kIsNotArrayIndexMask; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 7219 | |
| 7220 | // Maximal string length. |
| 7221 | static const int kMaxLength = (1 << (32 - 2)) - 1; |
| 7222 | |
| 7223 | // Max length for computing hash. For strings longer than this limit the |
| 7224 | // string length is used as the hash value. |
| 7225 | static const int kMaxHashCalcLength = 16383; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7226 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 7227 | // Limit for truncation in short printing. |
| 7228 | static const int kMaxShortPrintLength = 1024; |
| 7229 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7230 | // Support for regular expressions. |
| 7231 | const uc16* GetTwoByteData(); |
| 7232 | const uc16* GetTwoByteData(unsigned start); |
| 7233 | |
| 7234 | // Support for StringInputBuffer |
| 7235 | static const unibrow::byte* ReadBlock(String* input, |
| 7236 | unibrow::byte* util_buffer, |
| 7237 | unsigned capacity, |
| 7238 | unsigned* remaining, |
| 7239 | unsigned* offset); |
| 7240 | static const unibrow::byte* ReadBlock(String** input, |
| 7241 | unibrow::byte* util_buffer, |
| 7242 | unsigned capacity, |
| 7243 | unsigned* remaining, |
| 7244 | unsigned* offset); |
| 7245 | |
| 7246 | // Helper function for flattening strings. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 7247 | template <typename sinkchar> |
| 7248 | static void WriteToFlat(String* source, |
| 7249 | sinkchar* sink, |
| 7250 | int from, |
| 7251 | int to); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7252 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 7253 | static inline bool IsAscii(const char* chars, int length) { |
| 7254 | const char* limit = chars + length; |
| 7255 | #ifdef V8_HOST_CAN_READ_UNALIGNED |
| 7256 | ASSERT(kMaxAsciiCharCode == 0x7F); |
| 7257 | const uintptr_t non_ascii_mask = kUintptrAllBitsSet / 0xFF * 0x80; |
| 7258 | while (chars <= limit - sizeof(uintptr_t)) { |
| 7259 | if (*reinterpret_cast<const uintptr_t*>(chars) & non_ascii_mask) { |
| 7260 | return false; |
| 7261 | } |
| 7262 | chars += sizeof(uintptr_t); |
| 7263 | } |
| 7264 | #endif |
| 7265 | while (chars < limit) { |
| 7266 | if (static_cast<uint8_t>(*chars) > kMaxAsciiCharCodeU) return false; |
| 7267 | ++chars; |
| 7268 | } |
| 7269 | return true; |
| 7270 | } |
| 7271 | |
| 7272 | static inline bool IsAscii(const uc16* chars, int length) { |
| 7273 | const uc16* limit = chars + length; |
| 7274 | while (chars < limit) { |
| 7275 | if (*chars > kMaxAsciiCharCodeU) return false; |
| 7276 | ++chars; |
| 7277 | } |
| 7278 | return true; |
| 7279 | } |
| 7280 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7281 | protected: |
| 7282 | class ReadBlockBuffer { |
| 7283 | public: |
| 7284 | ReadBlockBuffer(unibrow::byte* util_buffer_, |
| 7285 | unsigned cursor_, |
| 7286 | unsigned capacity_, |
| 7287 | unsigned remaining_) : |
| 7288 | util_buffer(util_buffer_), |
| 7289 | cursor(cursor_), |
| 7290 | capacity(capacity_), |
| 7291 | remaining(remaining_) { |
| 7292 | } |
| 7293 | unibrow::byte* util_buffer; |
| 7294 | unsigned cursor; |
| 7295 | unsigned capacity; |
| 7296 | unsigned remaining; |
| 7297 | }; |
| 7298 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7299 | static inline const unibrow::byte* ReadBlock(String* input, |
| 7300 | ReadBlockBuffer* buffer, |
| 7301 | unsigned* offset, |
| 7302 | unsigned max_chars); |
| 7303 | static void ReadBlockIntoBuffer(String* input, |
| 7304 | ReadBlockBuffer* buffer, |
| 7305 | unsigned* offset_ptr, |
| 7306 | unsigned max_chars); |
| 7307 | |
| 7308 | private: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7309 | // Try to flatten the top level ConsString that is hiding behind this |
| 7310 | // string. This is a no-op unless the string is a ConsString. Flatten |
| 7311 | // mutates the ConsString and might return a failure. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 7312 | MUST_USE_RESULT MaybeObject* SlowTryFlatten(PretenureFlag pretenure); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7313 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 7314 | static inline bool IsHashFieldComputed(uint32_t field); |
| 7315 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7316 | // Slow case of String::Equals. This implementation works on any strings |
| 7317 | // but it is most efficient on strings that are almost flat. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 7318 | bool SlowEquals(String* other); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7319 | |
| 7320 | // Slow case of AsArrayIndex. |
| 7321 | bool SlowAsArrayIndex(uint32_t* index); |
| 7322 | |
| 7323 | // Compute and set the hash code. |
| 7324 | uint32_t ComputeAndSetHash(); |
| 7325 | |
| 7326 | DISALLOW_IMPLICIT_CONSTRUCTORS(String); |
| 7327 | }; |
| 7328 | |
| 7329 | |
| 7330 | // The SeqString abstract class captures sequential string values. |
| 7331 | class SeqString: public String { |
| 7332 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7333 | // Casting. |
| 7334 | static inline SeqString* cast(Object* obj); |
| 7335 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7336 | // Layout description. |
| 7337 | static const int kHeaderSize = String::kSize; |
| 7338 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7339 | private: |
| 7340 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString); |
| 7341 | }; |
| 7342 | |
| 7343 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 7344 | // The AsciiString class captures sequential ASCII string objects. |
| 7345 | // Each character in the AsciiString is an ASCII character. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7346 | class SeqAsciiString: public SeqString { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7347 | public: |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 7348 | static const bool kHasAsciiEncoding = true; |
| 7349 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7350 | // Dispatched behavior. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7351 | inline uint16_t SeqAsciiStringGet(int index); |
| 7352 | inline void SeqAsciiStringSet(int index, uint16_t value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7353 | |
| 7354 | // Get the address of the characters in this string. |
| 7355 | inline Address GetCharsAddress(); |
| 7356 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 7357 | inline char* GetChars(); |
| 7358 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7359 | // Casting |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7360 | static inline SeqAsciiString* cast(Object* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7361 | |
| 7362 | // Garbage collection support. This method is called by the |
| 7363 | // garbage collector to compute the actual size of an AsciiString |
| 7364 | // instance. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 7365 | inline int SeqAsciiStringSize(InstanceType instance_type); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7366 | |
| 7367 | // Computes the size for an AsciiString instance of a given length. |
| 7368 | static int SizeFor(int length) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 7369 | return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7370 | } |
| 7371 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7372 | // Maximal memory usage for a single sequential ASCII string. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7373 | static const int kMaxSize = 512 * MB - 1; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7374 | // Maximal length of a single sequential ASCII string. |
| 7375 | // Q.v. String::kMaxLength which is the maximal size of concatenated strings. |
| 7376 | static const int kMaxLength = (kMaxSize - kHeaderSize); |
| 7377 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7378 | // Support for StringInputBuffer. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7379 | inline void SeqAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 7380 | unsigned* offset, |
| 7381 | unsigned chars); |
| 7382 | inline const unibrow::byte* SeqAsciiStringReadBlock(unsigned* remaining, |
| 7383 | unsigned* offset, |
| 7384 | unsigned chars); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7385 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 7386 | #ifdef DEBUG |
| 7387 | void SeqAsciiStringVerify(); |
| 7388 | #endif |
| 7389 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7390 | private: |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7391 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqAsciiString); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7392 | }; |
| 7393 | |
| 7394 | |
| 7395 | // The TwoByteString class captures sequential unicode string objects. |
| 7396 | // Each character in the TwoByteString is a two-byte uint16_t. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7397 | class SeqTwoByteString: public SeqString { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7398 | public: |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 7399 | static const bool kHasAsciiEncoding = false; |
| 7400 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7401 | // Dispatched behavior. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7402 | inline uint16_t SeqTwoByteStringGet(int index); |
| 7403 | inline void SeqTwoByteStringSet(int index, uint16_t value); |
| 7404 | |
| 7405 | // Get the address of the characters in this string. |
| 7406 | inline Address GetCharsAddress(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7407 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 7408 | inline uc16* GetChars(); |
| 7409 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7410 | // For regexp code. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7411 | const uint16_t* SeqTwoByteStringGetData(unsigned start); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7412 | |
| 7413 | // Casting |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7414 | static inline SeqTwoByteString* cast(Object* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7415 | |
| 7416 | // Garbage collection support. This method is called by the |
| 7417 | // garbage collector to compute the actual size of a TwoByteString |
| 7418 | // instance. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 7419 | inline int SeqTwoByteStringSize(InstanceType instance_type); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7420 | |
| 7421 | // Computes the size for a TwoByteString instance of a given length. |
| 7422 | static int SizeFor(int length) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 7423 | return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7424 | } |
| 7425 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7426 | // Maximal memory usage for a single sequential two-byte string. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7427 | static const int kMaxSize = 512 * MB - 1; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7428 | // Maximal length of a single sequential two-byte string. |
| 7429 | // Q.v. String::kMaxLength which is the maximal size of concatenated strings. |
| 7430 | static const int kMaxLength = (kMaxSize - kHeaderSize) / sizeof(uint16_t); |
| 7431 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7432 | // Support for StringInputBuffer. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7433 | inline void SeqTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 7434 | unsigned* offset_ptr, |
| 7435 | unsigned chars); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7436 | |
| 7437 | private: |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7438 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqTwoByteString); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7439 | }; |
| 7440 | |
| 7441 | |
| 7442 | // The ConsString class describes string values built by using the |
| 7443 | // addition operator on strings. A ConsString is a pair where the |
| 7444 | // first and second components are pointers to other string values. |
| 7445 | // One or both components of a ConsString can be pointers to other |
| 7446 | // ConsStrings, creating a binary tree of ConsStrings where the leaves |
| 7447 | // are non-ConsString string values. The string value represented by |
| 7448 | // a ConsString can be obtained by concatenating the leaf string |
| 7449 | // values in a left-to-right depth-first traversal of the tree. |
| 7450 | class ConsString: public String { |
| 7451 | public: |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 7452 | // First string of the cons cell. |
| 7453 | inline String* first(); |
| 7454 | // Doesn't check that the result is a string, even in debug mode. This is |
| 7455 | // useful during GC where the mark bits confuse the checks. |
| 7456 | inline Object* unchecked_first(); |
| 7457 | inline void set_first(String* first, |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 7458 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7459 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 7460 | // Second string of the cons cell. |
| 7461 | inline String* second(); |
| 7462 | // Doesn't check that the result is a string, even in debug mode. This is |
| 7463 | // useful during GC where the mark bits confuse the checks. |
| 7464 | inline Object* unchecked_second(); |
| 7465 | inline void set_second(String* second, |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 7466 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7467 | |
| 7468 | // Dispatched behavior. |
| 7469 | uint16_t ConsStringGet(int index); |
| 7470 | |
| 7471 | // Casting. |
| 7472 | static inline ConsString* cast(Object* obj); |
| 7473 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7474 | // Layout description. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 7475 | static const int kFirstOffset = POINTER_SIZE_ALIGN(String::kSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7476 | static const int kSecondOffset = kFirstOffset + kPointerSize; |
| 7477 | static const int kSize = kSecondOffset + kPointerSize; |
| 7478 | |
| 7479 | // Support for StringInputBuffer. |
| 7480 | inline const unibrow::byte* ConsStringReadBlock(ReadBlockBuffer* buffer, |
| 7481 | unsigned* offset_ptr, |
| 7482 | unsigned chars); |
| 7483 | inline void ConsStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 7484 | unsigned* offset_ptr, |
| 7485 | unsigned chars); |
| 7486 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 7487 | // Minimum length for a cons string. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7488 | static const int kMinLength = 13; |
| 7489 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 7490 | typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize> |
| 7491 | BodyDescriptor; |
| 7492 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 7493 | #ifdef DEBUG |
| 7494 | void ConsStringVerify(); |
| 7495 | #endif |
| 7496 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7497 | private: |
| 7498 | DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString); |
| 7499 | }; |
| 7500 | |
| 7501 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 7502 | // The Sliced String class describes strings that are substrings of another |
| 7503 | // sequential string. The motivation is to save time and memory when creating |
| 7504 | // a substring. A Sliced String is described as a pointer to the parent, |
| 7505 | // the offset from the start of the parent string and the length. Using |
| 7506 | // a Sliced String therefore requires unpacking of the parent string and |
| 7507 | // adding the offset to the start address. A substring of a Sliced String |
| 7508 | // are not nested since the double indirection is simplified when creating |
| 7509 | // such a substring. |
| 7510 | // Currently missing features are: |
| 7511 | // - handling externalized parent strings |
| 7512 | // - external strings as parent |
| 7513 | // - truncating sliced string to enable otherwise unneeded parent to be GC'ed. |
| 7514 | class SlicedString: public String { |
| 7515 | public: |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 7516 | inline String* parent(); |
| 7517 | inline void set_parent(String* parent); |
| 7518 | inline int offset(); |
| 7519 | inline void set_offset(int offset); |
| 7520 | |
| 7521 | // Dispatched behavior. |
| 7522 | uint16_t SlicedStringGet(int index); |
| 7523 | |
| 7524 | // Casting. |
| 7525 | static inline SlicedString* cast(Object* obj); |
| 7526 | |
| 7527 | // Layout description. |
| 7528 | static const int kParentOffset = POINTER_SIZE_ALIGN(String::kSize); |
| 7529 | static const int kOffsetOffset = kParentOffset + kPointerSize; |
| 7530 | static const int kSize = kOffsetOffset + kPointerSize; |
| 7531 | |
| 7532 | // Support for StringInputBuffer |
| 7533 | inline const unibrow::byte* SlicedStringReadBlock(ReadBlockBuffer* buffer, |
| 7534 | unsigned* offset_ptr, |
| 7535 | unsigned chars); |
| 7536 | inline void SlicedStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 7537 | unsigned* offset_ptr, |
| 7538 | unsigned chars); |
| 7539 | // Minimum length for a sliced string. |
| 7540 | static const int kMinLength = 13; |
| 7541 | |
| 7542 | typedef FixedBodyDescriptor<kParentOffset, |
| 7543 | kOffsetOffset + kPointerSize, kSize> |
| 7544 | BodyDescriptor; |
| 7545 | |
| 7546 | #ifdef DEBUG |
| 7547 | void SlicedStringVerify(); |
| 7548 | #endif |
| 7549 | |
| 7550 | private: |
| 7551 | DISALLOW_IMPLICIT_CONSTRUCTORS(SlicedString); |
| 7552 | }; |
| 7553 | |
| 7554 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7555 | // The ExternalString class describes string values that are backed by |
| 7556 | // a string resource that lies outside the V8 heap. ExternalStrings |
| 7557 | // consist of the length field common to all strings, a pointer to the |
| 7558 | // external resource. It is important to ensure (externally) that the |
| 7559 | // resource is not deallocated while the ExternalString is live in the |
| 7560 | // V8 heap. |
| 7561 | // |
| 7562 | // The API expects that all ExternalStrings are created through the |
| 7563 | // API. Therefore, ExternalStrings should not be used internally. |
| 7564 | class ExternalString: public String { |
| 7565 | public: |
| 7566 | // Casting |
| 7567 | static inline ExternalString* cast(Object* obj); |
| 7568 | |
| 7569 | // Layout description. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 7570 | static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 7571 | static const int kShortSize = kResourceOffset + kPointerSize; |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 7572 | static const int kResourceDataOffset = kResourceOffset + kPointerSize; |
| 7573 | static const int kSize = kResourceDataOffset + kPointerSize; |
| 7574 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 7575 | // Return whether external string is short (data pointer is not cached). |
| 7576 | inline bool is_short(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7577 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 7578 | STATIC_CHECK(kResourceOffset == Internals::kStringResourceOffset); |
| 7579 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7580 | private: |
| 7581 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString); |
| 7582 | }; |
| 7583 | |
| 7584 | |
| 7585 | // The ExternalAsciiString class is an external string backed by an |
| 7586 | // ASCII string. |
| 7587 | class ExternalAsciiString: public ExternalString { |
| 7588 | public: |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 7589 | static const bool kHasAsciiEncoding = true; |
| 7590 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7591 | typedef v8::String::ExternalAsciiStringResource Resource; |
| 7592 | |
| 7593 | // The underlying resource. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7594 | inline const Resource* resource(); |
| 7595 | inline void set_resource(const Resource* buffer); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7596 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 7597 | // Update the pointer cache to the external character array. |
| 7598 | // The cached pointer is always valid, as the external character array does = |
| 7599 | // not move during lifetime. Deserialization is the only exception, after |
| 7600 | // which the pointer cache has to be refreshed. |
| 7601 | inline void update_data_cache(); |
| 7602 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 7603 | inline const char* GetChars(); |
| 7604 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7605 | // Dispatched behavior. |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 7606 | inline uint16_t ExternalAsciiStringGet(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7607 | |
| 7608 | // Casting. |
| 7609 | static inline ExternalAsciiString* cast(Object* obj); |
| 7610 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7611 | // Garbage collection support. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 7612 | inline void ExternalAsciiStringIterateBody(ObjectVisitor* v); |
| 7613 | |
| 7614 | template<typename StaticVisitor> |
| 7615 | inline void ExternalAsciiStringIterateBody(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7616 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7617 | // Support for StringInputBuffer. |
| 7618 | const unibrow::byte* ExternalAsciiStringReadBlock(unsigned* remaining, |
| 7619 | unsigned* offset, |
| 7620 | unsigned chars); |
| 7621 | inline void ExternalAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 7622 | unsigned* offset, |
| 7623 | unsigned chars); |
| 7624 | |
| 7625 | private: |
| 7626 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalAsciiString); |
| 7627 | }; |
| 7628 | |
| 7629 | |
| 7630 | // The ExternalTwoByteString class is an external string backed by a UTF-16 |
| 7631 | // encoded string. |
| 7632 | class ExternalTwoByteString: public ExternalString { |
| 7633 | public: |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 7634 | static const bool kHasAsciiEncoding = false; |
| 7635 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7636 | typedef v8::String::ExternalStringResource Resource; |
| 7637 | |
| 7638 | // The underlying string resource. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7639 | inline const Resource* resource(); |
| 7640 | inline void set_resource(const Resource* buffer); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7641 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 7642 | // Update the pointer cache to the external character array. |
| 7643 | // The cached pointer is always valid, as the external character array does = |
| 7644 | // not move during lifetime. Deserialization is the only exception, after |
| 7645 | // which the pointer cache has to be refreshed. |
| 7646 | inline void update_data_cache(); |
| 7647 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 7648 | inline const uint16_t* GetChars(); |
| 7649 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7650 | // Dispatched behavior. |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 7651 | inline uint16_t ExternalTwoByteStringGet(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7652 | |
| 7653 | // For regexp code. |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 7654 | inline const uint16_t* ExternalTwoByteStringGetData(unsigned start); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7655 | |
| 7656 | // Casting. |
| 7657 | static inline ExternalTwoByteString* cast(Object* obj); |
| 7658 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7659 | // Garbage collection support. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 7660 | inline void ExternalTwoByteStringIterateBody(ObjectVisitor* v); |
| 7661 | |
| 7662 | template<typename StaticVisitor> |
| 7663 | inline void ExternalTwoByteStringIterateBody(); |
| 7664 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7665 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7666 | // Support for StringInputBuffer. |
| 7667 | void ExternalTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 7668 | unsigned* offset_ptr, |
| 7669 | unsigned chars); |
| 7670 | |
| 7671 | private: |
| 7672 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalTwoByteString); |
| 7673 | }; |
| 7674 | |
| 7675 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 7676 | // Utility superclass for stack-allocated objects that must be updated |
| 7677 | // on gc. It provides two ways for the gc to update instances, either |
| 7678 | // iterating or updating after gc. |
| 7679 | class Relocatable BASE_EMBEDDED { |
| 7680 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7681 | explicit inline Relocatable(Isolate* isolate); |
| 7682 | inline virtual ~Relocatable(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 7683 | virtual void IterateInstance(ObjectVisitor* v) { } |
| 7684 | virtual void PostGarbageCollection() { } |
| 7685 | |
| 7686 | static void PostGarbageCollectionProcessing(); |
| 7687 | static int ArchiveSpacePerThread(); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7688 | static char* ArchiveState(Isolate* isolate, char* to); |
| 7689 | static char* RestoreState(Isolate* isolate, char* from); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 7690 | static void Iterate(ObjectVisitor* v); |
| 7691 | static void Iterate(ObjectVisitor* v, Relocatable* top); |
| 7692 | static char* Iterate(ObjectVisitor* v, char* t); |
| 7693 | private: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7694 | Isolate* isolate_; |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 7695 | Relocatable* prev_; |
| 7696 | }; |
| 7697 | |
| 7698 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 7699 | // A flat string reader provides random access to the contents of a |
| 7700 | // string independent of the character width of the string. The handle |
| 7701 | // must be valid as long as the reader is being used. |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 7702 | class FlatStringReader : public Relocatable { |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 7703 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7704 | FlatStringReader(Isolate* isolate, Handle<String> str); |
| 7705 | FlatStringReader(Isolate* isolate, Vector<const char> input); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 7706 | void PostGarbageCollection(); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 7707 | inline uc32 Get(int index); |
| 7708 | int length() { return length_; } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 7709 | private: |
| 7710 | String** str_; |
| 7711 | bool is_ascii_; |
| 7712 | int length_; |
| 7713 | const void* start_; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 7714 | }; |
| 7715 | |
| 7716 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7717 | // Note that StringInputBuffers are not valid across a GC! To fix this |
| 7718 | // it would have to store a String Handle instead of a String* and |
| 7719 | // AsciiStringReadBlock would have to be modified to use memcpy. |
| 7720 | // |
| 7721 | // StringInputBuffer is able to traverse any string regardless of how |
| 7722 | // deeply nested a sequence of ConsStrings it is made of. However, |
| 7723 | // performance will be better if deep strings are flattened before they |
| 7724 | // are traversed. Since flattening requires memory allocation this is |
| 7725 | // not always desirable, however (esp. in debugging situations). |
| 7726 | class StringInputBuffer: public unibrow::InputBuffer<String, String*, 1024> { |
| 7727 | public: |
| 7728 | virtual void Seek(unsigned pos); |
| 7729 | inline StringInputBuffer(): unibrow::InputBuffer<String, String*, 1024>() {} |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 7730 | explicit inline StringInputBuffer(String* backing): |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7731 | unibrow::InputBuffer<String, String*, 1024>(backing) {} |
| 7732 | }; |
| 7733 | |
| 7734 | |
| 7735 | class SafeStringInputBuffer |
| 7736 | : public unibrow::InputBuffer<String, String**, 256> { |
| 7737 | public: |
| 7738 | virtual void Seek(unsigned pos); |
| 7739 | inline SafeStringInputBuffer() |
| 7740 | : unibrow::InputBuffer<String, String**, 256>() {} |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 7741 | explicit inline SafeStringInputBuffer(String** backing) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7742 | : unibrow::InputBuffer<String, String**, 256>(backing) {} |
| 7743 | }; |
| 7744 | |
| 7745 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7746 | template <typename T> |
| 7747 | class VectorIterator { |
| 7748 | public: |
| 7749 | VectorIterator(T* d, int l) : data_(Vector<const T>(d, l)), index_(0) { } |
| 7750 | explicit VectorIterator(Vector<const T> data) : data_(data), index_(0) { } |
| 7751 | T GetNext() { return data_[index_++]; } |
| 7752 | bool has_more() { return index_ < data_.length(); } |
| 7753 | private: |
| 7754 | Vector<const T> data_; |
| 7755 | int index_; |
| 7756 | }; |
| 7757 | |
| 7758 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7759 | // The Oddball describes objects null, undefined, true, and false. |
| 7760 | class Oddball: public HeapObject { |
| 7761 | public: |
| 7762 | // [to_string]: Cached to_string computed at startup. |
| 7763 | DECL_ACCESSORS(to_string, String) |
| 7764 | |
| 7765 | // [to_number]: Cached to_number computed at startup. |
| 7766 | DECL_ACCESSORS(to_number, Object) |
| 7767 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7768 | inline byte kind(); |
| 7769 | inline void set_kind(byte kind); |
| 7770 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7771 | // Casting. |
| 7772 | static inline Oddball* cast(Object* obj); |
| 7773 | |
| 7774 | // Dispatched behavior. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7775 | #ifdef DEBUG |
| 7776 | void OddballVerify(); |
| 7777 | #endif |
| 7778 | |
| 7779 | // Initialize the fields. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 7780 | MUST_USE_RESULT MaybeObject* Initialize(const char* to_string, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7781 | Object* to_number, |
| 7782 | byte kind); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7783 | |
| 7784 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 7785 | static const int kToStringOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7786 | static const int kToNumberOffset = kToStringOffset + kPointerSize; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 7787 | static const int kKindOffset = kToNumberOffset + kPointerSize; |
| 7788 | static const int kSize = kKindOffset + kPointerSize; |
| 7789 | |
| 7790 | static const byte kFalse = 0; |
| 7791 | static const byte kTrue = 1; |
| 7792 | static const byte kNotBooleanMask = ~1; |
| 7793 | static const byte kTheHole = 2; |
| 7794 | static const byte kNull = 3; |
| 7795 | static const byte kArgumentMarker = 4; |
| 7796 | static const byte kUndefined = 5; |
| 7797 | static const byte kOther = 6; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7798 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 7799 | typedef FixedBodyDescriptor<kToStringOffset, |
| 7800 | kToNumberOffset + kPointerSize, |
| 7801 | kSize> BodyDescriptor; |
| 7802 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 7803 | STATIC_CHECK(kKindOffset == Internals::kOddballKindOffset); |
| 7804 | STATIC_CHECK(kNull == Internals::kNullOddballKind); |
| 7805 | STATIC_CHECK(kUndefined == Internals::kUndefinedOddballKind); |
| 7806 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7807 | private: |
| 7808 | DISALLOW_IMPLICIT_CONSTRUCTORS(Oddball); |
| 7809 | }; |
| 7810 | |
| 7811 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7812 | class JSGlobalPropertyCell: public HeapObject { |
| 7813 | public: |
| 7814 | // [value]: value of the global property. |
| 7815 | DECL_ACCESSORS(value, Object) |
| 7816 | |
| 7817 | // Casting. |
| 7818 | static inline JSGlobalPropertyCell* cast(Object* obj); |
| 7819 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7820 | #ifdef DEBUG |
| 7821 | void JSGlobalPropertyCellVerify(); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7822 | #endif |
| 7823 | #ifdef OBJECT_PRINT |
| 7824 | inline void JSGlobalPropertyCellPrint() { |
| 7825 | JSGlobalPropertyCellPrint(stdout); |
| 7826 | } |
| 7827 | void JSGlobalPropertyCellPrint(FILE* out); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7828 | #endif |
| 7829 | |
| 7830 | // Layout description. |
| 7831 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 7832 | static const int kSize = kValueOffset + kPointerSize; |
| 7833 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 7834 | typedef FixedBodyDescriptor<kValueOffset, |
| 7835 | kValueOffset + kPointerSize, |
| 7836 | kSize> BodyDescriptor; |
| 7837 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7838 | private: |
| 7839 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalPropertyCell); |
| 7840 | }; |
| 7841 | |
| 7842 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7843 | // The JSProxy describes EcmaScript Harmony proxies |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 7844 | class JSProxy: public JSReceiver { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7845 | public: |
| 7846 | // [handler]: The handler property. |
| 7847 | DECL_ACCESSORS(handler, Object) |
| 7848 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7849 | // [hash]: The hash code property (undefined if not initialized yet). |
| 7850 | DECL_ACCESSORS(hash, Object) |
| 7851 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7852 | // Casting. |
| 7853 | static inline JSProxy* cast(Object* obj); |
| 7854 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 7855 | bool HasPropertyWithHandler(String* name); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7856 | bool HasElementWithHandler(uint32_t index); |
| 7857 | |
| 7858 | MUST_USE_RESULT MaybeObject* GetPropertyWithHandler( |
| 7859 | Object* receiver, |
| 7860 | String* name); |
| 7861 | MUST_USE_RESULT MaybeObject* GetElementWithHandler( |
| 7862 | Object* receiver, |
| 7863 | uint32_t index); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 7864 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 7865 | MUST_USE_RESULT MaybeObject* SetPropertyWithHandler( |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 7866 | JSReceiver* receiver, |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 7867 | String* name, |
| 7868 | Object* value, |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 7869 | PropertyAttributes attributes, |
| 7870 | StrictModeFlag strict_mode); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7871 | MUST_USE_RESULT MaybeObject* SetElementWithHandler( |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 7872 | JSReceiver* receiver, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7873 | uint32_t index, |
| 7874 | Object* value, |
| 7875 | StrictModeFlag strict_mode); |
| 7876 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 7877 | // If the handler defines an accessor property with a setter, invoke it. |
| 7878 | // If it defines an accessor property without a setter, or a data property |
| 7879 | // that is read-only, throw. In all these cases set '*done' to true, |
| 7880 | // otherwise set it to false. |
| 7881 | MUST_USE_RESULT MaybeObject* SetPropertyViaPrototypesWithHandler( |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 7882 | JSReceiver* receiver, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7883 | String* name, |
| 7884 | Object* value, |
| 7885 | PropertyAttributes attributes, |
| 7886 | StrictModeFlag strict_mode, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 7887 | bool* done); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 7888 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 7889 | MUST_USE_RESULT MaybeObject* DeletePropertyWithHandler( |
| 7890 | String* name, |
| 7891 | DeleteMode mode); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7892 | MUST_USE_RESULT MaybeObject* DeleteElementWithHandler( |
| 7893 | uint32_t index, |
| 7894 | DeleteMode mode); |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 7895 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 7896 | MUST_USE_RESULT PropertyAttributes GetPropertyAttributeWithHandler( |
| 7897 | JSReceiver* receiver, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7898 | String* name); |
| 7899 | MUST_USE_RESULT PropertyAttributes GetElementAttributeWithHandler( |
| 7900 | JSReceiver* receiver, |
| 7901 | uint32_t index); |
| 7902 | |
| 7903 | MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 7904 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 7905 | // Turn this into an (empty) JSObject. |
| 7906 | void Fix(); |
| 7907 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 7908 | // Initializes the body after the handler slot. |
| 7909 | inline void InitializeBody(int object_size, Object* value); |
| 7910 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7911 | // Invoke a trap by name. If the trap does not exist on this's handler, |
| 7912 | // but derived_trap is non-NULL, invoke that instead. May cause GC. |
| 7913 | Handle<Object> CallTrap(const char* name, |
| 7914 | Handle<Object> derived_trap, |
| 7915 | int argc, |
| 7916 | Handle<Object> args[]); |
| 7917 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7918 | // Dispatched behavior. |
| 7919 | #ifdef OBJECT_PRINT |
| 7920 | inline void JSProxyPrint() { |
| 7921 | JSProxyPrint(stdout); |
| 7922 | } |
| 7923 | void JSProxyPrint(FILE* out); |
| 7924 | #endif |
| 7925 | #ifdef DEBUG |
| 7926 | void JSProxyVerify(); |
| 7927 | #endif |
| 7928 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 7929 | // Layout description. We add padding so that a proxy has the same |
| 7930 | // size as a virgin JSObject. This is essential for becoming a JSObject |
| 7931 | // upon freeze. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7932 | static const int kHandlerOffset = HeapObject::kHeaderSize; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7933 | static const int kHashOffset = kHandlerOffset + kPointerSize; |
| 7934 | static const int kPaddingOffset = kHashOffset + kPointerSize; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 7935 | static const int kSize = JSObject::kHeaderSize; |
| 7936 | static const int kHeaderSize = kPaddingOffset; |
| 7937 | static const int kPaddingSize = kSize - kPaddingOffset; |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 7938 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 7939 | STATIC_CHECK(kPaddingSize >= 0); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7940 | |
| 7941 | typedef FixedBodyDescriptor<kHandlerOffset, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7942 | kPaddingOffset, |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7943 | kSize> BodyDescriptor; |
| 7944 | |
| 7945 | private: |
| 7946 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxy); |
| 7947 | }; |
| 7948 | |
| 7949 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 7950 | class JSFunctionProxy: public JSProxy { |
| 7951 | public: |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 7952 | // [call_trap]: The call trap. |
| 7953 | DECL_ACCESSORS(call_trap, Object) |
| 7954 | |
| 7955 | // [construct_trap]: The construct trap. |
| 7956 | DECL_ACCESSORS(construct_trap, Object) |
| 7957 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 7958 | // Casting. |
| 7959 | static inline JSFunctionProxy* cast(Object* obj); |
| 7960 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 7961 | // Dispatched behavior. |
| 7962 | #ifdef OBJECT_PRINT |
| 7963 | inline void JSFunctionProxyPrint() { |
| 7964 | JSFunctionProxyPrint(stdout); |
| 7965 | } |
| 7966 | void JSFunctionProxyPrint(FILE* out); |
| 7967 | #endif |
| 7968 | #ifdef DEBUG |
| 7969 | void JSFunctionProxyVerify(); |
| 7970 | #endif |
| 7971 | |
| 7972 | // Layout description. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7973 | static const int kCallTrapOffset = JSProxy::kPaddingOffset; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 7974 | static const int kConstructTrapOffset = kCallTrapOffset + kPointerSize; |
| 7975 | static const int kPaddingOffset = kConstructTrapOffset + kPointerSize; |
| 7976 | static const int kSize = JSFunction::kSize; |
| 7977 | static const int kPaddingSize = kSize - kPaddingOffset; |
| 7978 | |
| 7979 | STATIC_CHECK(kPaddingSize >= 0); |
| 7980 | |
| 7981 | typedef FixedBodyDescriptor<kHandlerOffset, |
| 7982 | kConstructTrapOffset + kPointerSize, |
| 7983 | kSize> BodyDescriptor; |
| 7984 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 7985 | private: |
| 7986 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunctionProxy); |
| 7987 | }; |
| 7988 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 7989 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7990 | // The JSSet describes EcmaScript Harmony sets |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7991 | class JSSet: public JSObject { |
| 7992 | public: |
| 7993 | // [set]: the backing hash set containing keys. |
| 7994 | DECL_ACCESSORS(table, Object) |
| 7995 | |
| 7996 | // Casting. |
| 7997 | static inline JSSet* cast(Object* obj); |
| 7998 | |
| 7999 | #ifdef OBJECT_PRINT |
| 8000 | inline void JSSetPrint() { |
| 8001 | JSSetPrint(stdout); |
| 8002 | } |
| 8003 | void JSSetPrint(FILE* out); |
| 8004 | #endif |
| 8005 | #ifdef DEBUG |
| 8006 | void JSSetVerify(); |
| 8007 | #endif |
| 8008 | |
| 8009 | static const int kTableOffset = JSObject::kHeaderSize; |
| 8010 | static const int kSize = kTableOffset + kPointerSize; |
| 8011 | |
| 8012 | private: |
| 8013 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSSet); |
| 8014 | }; |
| 8015 | |
| 8016 | |
| 8017 | // The JSMap describes EcmaScript Harmony maps |
| 8018 | class JSMap: public JSObject { |
| 8019 | public: |
| 8020 | // [table]: the backing hash table mapping keys to values. |
| 8021 | DECL_ACCESSORS(table, Object) |
| 8022 | |
| 8023 | // Casting. |
| 8024 | static inline JSMap* cast(Object* obj); |
| 8025 | |
| 8026 | #ifdef OBJECT_PRINT |
| 8027 | inline void JSMapPrint() { |
| 8028 | JSMapPrint(stdout); |
| 8029 | } |
| 8030 | void JSMapPrint(FILE* out); |
| 8031 | #endif |
| 8032 | #ifdef DEBUG |
| 8033 | void JSMapVerify(); |
| 8034 | #endif |
| 8035 | |
| 8036 | static const int kTableOffset = JSObject::kHeaderSize; |
| 8037 | static const int kSize = kTableOffset + kPointerSize; |
| 8038 | |
| 8039 | private: |
| 8040 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSMap); |
| 8041 | }; |
| 8042 | |
| 8043 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 8044 | // The JSWeakMap describes EcmaScript Harmony weak maps |
| 8045 | class JSWeakMap: public JSObject { |
| 8046 | public: |
| 8047 | // [table]: the backing hash table mapping keys to values. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 8048 | DECL_ACCESSORS(table, Object) |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 8049 | |
| 8050 | // [next]: linked list of encountered weak maps during GC. |
| 8051 | DECL_ACCESSORS(next, Object) |
| 8052 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 8053 | // Casting. |
| 8054 | static inline JSWeakMap* cast(Object* obj); |
| 8055 | |
| 8056 | #ifdef OBJECT_PRINT |
| 8057 | inline void JSWeakMapPrint() { |
| 8058 | JSWeakMapPrint(stdout); |
| 8059 | } |
| 8060 | void JSWeakMapPrint(FILE* out); |
| 8061 | #endif |
| 8062 | #ifdef DEBUG |
| 8063 | void JSWeakMapVerify(); |
| 8064 | #endif |
| 8065 | |
| 8066 | static const int kTableOffset = JSObject::kHeaderSize; |
| 8067 | static const int kNextOffset = kTableOffset + kPointerSize; |
| 8068 | static const int kSize = kNextOffset + kPointerSize; |
| 8069 | |
| 8070 | private: |
| 8071 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakMap); |
| 8072 | }; |
| 8073 | |
| 8074 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 8075 | // Foreign describes objects pointing from JavaScript to C structures. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 8076 | // Since they cannot contain references to JS HeapObjects they can be |
| 8077 | // placed in old_data_space. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 8078 | class Foreign: public HeapObject { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8079 | public: |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 8080 | // [address]: field containing the address. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 8081 | inline Address foreign_address(); |
| 8082 | inline void set_foreign_address(Address value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8083 | |
| 8084 | // Casting. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 8085 | static inline Foreign* cast(Object* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8086 | |
| 8087 | // Dispatched behavior. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 8088 | inline void ForeignIterateBody(ObjectVisitor* v); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 8089 | |
| 8090 | template<typename StaticVisitor> |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 8091 | inline void ForeignIterateBody(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 8092 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8093 | #ifdef OBJECT_PRINT |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 8094 | inline void ForeignPrint() { |
| 8095 | ForeignPrint(stdout); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8096 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 8097 | void ForeignPrint(FILE* out); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8098 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8099 | #ifdef DEBUG |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 8100 | void ForeignVerify(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8101 | #endif |
| 8102 | |
| 8103 | // Layout description. |
| 8104 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 8105 | static const int kForeignAddressOffset = HeapObject::kHeaderSize; |
| 8106 | static const int kSize = kForeignAddressOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8107 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 8108 | STATIC_CHECK(kForeignAddressOffset == Internals::kForeignAddressOffset); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 8109 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8110 | private: |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 8111 | DISALLOW_IMPLICIT_CONSTRUCTORS(Foreign); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8112 | }; |
| 8113 | |
| 8114 | |
| 8115 | // The JSArray describes JavaScript Arrays |
| 8116 | // Such an array can be in one of two modes: |
| 8117 | // - fast, backing storage is a FixedArray and length <= elements.length(); |
| 8118 | // Please note: push and pop can be used to grow and shrink the array. |
| 8119 | // - slow, backing storage is a HashTable with numbers as keys. |
| 8120 | class JSArray: public JSObject { |
| 8121 | public: |
| 8122 | // [length]: The length property. |
| 8123 | DECL_ACCESSORS(length, Object) |
| 8124 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 8125 | // Overload the length setter to skip write barrier when the length |
| 8126 | // is set to a smi. This matches the set function on FixedArray. |
| 8127 | inline void set_length(Smi* length); |
| 8128 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 8129 | MUST_USE_RESULT MaybeObject* JSArrayUpdateLengthFromIndex(uint32_t index, |
| 8130 | Object* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8131 | |
| 8132 | // Initialize the array with the given capacity. The function may |
| 8133 | // fail due to out-of-memory situations, but only if the requested |
| 8134 | // capacity is non-zero. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 8135 | MUST_USE_RESULT MaybeObject* Initialize(int capacity); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8136 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 8137 | // Initializes the array to a certain length. |
| 8138 | inline bool AllowsSetElementsLength(); |
| 8139 | MUST_USE_RESULT MaybeObject* SetElementsLength(Object* length); |
| 8140 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8141 | // Set the content of the array to the content of storage. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 8142 | MUST_USE_RESULT inline MaybeObject* SetContent(FixedArrayBase* storage); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8143 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8144 | // Casting. |
| 8145 | static inline JSArray* cast(Object* obj); |
| 8146 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 8147 | // Uses handles. Ensures that the fixed array backing the JSArray has at |
| 8148 | // least the stated size. |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 8149 | inline void EnsureSize(int minimum_size_of_backing_fixed_array); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 8150 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8151 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8152 | #ifdef OBJECT_PRINT |
| 8153 | inline void JSArrayPrint() { |
| 8154 | JSArrayPrint(stdout); |
| 8155 | } |
| 8156 | void JSArrayPrint(FILE* out); |
| 8157 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8158 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8159 | void JSArrayVerify(); |
| 8160 | #endif |
| 8161 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 8162 | // Number of element slots to pre-allocate for an empty array. |
| 8163 | static const int kPreallocatedArrayElements = 4; |
| 8164 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8165 | // Layout description. |
| 8166 | static const int kLengthOffset = JSObject::kHeaderSize; |
| 8167 | static const int kSize = kLengthOffset + kPointerSize; |
| 8168 | |
| 8169 | private: |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 8170 | // Expand the fixed array backing of a fast-case JSArray to at least |
| 8171 | // the requested size. |
| 8172 | void Expand(int minimum_size_of_backing_fixed_array); |
| 8173 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8174 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSArray); |
| 8175 | }; |
| 8176 | |
| 8177 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 8178 | // JSRegExpResult is just a JSArray with a specific initial map. |
| 8179 | // This initial map adds in-object properties for "index" and "input" |
| 8180 | // properties, as assigned by RegExp.prototype.exec, which allows |
| 8181 | // faster creation of RegExp exec results. |
| 8182 | // This class just holds constants used when creating the result. |
| 8183 | // After creation the result must be treated as a JSArray in all regards. |
| 8184 | class JSRegExpResult: public JSArray { |
| 8185 | public: |
| 8186 | // Offsets of object fields. |
| 8187 | static const int kIndexOffset = JSArray::kSize; |
| 8188 | static const int kInputOffset = kIndexOffset + kPointerSize; |
| 8189 | static const int kSize = kInputOffset + kPointerSize; |
| 8190 | // Indices of in-object properties. |
| 8191 | static const int kIndexIndex = 0; |
| 8192 | static const int kInputIndex = 1; |
| 8193 | private: |
| 8194 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSRegExpResult); |
| 8195 | }; |
| 8196 | |
| 8197 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 8198 | // An accessor must have a getter, but can have no setter. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8199 | // |
| 8200 | // When setting a property, V8 searches accessors in prototypes. |
| 8201 | // If an accessor was found and it does not have a setter, |
| 8202 | // the request is ignored. |
| 8203 | // |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 8204 | // If the accessor in the prototype has the READ_ONLY property attribute, then |
| 8205 | // a new value is added to the local object when the property is set. |
| 8206 | // This shadows the accessor in the prototype. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8207 | class AccessorInfo: public Struct { |
| 8208 | public: |
| 8209 | DECL_ACCESSORS(getter, Object) |
| 8210 | DECL_ACCESSORS(setter, Object) |
| 8211 | DECL_ACCESSORS(data, Object) |
| 8212 | DECL_ACCESSORS(name, Object) |
| 8213 | DECL_ACCESSORS(flag, Smi) |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 8214 | DECL_ACCESSORS(expected_receiver_type, Object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8215 | |
| 8216 | inline bool all_can_read(); |
| 8217 | inline void set_all_can_read(bool value); |
| 8218 | |
| 8219 | inline bool all_can_write(); |
| 8220 | inline void set_all_can_write(bool value); |
| 8221 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 8222 | inline bool prohibits_overwriting(); |
| 8223 | inline void set_prohibits_overwriting(bool value); |
| 8224 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8225 | inline PropertyAttributes property_attributes(); |
| 8226 | inline void set_property_attributes(PropertyAttributes attributes); |
| 8227 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 8228 | // Checks whether the given receiver is compatible with this accessor. |
| 8229 | inline bool IsCompatibleReceiver(Object* receiver); |
| 8230 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8231 | static inline AccessorInfo* cast(Object* obj); |
| 8232 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8233 | #ifdef OBJECT_PRINT |
| 8234 | inline void AccessorInfoPrint() { |
| 8235 | AccessorInfoPrint(stdout); |
| 8236 | } |
| 8237 | void AccessorInfoPrint(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 AccessorInfoVerify(); |
| 8241 | #endif |
| 8242 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 8243 | static const int kGetterOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8244 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 8245 | static const int kDataOffset = kSetterOffset + kPointerSize; |
| 8246 | static const int kNameOffset = kDataOffset + kPointerSize; |
| 8247 | static const int kFlagOffset = kNameOffset + kPointerSize; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 8248 | static const int kExpectedReceiverTypeOffset = kFlagOffset + kPointerSize; |
| 8249 | static const int kSize = kExpectedReceiverTypeOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8250 | |
| 8251 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8252 | // Bit positions in flag. |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 8253 | static const int kAllCanReadBit = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8254 | static const int kAllCanWriteBit = 1; |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 8255 | static const int kProhibitsOverwritingBit = 2; |
| 8256 | class AttributesField: public BitField<PropertyAttributes, 3, 3> {}; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 8257 | |
| 8258 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorInfo); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8259 | }; |
| 8260 | |
| 8261 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 8262 | // Support for JavaScript accessors: A pair of a getter and a setter. Each |
| 8263 | // accessor can either be |
| 8264 | // * a pointer to a JavaScript function or proxy: a real accessor |
| 8265 | // * undefined: considered an accessor by the spec, too, strangely enough |
| 8266 | // * the hole: an accessor which has not been set |
| 8267 | // * a pointer to a map: a transition used to ensure map sharing |
| 8268 | class AccessorPair: public Struct { |
| 8269 | public: |
| 8270 | DECL_ACCESSORS(getter, Object) |
| 8271 | DECL_ACCESSORS(setter, Object) |
| 8272 | |
| 8273 | static inline AccessorPair* cast(Object* obj); |
| 8274 | |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 8275 | MUST_USE_RESULT MaybeObject* CopyWithoutTransitions(); |
| 8276 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 8277 | Object* get(AccessorComponent component) { |
| 8278 | return component == ACCESSOR_GETTER ? getter() : setter(); |
| 8279 | } |
| 8280 | |
| 8281 | void set(AccessorComponent component, Object* value) { |
| 8282 | if (component == ACCESSOR_GETTER) { |
| 8283 | set_getter(value); |
| 8284 | } else { |
| 8285 | set_setter(value); |
| 8286 | } |
| 8287 | } |
| 8288 | |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 8289 | // Note: Returns undefined instead in case of a hole. |
| 8290 | Object* GetComponent(AccessorComponent component); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 8291 | |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 8292 | // Set both components, skipping arguments which are a JavaScript null. |
| 8293 | void SetComponents(Object* getter, Object* setter) { |
| 8294 | if (!getter->IsNull()) set_getter(getter); |
| 8295 | if (!setter->IsNull()) set_setter(setter); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 8296 | } |
| 8297 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 8298 | bool ContainsAccessor() { |
| 8299 | return IsJSAccessor(getter()) || IsJSAccessor(setter()); |
| 8300 | } |
| 8301 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 8302 | #ifdef OBJECT_PRINT |
| 8303 | void AccessorPairPrint(FILE* out = stdout); |
| 8304 | #endif |
| 8305 | #ifdef DEBUG |
| 8306 | void AccessorPairVerify(); |
| 8307 | #endif |
| 8308 | |
| 8309 | static const int kGetterOffset = HeapObject::kHeaderSize; |
| 8310 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 8311 | static const int kSize = kSetterOffset + kPointerSize; |
| 8312 | |
| 8313 | private: |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 8314 | // Strangely enough, in addition to functions and harmony proxies, the spec |
| 8315 | // requires us to consider undefined as a kind of accessor, too: |
| 8316 | // var obj = {}; |
| 8317 | // Object.defineProperty(obj, "foo", {get: undefined}); |
| 8318 | // assertTrue("foo" in obj); |
| 8319 | bool IsJSAccessor(Object* obj) { |
| 8320 | return obj->IsSpecFunction() || obj->IsUndefined(); |
| 8321 | } |
| 8322 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 8323 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorPair); |
| 8324 | }; |
| 8325 | |
| 8326 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8327 | class AccessCheckInfo: public Struct { |
| 8328 | public: |
| 8329 | DECL_ACCESSORS(named_callback, Object) |
| 8330 | DECL_ACCESSORS(indexed_callback, Object) |
| 8331 | DECL_ACCESSORS(data, Object) |
| 8332 | |
| 8333 | static inline AccessCheckInfo* cast(Object* obj); |
| 8334 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8335 | #ifdef OBJECT_PRINT |
| 8336 | inline void AccessCheckInfoPrint() { |
| 8337 | AccessCheckInfoPrint(stdout); |
| 8338 | } |
| 8339 | void AccessCheckInfoPrint(FILE* out); |
| 8340 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8341 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8342 | void AccessCheckInfoVerify(); |
| 8343 | #endif |
| 8344 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 8345 | static const int kNamedCallbackOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8346 | static const int kIndexedCallbackOffset = kNamedCallbackOffset + kPointerSize; |
| 8347 | static const int kDataOffset = kIndexedCallbackOffset + kPointerSize; |
| 8348 | static const int kSize = kDataOffset + kPointerSize; |
| 8349 | |
| 8350 | private: |
| 8351 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessCheckInfo); |
| 8352 | }; |
| 8353 | |
| 8354 | |
| 8355 | class InterceptorInfo: public Struct { |
| 8356 | public: |
| 8357 | DECL_ACCESSORS(getter, Object) |
| 8358 | DECL_ACCESSORS(setter, Object) |
| 8359 | DECL_ACCESSORS(query, Object) |
| 8360 | DECL_ACCESSORS(deleter, Object) |
| 8361 | DECL_ACCESSORS(enumerator, Object) |
| 8362 | DECL_ACCESSORS(data, Object) |
| 8363 | |
| 8364 | static inline InterceptorInfo* cast(Object* obj); |
| 8365 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8366 | #ifdef OBJECT_PRINT |
| 8367 | inline void InterceptorInfoPrint() { |
| 8368 | InterceptorInfoPrint(stdout); |
| 8369 | } |
| 8370 | void InterceptorInfoPrint(FILE* out); |
| 8371 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8372 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8373 | void InterceptorInfoVerify(); |
| 8374 | #endif |
| 8375 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 8376 | static const int kGetterOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8377 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 8378 | static const int kQueryOffset = kSetterOffset + kPointerSize; |
| 8379 | static const int kDeleterOffset = kQueryOffset + kPointerSize; |
| 8380 | static const int kEnumeratorOffset = kDeleterOffset + kPointerSize; |
| 8381 | static const int kDataOffset = kEnumeratorOffset + kPointerSize; |
| 8382 | static const int kSize = kDataOffset + kPointerSize; |
| 8383 | |
| 8384 | private: |
| 8385 | DISALLOW_IMPLICIT_CONSTRUCTORS(InterceptorInfo); |
| 8386 | }; |
| 8387 | |
| 8388 | |
| 8389 | class CallHandlerInfo: public Struct { |
| 8390 | public: |
| 8391 | DECL_ACCESSORS(callback, Object) |
| 8392 | DECL_ACCESSORS(data, Object) |
| 8393 | |
| 8394 | static inline CallHandlerInfo* cast(Object* obj); |
| 8395 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8396 | #ifdef OBJECT_PRINT |
| 8397 | inline void CallHandlerInfoPrint() { |
| 8398 | CallHandlerInfoPrint(stdout); |
| 8399 | } |
| 8400 | void CallHandlerInfoPrint(FILE* out); |
| 8401 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8402 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8403 | void CallHandlerInfoVerify(); |
| 8404 | #endif |
| 8405 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 8406 | static const int kCallbackOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8407 | static const int kDataOffset = kCallbackOffset + kPointerSize; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 8408 | static const int kSize = kDataOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8409 | |
| 8410 | private: |
| 8411 | DISALLOW_IMPLICIT_CONSTRUCTORS(CallHandlerInfo); |
| 8412 | }; |
| 8413 | |
| 8414 | |
| 8415 | class TemplateInfo: public Struct { |
| 8416 | public: |
| 8417 | DECL_ACCESSORS(tag, Object) |
| 8418 | DECL_ACCESSORS(property_list, Object) |
| 8419 | |
| 8420 | #ifdef DEBUG |
| 8421 | void TemplateInfoVerify(); |
| 8422 | #endif |
| 8423 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 8424 | static const int kTagOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8425 | static const int kPropertyListOffset = kTagOffset + kPointerSize; |
| 8426 | static const int kHeaderSize = kPropertyListOffset + kPointerSize; |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 8427 | |
| 8428 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8429 | DISALLOW_IMPLICIT_CONSTRUCTORS(TemplateInfo); |
| 8430 | }; |
| 8431 | |
| 8432 | |
| 8433 | class FunctionTemplateInfo: public TemplateInfo { |
| 8434 | public: |
| 8435 | DECL_ACCESSORS(serial_number, Object) |
| 8436 | DECL_ACCESSORS(call_code, Object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8437 | DECL_ACCESSORS(property_accessors, Object) |
| 8438 | DECL_ACCESSORS(prototype_template, Object) |
| 8439 | DECL_ACCESSORS(parent_template, Object) |
| 8440 | DECL_ACCESSORS(named_property_handler, Object) |
| 8441 | DECL_ACCESSORS(indexed_property_handler, Object) |
| 8442 | DECL_ACCESSORS(instance_template, Object) |
| 8443 | DECL_ACCESSORS(class_name, Object) |
| 8444 | DECL_ACCESSORS(signature, Object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8445 | DECL_ACCESSORS(instance_call_handler, Object) |
| 8446 | DECL_ACCESSORS(access_check_info, Object) |
| 8447 | DECL_ACCESSORS(flag, Smi) |
| 8448 | |
| 8449 | // Following properties use flag bits. |
| 8450 | DECL_BOOLEAN_ACCESSORS(hidden_prototype) |
| 8451 | DECL_BOOLEAN_ACCESSORS(undetectable) |
| 8452 | // If the bit is set, object instances created by this function |
| 8453 | // requires access check. |
| 8454 | DECL_BOOLEAN_ACCESSORS(needs_access_check) |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 8455 | DECL_BOOLEAN_ACCESSORS(read_only_prototype) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8456 | |
| 8457 | static inline FunctionTemplateInfo* cast(Object* obj); |
| 8458 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8459 | #ifdef OBJECT_PRINT |
| 8460 | inline void FunctionTemplateInfoPrint() { |
| 8461 | FunctionTemplateInfoPrint(stdout); |
| 8462 | } |
| 8463 | void FunctionTemplateInfoPrint(FILE* out); |
| 8464 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8465 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8466 | void FunctionTemplateInfoVerify(); |
| 8467 | #endif |
| 8468 | |
| 8469 | static const int kSerialNumberOffset = TemplateInfo::kHeaderSize; |
| 8470 | static const int kCallCodeOffset = kSerialNumberOffset + kPointerSize; |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 8471 | static const int kPropertyAccessorsOffset = kCallCodeOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8472 | static const int kPrototypeTemplateOffset = |
| 8473 | kPropertyAccessorsOffset + kPointerSize; |
| 8474 | static const int kParentTemplateOffset = |
| 8475 | kPrototypeTemplateOffset + kPointerSize; |
| 8476 | static const int kNamedPropertyHandlerOffset = |
| 8477 | kParentTemplateOffset + kPointerSize; |
| 8478 | static const int kIndexedPropertyHandlerOffset = |
| 8479 | kNamedPropertyHandlerOffset + kPointerSize; |
| 8480 | static const int kInstanceTemplateOffset = |
| 8481 | kIndexedPropertyHandlerOffset + kPointerSize; |
| 8482 | static const int kClassNameOffset = kInstanceTemplateOffset + kPointerSize; |
| 8483 | static const int kSignatureOffset = kClassNameOffset + kPointerSize; |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 8484 | static const int kInstanceCallHandlerOffset = kSignatureOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8485 | static const int kAccessCheckInfoOffset = |
| 8486 | kInstanceCallHandlerOffset + kPointerSize; |
| 8487 | static const int kFlagOffset = kAccessCheckInfoOffset + kPointerSize; |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 8488 | static const int kSize = kFlagOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8489 | |
| 8490 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8491 | // Bit position in the flag, from least significant bit position. |
| 8492 | static const int kHiddenPrototypeBit = 0; |
| 8493 | static const int kUndetectableBit = 1; |
| 8494 | static const int kNeedsAccessCheckBit = 2; |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 8495 | static const int kReadOnlyPrototypeBit = 3; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 8496 | |
| 8497 | DISALLOW_IMPLICIT_CONSTRUCTORS(FunctionTemplateInfo); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8498 | }; |
| 8499 | |
| 8500 | |
| 8501 | class ObjectTemplateInfo: public TemplateInfo { |
| 8502 | public: |
| 8503 | DECL_ACCESSORS(constructor, Object) |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 8504 | DECL_ACCESSORS(internal_field_count, Object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8505 | |
| 8506 | static inline ObjectTemplateInfo* cast(Object* obj); |
| 8507 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8508 | #ifdef OBJECT_PRINT |
| 8509 | inline void ObjectTemplateInfoPrint() { |
| 8510 | ObjectTemplateInfoPrint(stdout); |
| 8511 | } |
| 8512 | void ObjectTemplateInfoPrint(FILE* out); |
| 8513 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8514 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8515 | void ObjectTemplateInfoVerify(); |
| 8516 | #endif |
| 8517 | |
| 8518 | static const int kConstructorOffset = TemplateInfo::kHeaderSize; |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 8519 | static const int kInternalFieldCountOffset = |
| 8520 | kConstructorOffset + kPointerSize; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 8521 | static const int kSize = kInternalFieldCountOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8522 | }; |
| 8523 | |
| 8524 | |
| 8525 | class SignatureInfo: public Struct { |
| 8526 | public: |
| 8527 | DECL_ACCESSORS(receiver, Object) |
| 8528 | DECL_ACCESSORS(args, Object) |
| 8529 | |
| 8530 | static inline SignatureInfo* cast(Object* obj); |
| 8531 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8532 | #ifdef OBJECT_PRINT |
| 8533 | inline void SignatureInfoPrint() { |
| 8534 | SignatureInfoPrint(stdout); |
| 8535 | } |
| 8536 | void SignatureInfoPrint(FILE* out); |
| 8537 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8538 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8539 | void SignatureInfoVerify(); |
| 8540 | #endif |
| 8541 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 8542 | static const int kReceiverOffset = Struct::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8543 | static const int kArgsOffset = kReceiverOffset + kPointerSize; |
| 8544 | static const int kSize = kArgsOffset + kPointerSize; |
| 8545 | |
| 8546 | private: |
| 8547 | DISALLOW_IMPLICIT_CONSTRUCTORS(SignatureInfo); |
| 8548 | }; |
| 8549 | |
| 8550 | |
| 8551 | class TypeSwitchInfo: public Struct { |
| 8552 | public: |
| 8553 | DECL_ACCESSORS(types, Object) |
| 8554 | |
| 8555 | static inline TypeSwitchInfo* cast(Object* obj); |
| 8556 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8557 | #ifdef OBJECT_PRINT |
| 8558 | inline void TypeSwitchInfoPrint() { |
| 8559 | TypeSwitchInfoPrint(stdout); |
| 8560 | } |
| 8561 | void TypeSwitchInfoPrint(FILE* out); |
| 8562 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8563 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8564 | void TypeSwitchInfoVerify(); |
| 8565 | #endif |
| 8566 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 8567 | static const int kTypesOffset = Struct::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8568 | static const int kSize = kTypesOffset + kPointerSize; |
| 8569 | }; |
| 8570 | |
| 8571 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 8572 | #ifdef ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 8573 | // The DebugInfo class holds additional information for a function being |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8574 | // debugged. |
| 8575 | class DebugInfo: public Struct { |
| 8576 | public: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 8577 | // The shared function info for the source being debugged. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8578 | DECL_ACCESSORS(shared, SharedFunctionInfo) |
| 8579 | // Code object for the original code. |
| 8580 | DECL_ACCESSORS(original_code, Code) |
| 8581 | // Code object for the patched code. This code object is the code object |
| 8582 | // currently active for the function. |
| 8583 | DECL_ACCESSORS(code, Code) |
| 8584 | // Fixed array holding status information for each active break point. |
| 8585 | DECL_ACCESSORS(break_points, FixedArray) |
| 8586 | |
| 8587 | // Check if there is a break point at a code position. |
| 8588 | bool HasBreakPoint(int code_position); |
| 8589 | // Get the break point info object for a code position. |
| 8590 | Object* GetBreakPointInfo(int code_position); |
| 8591 | // Clear a break point. |
| 8592 | static void ClearBreakPoint(Handle<DebugInfo> debug_info, |
| 8593 | int code_position, |
| 8594 | Handle<Object> break_point_object); |
| 8595 | // Set a break point. |
| 8596 | static void SetBreakPoint(Handle<DebugInfo> debug_info, int code_position, |
| 8597 | int source_position, int statement_position, |
| 8598 | Handle<Object> break_point_object); |
| 8599 | // Get the break point objects for a code position. |
| 8600 | Object* GetBreakPointObjects(int code_position); |
| 8601 | // Find the break point info holding this break point object. |
| 8602 | static Object* FindBreakPointInfo(Handle<DebugInfo> debug_info, |
| 8603 | Handle<Object> break_point_object); |
| 8604 | // Get the number of break points for this function. |
| 8605 | int GetBreakPointCount(); |
| 8606 | |
| 8607 | static inline DebugInfo* cast(Object* obj); |
| 8608 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8609 | #ifdef OBJECT_PRINT |
| 8610 | inline void DebugInfoPrint() { |
| 8611 | DebugInfoPrint(stdout); |
| 8612 | } |
| 8613 | void DebugInfoPrint(FILE* out); |
| 8614 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8615 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8616 | void DebugInfoVerify(); |
| 8617 | #endif |
| 8618 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 8619 | static const int kSharedFunctionInfoIndex = Struct::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8620 | static const int kOriginalCodeIndex = kSharedFunctionInfoIndex + kPointerSize; |
| 8621 | static const int kPatchedCodeIndex = kOriginalCodeIndex + kPointerSize; |
| 8622 | static const int kActiveBreakPointsCountIndex = |
| 8623 | kPatchedCodeIndex + kPointerSize; |
| 8624 | static const int kBreakPointsStateIndex = |
| 8625 | kActiveBreakPointsCountIndex + kPointerSize; |
| 8626 | static const int kSize = kBreakPointsStateIndex + kPointerSize; |
| 8627 | |
| 8628 | private: |
| 8629 | static const int kNoBreakPointInfo = -1; |
| 8630 | |
| 8631 | // Lookup the index in the break_points array for a code position. |
| 8632 | int GetBreakPointInfoIndex(int code_position); |
| 8633 | |
| 8634 | DISALLOW_IMPLICIT_CONSTRUCTORS(DebugInfo); |
| 8635 | }; |
| 8636 | |
| 8637 | |
| 8638 | // The BreakPointInfo class holds information for break points set in a |
| 8639 | // function. The DebugInfo object holds a BreakPointInfo object for each code |
| 8640 | // position with one or more break points. |
| 8641 | class BreakPointInfo: public Struct { |
| 8642 | public: |
| 8643 | // The position in the code for the break point. |
| 8644 | DECL_ACCESSORS(code_position, Smi) |
| 8645 | // The position in the source for the break position. |
| 8646 | DECL_ACCESSORS(source_position, Smi) |
| 8647 | // The position in the source for the last statement before this break |
| 8648 | // position. |
| 8649 | DECL_ACCESSORS(statement_position, Smi) |
| 8650 | // List of related JavaScript break points. |
| 8651 | DECL_ACCESSORS(break_point_objects, Object) |
| 8652 | |
| 8653 | // Removes a break point. |
| 8654 | static void ClearBreakPoint(Handle<BreakPointInfo> info, |
| 8655 | Handle<Object> break_point_object); |
| 8656 | // Set a break point. |
| 8657 | static void SetBreakPoint(Handle<BreakPointInfo> info, |
| 8658 | Handle<Object> break_point_object); |
| 8659 | // Check if break point info has this break point object. |
| 8660 | static bool HasBreakPointObject(Handle<BreakPointInfo> info, |
| 8661 | Handle<Object> break_point_object); |
| 8662 | // Get the number of break points for this code position. |
| 8663 | int GetBreakPointCount(); |
| 8664 | |
| 8665 | static inline BreakPointInfo* cast(Object* obj); |
| 8666 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 8667 | #ifdef OBJECT_PRINT |
| 8668 | inline void BreakPointInfoPrint() { |
| 8669 | BreakPointInfoPrint(stdout); |
| 8670 | } |
| 8671 | void BreakPointInfoPrint(FILE* out); |
| 8672 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8673 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8674 | void BreakPointInfoVerify(); |
| 8675 | #endif |
| 8676 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 8677 | static const int kCodePositionIndex = Struct::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8678 | static const int kSourcePositionIndex = kCodePositionIndex + kPointerSize; |
| 8679 | static const int kStatementPositionIndex = |
| 8680 | kSourcePositionIndex + kPointerSize; |
| 8681 | static const int kBreakPointObjectsIndex = |
| 8682 | kStatementPositionIndex + kPointerSize; |
| 8683 | static const int kSize = kBreakPointObjectsIndex + kPointerSize; |
| 8684 | |
| 8685 | private: |
| 8686 | DISALLOW_IMPLICIT_CONSTRUCTORS(BreakPointInfo); |
| 8687 | }; |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 8688 | #endif // ENABLE_DEBUGGER_SUPPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8689 | |
| 8690 | |
| 8691 | #undef DECL_BOOLEAN_ACCESSORS |
| 8692 | #undef DECL_ACCESSORS |
| 8693 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 8694 | #define VISITOR_SYNCHRONIZATION_TAGS_LIST(V) \ |
| 8695 | V(kSymbolTable, "symbol_table", "(Symbols)") \ |
| 8696 | V(kExternalStringsTable, "external_strings_table", "(External strings)") \ |
| 8697 | V(kStrongRootList, "strong_root_list", "(Strong roots)") \ |
| 8698 | V(kSymbol, "symbol", "(Symbol)") \ |
| 8699 | V(kBootstrapper, "bootstrapper", "(Bootstrapper)") \ |
| 8700 | V(kTop, "top", "(Isolate)") \ |
| 8701 | V(kRelocatable, "relocatable", "(Relocatable)") \ |
| 8702 | V(kDebug, "debug", "(Debugger)") \ |
| 8703 | V(kCompilationCache, "compilationcache", "(Compilation cache)") \ |
| 8704 | V(kHandleScope, "handlescope", "(Handle scope)") \ |
| 8705 | V(kBuiltins, "builtins", "(Builtins)") \ |
| 8706 | V(kGlobalHandles, "globalhandles", "(Global handles)") \ |
| 8707 | V(kThreadManager, "threadmanager", "(Thread manager)") \ |
| 8708 | V(kExtensions, "Extensions", "(Extensions)") |
| 8709 | |
| 8710 | class VisitorSynchronization : public AllStatic { |
| 8711 | public: |
| 8712 | #define DECLARE_ENUM(enum_item, ignore1, ignore2) enum_item, |
| 8713 | enum SyncTag { |
| 8714 | VISITOR_SYNCHRONIZATION_TAGS_LIST(DECLARE_ENUM) |
| 8715 | kNumberOfSyncTags |
| 8716 | }; |
| 8717 | #undef DECLARE_ENUM |
| 8718 | |
| 8719 | static const char* const kTags[kNumberOfSyncTags]; |
| 8720 | static const char* const kTagNames[kNumberOfSyncTags]; |
| 8721 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8722 | |
| 8723 | // Abstract base class for visiting, and optionally modifying, the |
| 8724 | // pointers contained in Objects. Used in GC and serialization/deserialization. |
| 8725 | class ObjectVisitor BASE_EMBEDDED { |
| 8726 | public: |
| 8727 | virtual ~ObjectVisitor() {} |
| 8728 | |
| 8729 | // Visits a contiguous arrays of pointers in the half-open range |
| 8730 | // [start, end). Any or all of the values may be modified on return. |
| 8731 | virtual void VisitPointers(Object** start, Object** end) = 0; |
| 8732 | |
| 8733 | // To allow lazy clearing of inline caches the visitor has |
| 8734 | // a rich interface for iterating over Code objects.. |
| 8735 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8736 | // Visits a code target in the instruction stream. |
| 8737 | virtual void VisitCodeTarget(RelocInfo* rinfo); |
| 8738 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 8739 | // Visits a code entry in a JS function. |
| 8740 | virtual void VisitCodeEntry(Address entry_address); |
| 8741 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 8742 | // Visits a global property cell reference in the instruction stream. |
| 8743 | virtual void VisitGlobalPropertyCell(RelocInfo* rinfo); |
| 8744 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8745 | // Visits a runtime entry in the instruction stream. |
| 8746 | virtual void VisitRuntimeEntry(RelocInfo* rinfo) {} |
| 8747 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 8748 | // Visits the resource of an ASCII or two-byte string. |
| 8749 | virtual void VisitExternalAsciiString( |
| 8750 | v8::String::ExternalAsciiStringResource** resource) {} |
| 8751 | virtual void VisitExternalTwoByteString( |
| 8752 | v8::String::ExternalStringResource** resource) {} |
| 8753 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8754 | // Visits a debug call target in the instruction stream. |
| 8755 | virtual void VisitDebugTarget(RelocInfo* rinfo); |
| 8756 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8757 | // Handy shorthand for visiting a single pointer. |
| 8758 | virtual void VisitPointer(Object** p) { VisitPointers(p, p + 1); } |
| 8759 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 8760 | // Visit pointer embedded into a code object. |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 8761 | virtual void VisitEmbeddedPointer(RelocInfo* rinfo); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 8762 | |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 8763 | virtual void VisitSharedFunctionInfo(SharedFunctionInfo* shared) {} |
| 8764 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8765 | // Visits a contiguous arrays of external references (references to the C++ |
| 8766 | // heap) in the half-open range [start, end). Any or all of the values |
| 8767 | // may be modified on return. |
| 8768 | virtual void VisitExternalReferences(Address* start, Address* end) {} |
| 8769 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 8770 | virtual void VisitExternalReference(RelocInfo* rinfo); |
| 8771 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8772 | inline void VisitExternalReference(Address* p) { |
| 8773 | VisitExternalReferences(p, p + 1); |
| 8774 | } |
| 8775 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 8776 | // Visits a handle that has an embedder-assigned class ID. |
| 8777 | virtual void VisitEmbedderReference(Object** p, uint16_t class_id) {} |
| 8778 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8779 | // Intended for serialization/deserialization checking: insert, or |
| 8780 | // 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] | 8781 | // Also used for marking up GC roots in heap snapshots. |
| 8782 | virtual void Synchronize(VisitorSynchronization::SyncTag tag) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8783 | }; |
| 8784 | |
| 8785 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 8786 | class StructBodyDescriptor : public |
| 8787 | FlexibleBodyDescriptor<HeapObject::kHeaderSize> { |
| 8788 | public: |
| 8789 | static inline int SizeOf(Map* map, HeapObject* object) { |
| 8790 | return map->instance_size(); |
| 8791 | } |
| 8792 | }; |
| 8793 | |
| 8794 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 8795 | // BooleanBit is a helper class for setting and getting a bit in an |
| 8796 | // integer or Smi. |
| 8797 | class BooleanBit : public AllStatic { |
| 8798 | public: |
| 8799 | static inline bool get(Smi* smi, int bit_position) { |
| 8800 | return get(smi->value(), bit_position); |
| 8801 | } |
| 8802 | |
| 8803 | static inline bool get(int value, int bit_position) { |
| 8804 | return (value & (1 << bit_position)) != 0; |
| 8805 | } |
| 8806 | |
| 8807 | static inline Smi* set(Smi* smi, int bit_position, bool v) { |
| 8808 | return Smi::FromInt(set(smi->value(), bit_position, v)); |
| 8809 | } |
| 8810 | |
| 8811 | static inline int set(int value, int bit_position, bool v) { |
| 8812 | if (v) { |
| 8813 | value |= (1 << bit_position); |
| 8814 | } else { |
| 8815 | value &= ~(1 << bit_position); |
| 8816 | } |
| 8817 | return value; |
| 8818 | } |
| 8819 | }; |
| 8820 | |
| 8821 | } } // namespace v8::internal |
| 8822 | |
| 8823 | #endif // V8_OBJECTS_H_ |