kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1 | // Copyright 2011 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 | // Review notes: |
| 29 | // |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 30 | // - The use of macros in these inline functions may seem superfluous |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 31 | // but it is absolutely needed to make sure gcc generates optimal |
| 32 | // code. gcc is not happy when attempting to inline too deep. |
| 33 | // |
| 34 | |
| 35 | #ifndef V8_OBJECTS_INL_H_ |
| 36 | #define V8_OBJECTS_INL_H_ |
| 37 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 38 | #include "elements.h" |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 39 | #include "objects.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 40 | #include "contexts.h" |
| 41 | #include "conversions-inl.h" |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 42 | #include "heap.h" |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 43 | #include "isolate.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 44 | #include "property.h" |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 45 | #include "spaces.h" |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 46 | #include "store-buffer.h" |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 47 | #include "v8memory.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 48 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 49 | #include "incremental-marking.h" |
| 50 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 51 | namespace v8 { |
| 52 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 53 | |
| 54 | PropertyDetails::PropertyDetails(Smi* smi) { |
| 55 | value_ = smi->value(); |
| 56 | } |
| 57 | |
| 58 | |
| 59 | Smi* PropertyDetails::AsSmi() { |
| 60 | return Smi::FromInt(value_); |
| 61 | } |
| 62 | |
| 63 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 64 | PropertyDetails PropertyDetails::AsDeleted() { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 65 | Smi* smi = Smi::FromInt(value_ | DeletedField::encode(1)); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 66 | return PropertyDetails(smi); |
| 67 | } |
| 68 | |
| 69 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 70 | #define TYPE_CHECKER(type, instancetype) \ |
| 71 | bool Object::Is##type() { \ |
| 72 | return Object::IsHeapObject() && \ |
| 73 | HeapObject::cast(this)->map()->instance_type() == instancetype; \ |
| 74 | } |
| 75 | |
| 76 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 77 | #define CAST_ACCESSOR(type) \ |
| 78 | type* type::cast(Object* object) { \ |
| 79 | ASSERT(object->Is##type()); \ |
| 80 | return reinterpret_cast<type*>(object); \ |
| 81 | } |
| 82 | |
| 83 | |
| 84 | #define INT_ACCESSORS(holder, name, offset) \ |
| 85 | int holder::name() { return READ_INT_FIELD(this, offset); } \ |
| 86 | void holder::set_##name(int value) { WRITE_INT_FIELD(this, offset, value); } |
| 87 | |
| 88 | |
| 89 | #define ACCESSORS(holder, name, type, offset) \ |
| 90 | type* holder::name() { return type::cast(READ_FIELD(this, offset)); } \ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 91 | void holder::set_##name(type* value, WriteBarrierMode mode) { \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 92 | WRITE_FIELD(this, offset, value); \ |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 93 | CONDITIONAL_WRITE_BARRIER(GetHeap(), this, offset, value, mode); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | |
| 97 | #define SMI_ACCESSORS(holder, name, offset) \ |
| 98 | int holder::name() { \ |
| 99 | Object* value = READ_FIELD(this, offset); \ |
| 100 | return Smi::cast(value)->value(); \ |
| 101 | } \ |
| 102 | void holder::set_##name(int value) { \ |
| 103 | WRITE_FIELD(this, offset, Smi::FromInt(value)); \ |
| 104 | } |
| 105 | |
| 106 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 107 | #define BOOL_GETTER(holder, field, name, offset) \ |
| 108 | bool holder::name() { \ |
| 109 | return BooleanBit::get(field(), offset); \ |
| 110 | } \ |
| 111 | |
| 112 | |
| 113 | #define BOOL_ACCESSORS(holder, field, name, offset) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 114 | bool holder::name() { \ |
| 115 | return BooleanBit::get(field(), offset); \ |
| 116 | } \ |
| 117 | void holder::set_##name(bool value) { \ |
| 118 | set_##field(BooleanBit::set(field(), offset, value)); \ |
| 119 | } |
| 120 | |
| 121 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 122 | bool Object::IsFixedArrayBase() { |
| 123 | return IsFixedArray() || IsFixedDoubleArray(); |
| 124 | } |
| 125 | |
| 126 | |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 127 | bool Object::IsInstanceOf(FunctionTemplateInfo* expected) { |
| 128 | // There is a constraint on the object; check. |
| 129 | if (!this->IsJSObject()) return false; |
| 130 | // Fetch the constructor function of the object. |
| 131 | Object* cons_obj = JSObject::cast(this)->map()->constructor(); |
| 132 | if (!cons_obj->IsJSFunction()) return false; |
| 133 | JSFunction* fun = JSFunction::cast(cons_obj); |
| 134 | // Iterate through the chain of inheriting function templates to |
| 135 | // see if the required one occurs. |
| 136 | for (Object* type = fun->shared()->function_data(); |
| 137 | type->IsFunctionTemplateInfo(); |
| 138 | type = FunctionTemplateInfo::cast(type)->parent_template()) { |
| 139 | if (type == expected) return true; |
| 140 | } |
| 141 | // Didn't find the required type in the inheritance chain. |
| 142 | return false; |
| 143 | } |
| 144 | |
| 145 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 146 | bool Object::IsSmi() { |
| 147 | return HAS_SMI_TAG(this); |
| 148 | } |
| 149 | |
| 150 | |
| 151 | bool Object::IsHeapObject() { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 152 | return Internals::HasHeapObjectTag(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 156 | bool Object::NonFailureIsHeapObject() { |
| 157 | ASSERT(!this->IsFailure()); |
| 158 | return (reinterpret_cast<intptr_t>(this) & kSmiTagMask) != 0; |
| 159 | } |
| 160 | |
| 161 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 162 | TYPE_CHECKER(HeapNumber, HEAP_NUMBER_TYPE) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 163 | |
| 164 | |
| 165 | bool Object::IsString() { |
| 166 | return Object::IsHeapObject() |
| 167 | && HeapObject::cast(this)->map()->instance_type() < FIRST_NONSTRING_TYPE; |
| 168 | } |
| 169 | |
| 170 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 171 | bool Object::IsSpecObject() { |
| 172 | return Object::IsHeapObject() |
| 173 | && HeapObject::cast(this)->map()->instance_type() >= FIRST_SPEC_OBJECT_TYPE; |
| 174 | } |
| 175 | |
| 176 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 177 | bool Object::IsSpecFunction() { |
| 178 | if (!Object::IsHeapObject()) return false; |
| 179 | InstanceType type = HeapObject::cast(this)->map()->instance_type(); |
| 180 | return type == JS_FUNCTION_TYPE || type == JS_FUNCTION_PROXY_TYPE; |
| 181 | } |
| 182 | |
| 183 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 184 | bool Object::IsSymbol() { |
| 185 | if (!this->IsHeapObject()) return false; |
| 186 | uint32_t type = HeapObject::cast(this)->map()->instance_type(); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 187 | // Because the symbol tag is non-zero and no non-string types have the |
| 188 | // symbol bit set we can test for symbols with a very simple test |
| 189 | // operation. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 190 | STATIC_ASSERT(kSymbolTag != 0); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 191 | ASSERT(kNotStringTag + kIsSymbolMask > LAST_TYPE); |
| 192 | return (type & kIsSymbolMask) != 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | |
| 196 | bool Object::IsConsString() { |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 197 | if (!IsString()) return false; |
| 198 | return StringShape(String::cast(this)).IsCons(); |
| 199 | } |
| 200 | |
| 201 | |
| 202 | bool Object::IsSlicedString() { |
| 203 | if (!IsString()) return false; |
| 204 | return StringShape(String::cast(this)).IsSliced(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 208 | bool Object::IsSeqString() { |
| 209 | if (!IsString()) return false; |
| 210 | return StringShape(String::cast(this)).IsSequential(); |
| 211 | } |
| 212 | |
| 213 | |
| 214 | bool Object::IsSeqAsciiString() { |
| 215 | if (!IsString()) return false; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 216 | return StringShape(String::cast(this)).IsSequential() && |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 217 | String::cast(this)->IsAsciiRepresentation(); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | |
| 221 | bool Object::IsSeqTwoByteString() { |
| 222 | if (!IsString()) return false; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 223 | return StringShape(String::cast(this)).IsSequential() && |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 224 | String::cast(this)->IsTwoByteRepresentation(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | |
| 228 | bool Object::IsExternalString() { |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 229 | if (!IsString()) return false; |
| 230 | return StringShape(String::cast(this)).IsExternal(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | |
| 234 | bool Object::IsExternalAsciiString() { |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 235 | if (!IsString()) return false; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 236 | return StringShape(String::cast(this)).IsExternal() && |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 237 | String::cast(this)->IsAsciiRepresentation(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | |
| 241 | bool Object::IsExternalTwoByteString() { |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 242 | if (!IsString()) return false; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 243 | return StringShape(String::cast(this)).IsExternal() && |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 244 | String::cast(this)->IsTwoByteRepresentation(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 245 | } |
| 246 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 247 | bool Object::HasValidElements() { |
| 248 | // Dictionary is covered under FixedArray. |
| 249 | return IsFixedArray() || IsFixedDoubleArray() || IsExternalArray(); |
| 250 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 251 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 252 | StringShape::StringShape(String* str) |
| 253 | : type_(str->map()->instance_type()) { |
| 254 | set_valid(); |
| 255 | ASSERT((type_ & kIsNotStringMask) == kStringTag); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 259 | StringShape::StringShape(Map* map) |
| 260 | : type_(map->instance_type()) { |
| 261 | set_valid(); |
| 262 | ASSERT((type_ & kIsNotStringMask) == kStringTag); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 266 | StringShape::StringShape(InstanceType t) |
| 267 | : type_(static_cast<uint32_t>(t)) { |
| 268 | set_valid(); |
| 269 | ASSERT((type_ & kIsNotStringMask) == kStringTag); |
| 270 | } |
| 271 | |
| 272 | |
| 273 | bool StringShape::IsSymbol() { |
| 274 | ASSERT(valid()); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 275 | STATIC_ASSERT(kSymbolTag != 0); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 276 | return (type_ & kIsSymbolMask) != 0; |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 280 | bool String::IsAsciiRepresentation() { |
| 281 | uint32_t type = map()->instance_type(); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 282 | return (type & kStringEncodingMask) == kAsciiStringTag; |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 286 | bool String::IsTwoByteRepresentation() { |
| 287 | uint32_t type = map()->instance_type(); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 288 | return (type & kStringEncodingMask) == kTwoByteStringTag; |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 292 | bool String::IsAsciiRepresentationUnderneath() { |
| 293 | uint32_t type = map()->instance_type(); |
| 294 | STATIC_ASSERT(kIsIndirectStringTag != 0); |
| 295 | STATIC_ASSERT((kIsIndirectStringMask & kStringEncodingMask) == 0); |
| 296 | ASSERT(IsFlat()); |
| 297 | switch (type & (kIsIndirectStringMask | kStringEncodingMask)) { |
| 298 | case kAsciiStringTag: |
| 299 | return true; |
| 300 | case kTwoByteStringTag: |
| 301 | return false; |
| 302 | default: // Cons or sliced string. Need to go deeper. |
| 303 | return GetUnderlying()->IsAsciiRepresentation(); |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | |
| 308 | bool String::IsTwoByteRepresentationUnderneath() { |
| 309 | uint32_t type = map()->instance_type(); |
| 310 | STATIC_ASSERT(kIsIndirectStringTag != 0); |
| 311 | STATIC_ASSERT((kIsIndirectStringMask & kStringEncodingMask) == 0); |
| 312 | ASSERT(IsFlat()); |
| 313 | switch (type & (kIsIndirectStringMask | kStringEncodingMask)) { |
| 314 | case kAsciiStringTag: |
| 315 | return false; |
| 316 | case kTwoByteStringTag: |
| 317 | return true; |
| 318 | default: // Cons or sliced string. Need to go deeper. |
| 319 | return GetUnderlying()->IsTwoByteRepresentation(); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 324 | bool String::HasOnlyAsciiChars() { |
| 325 | uint32_t type = map()->instance_type(); |
| 326 | return (type & kStringEncodingMask) == kAsciiStringTag || |
| 327 | (type & kAsciiDataHintMask) == kAsciiDataHintTag; |
ricow@chromium.org | aa1b616 | 2010-03-29 07:44:58 +0000 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 331 | bool StringShape::IsCons() { |
| 332 | return (type_ & kStringRepresentationMask) == kConsStringTag; |
| 333 | } |
| 334 | |
| 335 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 336 | bool StringShape::IsSliced() { |
| 337 | return (type_ & kStringRepresentationMask) == kSlicedStringTag; |
| 338 | } |
| 339 | |
| 340 | |
| 341 | bool StringShape::IsIndirect() { |
| 342 | return (type_ & kIsIndirectStringMask) == kIsIndirectStringTag; |
| 343 | } |
| 344 | |
| 345 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 346 | bool StringShape::IsExternal() { |
| 347 | return (type_ & kStringRepresentationMask) == kExternalStringTag; |
| 348 | } |
| 349 | |
| 350 | |
| 351 | bool StringShape::IsSequential() { |
| 352 | return (type_ & kStringRepresentationMask) == kSeqStringTag; |
| 353 | } |
| 354 | |
| 355 | |
| 356 | StringRepresentationTag StringShape::representation_tag() { |
| 357 | uint32_t tag = (type_ & kStringRepresentationMask); |
| 358 | return static_cast<StringRepresentationTag>(tag); |
| 359 | } |
| 360 | |
| 361 | |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 362 | uint32_t StringShape::encoding_tag() { |
| 363 | return type_ & kStringEncodingMask; |
| 364 | } |
| 365 | |
| 366 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 367 | uint32_t StringShape::full_representation_tag() { |
| 368 | return (type_ & (kStringRepresentationMask | kStringEncodingMask)); |
| 369 | } |
| 370 | |
| 371 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 372 | STATIC_CHECK((kStringRepresentationMask | kStringEncodingMask) == |
| 373 | Internals::kFullStringRepresentationMask); |
| 374 | |
| 375 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 376 | bool StringShape::IsSequentialAscii() { |
| 377 | return full_representation_tag() == (kSeqStringTag | kAsciiStringTag); |
| 378 | } |
| 379 | |
| 380 | |
| 381 | bool StringShape::IsSequentialTwoByte() { |
ager@chromium.org | 80787b7 | 2009-04-17 10:24:24 +0000 | [diff] [blame] | 382 | return full_representation_tag() == (kSeqStringTag | kTwoByteStringTag); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | |
| 386 | bool StringShape::IsExternalAscii() { |
| 387 | return full_representation_tag() == (kExternalStringTag | kAsciiStringTag); |
| 388 | } |
| 389 | |
| 390 | |
| 391 | bool StringShape::IsExternalTwoByte() { |
ager@chromium.org | 80787b7 | 2009-04-17 10:24:24 +0000 | [diff] [blame] | 392 | return full_representation_tag() == (kExternalStringTag | kTwoByteStringTag); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 396 | STATIC_CHECK((kExternalStringTag | kTwoByteStringTag) == |
| 397 | Internals::kExternalTwoByteRepresentationTag); |
| 398 | |
| 399 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 400 | uc32 FlatStringReader::Get(int index) { |
| 401 | ASSERT(0 <= index && index <= length_); |
| 402 | if (is_ascii_) { |
| 403 | return static_cast<const byte*>(start_)[index]; |
| 404 | } else { |
| 405 | return static_cast<const uc16*>(start_)[index]; |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 410 | bool Object::IsNumber() { |
| 411 | return IsSmi() || IsHeapNumber(); |
| 412 | } |
| 413 | |
| 414 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 415 | TYPE_CHECKER(ByteArray, BYTE_ARRAY_TYPE) |
| 416 | TYPE_CHECKER(FreeSpace, FREE_SPACE_TYPE) |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 417 | |
| 418 | |
| 419 | bool Object::IsFiller() { |
| 420 | if (!Object::IsHeapObject()) return false; |
| 421 | InstanceType instance_type = HeapObject::cast(this)->map()->instance_type(); |
| 422 | return instance_type == FREE_SPACE_TYPE || instance_type == FILLER_TYPE; |
| 423 | } |
| 424 | |
| 425 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 426 | TYPE_CHECKER(ExternalPixelArray, EXTERNAL_PIXEL_ARRAY_TYPE) |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 427 | |
| 428 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 429 | bool Object::IsExternalArray() { |
| 430 | if (!Object::IsHeapObject()) |
| 431 | return false; |
| 432 | InstanceType instance_type = |
| 433 | HeapObject::cast(this)->map()->instance_type(); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 434 | return (instance_type >= FIRST_EXTERNAL_ARRAY_TYPE && |
| 435 | instance_type <= LAST_EXTERNAL_ARRAY_TYPE); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 439 | TYPE_CHECKER(ExternalByteArray, EXTERNAL_BYTE_ARRAY_TYPE) |
| 440 | TYPE_CHECKER(ExternalUnsignedByteArray, EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE) |
| 441 | TYPE_CHECKER(ExternalShortArray, EXTERNAL_SHORT_ARRAY_TYPE) |
| 442 | TYPE_CHECKER(ExternalUnsignedShortArray, EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE) |
| 443 | TYPE_CHECKER(ExternalIntArray, EXTERNAL_INT_ARRAY_TYPE) |
| 444 | TYPE_CHECKER(ExternalUnsignedIntArray, EXTERNAL_UNSIGNED_INT_ARRAY_TYPE) |
| 445 | TYPE_CHECKER(ExternalFloatArray, EXTERNAL_FLOAT_ARRAY_TYPE) |
| 446 | TYPE_CHECKER(ExternalDoubleArray, EXTERNAL_DOUBLE_ARRAY_TYPE) |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 447 | |
| 448 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 449 | bool MaybeObject::IsFailure() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 450 | return HAS_FAILURE_TAG(this); |
| 451 | } |
| 452 | |
| 453 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 454 | bool MaybeObject::IsRetryAfterGC() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 455 | return HAS_FAILURE_TAG(this) |
| 456 | && Failure::cast(this)->type() == Failure::RETRY_AFTER_GC; |
| 457 | } |
| 458 | |
| 459 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 460 | bool MaybeObject::IsOutOfMemory() { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 461 | return HAS_FAILURE_TAG(this) |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 462 | && Failure::cast(this)->IsOutOfMemoryException(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 466 | bool MaybeObject::IsException() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 467 | return this == Failure::Exception(); |
| 468 | } |
| 469 | |
| 470 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 471 | bool MaybeObject::IsTheHole() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 472 | return !IsFailure() && ToObjectUnchecked()->IsTheHole(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | |
| 476 | Failure* Failure::cast(MaybeObject* obj) { |
| 477 | ASSERT(HAS_FAILURE_TAG(obj)); |
| 478 | return reinterpret_cast<Failure*>(obj); |
| 479 | } |
| 480 | |
| 481 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 482 | bool Object::IsJSReceiver() { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 483 | STATIC_ASSERT(LAST_JS_RECEIVER_TYPE == LAST_TYPE); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 484 | return IsHeapObject() && |
| 485 | HeapObject::cast(this)->map()->instance_type() >= FIRST_JS_RECEIVER_TYPE; |
| 486 | } |
| 487 | |
| 488 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 489 | bool Object::IsJSObject() { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 490 | STATIC_ASSERT(LAST_JS_OBJECT_TYPE == LAST_TYPE); |
| 491 | return IsHeapObject() && |
| 492 | HeapObject::cast(this)->map()->instance_type() >= FIRST_JS_OBJECT_TYPE; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | |
| 496 | bool Object::IsJSProxy() { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 497 | if (!Object::IsHeapObject()) return false; |
| 498 | InstanceType type = HeapObject::cast(this)->map()->instance_type(); |
| 499 | return FIRST_JS_PROXY_TYPE <= type && type <= LAST_JS_PROXY_TYPE; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 503 | TYPE_CHECKER(JSFunctionProxy, JS_FUNCTION_PROXY_TYPE) |
| 504 | TYPE_CHECKER(JSSet, JS_SET_TYPE) |
| 505 | TYPE_CHECKER(JSMap, JS_MAP_TYPE) |
| 506 | TYPE_CHECKER(JSWeakMap, JS_WEAK_MAP_TYPE) |
| 507 | TYPE_CHECKER(JSContextExtensionObject, JS_CONTEXT_EXTENSION_OBJECT_TYPE) |
| 508 | TYPE_CHECKER(Map, MAP_TYPE) |
| 509 | TYPE_CHECKER(FixedArray, FIXED_ARRAY_TYPE) |
| 510 | TYPE_CHECKER(FixedDoubleArray, FIXED_DOUBLE_ARRAY_TYPE) |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 511 | |
| 512 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 513 | bool Object::IsDescriptorArray() { |
| 514 | return IsFixedArray(); |
| 515 | } |
| 516 | |
| 517 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 518 | bool Object::IsDeoptimizationInputData() { |
| 519 | // Must be a fixed array. |
| 520 | if (!IsFixedArray()) return false; |
| 521 | |
| 522 | // There's no sure way to detect the difference between a fixed array and |
| 523 | // a deoptimization data array. Since this is used for asserts we can |
| 524 | // check that the length is zero or else the fixed size plus a multiple of |
| 525 | // the entry size. |
| 526 | int length = FixedArray::cast(this)->length(); |
| 527 | if (length == 0) return true; |
| 528 | |
| 529 | length -= DeoptimizationInputData::kFirstDeoptEntryIndex; |
| 530 | return length >= 0 && |
| 531 | length % DeoptimizationInputData::kDeoptEntrySize == 0; |
| 532 | } |
| 533 | |
| 534 | |
| 535 | bool Object::IsDeoptimizationOutputData() { |
| 536 | if (!IsFixedArray()) return false; |
| 537 | // There's actually no way to see the difference between a fixed array and |
| 538 | // a deoptimization data array. Since this is used for asserts we can check |
| 539 | // that the length is plausible though. |
| 540 | if (FixedArray::cast(this)->length() % 2 != 0) return false; |
| 541 | return true; |
| 542 | } |
| 543 | |
| 544 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 545 | bool Object::IsContext() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 546 | if (Object::IsHeapObject()) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 547 | Map* map = HeapObject::cast(this)->map(); |
| 548 | Heap* heap = map->GetHeap(); |
| 549 | return (map == heap->function_context_map() || |
| 550 | map == heap->catch_context_map() || |
| 551 | map == heap->with_context_map() || |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 552 | map == heap->global_context_map() || |
| 553 | map == heap->block_context_map()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 554 | } |
| 555 | return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | |
| 559 | bool Object::IsGlobalContext() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 560 | return Object::IsHeapObject() && |
| 561 | HeapObject::cast(this)->map() == |
| 562 | HeapObject::cast(this)->GetHeap()->global_context_map(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame^] | 566 | bool Object::IsScopeInfo() { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 567 | return Object::IsHeapObject() && |
| 568 | HeapObject::cast(this)->map() == |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame^] | 569 | HeapObject::cast(this)->GetHeap()->scope_info_map(); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 573 | TYPE_CHECKER(JSFunction, JS_FUNCTION_TYPE) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 574 | |
| 575 | |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 576 | template <> inline bool Is<JSFunction>(Object* obj) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 577 | return obj->IsJSFunction(); |
| 578 | } |
| 579 | |
| 580 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 581 | TYPE_CHECKER(Code, CODE_TYPE) |
| 582 | TYPE_CHECKER(Oddball, ODDBALL_TYPE) |
| 583 | TYPE_CHECKER(JSGlobalPropertyCell, JS_GLOBAL_PROPERTY_CELL_TYPE) |
| 584 | TYPE_CHECKER(SharedFunctionInfo, SHARED_FUNCTION_INFO_TYPE) |
| 585 | TYPE_CHECKER(JSValue, JS_VALUE_TYPE) |
| 586 | TYPE_CHECKER(JSMessageObject, JS_MESSAGE_OBJECT_TYPE) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 587 | |
| 588 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 589 | bool Object::IsStringWrapper() { |
| 590 | return IsJSValue() && JSValue::cast(this)->value()->IsString(); |
| 591 | } |
| 592 | |
| 593 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 594 | TYPE_CHECKER(Foreign, FOREIGN_TYPE) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 595 | |
| 596 | |
| 597 | bool Object::IsBoolean() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 598 | return IsOddball() && |
| 599 | ((Oddball::cast(this)->kind() & Oddball::kNotBooleanMask) == 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 603 | TYPE_CHECKER(JSArray, JS_ARRAY_TYPE) |
| 604 | TYPE_CHECKER(JSRegExp, JS_REGEXP_TYPE) |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 605 | |
| 606 | |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 607 | template <> inline bool Is<JSArray>(Object* obj) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 608 | return obj->IsJSArray(); |
| 609 | } |
| 610 | |
| 611 | |
| 612 | bool Object::IsHashTable() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 613 | return Object::IsHeapObject() && |
| 614 | HeapObject::cast(this)->map() == |
| 615 | HeapObject::cast(this)->GetHeap()->hash_table_map(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | |
| 619 | bool Object::IsDictionary() { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 620 | return IsHashTable() && |
| 621 | this != HeapObject::cast(this)->GetHeap()->symbol_table(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | |
| 625 | bool Object::IsSymbolTable() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 626 | return IsHashTable() && this == |
| 627 | HeapObject::cast(this)->GetHeap()->raw_unchecked_symbol_table(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 631 | bool Object::IsJSFunctionResultCache() { |
| 632 | if (!IsFixedArray()) return false; |
| 633 | FixedArray* self = FixedArray::cast(this); |
| 634 | int length = self->length(); |
| 635 | if (length < JSFunctionResultCache::kEntriesIndex) return false; |
| 636 | if ((length - JSFunctionResultCache::kEntriesIndex) |
| 637 | % JSFunctionResultCache::kEntrySize != 0) { |
| 638 | return false; |
| 639 | } |
| 640 | #ifdef DEBUG |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 641 | if (FLAG_verify_heap) { |
| 642 | reinterpret_cast<JSFunctionResultCache*>(this)-> |
| 643 | JSFunctionResultCacheVerify(); |
| 644 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 645 | #endif |
| 646 | return true; |
| 647 | } |
| 648 | |
| 649 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 650 | bool Object::IsNormalizedMapCache() { |
| 651 | if (!IsFixedArray()) return false; |
| 652 | if (FixedArray::cast(this)->length() != NormalizedMapCache::kEntries) { |
| 653 | return false; |
| 654 | } |
| 655 | #ifdef DEBUG |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 656 | if (FLAG_verify_heap) { |
| 657 | reinterpret_cast<NormalizedMapCache*>(this)->NormalizedMapCacheVerify(); |
| 658 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 659 | #endif |
| 660 | return true; |
| 661 | } |
| 662 | |
| 663 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 664 | bool Object::IsCompilationCacheTable() { |
| 665 | return IsHashTable(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 669 | bool Object::IsCodeCacheHashTable() { |
| 670 | return IsHashTable(); |
| 671 | } |
| 672 | |
| 673 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 674 | bool Object::IsPolymorphicCodeCacheHashTable() { |
| 675 | return IsHashTable(); |
| 676 | } |
| 677 | |
| 678 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 679 | bool Object::IsMapCache() { |
| 680 | return IsHashTable(); |
| 681 | } |
| 682 | |
| 683 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 684 | bool Object::IsPrimitive() { |
| 685 | return IsOddball() || IsNumber() || IsString(); |
| 686 | } |
| 687 | |
| 688 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 689 | bool Object::IsJSGlobalProxy() { |
| 690 | bool result = IsHeapObject() && |
| 691 | (HeapObject::cast(this)->map()->instance_type() == |
| 692 | JS_GLOBAL_PROXY_TYPE); |
| 693 | ASSERT(!result || IsAccessCheckNeeded()); |
| 694 | return result; |
| 695 | } |
| 696 | |
| 697 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 698 | bool Object::IsGlobalObject() { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 699 | if (!IsHeapObject()) return false; |
| 700 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 701 | InstanceType type = HeapObject::cast(this)->map()->instance_type(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 702 | return type == JS_GLOBAL_OBJECT_TYPE || |
| 703 | type == JS_BUILTINS_OBJECT_TYPE; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 707 | TYPE_CHECKER(JSGlobalObject, JS_GLOBAL_OBJECT_TYPE) |
| 708 | TYPE_CHECKER(JSBuiltinsObject, JS_BUILTINS_OBJECT_TYPE) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 709 | |
| 710 | |
| 711 | bool Object::IsUndetectableObject() { |
| 712 | return IsHeapObject() |
| 713 | && HeapObject::cast(this)->map()->is_undetectable(); |
| 714 | } |
| 715 | |
| 716 | |
| 717 | bool Object::IsAccessCheckNeeded() { |
| 718 | return IsHeapObject() |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 719 | && HeapObject::cast(this)->map()->is_access_check_needed(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | |
| 723 | bool Object::IsStruct() { |
| 724 | if (!IsHeapObject()) return false; |
| 725 | switch (HeapObject::cast(this)->map()->instance_type()) { |
| 726 | #define MAKE_STRUCT_CASE(NAME, Name, name) case NAME##_TYPE: return true; |
| 727 | STRUCT_LIST(MAKE_STRUCT_CASE) |
| 728 | #undef MAKE_STRUCT_CASE |
| 729 | default: return false; |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | |
| 734 | #define MAKE_STRUCT_PREDICATE(NAME, Name, name) \ |
| 735 | bool Object::Is##Name() { \ |
| 736 | return Object::IsHeapObject() \ |
| 737 | && HeapObject::cast(this)->map()->instance_type() == NAME##_TYPE; \ |
| 738 | } |
| 739 | STRUCT_LIST(MAKE_STRUCT_PREDICATE) |
| 740 | #undef MAKE_STRUCT_PREDICATE |
| 741 | |
| 742 | |
| 743 | bool Object::IsUndefined() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 744 | return IsOddball() && Oddball::cast(this)->kind() == Oddball::kUndefined; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 748 | bool Object::IsNull() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 749 | return IsOddball() && Oddball::cast(this)->kind() == Oddball::kNull; |
| 750 | } |
| 751 | |
| 752 | |
| 753 | bool Object::IsTheHole() { |
| 754 | return IsOddball() && Oddball::cast(this)->kind() == Oddball::kTheHole; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | |
| 758 | bool Object::IsTrue() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 759 | return IsOddball() && Oddball::cast(this)->kind() == Oddball::kTrue; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | |
| 763 | bool Object::IsFalse() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 764 | return IsOddball() && Oddball::cast(this)->kind() == Oddball::kFalse; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 768 | bool Object::IsArgumentsMarker() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 769 | return IsOddball() && Oddball::cast(this)->kind() == Oddball::kArgumentMarker; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 773 | double Object::Number() { |
| 774 | ASSERT(IsNumber()); |
| 775 | return IsSmi() |
| 776 | ? static_cast<double>(reinterpret_cast<Smi*>(this)->value()) |
| 777 | : reinterpret_cast<HeapNumber*>(this)->value(); |
| 778 | } |
| 779 | |
| 780 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 781 | MaybeObject* Object::ToSmi() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 782 | if (IsSmi()) return this; |
| 783 | if (IsHeapNumber()) { |
| 784 | double value = HeapNumber::cast(this)->value(); |
| 785 | int int_value = FastD2I(value); |
| 786 | if (value == FastI2D(int_value) && Smi::IsValid(int_value)) { |
| 787 | return Smi::FromInt(int_value); |
| 788 | } |
| 789 | } |
| 790 | return Failure::Exception(); |
| 791 | } |
| 792 | |
| 793 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 794 | bool Object::HasSpecificClassOf(String* name) { |
| 795 | return this->IsJSObject() && (JSObject::cast(this)->class_name() == name); |
| 796 | } |
| 797 | |
| 798 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 799 | MaybeObject* Object::GetElement(uint32_t index) { |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 800 | // GetElement can trigger a getter which can cause allocation. |
| 801 | // This was not always the case. This ASSERT is here to catch |
| 802 | // leftover incorrect uses. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 803 | ASSERT(HEAP->IsAllocationAllowed()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 804 | return GetElementWithReceiver(this, index); |
| 805 | } |
| 806 | |
| 807 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 808 | Object* Object::GetElementNoExceptionThrown(uint32_t index) { |
| 809 | MaybeObject* maybe = GetElementWithReceiver(this, index); |
| 810 | ASSERT(!maybe->IsFailure()); |
| 811 | Object* result = NULL; // Initialization to please compiler. |
| 812 | maybe->ToObject(&result); |
| 813 | return result; |
| 814 | } |
| 815 | |
| 816 | |
| 817 | MaybeObject* Object::GetProperty(String* key) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 818 | PropertyAttributes attributes; |
| 819 | return GetPropertyWithReceiver(this, key, &attributes); |
| 820 | } |
| 821 | |
| 822 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 823 | MaybeObject* Object::GetProperty(String* key, PropertyAttributes* attributes) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 824 | return GetPropertyWithReceiver(this, key, attributes); |
| 825 | } |
| 826 | |
| 827 | |
| 828 | #define FIELD_ADDR(p, offset) \ |
| 829 | (reinterpret_cast<byte*>(p) + offset - kHeapObjectTag) |
| 830 | |
| 831 | #define READ_FIELD(p, offset) \ |
| 832 | (*reinterpret_cast<Object**>(FIELD_ADDR(p, offset))) |
| 833 | |
| 834 | #define WRITE_FIELD(p, offset, value) \ |
| 835 | (*reinterpret_cast<Object**>(FIELD_ADDR(p, offset)) = value) |
| 836 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 837 | #define WRITE_BARRIER(heap, object, offset, value) \ |
| 838 | heap->incremental_marking()->RecordWrite( \ |
| 839 | object, HeapObject::RawField(object, offset), value); \ |
| 840 | if (heap->InNewSpace(value)) { \ |
| 841 | heap->RecordWrite(object->address(), offset); \ |
| 842 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 843 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 844 | #define CONDITIONAL_WRITE_BARRIER(heap, object, offset, value, mode) \ |
| 845 | if (mode == UPDATE_WRITE_BARRIER) { \ |
| 846 | heap->incremental_marking()->RecordWrite( \ |
| 847 | object, HeapObject::RawField(object, offset), value); \ |
| 848 | if (heap->InNewSpace(value)) { \ |
| 849 | heap->RecordWrite(object->address(), offset); \ |
| 850 | } \ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 851 | } |
| 852 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 853 | #ifndef V8_TARGET_ARCH_MIPS |
| 854 | #define READ_DOUBLE_FIELD(p, offset) \ |
| 855 | (*reinterpret_cast<double*>(FIELD_ADDR(p, offset))) |
| 856 | #else // V8_TARGET_ARCH_MIPS |
| 857 | // Prevent gcc from using load-double (mips ldc1) on (possibly) |
| 858 | // non-64-bit aligned HeapNumber::value. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 859 | static inline double read_double_field(void* p, int offset) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 860 | union conversion { |
| 861 | double d; |
| 862 | uint32_t u[2]; |
| 863 | } c; |
| 864 | c.u[0] = (*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset))); |
| 865 | c.u[1] = (*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset + 4))); |
| 866 | return c.d; |
| 867 | } |
| 868 | #define READ_DOUBLE_FIELD(p, offset) read_double_field(p, offset) |
| 869 | #endif // V8_TARGET_ARCH_MIPS |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 870 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 871 | #ifndef V8_TARGET_ARCH_MIPS |
| 872 | #define WRITE_DOUBLE_FIELD(p, offset, value) \ |
| 873 | (*reinterpret_cast<double*>(FIELD_ADDR(p, offset)) = value) |
| 874 | #else // V8_TARGET_ARCH_MIPS |
| 875 | // Prevent gcc from using store-double (mips sdc1) on (possibly) |
| 876 | // non-64-bit aligned HeapNumber::value. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 877 | static inline void write_double_field(void* p, int offset, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 878 | double value) { |
| 879 | union conversion { |
| 880 | double d; |
| 881 | uint32_t u[2]; |
| 882 | } c; |
| 883 | c.d = value; |
| 884 | (*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset))) = c.u[0]; |
| 885 | (*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset + 4))) = c.u[1]; |
| 886 | } |
| 887 | #define WRITE_DOUBLE_FIELD(p, offset, value) \ |
| 888 | write_double_field(p, offset, value) |
| 889 | #endif // V8_TARGET_ARCH_MIPS |
| 890 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 891 | |
| 892 | #define READ_INT_FIELD(p, offset) \ |
| 893 | (*reinterpret_cast<int*>(FIELD_ADDR(p, offset))) |
| 894 | |
| 895 | #define WRITE_INT_FIELD(p, offset, value) \ |
| 896 | (*reinterpret_cast<int*>(FIELD_ADDR(p, offset)) = value) |
| 897 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 898 | #define READ_INTPTR_FIELD(p, offset) \ |
| 899 | (*reinterpret_cast<intptr_t*>(FIELD_ADDR(p, offset))) |
| 900 | |
| 901 | #define WRITE_INTPTR_FIELD(p, offset, value) \ |
| 902 | (*reinterpret_cast<intptr_t*>(FIELD_ADDR(p, offset)) = value) |
| 903 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 904 | #define READ_UINT32_FIELD(p, offset) \ |
| 905 | (*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset))) |
| 906 | |
| 907 | #define WRITE_UINT32_FIELD(p, offset, value) \ |
| 908 | (*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset)) = value) |
| 909 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 910 | #define READ_SHORT_FIELD(p, offset) \ |
| 911 | (*reinterpret_cast<uint16_t*>(FIELD_ADDR(p, offset))) |
| 912 | |
| 913 | #define WRITE_SHORT_FIELD(p, offset, value) \ |
| 914 | (*reinterpret_cast<uint16_t*>(FIELD_ADDR(p, offset)) = value) |
| 915 | |
| 916 | #define READ_BYTE_FIELD(p, offset) \ |
| 917 | (*reinterpret_cast<byte*>(FIELD_ADDR(p, offset))) |
| 918 | |
| 919 | #define WRITE_BYTE_FIELD(p, offset, value) \ |
| 920 | (*reinterpret_cast<byte*>(FIELD_ADDR(p, offset)) = value) |
| 921 | |
| 922 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 923 | Object** HeapObject::RawField(HeapObject* obj, int byte_offset) { |
| 924 | return &READ_FIELD(obj, byte_offset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | |
| 928 | int Smi::value() { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 929 | return Internals::SmiValue(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | |
| 933 | Smi* Smi::FromInt(int value) { |
| 934 | ASSERT(Smi::IsValid(value)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 935 | int smi_shift_bits = kSmiTagSize + kSmiShiftSize; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 936 | intptr_t tagged_value = |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 937 | (static_cast<intptr_t>(value) << smi_shift_bits) | kSmiTag; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 938 | return reinterpret_cast<Smi*>(tagged_value); |
| 939 | } |
| 940 | |
| 941 | |
| 942 | Smi* Smi::FromIntptr(intptr_t value) { |
| 943 | ASSERT(Smi::IsValid(value)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 944 | int smi_shift_bits = kSmiTagSize + kSmiShiftSize; |
| 945 | return reinterpret_cast<Smi*>((value << smi_shift_bits) | kSmiTag); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | |
| 949 | Failure::Type Failure::type() const { |
| 950 | return static_cast<Type>(value() & kFailureTypeTagMask); |
| 951 | } |
| 952 | |
| 953 | |
| 954 | bool Failure::IsInternalError() const { |
| 955 | return type() == INTERNAL_ERROR; |
| 956 | } |
| 957 | |
| 958 | |
| 959 | bool Failure::IsOutOfMemoryException() const { |
| 960 | return type() == OUT_OF_MEMORY_EXCEPTION; |
| 961 | } |
| 962 | |
| 963 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 964 | AllocationSpace Failure::allocation_space() const { |
| 965 | ASSERT_EQ(RETRY_AFTER_GC, type()); |
| 966 | return static_cast<AllocationSpace>((value() >> kFailureTypeTagSize) |
| 967 | & kSpaceTagMask); |
| 968 | } |
| 969 | |
| 970 | |
| 971 | Failure* Failure::InternalError() { |
| 972 | return Construct(INTERNAL_ERROR); |
| 973 | } |
| 974 | |
| 975 | |
| 976 | Failure* Failure::Exception() { |
| 977 | return Construct(EXCEPTION); |
| 978 | } |
| 979 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 980 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 981 | Failure* Failure::OutOfMemoryException() { |
| 982 | return Construct(OUT_OF_MEMORY_EXCEPTION); |
| 983 | } |
| 984 | |
| 985 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 986 | intptr_t Failure::value() const { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 987 | return static_cast<intptr_t>( |
| 988 | reinterpret_cast<uintptr_t>(this) >> kFailureTagSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 992 | Failure* Failure::RetryAfterGC() { |
| 993 | return RetryAfterGC(NEW_SPACE); |
| 994 | } |
| 995 | |
| 996 | |
| 997 | Failure* Failure::RetryAfterGC(AllocationSpace space) { |
| 998 | ASSERT((space & ~kSpaceTagMask) == 0); |
| 999 | return Construct(RETRY_AFTER_GC, space); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1003 | Failure* Failure::Construct(Type type, intptr_t value) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1004 | uintptr_t info = |
| 1005 | (static_cast<uintptr_t>(value) << kFailureTypeTagSize) | type; |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 1006 | ASSERT(((info << kFailureTagSize) >> kFailureTagSize) == info); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1007 | return reinterpret_cast<Failure*>((info << kFailureTagSize) | kFailureTag); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 1011 | bool Smi::IsValid(intptr_t value) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1012 | #ifdef DEBUG |
| 1013 | bool in_range = (value >= kMinValue) && (value <= kMaxValue); |
| 1014 | #endif |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1015 | |
| 1016 | #ifdef V8_TARGET_ARCH_X64 |
| 1017 | // To be representable as a long smi, the value must be a 32-bit integer. |
| 1018 | bool result = (value == static_cast<int32_t>(value)); |
| 1019 | #else |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1020 | // To be representable as an tagged small integer, the two |
| 1021 | // most-significant bits of 'value' must be either 00 or 11 due to |
| 1022 | // sign-extension. To check this we add 01 to the two |
| 1023 | // most-significant bits, and check if the most-significant bit is 0 |
| 1024 | // |
| 1025 | // CAUTION: The original code below: |
| 1026 | // bool result = ((value + 0x40000000) & 0x80000000) == 0; |
| 1027 | // may lead to incorrect results according to the C language spec, and |
| 1028 | // in fact doesn't work correctly with gcc4.1.1 in some cases: The |
| 1029 | // compiler may produce undefined results in case of signed integer |
| 1030 | // overflow. The computation must be done w/ unsigned ints. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1031 | bool result = (static_cast<uintptr_t>(value + 0x40000000U) < 0x80000000U); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1032 | #endif |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1033 | ASSERT(result == in_range); |
| 1034 | return result; |
| 1035 | } |
| 1036 | |
| 1037 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1038 | MapWord MapWord::FromMap(Map* map) { |
| 1039 | return MapWord(reinterpret_cast<uintptr_t>(map)); |
| 1040 | } |
| 1041 | |
| 1042 | |
| 1043 | Map* MapWord::ToMap() { |
| 1044 | return reinterpret_cast<Map*>(value_); |
| 1045 | } |
| 1046 | |
| 1047 | |
| 1048 | bool MapWord::IsForwardingAddress() { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1049 | return HAS_SMI_TAG(reinterpret_cast<Object*>(value_)); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | |
| 1053 | MapWord MapWord::FromForwardingAddress(HeapObject* object) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1054 | Address raw = reinterpret_cast<Address>(object) - kHeapObjectTag; |
| 1055 | return MapWord(reinterpret_cast<uintptr_t>(raw)); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | |
| 1059 | HeapObject* MapWord::ToForwardingAddress() { |
| 1060 | ASSERT(IsForwardingAddress()); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1061 | return HeapObject::FromAddress(reinterpret_cast<Address>(value_)); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1065 | #ifdef DEBUG |
| 1066 | void HeapObject::VerifyObjectField(int offset) { |
| 1067 | VerifyPointer(READ_FIELD(this, offset)); |
| 1068 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1069 | |
| 1070 | void HeapObject::VerifySmiField(int offset) { |
| 1071 | ASSERT(READ_FIELD(this, offset)->IsSmi()); |
| 1072 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1073 | #endif |
| 1074 | |
| 1075 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1076 | Heap* HeapObject::GetHeap() { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1077 | Heap* heap = |
| 1078 | MemoryChunk::FromAddress(reinterpret_cast<Address>(this))->heap(); |
| 1079 | ASSERT(heap != NULL); |
| 1080 | ASSERT(heap->isolate() == Isolate::Current()); |
| 1081 | return heap; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | |
| 1085 | Isolate* HeapObject::GetIsolate() { |
| 1086 | return GetHeap()->isolate(); |
| 1087 | } |
| 1088 | |
| 1089 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1090 | Map* HeapObject::map() { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1091 | return map_word().ToMap(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | |
| 1095 | void HeapObject::set_map(Map* value) { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1096 | set_map_word(MapWord::FromMap(value)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1097 | if (value != NULL) { |
| 1098 | // TODO(1600) We are passing NULL as a slot because maps can never be on |
| 1099 | // evacuation candidate. |
| 1100 | value->GetHeap()->incremental_marking()->RecordWrite(this, NULL, value); |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | |
| 1105 | // Unsafe accessor omitting write barrier. |
| 1106 | void HeapObject::set_map_unsafe(Map* value) { |
| 1107 | set_map_word(MapWord::FromMap(value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1111 | MapWord HeapObject::map_word() { |
| 1112 | return MapWord(reinterpret_cast<uintptr_t>(READ_FIELD(this, kMapOffset))); |
| 1113 | } |
| 1114 | |
| 1115 | |
| 1116 | void HeapObject::set_map_word(MapWord map_word) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1117 | // WRITE_FIELD does not invoke write barrier, but there is no need |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1118 | // here. |
| 1119 | WRITE_FIELD(this, kMapOffset, reinterpret_cast<Object*>(map_word.value_)); |
| 1120 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1121 | |
| 1122 | |
| 1123 | HeapObject* HeapObject::FromAddress(Address address) { |
| 1124 | ASSERT_TAG_ALIGNED(address); |
| 1125 | return reinterpret_cast<HeapObject*>(address + kHeapObjectTag); |
| 1126 | } |
| 1127 | |
| 1128 | |
| 1129 | Address HeapObject::address() { |
| 1130 | return reinterpret_cast<Address>(this) - kHeapObjectTag; |
| 1131 | } |
| 1132 | |
| 1133 | |
| 1134 | int HeapObject::Size() { |
| 1135 | return SizeFromMap(map()); |
| 1136 | } |
| 1137 | |
| 1138 | |
| 1139 | void HeapObject::IteratePointers(ObjectVisitor* v, int start, int end) { |
| 1140 | v->VisitPointers(reinterpret_cast<Object**>(FIELD_ADDR(this, start)), |
| 1141 | reinterpret_cast<Object**>(FIELD_ADDR(this, end))); |
| 1142 | } |
| 1143 | |
| 1144 | |
| 1145 | void HeapObject::IteratePointer(ObjectVisitor* v, int offset) { |
| 1146 | v->VisitPointer(reinterpret_cast<Object**>(FIELD_ADDR(this, offset))); |
| 1147 | } |
| 1148 | |
| 1149 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1150 | double HeapNumber::value() { |
| 1151 | return READ_DOUBLE_FIELD(this, kValueOffset); |
| 1152 | } |
| 1153 | |
| 1154 | |
| 1155 | void HeapNumber::set_value(double value) { |
| 1156 | WRITE_DOUBLE_FIELD(this, kValueOffset, value); |
| 1157 | } |
| 1158 | |
| 1159 | |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 1160 | int HeapNumber::get_exponent() { |
| 1161 | return ((READ_INT_FIELD(this, kExponentOffset) & kExponentMask) >> |
| 1162 | kExponentShift) - kExponentBias; |
| 1163 | } |
| 1164 | |
| 1165 | |
| 1166 | int HeapNumber::get_sign() { |
| 1167 | return READ_INT_FIELD(this, kExponentOffset) & kSignMask; |
| 1168 | } |
| 1169 | |
| 1170 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1171 | ACCESSORS(JSObject, properties, FixedArray, kPropertiesOffset) |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1172 | |
| 1173 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1174 | FixedArrayBase* JSObject::elements() { |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1175 | Object* array = READ_FIELD(this, kElementsOffset); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1176 | return static_cast<FixedArrayBase*>(array); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1177 | } |
| 1178 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1179 | void JSObject::ValidateSmiOnlyElements() { |
| 1180 | #if DEBUG |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1181 | if (map()->elements_kind() == FAST_SMI_ONLY_ELEMENTS) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1182 | Heap* heap = GetHeap(); |
| 1183 | // Don't use elements, since integrity checks will fail if there |
| 1184 | // are filler pointers in the array. |
| 1185 | FixedArray* fixed_array = |
| 1186 | reinterpret_cast<FixedArray*>(READ_FIELD(this, kElementsOffset)); |
| 1187 | Map* map = fixed_array->map(); |
| 1188 | // Arrays that have been shifted in place can't be verified. |
| 1189 | if (map != heap->raw_unchecked_one_pointer_filler_map() && |
| 1190 | map != heap->raw_unchecked_two_pointer_filler_map() && |
| 1191 | map != heap->free_space_map()) { |
| 1192 | for (int i = 0; i < fixed_array->length(); i++) { |
| 1193 | Object* current = fixed_array->get(i); |
| 1194 | ASSERT(current->IsSmi() || current == heap->the_hole_value()); |
| 1195 | } |
| 1196 | } |
| 1197 | } |
| 1198 | #endif |
| 1199 | } |
| 1200 | |
| 1201 | |
| 1202 | MaybeObject* JSObject::EnsureCanContainNonSmiElements() { |
| 1203 | #if DEBUG |
| 1204 | ValidateSmiOnlyElements(); |
| 1205 | #endif |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1206 | if ((map()->elements_kind() == FAST_SMI_ONLY_ELEMENTS)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1207 | Object* obj; |
| 1208 | MaybeObject* maybe_obj = GetElementsTransitionMap(FAST_ELEMENTS); |
| 1209 | if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
| 1210 | set_map(Map::cast(obj)); |
| 1211 | } |
| 1212 | return this; |
| 1213 | } |
| 1214 | |
| 1215 | |
| 1216 | MaybeObject* JSObject::EnsureCanContainElements(Object** objects, |
| 1217 | uint32_t count) { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1218 | if (map()->elements_kind() == FAST_SMI_ONLY_ELEMENTS) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1219 | for (uint32_t i = 0; i < count; ++i) { |
| 1220 | Object* current = *objects++; |
| 1221 | if (!current->IsSmi() && current != GetHeap()->the_hole_value()) { |
| 1222 | return EnsureCanContainNonSmiElements(); |
| 1223 | } |
| 1224 | } |
| 1225 | } |
| 1226 | return this; |
| 1227 | } |
| 1228 | |
| 1229 | |
| 1230 | MaybeObject* JSObject::EnsureCanContainElements(FixedArray* elements) { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1231 | Object** objects = reinterpret_cast<Object**>( |
| 1232 | FIELD_ADDR(elements, elements->OffsetOfElementAt(0))); |
| 1233 | return EnsureCanContainElements(objects, elements->length()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1234 | } |
| 1235 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1236 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1237 | void JSObject::set_elements(FixedArrayBase* value, WriteBarrierMode mode) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1238 | ASSERT((map()->has_fast_elements() || |
| 1239 | map()->has_fast_smi_only_elements()) == |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1240 | (value->map() == GetHeap()->fixed_array_map() || |
| 1241 | value->map() == GetHeap()->fixed_cow_array_map())); |
lrn@chromium.org | d4e9e22 | 2011-08-03 12:01:58 +0000 | [diff] [blame] | 1242 | ASSERT(map()->has_fast_double_elements() == |
| 1243 | value->IsFixedDoubleArray()); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1244 | ASSERT(value->HasValidElements()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1245 | #ifdef DEBUG |
| 1246 | ValidateSmiOnlyElements(); |
| 1247 | #endif |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1248 | WRITE_FIELD(this, kElementsOffset, value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1249 | CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kElementsOffset, value, mode); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1250 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1251 | |
| 1252 | |
| 1253 | void JSObject::initialize_properties() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1254 | ASSERT(!GetHeap()->InNewSpace(GetHeap()->empty_fixed_array())); |
| 1255 | WRITE_FIELD(this, kPropertiesOffset, GetHeap()->empty_fixed_array()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | |
| 1259 | void JSObject::initialize_elements() { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1260 | ASSERT(map()->has_fast_elements() || map()->has_fast_smi_only_elements()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1261 | ASSERT(!GetHeap()->InNewSpace(GetHeap()->empty_fixed_array())); |
| 1262 | WRITE_FIELD(this, kElementsOffset, GetHeap()->empty_fixed_array()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1266 | MaybeObject* JSObject::ResetElements() { |
| 1267 | Object* obj; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1268 | ElementsKind elements_kind = FLAG_smi_only_arrays |
| 1269 | ? FAST_SMI_ONLY_ELEMENTS |
| 1270 | : FAST_ELEMENTS; |
| 1271 | MaybeObject* maybe_obj = GetElementsTransitionMap(elements_kind); |
| 1272 | if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1273 | set_map(Map::cast(obj)); |
| 1274 | initialize_elements(); |
| 1275 | return this; |
| 1276 | } |
| 1277 | |
| 1278 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1279 | ACCESSORS(Oddball, to_string, String, kToStringOffset) |
| 1280 | ACCESSORS(Oddball, to_number, Object, kToNumberOffset) |
| 1281 | |
| 1282 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1283 | byte Oddball::kind() { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1284 | return Smi::cast(READ_FIELD(this, kKindOffset))->value(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | |
| 1288 | void Oddball::set_kind(byte value) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1289 | WRITE_FIELD(this, kKindOffset, Smi::FromInt(value)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1290 | } |
| 1291 | |
| 1292 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1293 | Object* JSGlobalPropertyCell::value() { |
| 1294 | return READ_FIELD(this, kValueOffset); |
| 1295 | } |
| 1296 | |
| 1297 | |
| 1298 | void JSGlobalPropertyCell::set_value(Object* val, WriteBarrierMode ignored) { |
| 1299 | // The write barrier is not used for global property cells. |
| 1300 | ASSERT(!val->IsJSGlobalPropertyCell()); |
| 1301 | WRITE_FIELD(this, kValueOffset, val); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1302 | GetHeap()->incremental_marking()->RecordWrite( |
| 1303 | this, HeapObject::RawField(this, kValueOffset), val); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1304 | } |
| 1305 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1306 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1307 | int JSObject::GetHeaderSize() { |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1308 | InstanceType type = map()->instance_type(); |
| 1309 | // Check for the most common kind of JavaScript object before |
| 1310 | // falling into the generic switch. This speeds up the internal |
| 1311 | // field operations considerably on average. |
| 1312 | if (type == JS_OBJECT_TYPE) return JSObject::kHeaderSize; |
| 1313 | switch (type) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1314 | case JS_GLOBAL_PROXY_TYPE: |
| 1315 | return JSGlobalProxy::kSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1316 | case JS_GLOBAL_OBJECT_TYPE: |
| 1317 | return JSGlobalObject::kSize; |
| 1318 | case JS_BUILTINS_OBJECT_TYPE: |
| 1319 | return JSBuiltinsObject::kSize; |
| 1320 | case JS_FUNCTION_TYPE: |
| 1321 | return JSFunction::kSize; |
| 1322 | case JS_VALUE_TYPE: |
| 1323 | return JSValue::kSize; |
| 1324 | case JS_ARRAY_TYPE: |
| 1325 | return JSValue::kSize; |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1326 | case JS_WEAK_MAP_TYPE: |
| 1327 | return JSWeakMap::kSize; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1328 | case JS_REGEXP_TYPE: |
| 1329 | return JSValue::kSize; |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1330 | case JS_CONTEXT_EXTENSION_OBJECT_TYPE: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1331 | return JSObject::kHeaderSize; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1332 | case JS_MESSAGE_OBJECT_TYPE: |
| 1333 | return JSMessageObject::kSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1334 | default: |
| 1335 | UNREACHABLE(); |
| 1336 | return 0; |
| 1337 | } |
| 1338 | } |
| 1339 | |
| 1340 | |
| 1341 | int JSObject::GetInternalFieldCount() { |
| 1342 | ASSERT(1 << kPointerSizeLog2 == kPointerSize); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1343 | // Make sure to adjust for the number of in-object properties. These |
| 1344 | // properties do contribute to the size, but are not internal fields. |
| 1345 | return ((Size() - GetHeaderSize()) >> kPointerSizeLog2) - |
| 1346 | map()->inobject_properties(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1350 | int JSObject::GetInternalFieldOffset(int index) { |
| 1351 | ASSERT(index < GetInternalFieldCount() && index >= 0); |
| 1352 | return GetHeaderSize() + (kPointerSize * index); |
| 1353 | } |
| 1354 | |
| 1355 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1356 | Object* JSObject::GetInternalField(int index) { |
| 1357 | ASSERT(index < GetInternalFieldCount() && index >= 0); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1358 | // Internal objects do follow immediately after the header, whereas in-object |
| 1359 | // properties are at the end of the object. Therefore there is no need |
| 1360 | // to adjust the index here. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1361 | return READ_FIELD(this, GetHeaderSize() + (kPointerSize * index)); |
| 1362 | } |
| 1363 | |
| 1364 | |
| 1365 | void JSObject::SetInternalField(int index, Object* value) { |
| 1366 | ASSERT(index < GetInternalFieldCount() && index >= 0); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1367 | // Internal objects do follow immediately after the header, whereas in-object |
| 1368 | // properties are at the end of the object. Therefore there is no need |
| 1369 | // to adjust the index here. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1370 | int offset = GetHeaderSize() + (kPointerSize * index); |
| 1371 | WRITE_FIELD(this, offset, value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1372 | WRITE_BARRIER(GetHeap(), this, offset, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1373 | } |
| 1374 | |
| 1375 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1376 | // Access fast-case object properties at index. The use of these routines |
| 1377 | // is needed to correctly distinguish between properties stored in-object and |
| 1378 | // properties stored in the properties array. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1379 | Object* JSObject::FastPropertyAt(int index) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1380 | // Adjust for the number of properties stored in the object. |
| 1381 | index -= map()->inobject_properties(); |
| 1382 | if (index < 0) { |
| 1383 | int offset = map()->instance_size() + (index * kPointerSize); |
| 1384 | return READ_FIELD(this, offset); |
| 1385 | } else { |
| 1386 | ASSERT(index < properties()->length()); |
| 1387 | return properties()->get(index); |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1392 | Object* JSObject::FastPropertyAtPut(int index, Object* value) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1393 | // Adjust for the number of properties stored in the object. |
| 1394 | index -= map()->inobject_properties(); |
| 1395 | if (index < 0) { |
| 1396 | int offset = map()->instance_size() + (index * kPointerSize); |
| 1397 | WRITE_FIELD(this, offset, value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1398 | WRITE_BARRIER(GetHeap(), this, offset, value); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1399 | } else { |
| 1400 | ASSERT(index < properties()->length()); |
| 1401 | properties()->set(index, value); |
| 1402 | } |
| 1403 | return value; |
| 1404 | } |
| 1405 | |
| 1406 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1407 | int JSObject::GetInObjectPropertyOffset(int index) { |
| 1408 | // Adjust for the number of properties stored in the object. |
| 1409 | index -= map()->inobject_properties(); |
| 1410 | ASSERT(index < 0); |
| 1411 | return map()->instance_size() + (index * kPointerSize); |
| 1412 | } |
| 1413 | |
| 1414 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1415 | Object* JSObject::InObjectPropertyAt(int index) { |
| 1416 | // Adjust for the number of properties stored in the object. |
| 1417 | index -= map()->inobject_properties(); |
| 1418 | ASSERT(index < 0); |
| 1419 | int offset = map()->instance_size() + (index * kPointerSize); |
| 1420 | return READ_FIELD(this, offset); |
| 1421 | } |
| 1422 | |
| 1423 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1424 | Object* JSObject::InObjectPropertyAtPut(int index, |
| 1425 | Object* value, |
| 1426 | WriteBarrierMode mode) { |
| 1427 | // Adjust for the number of properties stored in the object. |
| 1428 | index -= map()->inobject_properties(); |
| 1429 | ASSERT(index < 0); |
| 1430 | int offset = map()->instance_size() + (index * kPointerSize); |
| 1431 | WRITE_FIELD(this, offset, value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1432 | CONDITIONAL_WRITE_BARRIER(GetHeap(), this, offset, value, mode); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1433 | return value; |
| 1434 | } |
| 1435 | |
| 1436 | |
| 1437 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1438 | void JSObject::InitializeBody(Map* map, |
| 1439 | Object* pre_allocated_value, |
| 1440 | Object* filler_value) { |
| 1441 | ASSERT(!filler_value->IsHeapObject() || |
| 1442 | !GetHeap()->InNewSpace(filler_value)); |
| 1443 | ASSERT(!pre_allocated_value->IsHeapObject() || |
| 1444 | !GetHeap()->InNewSpace(pre_allocated_value)); |
| 1445 | int size = map->instance_size(); |
| 1446 | int offset = kHeaderSize; |
| 1447 | if (filler_value != pre_allocated_value) { |
| 1448 | int pre_allocated = map->pre_allocated_property_fields(); |
| 1449 | ASSERT(pre_allocated * kPointerSize + kHeaderSize <= size); |
| 1450 | for (int i = 0; i < pre_allocated; i++) { |
| 1451 | WRITE_FIELD(this, offset, pre_allocated_value); |
| 1452 | offset += kPointerSize; |
| 1453 | } |
| 1454 | } |
| 1455 | while (offset < size) { |
| 1456 | WRITE_FIELD(this, offset, filler_value); |
| 1457 | offset += kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1458 | } |
| 1459 | } |
| 1460 | |
| 1461 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1462 | bool JSObject::HasFastProperties() { |
| 1463 | return !properties()->IsDictionary(); |
| 1464 | } |
| 1465 | |
| 1466 | |
| 1467 | int JSObject::MaxFastProperties() { |
| 1468 | // Allow extra fast properties if the object has more than |
| 1469 | // kMaxFastProperties in-object properties. When this is the case, |
| 1470 | // it is very unlikely that the object is being used as a dictionary |
| 1471 | // and there is a good chance that allowing more map transitions |
| 1472 | // will be worth it. |
| 1473 | return Max(map()->inobject_properties(), kMaxFastProperties); |
| 1474 | } |
| 1475 | |
| 1476 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1477 | void Struct::InitializeBody(int object_size) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1478 | Object* value = GetHeap()->undefined_value(); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1479 | for (int offset = kHeaderSize; offset < object_size; offset += kPointerSize) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1480 | WRITE_FIELD(this, offset, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1481 | } |
| 1482 | } |
| 1483 | |
| 1484 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1485 | bool Object::ToArrayIndex(uint32_t* index) { |
| 1486 | if (IsSmi()) { |
| 1487 | int value = Smi::cast(this)->value(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1488 | if (value < 0) return false; |
| 1489 | *index = value; |
| 1490 | return true; |
| 1491 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1492 | if (IsHeapNumber()) { |
| 1493 | double value = HeapNumber::cast(this)->value(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1494 | uint32_t uint_value = static_cast<uint32_t>(value); |
| 1495 | if (value == static_cast<double>(uint_value)) { |
| 1496 | *index = uint_value; |
| 1497 | return true; |
| 1498 | } |
| 1499 | } |
| 1500 | return false; |
| 1501 | } |
| 1502 | |
| 1503 | |
| 1504 | bool Object::IsStringObjectWithCharacterAt(uint32_t index) { |
| 1505 | if (!this->IsJSValue()) return false; |
| 1506 | |
| 1507 | JSValue* js_value = JSValue::cast(this); |
| 1508 | if (!js_value->value()->IsString()) return false; |
| 1509 | |
| 1510 | String* str = String::cast(js_value->value()); |
| 1511 | if (index >= (uint32_t)str->length()) return false; |
| 1512 | |
| 1513 | return true; |
| 1514 | } |
| 1515 | |
| 1516 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1517 | FixedArrayBase* FixedArrayBase::cast(Object* object) { |
| 1518 | ASSERT(object->IsFixedArray() || object->IsFixedDoubleArray()); |
| 1519 | return reinterpret_cast<FixedArrayBase*>(object); |
| 1520 | } |
| 1521 | |
| 1522 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1523 | Object* FixedArray::get(int index) { |
| 1524 | ASSERT(index >= 0 && index < this->length()); |
| 1525 | return READ_FIELD(this, kHeaderSize + index * kPointerSize); |
| 1526 | } |
| 1527 | |
| 1528 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1529 | void FixedArray::set(int index, Smi* value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1530 | ASSERT(map() != HEAP->fixed_cow_array_map()); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1531 | ASSERT(index >= 0 && index < this->length()); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1532 | ASSERT(reinterpret_cast<Object*>(value)->IsSmi()); |
| 1533 | int offset = kHeaderSize + index * kPointerSize; |
| 1534 | WRITE_FIELD(this, offset, value); |
| 1535 | } |
| 1536 | |
| 1537 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1538 | void FixedArray::set(int index, Object* value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1539 | ASSERT(map() != HEAP->fixed_cow_array_map()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1540 | ASSERT(index >= 0 && index < this->length()); |
| 1541 | int offset = kHeaderSize + index * kPointerSize; |
| 1542 | WRITE_FIELD(this, offset, value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1543 | WRITE_BARRIER(GetHeap(), this, offset, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1544 | } |
| 1545 | |
| 1546 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1547 | inline bool FixedDoubleArray::is_the_hole_nan(double value) { |
| 1548 | return BitCast<uint64_t, double>(value) == kHoleNanInt64; |
| 1549 | } |
| 1550 | |
| 1551 | |
| 1552 | inline double FixedDoubleArray::hole_nan_as_double() { |
| 1553 | return BitCast<double, uint64_t>(kHoleNanInt64); |
| 1554 | } |
| 1555 | |
| 1556 | |
| 1557 | inline double FixedDoubleArray::canonical_not_the_hole_nan_as_double() { |
| 1558 | ASSERT(BitCast<uint64_t>(OS::nan_value()) != kHoleNanInt64); |
| 1559 | ASSERT((BitCast<uint64_t>(OS::nan_value()) >> 32) != kHoleNanUpper32); |
| 1560 | return OS::nan_value(); |
| 1561 | } |
| 1562 | |
| 1563 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1564 | double FixedDoubleArray::get_scalar(int index) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1565 | ASSERT(map() != HEAP->fixed_cow_array_map() && |
| 1566 | map() != HEAP->fixed_array_map()); |
| 1567 | ASSERT(index >= 0 && index < this->length()); |
| 1568 | double result = READ_DOUBLE_FIELD(this, kHeaderSize + index * kDoubleSize); |
| 1569 | ASSERT(!is_the_hole_nan(result)); |
| 1570 | return result; |
| 1571 | } |
| 1572 | |
| 1573 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1574 | MaybeObject* FixedDoubleArray::get(int index) { |
| 1575 | if (is_the_hole(index)) { |
| 1576 | return GetHeap()->the_hole_value(); |
| 1577 | } else { |
| 1578 | return GetHeap()->NumberFromDouble(get_scalar(index)); |
| 1579 | } |
| 1580 | } |
| 1581 | |
| 1582 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1583 | void FixedDoubleArray::set(int index, double value) { |
| 1584 | ASSERT(map() != HEAP->fixed_cow_array_map() && |
| 1585 | map() != HEAP->fixed_array_map()); |
| 1586 | int offset = kHeaderSize + index * kDoubleSize; |
| 1587 | if (isnan(value)) value = canonical_not_the_hole_nan_as_double(); |
| 1588 | WRITE_DOUBLE_FIELD(this, offset, value); |
| 1589 | } |
| 1590 | |
| 1591 | |
| 1592 | void FixedDoubleArray::set_the_hole(int index) { |
| 1593 | ASSERT(map() != HEAP->fixed_cow_array_map() && |
| 1594 | map() != HEAP->fixed_array_map()); |
| 1595 | int offset = kHeaderSize + index * kDoubleSize; |
| 1596 | WRITE_DOUBLE_FIELD(this, offset, hole_nan_as_double()); |
| 1597 | } |
| 1598 | |
| 1599 | |
| 1600 | bool FixedDoubleArray::is_the_hole(int index) { |
| 1601 | int offset = kHeaderSize + index * kDoubleSize; |
| 1602 | return is_the_hole_nan(READ_DOUBLE_FIELD(this, offset)); |
| 1603 | } |
| 1604 | |
| 1605 | |
| 1606 | void FixedDoubleArray::Initialize(FixedDoubleArray* from) { |
| 1607 | int old_length = from->length(); |
| 1608 | ASSERT(old_length < length()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1609 | if (old_length * kDoubleSize >= OS::kMinComplexMemCopy) { |
| 1610 | OS::MemCopy(FIELD_ADDR(this, kHeaderSize), |
| 1611 | FIELD_ADDR(from, kHeaderSize), |
| 1612 | old_length * kDoubleSize); |
| 1613 | } else { |
| 1614 | for (int i = 0; i < old_length; ++i) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1615 | if (from->is_the_hole(i)) { |
| 1616 | set_the_hole(i); |
| 1617 | } else { |
| 1618 | set(i, from->get_scalar(i)); |
| 1619 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1620 | } |
| 1621 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1622 | int offset = kHeaderSize + old_length * kDoubleSize; |
| 1623 | for (int current = from->length(); current < length(); ++current) { |
| 1624 | WRITE_DOUBLE_FIELD(this, offset, hole_nan_as_double()); |
| 1625 | offset += kDoubleSize; |
| 1626 | } |
| 1627 | } |
| 1628 | |
| 1629 | |
| 1630 | void FixedDoubleArray::Initialize(FixedArray* from) { |
| 1631 | int old_length = from->length(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1632 | ASSERT(old_length <= length()); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1633 | for (int i = 0; i < old_length; i++) { |
| 1634 | Object* hole_or_object = from->get(i); |
| 1635 | if (hole_or_object->IsTheHole()) { |
| 1636 | set_the_hole(i); |
| 1637 | } else { |
| 1638 | set(i, hole_or_object->Number()); |
| 1639 | } |
| 1640 | } |
| 1641 | int offset = kHeaderSize + old_length * kDoubleSize; |
| 1642 | for (int current = from->length(); current < length(); ++current) { |
| 1643 | WRITE_DOUBLE_FIELD(this, offset, hole_nan_as_double()); |
| 1644 | offset += kDoubleSize; |
| 1645 | } |
| 1646 | } |
| 1647 | |
| 1648 | |
| 1649 | void FixedDoubleArray::Initialize(NumberDictionary* from) { |
| 1650 | int offset = kHeaderSize; |
| 1651 | for (int current = 0; current < length(); ++current) { |
| 1652 | WRITE_DOUBLE_FIELD(this, offset, hole_nan_as_double()); |
| 1653 | offset += kDoubleSize; |
| 1654 | } |
| 1655 | for (int i = 0; i < from->Capacity(); i++) { |
| 1656 | Object* key = from->KeyAt(i); |
| 1657 | if (key->IsNumber()) { |
| 1658 | uint32_t entry = static_cast<uint32_t>(key->Number()); |
| 1659 | set(entry, from->ValueAt(i)->Number()); |
| 1660 | } |
| 1661 | } |
| 1662 | } |
| 1663 | |
| 1664 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1665 | WriteBarrierMode HeapObject::GetWriteBarrierMode(const AssertNoAllocation&) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1666 | Heap* heap = GetHeap(); |
| 1667 | if (heap->incremental_marking()->IsMarking()) return UPDATE_WRITE_BARRIER; |
| 1668 | if (heap->InNewSpace(this)) return SKIP_WRITE_BARRIER; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1669 | return UPDATE_WRITE_BARRIER; |
| 1670 | } |
| 1671 | |
| 1672 | |
| 1673 | void FixedArray::set(int index, |
| 1674 | Object* value, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1675 | WriteBarrierMode mode) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1676 | ASSERT(map() != HEAP->fixed_cow_array_map()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1677 | ASSERT(index >= 0 && index < this->length()); |
| 1678 | int offset = kHeaderSize + index * kPointerSize; |
| 1679 | WRITE_FIELD(this, offset, value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1680 | CONDITIONAL_WRITE_BARRIER(GetHeap(), this, offset, value, mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1681 | } |
| 1682 | |
| 1683 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1684 | void FixedArray::NoWriteBarrierSet(FixedArray* array, |
| 1685 | int index, |
| 1686 | Object* value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1687 | ASSERT(array->map() != HEAP->raw_unchecked_fixed_cow_array_map()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1688 | ASSERT(index >= 0 && index < array->length()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1689 | ASSERT(!HEAP->InNewSpace(value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1690 | WRITE_FIELD(array, kHeaderSize + index * kPointerSize, value); |
| 1691 | } |
| 1692 | |
| 1693 | |
| 1694 | void FixedArray::set_undefined(int index) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1695 | ASSERT(map() != HEAP->fixed_cow_array_map()); |
| 1696 | set_undefined(GetHeap(), index); |
| 1697 | } |
| 1698 | |
| 1699 | |
| 1700 | void FixedArray::set_undefined(Heap* heap, int index) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1701 | ASSERT(index >= 0 && index < this->length()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1702 | ASSERT(!heap->InNewSpace(heap->undefined_value())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1703 | WRITE_FIELD(this, kHeaderSize + index * kPointerSize, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1704 | heap->undefined_value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1705 | } |
| 1706 | |
| 1707 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1708 | void FixedArray::set_null(int index) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1709 | set_null(GetHeap(), index); |
| 1710 | } |
| 1711 | |
| 1712 | |
| 1713 | void FixedArray::set_null(Heap* heap, int index) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1714 | ASSERT(index >= 0 && index < this->length()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1715 | ASSERT(!heap->InNewSpace(heap->null_value())); |
| 1716 | WRITE_FIELD(this, kHeaderSize + index * kPointerSize, heap->null_value()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1717 | } |
| 1718 | |
| 1719 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1720 | void FixedArray::set_the_hole(int index) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1721 | ASSERT(map() != HEAP->fixed_cow_array_map()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1722 | ASSERT(index >= 0 && index < this->length()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1723 | ASSERT(!HEAP->InNewSpace(HEAP->the_hole_value())); |
| 1724 | WRITE_FIELD(this, |
| 1725 | kHeaderSize + index * kPointerSize, |
| 1726 | GetHeap()->the_hole_value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1727 | } |
| 1728 | |
| 1729 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1730 | void FixedArray::set_unchecked(int index, Smi* value) { |
| 1731 | ASSERT(reinterpret_cast<Object*>(value)->IsSmi()); |
| 1732 | int offset = kHeaderSize + index * kPointerSize; |
| 1733 | WRITE_FIELD(this, offset, value); |
| 1734 | } |
| 1735 | |
| 1736 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1737 | void FixedArray::set_unchecked(Heap* heap, |
| 1738 | int index, |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1739 | Object* value, |
| 1740 | WriteBarrierMode mode) { |
| 1741 | int offset = kHeaderSize + index * kPointerSize; |
| 1742 | WRITE_FIELD(this, offset, value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1743 | CONDITIONAL_WRITE_BARRIER(heap, this, offset, value, mode); |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1744 | } |
| 1745 | |
| 1746 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1747 | void FixedArray::set_null_unchecked(Heap* heap, int index) { |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1748 | ASSERT(index >= 0 && index < this->length()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1749 | ASSERT(!HEAP->InNewSpace(heap->null_value())); |
| 1750 | WRITE_FIELD(this, kHeaderSize + index * kPointerSize, heap->null_value()); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1754 | Object** FixedArray::data_start() { |
| 1755 | return HeapObject::RawField(this, kHeaderSize); |
| 1756 | } |
| 1757 | |
| 1758 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1759 | bool DescriptorArray::IsEmpty() { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1760 | ASSERT(this->IsSmi() || |
| 1761 | this->length() > kFirstIndex || |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1762 | this == HEAP->empty_descriptor_array()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1763 | return this->IsSmi() || length() <= kFirstIndex; |
| 1764 | } |
| 1765 | |
| 1766 | |
| 1767 | int DescriptorArray::bit_field3_storage() { |
| 1768 | Object* storage = READ_FIELD(this, kBitField3StorageOffset); |
| 1769 | return Smi::cast(storage)->value(); |
| 1770 | } |
| 1771 | |
| 1772 | void DescriptorArray::set_bit_field3_storage(int value) { |
| 1773 | ASSERT(!IsEmpty()); |
| 1774 | WRITE_FIELD(this, kBitField3StorageOffset, Smi::FromInt(value)); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1778 | void DescriptorArray::NoWriteBarrierSwap(FixedArray* array, |
| 1779 | int first, |
| 1780 | int second) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1781 | Object* tmp = array->get(first); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1782 | NoWriteBarrierSet(array, first, array->get(second)); |
| 1783 | NoWriteBarrierSet(array, second, tmp); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1784 | } |
| 1785 | |
| 1786 | |
| 1787 | int DescriptorArray::Search(String* name) { |
| 1788 | SLOW_ASSERT(IsSortedNoDuplicates()); |
| 1789 | |
| 1790 | // Check for empty descriptor array. |
| 1791 | int nof = number_of_descriptors(); |
| 1792 | if (nof == 0) return kNotFound; |
| 1793 | |
| 1794 | // Fast case: do linear search for small arrays. |
| 1795 | const int kMaxElementsForLinearSearch = 8; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1796 | if (StringShape(name).IsSymbol() && nof < kMaxElementsForLinearSearch) { |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1797 | return LinearSearch(name, nof); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1798 | } |
| 1799 | |
| 1800 | // Slow case: perform binary search. |
| 1801 | return BinarySearch(name, 0, nof - 1); |
| 1802 | } |
| 1803 | |
| 1804 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1805 | int DescriptorArray::SearchWithCache(String* name) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1806 | int number = GetIsolate()->descriptor_lookup_cache()->Lookup(this, name); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1807 | if (number == DescriptorLookupCache::kAbsent) { |
| 1808 | number = Search(name); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1809 | GetIsolate()->descriptor_lookup_cache()->Update(this, name, number); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1810 | } |
| 1811 | return number; |
| 1812 | } |
| 1813 | |
| 1814 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1815 | String* DescriptorArray::GetKey(int descriptor_number) { |
| 1816 | ASSERT(descriptor_number < number_of_descriptors()); |
| 1817 | return String::cast(get(ToKeyIndex(descriptor_number))); |
| 1818 | } |
| 1819 | |
| 1820 | |
| 1821 | Object* DescriptorArray::GetValue(int descriptor_number) { |
| 1822 | ASSERT(descriptor_number < number_of_descriptors()); |
| 1823 | return GetContentArray()->get(ToValueIndex(descriptor_number)); |
| 1824 | } |
| 1825 | |
| 1826 | |
| 1827 | Smi* DescriptorArray::GetDetails(int descriptor_number) { |
| 1828 | ASSERT(descriptor_number < number_of_descriptors()); |
| 1829 | return Smi::cast(GetContentArray()->get(ToDetailsIndex(descriptor_number))); |
| 1830 | } |
| 1831 | |
| 1832 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1833 | PropertyType DescriptorArray::GetType(int descriptor_number) { |
| 1834 | ASSERT(descriptor_number < number_of_descriptors()); |
| 1835 | return PropertyDetails(GetDetails(descriptor_number)).type(); |
| 1836 | } |
| 1837 | |
| 1838 | |
| 1839 | int DescriptorArray::GetFieldIndex(int descriptor_number) { |
| 1840 | return Descriptor::IndexFromValue(GetValue(descriptor_number)); |
| 1841 | } |
| 1842 | |
| 1843 | |
| 1844 | JSFunction* DescriptorArray::GetConstantFunction(int descriptor_number) { |
| 1845 | return JSFunction::cast(GetValue(descriptor_number)); |
| 1846 | } |
| 1847 | |
| 1848 | |
| 1849 | Object* DescriptorArray::GetCallbacksObject(int descriptor_number) { |
| 1850 | ASSERT(GetType(descriptor_number) == CALLBACKS); |
| 1851 | return GetValue(descriptor_number); |
| 1852 | } |
| 1853 | |
| 1854 | |
| 1855 | AccessorDescriptor* DescriptorArray::GetCallbacks(int descriptor_number) { |
| 1856 | ASSERT(GetType(descriptor_number) == CALLBACKS); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1857 | Foreign* p = Foreign::cast(GetCallbacksObject(descriptor_number)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame^] | 1858 | return reinterpret_cast<AccessorDescriptor*>(p->foreign_address()); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | |
| 1862 | bool DescriptorArray::IsProperty(int descriptor_number) { |
| 1863 | return GetType(descriptor_number) < FIRST_PHANTOM_PROPERTY_TYPE; |
| 1864 | } |
| 1865 | |
| 1866 | |
| 1867 | bool DescriptorArray::IsTransition(int descriptor_number) { |
| 1868 | PropertyType t = GetType(descriptor_number); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1869 | return t == MAP_TRANSITION || t == CONSTANT_TRANSITION || |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 1870 | t == ELEMENTS_TRANSITION; |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1871 | } |
| 1872 | |
| 1873 | |
| 1874 | bool DescriptorArray::IsNullDescriptor(int descriptor_number) { |
| 1875 | return GetType(descriptor_number) == NULL_DESCRIPTOR; |
| 1876 | } |
| 1877 | |
| 1878 | |
| 1879 | bool DescriptorArray::IsDontEnum(int descriptor_number) { |
| 1880 | return PropertyDetails(GetDetails(descriptor_number)).IsDontEnum(); |
| 1881 | } |
| 1882 | |
| 1883 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1884 | void DescriptorArray::Get(int descriptor_number, Descriptor* desc) { |
| 1885 | desc->Init(GetKey(descriptor_number), |
| 1886 | GetValue(descriptor_number), |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1887 | PropertyDetails(GetDetails(descriptor_number))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1888 | } |
| 1889 | |
| 1890 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1891 | void DescriptorArray::Set(int descriptor_number, |
| 1892 | Descriptor* desc, |
| 1893 | const WhitenessWitness&) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1894 | // Range check. |
| 1895 | ASSERT(descriptor_number < number_of_descriptors()); |
| 1896 | |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 1897 | // Make sure none of the elements in desc are in new space. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1898 | ASSERT(!HEAP->InNewSpace(desc->GetKey())); |
| 1899 | ASSERT(!HEAP->InNewSpace(desc->GetValue())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1900 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1901 | NoWriteBarrierSet(this, |
| 1902 | ToKeyIndex(descriptor_number), |
| 1903 | desc->GetKey()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1904 | FixedArray* content_array = GetContentArray(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1905 | NoWriteBarrierSet(content_array, |
| 1906 | ToValueIndex(descriptor_number), |
| 1907 | desc->GetValue()); |
| 1908 | NoWriteBarrierSet(content_array, |
| 1909 | ToDetailsIndex(descriptor_number), |
| 1910 | desc->GetDetails().AsSmi()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1911 | } |
| 1912 | |
| 1913 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1914 | void DescriptorArray::CopyFrom(int index, |
| 1915 | DescriptorArray* src, |
| 1916 | int src_index, |
| 1917 | const WhitenessWitness& witness) { |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1918 | Descriptor desc; |
| 1919 | src->Get(src_index, &desc); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1920 | Set(index, &desc, witness); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1921 | } |
| 1922 | |
| 1923 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1924 | void DescriptorArray::NoWriteBarrierSwapDescriptors(int first, int second) { |
| 1925 | NoWriteBarrierSwap(this, ToKeyIndex(first), ToKeyIndex(second)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1926 | FixedArray* content_array = GetContentArray(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1927 | NoWriteBarrierSwap(content_array, |
| 1928 | ToValueIndex(first), |
| 1929 | ToValueIndex(second)); |
| 1930 | NoWriteBarrierSwap(content_array, |
| 1931 | ToDetailsIndex(first), |
| 1932 | ToDetailsIndex(second)); |
| 1933 | } |
| 1934 | |
| 1935 | |
| 1936 | DescriptorArray::WhitenessWitness::WhitenessWitness(DescriptorArray* array) |
| 1937 | : marking_(array->GetHeap()->incremental_marking()) { |
| 1938 | marking_->EnterNoMarkingScope(); |
| 1939 | if (array->number_of_descriptors() > 0) { |
| 1940 | ASSERT(Marking::Color(array) == Marking::WHITE_OBJECT); |
| 1941 | ASSERT(Marking::Color(array->GetContentArray()) == Marking::WHITE_OBJECT); |
| 1942 | } |
| 1943 | } |
| 1944 | |
| 1945 | |
| 1946 | DescriptorArray::WhitenessWitness::~WhitenessWitness() { |
| 1947 | marking_->LeaveNoMarkingScope(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1948 | } |
| 1949 | |
| 1950 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1951 | template<typename Shape, typename Key> |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 1952 | int HashTable<Shape, Key>::ComputeCapacity(int at_least_space_for) { |
| 1953 | const int kMinCapacity = 32; |
| 1954 | int capacity = RoundUpToPowerOf2(at_least_space_for * 2); |
| 1955 | if (capacity < kMinCapacity) { |
| 1956 | capacity = kMinCapacity; // Guarantee min capacity. |
| 1957 | } |
| 1958 | return capacity; |
| 1959 | } |
| 1960 | |
| 1961 | |
| 1962 | template<typename Shape, typename Key> |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1963 | int HashTable<Shape, Key>::FindEntry(Key key) { |
| 1964 | return FindEntry(GetIsolate(), key); |
| 1965 | } |
| 1966 | |
| 1967 | |
| 1968 | // Find entry for key otherwise return kNotFound. |
| 1969 | template<typename Shape, typename Key> |
| 1970 | int HashTable<Shape, Key>::FindEntry(Isolate* isolate, Key key) { |
| 1971 | uint32_t capacity = Capacity(); |
| 1972 | uint32_t entry = FirstProbe(Shape::Hash(key), capacity); |
| 1973 | uint32_t count = 1; |
| 1974 | // EnsureCapacity will guarantee the hash table is never full. |
| 1975 | while (true) { |
| 1976 | Object* element = KeyAt(entry); |
| 1977 | if (element == isolate->heap()->undefined_value()) break; // Empty entry. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame^] | 1978 | if (element != isolate->heap()->the_hole_value() && |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1979 | Shape::IsMatch(key, element)) return entry; |
| 1980 | entry = NextProbe(entry, count++, capacity); |
| 1981 | } |
| 1982 | return kNotFound; |
| 1983 | } |
| 1984 | |
| 1985 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 1986 | bool NumberDictionary::requires_slow_elements() { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1987 | Object* max_index_object = get(kMaxNumberKeyIndex); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1988 | if (!max_index_object->IsSmi()) return false; |
| 1989 | return 0 != |
| 1990 | (Smi::cast(max_index_object)->value() & kRequiresSlowElementsMask); |
| 1991 | } |
| 1992 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 1993 | uint32_t NumberDictionary::max_number_key() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1994 | ASSERT(!requires_slow_elements()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1995 | Object* max_index_object = get(kMaxNumberKeyIndex); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1996 | if (!max_index_object->IsSmi()) return 0; |
| 1997 | uint32_t value = static_cast<uint32_t>(Smi::cast(max_index_object)->value()); |
| 1998 | return value >> kRequiresSlowElementsTagSize; |
| 1999 | } |
| 2000 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2001 | void NumberDictionary::set_requires_slow_elements() { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2002 | set(kMaxNumberKeyIndex, Smi::FromInt(kRequiresSlowElementsMask)); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2006 | // ------------------------------------ |
| 2007 | // Cast operations |
| 2008 | |
| 2009 | |
| 2010 | CAST_ACCESSOR(FixedArray) |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2011 | CAST_ACCESSOR(FixedDoubleArray) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2012 | CAST_ACCESSOR(DescriptorArray) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2013 | CAST_ACCESSOR(DeoptimizationInputData) |
| 2014 | CAST_ACCESSOR(DeoptimizationOutputData) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2015 | CAST_ACCESSOR(SymbolTable) |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2016 | CAST_ACCESSOR(JSFunctionResultCache) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2017 | CAST_ACCESSOR(NormalizedMapCache) |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame^] | 2018 | CAST_ACCESSOR(ScopeInfo) |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2019 | CAST_ACCESSOR(CompilationCacheTable) |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2020 | CAST_ACCESSOR(CodeCacheHashTable) |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 2021 | CAST_ACCESSOR(PolymorphicCodeCacheHashTable) |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2022 | CAST_ACCESSOR(MapCache) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2023 | CAST_ACCESSOR(String) |
| 2024 | CAST_ACCESSOR(SeqString) |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2025 | CAST_ACCESSOR(SeqAsciiString) |
| 2026 | CAST_ACCESSOR(SeqTwoByteString) |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2027 | CAST_ACCESSOR(SlicedString) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2028 | CAST_ACCESSOR(ConsString) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2029 | CAST_ACCESSOR(ExternalString) |
| 2030 | CAST_ACCESSOR(ExternalAsciiString) |
| 2031 | CAST_ACCESSOR(ExternalTwoByteString) |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2032 | CAST_ACCESSOR(JSReceiver) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2033 | CAST_ACCESSOR(JSObject) |
| 2034 | CAST_ACCESSOR(Smi) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2035 | CAST_ACCESSOR(HeapObject) |
| 2036 | CAST_ACCESSOR(HeapNumber) |
| 2037 | CAST_ACCESSOR(Oddball) |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2038 | CAST_ACCESSOR(JSGlobalPropertyCell) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2039 | CAST_ACCESSOR(SharedFunctionInfo) |
| 2040 | CAST_ACCESSOR(Map) |
| 2041 | CAST_ACCESSOR(JSFunction) |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2042 | CAST_ACCESSOR(GlobalObject) |
| 2043 | CAST_ACCESSOR(JSGlobalProxy) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2044 | CAST_ACCESSOR(JSGlobalObject) |
| 2045 | CAST_ACCESSOR(JSBuiltinsObject) |
| 2046 | CAST_ACCESSOR(Code) |
| 2047 | CAST_ACCESSOR(JSArray) |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2048 | CAST_ACCESSOR(JSRegExp) |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2049 | CAST_ACCESSOR(JSProxy) |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2050 | CAST_ACCESSOR(JSFunctionProxy) |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2051 | CAST_ACCESSOR(JSSet) |
| 2052 | CAST_ACCESSOR(JSMap) |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2053 | CAST_ACCESSOR(JSWeakMap) |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2054 | CAST_ACCESSOR(Foreign) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2055 | CAST_ACCESSOR(ByteArray) |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2056 | CAST_ACCESSOR(FreeSpace) |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2057 | CAST_ACCESSOR(ExternalArray) |
| 2058 | CAST_ACCESSOR(ExternalByteArray) |
| 2059 | CAST_ACCESSOR(ExternalUnsignedByteArray) |
| 2060 | CAST_ACCESSOR(ExternalShortArray) |
| 2061 | CAST_ACCESSOR(ExternalUnsignedShortArray) |
| 2062 | CAST_ACCESSOR(ExternalIntArray) |
| 2063 | CAST_ACCESSOR(ExternalUnsignedIntArray) |
| 2064 | CAST_ACCESSOR(ExternalFloatArray) |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 2065 | CAST_ACCESSOR(ExternalDoubleArray) |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2066 | CAST_ACCESSOR(ExternalPixelArray) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2067 | CAST_ACCESSOR(Struct) |
| 2068 | |
| 2069 | |
| 2070 | #define MAKE_STRUCT_CAST(NAME, Name, name) CAST_ACCESSOR(Name) |
| 2071 | STRUCT_LIST(MAKE_STRUCT_CAST) |
| 2072 | #undef MAKE_STRUCT_CAST |
| 2073 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2074 | |
| 2075 | template <typename Shape, typename Key> |
| 2076 | HashTable<Shape, Key>* HashTable<Shape, Key>::cast(Object* obj) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2077 | ASSERT(obj->IsHashTable()); |
| 2078 | return reinterpret_cast<HashTable*>(obj); |
| 2079 | } |
| 2080 | |
| 2081 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2082 | SMI_ACCESSORS(FixedArrayBase, length, kLengthOffset) |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2083 | SMI_ACCESSORS(FreeSpace, size, kSizeOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2084 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2085 | SMI_ACCESSORS(String, length, kLengthOffset) |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2086 | |
| 2087 | |
| 2088 | uint32_t String::hash_field() { |
| 2089 | return READ_UINT32_FIELD(this, kHashFieldOffset); |
| 2090 | } |
| 2091 | |
| 2092 | |
| 2093 | void String::set_hash_field(uint32_t value) { |
| 2094 | WRITE_UINT32_FIELD(this, kHashFieldOffset, value); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2095 | #if V8_HOST_ARCH_64_BIT |
| 2096 | WRITE_UINT32_FIELD(this, kHashFieldOffset + kIntSize, 0); |
| 2097 | #endif |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2098 | } |
| 2099 | |
| 2100 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2101 | bool String::Equals(String* other) { |
| 2102 | if (other == this) return true; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2103 | if (StringShape(this).IsSymbol() && StringShape(other).IsSymbol()) { |
| 2104 | return false; |
| 2105 | } |
| 2106 | return SlowEquals(other); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2107 | } |
| 2108 | |
| 2109 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2110 | MaybeObject* String::TryFlatten(PretenureFlag pretenure) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2111 | if (!StringShape(this).IsCons()) return this; |
| 2112 | ConsString* cons = ConsString::cast(this); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2113 | if (cons->IsFlat()) return cons->first(); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2114 | return SlowTryFlatten(pretenure); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2115 | } |
| 2116 | |
| 2117 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2118 | String* String::TryFlattenGetString(PretenureFlag pretenure) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2119 | MaybeObject* flat = TryFlatten(pretenure); |
| 2120 | Object* successfully_flattened; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2121 | if (!flat->ToObject(&successfully_flattened)) return this; |
| 2122 | return String::cast(successfully_flattened); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2123 | } |
| 2124 | |
| 2125 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2126 | uint16_t String::Get(int index) { |
| 2127 | ASSERT(index >= 0 && index < length()); |
| 2128 | switch (StringShape(this).full_representation_tag()) { |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 2129 | case kSeqStringTag | kAsciiStringTag: |
| 2130 | return SeqAsciiString::cast(this)->SeqAsciiStringGet(index); |
| 2131 | case kSeqStringTag | kTwoByteStringTag: |
| 2132 | return SeqTwoByteString::cast(this)->SeqTwoByteStringGet(index); |
| 2133 | case kConsStringTag | kAsciiStringTag: |
| 2134 | case kConsStringTag | kTwoByteStringTag: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2135 | return ConsString::cast(this)->ConsStringGet(index); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 2136 | case kExternalStringTag | kAsciiStringTag: |
| 2137 | return ExternalAsciiString::cast(this)->ExternalAsciiStringGet(index); |
| 2138 | case kExternalStringTag | kTwoByteStringTag: |
| 2139 | return ExternalTwoByteString::cast(this)->ExternalTwoByteStringGet(index); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2140 | case kSlicedStringTag | kAsciiStringTag: |
| 2141 | case kSlicedStringTag | kTwoByteStringTag: |
| 2142 | return SlicedString::cast(this)->SlicedStringGet(index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2143 | default: |
| 2144 | break; |
| 2145 | } |
| 2146 | |
| 2147 | UNREACHABLE(); |
| 2148 | return 0; |
| 2149 | } |
| 2150 | |
| 2151 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2152 | void String::Set(int index, uint16_t value) { |
| 2153 | ASSERT(index >= 0 && index < length()); |
| 2154 | ASSERT(StringShape(this).IsSequential()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2155 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 2156 | return this->IsAsciiRepresentation() |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2157 | ? SeqAsciiString::cast(this)->SeqAsciiStringSet(index, value) |
| 2158 | : SeqTwoByteString::cast(this)->SeqTwoByteStringSet(index, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2159 | } |
| 2160 | |
| 2161 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2162 | bool String::IsFlat() { |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2163 | if (!StringShape(this).IsCons()) return true; |
| 2164 | return ConsString::cast(this)->second()->length() == 0; |
| 2165 | } |
| 2166 | |
| 2167 | |
| 2168 | String* String::GetUnderlying() { |
| 2169 | // Giving direct access to underlying string only makes sense if the |
| 2170 | // wrapping string is already flattened. |
| 2171 | ASSERT(this->IsFlat()); |
| 2172 | ASSERT(StringShape(this).IsIndirect()); |
| 2173 | STATIC_ASSERT(ConsString::kFirstOffset == SlicedString::kParentOffset); |
| 2174 | const int kUnderlyingOffset = SlicedString::kParentOffset; |
| 2175 | return String::cast(READ_FIELD(this, kUnderlyingOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2176 | } |
| 2177 | |
| 2178 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2179 | uint16_t SeqAsciiString::SeqAsciiStringGet(int index) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2180 | ASSERT(index >= 0 && index < length()); |
| 2181 | return READ_BYTE_FIELD(this, kHeaderSize + index * kCharSize); |
| 2182 | } |
| 2183 | |
| 2184 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2185 | void SeqAsciiString::SeqAsciiStringSet(int index, uint16_t value) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2186 | ASSERT(index >= 0 && index < length() && value <= kMaxAsciiCharCode); |
| 2187 | WRITE_BYTE_FIELD(this, kHeaderSize + index * kCharSize, |
| 2188 | static_cast<byte>(value)); |
| 2189 | } |
| 2190 | |
| 2191 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2192 | Address SeqAsciiString::GetCharsAddress() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2193 | return FIELD_ADDR(this, kHeaderSize); |
| 2194 | } |
| 2195 | |
| 2196 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2197 | char* SeqAsciiString::GetChars() { |
| 2198 | return reinterpret_cast<char*>(GetCharsAddress()); |
| 2199 | } |
| 2200 | |
| 2201 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2202 | Address SeqTwoByteString::GetCharsAddress() { |
| 2203 | return FIELD_ADDR(this, kHeaderSize); |
| 2204 | } |
| 2205 | |
| 2206 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2207 | uc16* SeqTwoByteString::GetChars() { |
| 2208 | return reinterpret_cast<uc16*>(FIELD_ADDR(this, kHeaderSize)); |
| 2209 | } |
| 2210 | |
| 2211 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2212 | uint16_t SeqTwoByteString::SeqTwoByteStringGet(int index) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2213 | ASSERT(index >= 0 && index < length()); |
| 2214 | return READ_SHORT_FIELD(this, kHeaderSize + index * kShortSize); |
| 2215 | } |
| 2216 | |
| 2217 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2218 | void SeqTwoByteString::SeqTwoByteStringSet(int index, uint16_t value) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2219 | ASSERT(index >= 0 && index < length()); |
| 2220 | WRITE_SHORT_FIELD(this, kHeaderSize + index * kShortSize, value); |
| 2221 | } |
| 2222 | |
| 2223 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2224 | int SeqTwoByteString::SeqTwoByteStringSize(InstanceType instance_type) { |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2225 | return SizeFor(length()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2226 | } |
| 2227 | |
| 2228 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2229 | int SeqAsciiString::SeqAsciiStringSize(InstanceType instance_type) { |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2230 | return SizeFor(length()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2231 | } |
| 2232 | |
| 2233 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2234 | String* SlicedString::parent() { |
| 2235 | return String::cast(READ_FIELD(this, kParentOffset)); |
| 2236 | } |
| 2237 | |
| 2238 | |
| 2239 | void SlicedString::set_parent(String* parent) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2240 | ASSERT(parent->IsSeqString() || parent->IsExternalString()); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2241 | WRITE_FIELD(this, kParentOffset, parent); |
| 2242 | } |
| 2243 | |
| 2244 | |
| 2245 | SMI_ACCESSORS(SlicedString, offset, kOffsetOffset) |
| 2246 | |
| 2247 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 2248 | String* ConsString::first() { |
| 2249 | return String::cast(READ_FIELD(this, kFirstOffset)); |
| 2250 | } |
| 2251 | |
| 2252 | |
| 2253 | Object* ConsString::unchecked_first() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2254 | return READ_FIELD(this, kFirstOffset); |
| 2255 | } |
| 2256 | |
| 2257 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 2258 | void ConsString::set_first(String* value, WriteBarrierMode mode) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2259 | WRITE_FIELD(this, kFirstOffset, value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2260 | CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kFirstOffset, value, mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2261 | } |
| 2262 | |
| 2263 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 2264 | String* ConsString::second() { |
| 2265 | return String::cast(READ_FIELD(this, kSecondOffset)); |
| 2266 | } |
| 2267 | |
| 2268 | |
| 2269 | Object* ConsString::unchecked_second() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2270 | return READ_FIELD(this, kSecondOffset); |
| 2271 | } |
| 2272 | |
| 2273 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 2274 | void ConsString::set_second(String* value, WriteBarrierMode mode) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2275 | WRITE_FIELD(this, kSecondOffset, value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2276 | CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kSecondOffset, value, mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2277 | } |
| 2278 | |
| 2279 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2280 | const ExternalAsciiString::Resource* ExternalAsciiString::resource() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2281 | return *reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset)); |
| 2282 | } |
| 2283 | |
| 2284 | |
| 2285 | void ExternalAsciiString::set_resource( |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2286 | const ExternalAsciiString::Resource* resource) { |
| 2287 | *reinterpret_cast<const Resource**>( |
| 2288 | FIELD_ADDR(this, kResourceOffset)) = resource; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2289 | } |
| 2290 | |
| 2291 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2292 | const ExternalTwoByteString::Resource* ExternalTwoByteString::resource() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2293 | return *reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset)); |
| 2294 | } |
| 2295 | |
| 2296 | |
| 2297 | void ExternalTwoByteString::set_resource( |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2298 | const ExternalTwoByteString::Resource* resource) { |
| 2299 | *reinterpret_cast<const Resource**>( |
| 2300 | FIELD_ADDR(this, kResourceOffset)) = resource; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2301 | } |
| 2302 | |
| 2303 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2304 | void JSFunctionResultCache::MakeZeroSize() { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2305 | set_finger_index(kEntriesIndex); |
| 2306 | set_size(kEntriesIndex); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2307 | } |
| 2308 | |
| 2309 | |
| 2310 | void JSFunctionResultCache::Clear() { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2311 | int cache_size = size(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2312 | Object** entries_start = RawField(this, OffsetOfElementAt(kEntriesIndex)); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2313 | MemsetPointer(entries_start, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2314 | GetHeap()->the_hole_value(), |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2315 | cache_size - kEntriesIndex); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2316 | MakeZeroSize(); |
| 2317 | } |
| 2318 | |
| 2319 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2320 | int JSFunctionResultCache::size() { |
| 2321 | return Smi::cast(get(kCacheSizeIndex))->value(); |
| 2322 | } |
| 2323 | |
| 2324 | |
| 2325 | void JSFunctionResultCache::set_size(int size) { |
| 2326 | set(kCacheSizeIndex, Smi::FromInt(size)); |
| 2327 | } |
| 2328 | |
| 2329 | |
| 2330 | int JSFunctionResultCache::finger_index() { |
| 2331 | return Smi::cast(get(kFingerIndex))->value(); |
| 2332 | } |
| 2333 | |
| 2334 | |
| 2335 | void JSFunctionResultCache::set_finger_index(int finger_index) { |
| 2336 | set(kFingerIndex, Smi::FromInt(finger_index)); |
| 2337 | } |
| 2338 | |
| 2339 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2340 | byte ByteArray::get(int index) { |
| 2341 | ASSERT(index >= 0 && index < this->length()); |
| 2342 | return READ_BYTE_FIELD(this, kHeaderSize + index * kCharSize); |
| 2343 | } |
| 2344 | |
| 2345 | |
| 2346 | void ByteArray::set(int index, byte value) { |
| 2347 | ASSERT(index >= 0 && index < this->length()); |
| 2348 | WRITE_BYTE_FIELD(this, kHeaderSize + index * kCharSize, value); |
| 2349 | } |
| 2350 | |
| 2351 | |
| 2352 | int ByteArray::get_int(int index) { |
| 2353 | ASSERT(index >= 0 && (index * kIntSize) < this->length()); |
| 2354 | return READ_INT_FIELD(this, kHeaderSize + index * kIntSize); |
| 2355 | } |
| 2356 | |
| 2357 | |
| 2358 | ByteArray* ByteArray::FromDataStartAddress(Address address) { |
| 2359 | ASSERT_TAG_ALIGNED(address); |
| 2360 | return reinterpret_cast<ByteArray*>(address - kHeaderSize + kHeapObjectTag); |
| 2361 | } |
| 2362 | |
| 2363 | |
| 2364 | Address ByteArray::GetDataStartAddress() { |
| 2365 | return reinterpret_cast<Address>(this) - kHeapObjectTag + kHeaderSize; |
| 2366 | } |
| 2367 | |
| 2368 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2369 | uint8_t* ExternalPixelArray::external_pixel_pointer() { |
| 2370 | return reinterpret_cast<uint8_t*>(external_pointer()); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2371 | } |
| 2372 | |
| 2373 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2374 | uint8_t ExternalPixelArray::get_scalar(int index) { |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2375 | ASSERT((index >= 0) && (index < this->length())); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2376 | uint8_t* ptr = external_pixel_pointer(); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2377 | return ptr[index]; |
| 2378 | } |
| 2379 | |
| 2380 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2381 | MaybeObject* ExternalPixelArray::get(int index) { |
| 2382 | return Smi::FromInt(static_cast<int>(get_scalar(index))); |
| 2383 | } |
| 2384 | |
| 2385 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2386 | void ExternalPixelArray::set(int index, uint8_t value) { |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2387 | ASSERT((index >= 0) && (index < this->length())); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2388 | uint8_t* ptr = external_pixel_pointer(); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2389 | ptr[index] = value; |
| 2390 | } |
| 2391 | |
| 2392 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2393 | void* ExternalArray::external_pointer() { |
| 2394 | intptr_t ptr = READ_INTPTR_FIELD(this, kExternalPointerOffset); |
| 2395 | return reinterpret_cast<void*>(ptr); |
| 2396 | } |
| 2397 | |
| 2398 | |
| 2399 | void ExternalArray::set_external_pointer(void* value, WriteBarrierMode mode) { |
| 2400 | intptr_t ptr = reinterpret_cast<intptr_t>(value); |
| 2401 | WRITE_INTPTR_FIELD(this, kExternalPointerOffset, ptr); |
| 2402 | } |
| 2403 | |
| 2404 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2405 | int8_t ExternalByteArray::get_scalar(int index) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2406 | ASSERT((index >= 0) && (index < this->length())); |
| 2407 | int8_t* ptr = static_cast<int8_t*>(external_pointer()); |
| 2408 | return ptr[index]; |
| 2409 | } |
| 2410 | |
| 2411 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2412 | MaybeObject* ExternalByteArray::get(int index) { |
| 2413 | return Smi::FromInt(static_cast<int>(get_scalar(index))); |
| 2414 | } |
| 2415 | |
| 2416 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2417 | void ExternalByteArray::set(int index, int8_t value) { |
| 2418 | ASSERT((index >= 0) && (index < this->length())); |
| 2419 | int8_t* ptr = static_cast<int8_t*>(external_pointer()); |
| 2420 | ptr[index] = value; |
| 2421 | } |
| 2422 | |
| 2423 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2424 | uint8_t ExternalUnsignedByteArray::get_scalar(int index) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2425 | ASSERT((index >= 0) && (index < this->length())); |
| 2426 | uint8_t* ptr = static_cast<uint8_t*>(external_pointer()); |
| 2427 | return ptr[index]; |
| 2428 | } |
| 2429 | |
| 2430 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2431 | MaybeObject* ExternalUnsignedByteArray::get(int index) { |
| 2432 | return Smi::FromInt(static_cast<int>(get_scalar(index))); |
| 2433 | } |
| 2434 | |
| 2435 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2436 | void ExternalUnsignedByteArray::set(int index, uint8_t value) { |
| 2437 | ASSERT((index >= 0) && (index < this->length())); |
| 2438 | uint8_t* ptr = static_cast<uint8_t*>(external_pointer()); |
| 2439 | ptr[index] = value; |
| 2440 | } |
| 2441 | |
| 2442 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2443 | int16_t ExternalShortArray::get_scalar(int index) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2444 | ASSERT((index >= 0) && (index < this->length())); |
| 2445 | int16_t* ptr = static_cast<int16_t*>(external_pointer()); |
| 2446 | return ptr[index]; |
| 2447 | } |
| 2448 | |
| 2449 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2450 | MaybeObject* ExternalShortArray::get(int index) { |
| 2451 | return Smi::FromInt(static_cast<int>(get_scalar(index))); |
| 2452 | } |
| 2453 | |
| 2454 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2455 | void ExternalShortArray::set(int index, int16_t value) { |
| 2456 | ASSERT((index >= 0) && (index < this->length())); |
| 2457 | int16_t* ptr = static_cast<int16_t*>(external_pointer()); |
| 2458 | ptr[index] = value; |
| 2459 | } |
| 2460 | |
| 2461 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2462 | uint16_t ExternalUnsignedShortArray::get_scalar(int index) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2463 | ASSERT((index >= 0) && (index < this->length())); |
| 2464 | uint16_t* ptr = static_cast<uint16_t*>(external_pointer()); |
| 2465 | return ptr[index]; |
| 2466 | } |
| 2467 | |
| 2468 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2469 | MaybeObject* ExternalUnsignedShortArray::get(int index) { |
| 2470 | return Smi::FromInt(static_cast<int>(get_scalar(index))); |
| 2471 | } |
| 2472 | |
| 2473 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2474 | void ExternalUnsignedShortArray::set(int index, uint16_t value) { |
| 2475 | ASSERT((index >= 0) && (index < this->length())); |
| 2476 | uint16_t* ptr = static_cast<uint16_t*>(external_pointer()); |
| 2477 | ptr[index] = value; |
| 2478 | } |
| 2479 | |
| 2480 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2481 | int32_t ExternalIntArray::get_scalar(int index) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2482 | ASSERT((index >= 0) && (index < this->length())); |
| 2483 | int32_t* ptr = static_cast<int32_t*>(external_pointer()); |
| 2484 | return ptr[index]; |
| 2485 | } |
| 2486 | |
| 2487 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2488 | MaybeObject* ExternalIntArray::get(int index) { |
| 2489 | return GetHeap()->NumberFromInt32(get_scalar(index)); |
| 2490 | } |
| 2491 | |
| 2492 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2493 | void ExternalIntArray::set(int index, int32_t value) { |
| 2494 | ASSERT((index >= 0) && (index < this->length())); |
| 2495 | int32_t* ptr = static_cast<int32_t*>(external_pointer()); |
| 2496 | ptr[index] = value; |
| 2497 | } |
| 2498 | |
| 2499 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2500 | uint32_t ExternalUnsignedIntArray::get_scalar(int index) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2501 | ASSERT((index >= 0) && (index < this->length())); |
| 2502 | uint32_t* ptr = static_cast<uint32_t*>(external_pointer()); |
| 2503 | return ptr[index]; |
| 2504 | } |
| 2505 | |
| 2506 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2507 | MaybeObject* ExternalUnsignedIntArray::get(int index) { |
| 2508 | return GetHeap()->NumberFromUint32(get_scalar(index)); |
| 2509 | } |
| 2510 | |
| 2511 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2512 | void ExternalUnsignedIntArray::set(int index, uint32_t value) { |
| 2513 | ASSERT((index >= 0) && (index < this->length())); |
| 2514 | uint32_t* ptr = static_cast<uint32_t*>(external_pointer()); |
| 2515 | ptr[index] = value; |
| 2516 | } |
| 2517 | |
| 2518 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2519 | float ExternalFloatArray::get_scalar(int index) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2520 | ASSERT((index >= 0) && (index < this->length())); |
| 2521 | float* ptr = static_cast<float*>(external_pointer()); |
| 2522 | return ptr[index]; |
| 2523 | } |
| 2524 | |
| 2525 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2526 | MaybeObject* ExternalFloatArray::get(int index) { |
| 2527 | return GetHeap()->NumberFromDouble(get_scalar(index)); |
| 2528 | } |
| 2529 | |
| 2530 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2531 | void ExternalFloatArray::set(int index, float value) { |
| 2532 | ASSERT((index >= 0) && (index < this->length())); |
| 2533 | float* ptr = static_cast<float*>(external_pointer()); |
| 2534 | ptr[index] = value; |
| 2535 | } |
| 2536 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2537 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2538 | double ExternalDoubleArray::get_scalar(int index) { |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 2539 | ASSERT((index >= 0) && (index < this->length())); |
| 2540 | double* ptr = static_cast<double*>(external_pointer()); |
| 2541 | return ptr[index]; |
| 2542 | } |
| 2543 | |
| 2544 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2545 | MaybeObject* ExternalDoubleArray::get(int index) { |
| 2546 | return GetHeap()->NumberFromDouble(get_scalar(index)); |
| 2547 | } |
| 2548 | |
| 2549 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 2550 | void ExternalDoubleArray::set(int index, double value) { |
| 2551 | ASSERT((index >= 0) && (index < this->length())); |
| 2552 | double* ptr = static_cast<double*>(external_pointer()); |
| 2553 | ptr[index] = value; |
| 2554 | } |
| 2555 | |
| 2556 | |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 2557 | int Map::visitor_id() { |
| 2558 | return READ_BYTE_FIELD(this, kVisitorIdOffset); |
| 2559 | } |
| 2560 | |
| 2561 | |
| 2562 | void Map::set_visitor_id(int id) { |
| 2563 | ASSERT(0 <= id && id < 256); |
| 2564 | WRITE_BYTE_FIELD(this, kVisitorIdOffset, static_cast<byte>(id)); |
| 2565 | } |
| 2566 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2567 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2568 | int Map::instance_size() { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2569 | return READ_BYTE_FIELD(this, kInstanceSizeOffset) << kPointerSizeLog2; |
| 2570 | } |
| 2571 | |
| 2572 | |
| 2573 | int Map::inobject_properties() { |
| 2574 | return READ_BYTE_FIELD(this, kInObjectPropertiesOffset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2575 | } |
| 2576 | |
| 2577 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 2578 | int Map::pre_allocated_property_fields() { |
| 2579 | return READ_BYTE_FIELD(this, kPreAllocatedPropertyFieldsOffset); |
| 2580 | } |
| 2581 | |
| 2582 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2583 | int HeapObject::SizeFromMap(Map* map) { |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 2584 | int instance_size = map->instance_size(); |
| 2585 | if (instance_size != kVariableSizeSentinel) return instance_size; |
| 2586 | // We can ignore the "symbol" bit becase it is only set for symbols |
| 2587 | // and implies a string type. |
| 2588 | int instance_type = static_cast<int>(map->instance_type()) & ~kIsSymbolMask; |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 2589 | // Only inline the most frequent cases. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2590 | if (instance_type == FIXED_ARRAY_TYPE) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2591 | return FixedArray::BodyDescriptor::SizeOf(map, this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2592 | } |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 2593 | if (instance_type == ASCII_STRING_TYPE) { |
| 2594 | return SeqAsciiString::SizeFor( |
| 2595 | reinterpret_cast<SeqAsciiString*>(this)->length()); |
| 2596 | } |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 2597 | if (instance_type == BYTE_ARRAY_TYPE) { |
| 2598 | return reinterpret_cast<ByteArray*>(this)->ByteArraySize(); |
| 2599 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2600 | if (instance_type == FREE_SPACE_TYPE) { |
| 2601 | return reinterpret_cast<FreeSpace*>(this)->size(); |
| 2602 | } |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 2603 | if (instance_type == STRING_TYPE) { |
| 2604 | return SeqTwoByteString::SizeFor( |
| 2605 | reinterpret_cast<SeqTwoByteString*>(this)->length()); |
| 2606 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2607 | if (instance_type == FIXED_DOUBLE_ARRAY_TYPE) { |
| 2608 | return FixedDoubleArray::SizeFor( |
| 2609 | reinterpret_cast<FixedDoubleArray*>(this)->length()); |
| 2610 | } |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 2611 | ASSERT(instance_type == CODE_TYPE); |
| 2612 | return reinterpret_cast<Code*>(this)->CodeSize(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2613 | } |
| 2614 | |
| 2615 | |
| 2616 | void Map::set_instance_size(int value) { |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2617 | ASSERT_EQ(0, value & (kPointerSize - 1)); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2618 | value >>= kPointerSizeLog2; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2619 | ASSERT(0 <= value && value < 256); |
| 2620 | WRITE_BYTE_FIELD(this, kInstanceSizeOffset, static_cast<byte>(value)); |
| 2621 | } |
| 2622 | |
| 2623 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2624 | void Map::set_inobject_properties(int value) { |
| 2625 | ASSERT(0 <= value && value < 256); |
| 2626 | WRITE_BYTE_FIELD(this, kInObjectPropertiesOffset, static_cast<byte>(value)); |
| 2627 | } |
| 2628 | |
| 2629 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 2630 | void Map::set_pre_allocated_property_fields(int value) { |
| 2631 | ASSERT(0 <= value && value < 256); |
| 2632 | WRITE_BYTE_FIELD(this, |
| 2633 | kPreAllocatedPropertyFieldsOffset, |
| 2634 | static_cast<byte>(value)); |
| 2635 | } |
| 2636 | |
| 2637 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2638 | InstanceType Map::instance_type() { |
| 2639 | return static_cast<InstanceType>(READ_BYTE_FIELD(this, kInstanceTypeOffset)); |
| 2640 | } |
| 2641 | |
| 2642 | |
| 2643 | void Map::set_instance_type(InstanceType value) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2644 | WRITE_BYTE_FIELD(this, kInstanceTypeOffset, value); |
| 2645 | } |
| 2646 | |
| 2647 | |
| 2648 | int Map::unused_property_fields() { |
| 2649 | return READ_BYTE_FIELD(this, kUnusedPropertyFieldsOffset); |
| 2650 | } |
| 2651 | |
| 2652 | |
| 2653 | void Map::set_unused_property_fields(int value) { |
| 2654 | WRITE_BYTE_FIELD(this, kUnusedPropertyFieldsOffset, Min(value, 255)); |
| 2655 | } |
| 2656 | |
| 2657 | |
| 2658 | byte Map::bit_field() { |
| 2659 | return READ_BYTE_FIELD(this, kBitFieldOffset); |
| 2660 | } |
| 2661 | |
| 2662 | |
| 2663 | void Map::set_bit_field(byte value) { |
| 2664 | WRITE_BYTE_FIELD(this, kBitFieldOffset, value); |
| 2665 | } |
| 2666 | |
| 2667 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 2668 | byte Map::bit_field2() { |
| 2669 | return READ_BYTE_FIELD(this, kBitField2Offset); |
| 2670 | } |
| 2671 | |
| 2672 | |
| 2673 | void Map::set_bit_field2(byte value) { |
| 2674 | WRITE_BYTE_FIELD(this, kBitField2Offset, value); |
| 2675 | } |
| 2676 | |
| 2677 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2678 | void Map::set_non_instance_prototype(bool value) { |
| 2679 | if (value) { |
| 2680 | set_bit_field(bit_field() | (1 << kHasNonInstancePrototype)); |
| 2681 | } else { |
| 2682 | set_bit_field(bit_field() & ~(1 << kHasNonInstancePrototype)); |
| 2683 | } |
| 2684 | } |
| 2685 | |
| 2686 | |
| 2687 | bool Map::has_non_instance_prototype() { |
| 2688 | return ((1 << kHasNonInstancePrototype) & bit_field()) != 0; |
| 2689 | } |
| 2690 | |
| 2691 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 2692 | void Map::set_function_with_prototype(bool value) { |
| 2693 | if (value) { |
| 2694 | set_bit_field2(bit_field2() | (1 << kFunctionWithPrototype)); |
| 2695 | } else { |
| 2696 | set_bit_field2(bit_field2() & ~(1 << kFunctionWithPrototype)); |
| 2697 | } |
| 2698 | } |
| 2699 | |
| 2700 | |
| 2701 | bool Map::function_with_prototype() { |
| 2702 | return ((1 << kFunctionWithPrototype) & bit_field2()) != 0; |
| 2703 | } |
| 2704 | |
| 2705 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 2706 | void Map::set_is_access_check_needed(bool access_check_needed) { |
| 2707 | if (access_check_needed) { |
| 2708 | set_bit_field(bit_field() | (1 << kIsAccessCheckNeeded)); |
| 2709 | } else { |
| 2710 | set_bit_field(bit_field() & ~(1 << kIsAccessCheckNeeded)); |
| 2711 | } |
| 2712 | } |
| 2713 | |
| 2714 | |
| 2715 | bool Map::is_access_check_needed() { |
| 2716 | return ((1 << kIsAccessCheckNeeded) & bit_field()) != 0; |
| 2717 | } |
| 2718 | |
| 2719 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2720 | void Map::set_is_extensible(bool value) { |
| 2721 | if (value) { |
| 2722 | set_bit_field2(bit_field2() | (1 << kIsExtensible)); |
| 2723 | } else { |
| 2724 | set_bit_field2(bit_field2() & ~(1 << kIsExtensible)); |
| 2725 | } |
| 2726 | } |
| 2727 | |
| 2728 | bool Map::is_extensible() { |
| 2729 | return ((1 << kIsExtensible) & bit_field2()) != 0; |
| 2730 | } |
| 2731 | |
| 2732 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2733 | void Map::set_attached_to_shared_function_info(bool value) { |
| 2734 | if (value) { |
| 2735 | set_bit_field2(bit_field2() | (1 << kAttachedToSharedFunctionInfo)); |
| 2736 | } else { |
| 2737 | set_bit_field2(bit_field2() & ~(1 << kAttachedToSharedFunctionInfo)); |
| 2738 | } |
| 2739 | } |
| 2740 | |
| 2741 | bool Map::attached_to_shared_function_info() { |
| 2742 | return ((1 << kAttachedToSharedFunctionInfo) & bit_field2()) != 0; |
| 2743 | } |
| 2744 | |
| 2745 | |
| 2746 | void Map::set_is_shared(bool value) { |
| 2747 | if (value) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2748 | set_bit_field3(bit_field3() | (1 << kIsShared)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2749 | } else { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2750 | set_bit_field3(bit_field3() & ~(1 << kIsShared)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2751 | } |
| 2752 | } |
| 2753 | |
| 2754 | bool Map::is_shared() { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2755 | return ((1 << kIsShared) & bit_field3()) != 0; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2756 | } |
| 2757 | |
| 2758 | |
| 2759 | JSFunction* Map::unchecked_constructor() { |
| 2760 | return reinterpret_cast<JSFunction*>(READ_FIELD(this, kConstructorOffset)); |
| 2761 | } |
| 2762 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2763 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2764 | Code::Flags Code::flags() { |
| 2765 | return static_cast<Flags>(READ_INT_FIELD(this, kFlagsOffset)); |
| 2766 | } |
| 2767 | |
| 2768 | |
| 2769 | void Code::set_flags(Code::Flags flags) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2770 | STATIC_ASSERT(Code::NUMBER_OF_KINDS <= KindField::kMax + 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2771 | // Make sure that all call stubs have an arguments count. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2772 | ASSERT((ExtractKindFromFlags(flags) != CALL_IC && |
| 2773 | ExtractKindFromFlags(flags) != KEYED_CALL_IC) || |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2774 | ExtractArgumentsCountFromFlags(flags) >= 0); |
| 2775 | WRITE_INT_FIELD(this, kFlagsOffset, flags); |
| 2776 | } |
| 2777 | |
| 2778 | |
| 2779 | Code::Kind Code::kind() { |
| 2780 | return ExtractKindFromFlags(flags()); |
| 2781 | } |
| 2782 | |
| 2783 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2784 | InlineCacheState Code::ic_state() { |
| 2785 | InlineCacheState result = ExtractICStateFromFlags(flags()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2786 | // Only allow uninitialized or debugger states for non-IC code |
| 2787 | // objects. This is used in the debugger to determine whether or not |
| 2788 | // a call to code object has been replaced with a debug break call. |
| 2789 | ASSERT(is_inline_cache_stub() || |
| 2790 | result == UNINITIALIZED || |
| 2791 | result == DEBUG_BREAK || |
| 2792 | result == DEBUG_PREPARE_STEP_IN); |
| 2793 | return result; |
| 2794 | } |
| 2795 | |
| 2796 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2797 | Code::ExtraICState Code::extra_ic_state() { |
| 2798 | ASSERT(is_inline_cache_stub()); |
| 2799 | return ExtractExtraICStateFromFlags(flags()); |
| 2800 | } |
| 2801 | |
| 2802 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2803 | PropertyType Code::type() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2804 | return ExtractTypeFromFlags(flags()); |
| 2805 | } |
| 2806 | |
| 2807 | |
| 2808 | int Code::arguments_count() { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2809 | ASSERT(is_call_stub() || is_keyed_call_stub() || kind() == STUB); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2810 | return ExtractArgumentsCountFromFlags(flags()); |
| 2811 | } |
| 2812 | |
| 2813 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2814 | int Code::major_key() { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2815 | ASSERT(kind() == STUB || |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2816 | kind() == UNARY_OP_IC || |
| 2817 | kind() == BINARY_OP_IC || |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 2818 | kind() == COMPARE_IC || |
| 2819 | kind() == TO_BOOLEAN_IC); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2820 | return READ_BYTE_FIELD(this, kStubMajorKeyOffset); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2821 | } |
| 2822 | |
| 2823 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2824 | void Code::set_major_key(int major) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2825 | ASSERT(kind() == STUB || |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2826 | kind() == UNARY_OP_IC || |
| 2827 | kind() == BINARY_OP_IC || |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 2828 | kind() == COMPARE_IC || |
| 2829 | kind() == TO_BOOLEAN_IC); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2830 | ASSERT(0 <= major && major < 256); |
| 2831 | WRITE_BYTE_FIELD(this, kStubMajorKeyOffset, major); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2832 | } |
| 2833 | |
| 2834 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2835 | bool Code::is_pregenerated() { |
| 2836 | return kind() == STUB && IsPregeneratedField::decode(flags()); |
| 2837 | } |
| 2838 | |
| 2839 | |
| 2840 | void Code::set_is_pregenerated(bool value) { |
| 2841 | ASSERT(kind() == STUB); |
| 2842 | Flags f = flags(); |
| 2843 | f = static_cast<Flags>(IsPregeneratedField::update(f, value)); |
| 2844 | set_flags(f); |
| 2845 | } |
| 2846 | |
| 2847 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2848 | bool Code::optimizable() { |
| 2849 | ASSERT(kind() == FUNCTION); |
| 2850 | return READ_BYTE_FIELD(this, kOptimizableOffset) == 1; |
| 2851 | } |
| 2852 | |
| 2853 | |
| 2854 | void Code::set_optimizable(bool value) { |
| 2855 | ASSERT(kind() == FUNCTION); |
| 2856 | WRITE_BYTE_FIELD(this, kOptimizableOffset, value ? 1 : 0); |
| 2857 | } |
| 2858 | |
| 2859 | |
| 2860 | bool Code::has_deoptimization_support() { |
| 2861 | ASSERT(kind() == FUNCTION); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2862 | byte flags = READ_BYTE_FIELD(this, kFullCodeFlags); |
| 2863 | return FullCodeFlagsHasDeoptimizationSupportField::decode(flags); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2864 | } |
| 2865 | |
| 2866 | |
| 2867 | void Code::set_has_deoptimization_support(bool value) { |
| 2868 | ASSERT(kind() == FUNCTION); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2869 | byte flags = READ_BYTE_FIELD(this, kFullCodeFlags); |
| 2870 | flags = FullCodeFlagsHasDeoptimizationSupportField::update(flags, value); |
| 2871 | WRITE_BYTE_FIELD(this, kFullCodeFlags, flags); |
| 2872 | } |
| 2873 | |
| 2874 | |
| 2875 | bool Code::has_debug_break_slots() { |
| 2876 | ASSERT(kind() == FUNCTION); |
| 2877 | byte flags = READ_BYTE_FIELD(this, kFullCodeFlags); |
| 2878 | return FullCodeFlagsHasDebugBreakSlotsField::decode(flags); |
| 2879 | } |
| 2880 | |
| 2881 | |
| 2882 | void Code::set_has_debug_break_slots(bool value) { |
| 2883 | ASSERT(kind() == FUNCTION); |
| 2884 | byte flags = READ_BYTE_FIELD(this, kFullCodeFlags); |
| 2885 | flags = FullCodeFlagsHasDebugBreakSlotsField::update(flags, value); |
| 2886 | WRITE_BYTE_FIELD(this, kFullCodeFlags, flags); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2887 | } |
| 2888 | |
| 2889 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2890 | bool Code::is_compiled_optimizable() { |
| 2891 | ASSERT(kind() == FUNCTION); |
| 2892 | byte flags = READ_BYTE_FIELD(this, kFullCodeFlags); |
| 2893 | return FullCodeFlagsIsCompiledOptimizable::decode(flags); |
| 2894 | } |
| 2895 | |
| 2896 | |
| 2897 | void Code::set_compiled_optimizable(bool value) { |
| 2898 | ASSERT(kind() == FUNCTION); |
| 2899 | byte flags = READ_BYTE_FIELD(this, kFullCodeFlags); |
| 2900 | flags = FullCodeFlagsIsCompiledOptimizable::update(flags, value); |
| 2901 | WRITE_BYTE_FIELD(this, kFullCodeFlags, flags); |
| 2902 | } |
| 2903 | |
| 2904 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2905 | int Code::allow_osr_at_loop_nesting_level() { |
| 2906 | ASSERT(kind() == FUNCTION); |
| 2907 | return READ_BYTE_FIELD(this, kAllowOSRAtLoopNestingLevelOffset); |
| 2908 | } |
| 2909 | |
| 2910 | |
| 2911 | void Code::set_allow_osr_at_loop_nesting_level(int level) { |
| 2912 | ASSERT(kind() == FUNCTION); |
| 2913 | ASSERT(level >= 0 && level <= kMaxLoopNestingMarker); |
| 2914 | WRITE_BYTE_FIELD(this, kAllowOSRAtLoopNestingLevelOffset, level); |
| 2915 | } |
| 2916 | |
| 2917 | |
| 2918 | unsigned Code::stack_slots() { |
| 2919 | ASSERT(kind() == OPTIMIZED_FUNCTION); |
| 2920 | return READ_UINT32_FIELD(this, kStackSlotsOffset); |
| 2921 | } |
| 2922 | |
| 2923 | |
| 2924 | void Code::set_stack_slots(unsigned slots) { |
| 2925 | ASSERT(kind() == OPTIMIZED_FUNCTION); |
| 2926 | WRITE_UINT32_FIELD(this, kStackSlotsOffset, slots); |
| 2927 | } |
| 2928 | |
| 2929 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2930 | unsigned Code::safepoint_table_offset() { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2931 | ASSERT(kind() == OPTIMIZED_FUNCTION); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2932 | return READ_UINT32_FIELD(this, kSafepointTableOffsetOffset); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2933 | } |
| 2934 | |
| 2935 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2936 | void Code::set_safepoint_table_offset(unsigned offset) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2937 | ASSERT(kind() == OPTIMIZED_FUNCTION); |
| 2938 | ASSERT(IsAligned(offset, static_cast<unsigned>(kIntSize))); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2939 | WRITE_UINT32_FIELD(this, kSafepointTableOffsetOffset, offset); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2940 | } |
| 2941 | |
| 2942 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2943 | unsigned Code::stack_check_table_offset() { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2944 | ASSERT(kind() == FUNCTION); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2945 | return READ_UINT32_FIELD(this, kStackCheckTableOffsetOffset); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2946 | } |
| 2947 | |
| 2948 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2949 | void Code::set_stack_check_table_offset(unsigned offset) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2950 | ASSERT(kind() == FUNCTION); |
| 2951 | ASSERT(IsAligned(offset, static_cast<unsigned>(kIntSize))); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2952 | WRITE_UINT32_FIELD(this, kStackCheckTableOffsetOffset, offset); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2953 | } |
| 2954 | |
| 2955 | |
| 2956 | CheckType Code::check_type() { |
| 2957 | ASSERT(is_call_stub() || is_keyed_call_stub()); |
| 2958 | byte type = READ_BYTE_FIELD(this, kCheckTypeOffset); |
| 2959 | return static_cast<CheckType>(type); |
| 2960 | } |
| 2961 | |
| 2962 | |
| 2963 | void Code::set_check_type(CheckType value) { |
| 2964 | ASSERT(is_call_stub() || is_keyed_call_stub()); |
| 2965 | WRITE_BYTE_FIELD(this, kCheckTypeOffset, value); |
| 2966 | } |
| 2967 | |
| 2968 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2969 | byte Code::unary_op_type() { |
| 2970 | ASSERT(is_unary_op_stub()); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2971 | return READ_BYTE_FIELD(this, kUnaryOpTypeOffset); |
| 2972 | } |
| 2973 | |
| 2974 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2975 | void Code::set_unary_op_type(byte value) { |
| 2976 | ASSERT(is_unary_op_stub()); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2977 | WRITE_BYTE_FIELD(this, kUnaryOpTypeOffset, value); |
| 2978 | } |
| 2979 | |
| 2980 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2981 | byte Code::binary_op_type() { |
| 2982 | ASSERT(is_binary_op_stub()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2983 | return READ_BYTE_FIELD(this, kBinaryOpTypeOffset); |
| 2984 | } |
| 2985 | |
| 2986 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2987 | void Code::set_binary_op_type(byte value) { |
| 2988 | ASSERT(is_binary_op_stub()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2989 | WRITE_BYTE_FIELD(this, kBinaryOpTypeOffset, value); |
| 2990 | } |
| 2991 | |
| 2992 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2993 | byte Code::binary_op_result_type() { |
| 2994 | ASSERT(is_binary_op_stub()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2995 | return READ_BYTE_FIELD(this, kBinaryOpReturnTypeOffset); |
| 2996 | } |
| 2997 | |
| 2998 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2999 | void Code::set_binary_op_result_type(byte value) { |
| 3000 | ASSERT(is_binary_op_stub()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3001 | WRITE_BYTE_FIELD(this, kBinaryOpReturnTypeOffset, value); |
| 3002 | } |
| 3003 | |
| 3004 | |
| 3005 | byte Code::compare_state() { |
| 3006 | ASSERT(is_compare_ic_stub()); |
| 3007 | return READ_BYTE_FIELD(this, kCompareStateOffset); |
| 3008 | } |
| 3009 | |
| 3010 | |
| 3011 | void Code::set_compare_state(byte value) { |
| 3012 | ASSERT(is_compare_ic_stub()); |
| 3013 | WRITE_BYTE_FIELD(this, kCompareStateOffset, value); |
| 3014 | } |
| 3015 | |
| 3016 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 3017 | byte Code::to_boolean_state() { |
| 3018 | ASSERT(is_to_boolean_ic_stub()); |
| 3019 | return READ_BYTE_FIELD(this, kToBooleanTypeOffset); |
| 3020 | } |
| 3021 | |
| 3022 | |
| 3023 | void Code::set_to_boolean_state(byte value) { |
| 3024 | ASSERT(is_to_boolean_ic_stub()); |
| 3025 | WRITE_BYTE_FIELD(this, kToBooleanTypeOffset, value); |
| 3026 | } |
| 3027 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3028 | |
| 3029 | bool Code::has_function_cache() { |
| 3030 | ASSERT(kind() == STUB); |
| 3031 | return READ_BYTE_FIELD(this, kHasFunctionCacheOffset) != 0; |
| 3032 | } |
| 3033 | |
| 3034 | |
| 3035 | void Code::set_has_function_cache(bool flag) { |
| 3036 | ASSERT(kind() == STUB); |
| 3037 | WRITE_BYTE_FIELD(this, kHasFunctionCacheOffset, flag); |
| 3038 | } |
| 3039 | |
| 3040 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3041 | bool Code::is_inline_cache_stub() { |
| 3042 | Kind kind = this->kind(); |
| 3043 | return kind >= FIRST_IC_KIND && kind <= LAST_IC_KIND; |
| 3044 | } |
| 3045 | |
| 3046 | |
| 3047 | Code::Flags Code::ComputeFlags(Kind kind, |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3048 | InlineCacheState ic_state, |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3049 | ExtraICState extra_ic_state, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3050 | PropertyType type, |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3051 | int argc, |
| 3052 | InlineCacheHolderFlag holder) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3053 | // Extra IC state is only allowed for call IC stubs or for store IC |
| 3054 | // stubs. |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3055 | ASSERT(extra_ic_state == kNoExtraICState || |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 3056 | kind == CALL_IC || |
| 3057 | kind == STORE_IC || |
| 3058 | kind == KEYED_STORE_IC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3059 | // Compute the bit mask. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3060 | int bits = KindField::encode(kind) |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3061 | | ICStateField::encode(ic_state) |
| 3062 | | TypeField::encode(type) |
| 3063 | | ExtraICStateField::encode(extra_ic_state) |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 3064 | | (argc << kArgumentsCountShift) |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3065 | | CacheHolderField::encode(holder); |
| 3066 | return static_cast<Flags>(bits); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3067 | } |
| 3068 | |
| 3069 | |
| 3070 | Code::Flags Code::ComputeMonomorphicFlags(Kind kind, |
| 3071 | PropertyType type, |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3072 | ExtraICState extra_ic_state, |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3073 | InlineCacheHolderFlag holder, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3074 | int argc) { |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 3075 | return ComputeFlags(kind, MONOMORPHIC, extra_ic_state, type, argc, holder); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3076 | } |
| 3077 | |
| 3078 | |
| 3079 | Code::Kind Code::ExtractKindFromFlags(Flags flags) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3080 | return KindField::decode(flags); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3081 | } |
| 3082 | |
| 3083 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3084 | InlineCacheState Code::ExtractICStateFromFlags(Flags flags) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3085 | return ICStateField::decode(flags); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3086 | } |
| 3087 | |
| 3088 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3089 | Code::ExtraICState Code::ExtractExtraICStateFromFlags(Flags flags) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3090 | return ExtraICStateField::decode(flags); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3091 | } |
| 3092 | |
| 3093 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3094 | PropertyType Code::ExtractTypeFromFlags(Flags flags) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3095 | return TypeField::decode(flags); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3096 | } |
| 3097 | |
| 3098 | |
| 3099 | int Code::ExtractArgumentsCountFromFlags(Flags flags) { |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 3100 | return (flags & kArgumentsCountMask) >> kArgumentsCountShift; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3101 | } |
| 3102 | |
| 3103 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3104 | InlineCacheHolderFlag Code::ExtractCacheHolderFromFlags(Flags flags) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3105 | return CacheHolderField::decode(flags); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3106 | } |
| 3107 | |
| 3108 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3109 | Code::Flags Code::RemoveTypeFromFlags(Flags flags) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3110 | int bits = flags & ~TypeField::kMask; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3111 | return static_cast<Flags>(bits); |
| 3112 | } |
| 3113 | |
| 3114 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 3115 | Code* Code::GetCodeFromTargetAddress(Address address) { |
| 3116 | HeapObject* code = HeapObject::FromAddress(address - Code::kHeaderSize); |
| 3117 | // GetCodeFromTargetAddress might be called when marking objects during mark |
| 3118 | // sweep. reinterpret_cast is therefore used instead of the more appropriate |
| 3119 | // Code::cast. Code::cast does not work when the object's map is |
| 3120 | // marked. |
| 3121 | Code* result = reinterpret_cast<Code*>(code); |
| 3122 | return result; |
| 3123 | } |
| 3124 | |
| 3125 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 3126 | Object* Code::GetObjectFromEntryAddress(Address location_of_address) { |
| 3127 | return HeapObject:: |
| 3128 | FromAddress(Memory::Address_at(location_of_address) - Code::kHeaderSize); |
| 3129 | } |
| 3130 | |
| 3131 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3132 | Object* Map::prototype() { |
| 3133 | return READ_FIELD(this, kPrototypeOffset); |
| 3134 | } |
| 3135 | |
| 3136 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3137 | void Map::set_prototype(Object* value, WriteBarrierMode mode) { |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 3138 | ASSERT(value->IsNull() || value->IsJSReceiver()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3139 | WRITE_FIELD(this, kPrototypeOffset, value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3140 | CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kPrototypeOffset, value, mode); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3141 | } |
| 3142 | |
| 3143 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3144 | DescriptorArray* Map::instance_descriptors() { |
| 3145 | Object* object = READ_FIELD(this, kInstanceDescriptorsOrBitField3Offset); |
| 3146 | if (object->IsSmi()) { |
| 3147 | return HEAP->empty_descriptor_array(); |
| 3148 | } else { |
| 3149 | return DescriptorArray::cast(object); |
| 3150 | } |
| 3151 | } |
| 3152 | |
| 3153 | |
| 3154 | void Map::init_instance_descriptors() { |
| 3155 | WRITE_FIELD(this, kInstanceDescriptorsOrBitField3Offset, Smi::FromInt(0)); |
| 3156 | } |
| 3157 | |
| 3158 | |
| 3159 | void Map::clear_instance_descriptors() { |
| 3160 | Object* object = READ_FIELD(this, |
| 3161 | kInstanceDescriptorsOrBitField3Offset); |
| 3162 | if (!object->IsSmi()) { |
| 3163 | WRITE_FIELD( |
| 3164 | this, |
| 3165 | kInstanceDescriptorsOrBitField3Offset, |
| 3166 | Smi::FromInt(DescriptorArray::cast(object)->bit_field3_storage())); |
| 3167 | } |
| 3168 | } |
| 3169 | |
| 3170 | |
| 3171 | void Map::set_instance_descriptors(DescriptorArray* value, |
| 3172 | WriteBarrierMode mode) { |
| 3173 | Object* object = READ_FIELD(this, |
| 3174 | kInstanceDescriptorsOrBitField3Offset); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3175 | Heap* heap = GetHeap(); |
| 3176 | if (value == heap->empty_descriptor_array()) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3177 | clear_instance_descriptors(); |
| 3178 | return; |
| 3179 | } else { |
| 3180 | if (object->IsSmi()) { |
| 3181 | value->set_bit_field3_storage(Smi::cast(object)->value()); |
| 3182 | } else { |
| 3183 | value->set_bit_field3_storage( |
| 3184 | DescriptorArray::cast(object)->bit_field3_storage()); |
| 3185 | } |
| 3186 | } |
| 3187 | ASSERT(!is_shared()); |
| 3188 | WRITE_FIELD(this, kInstanceDescriptorsOrBitField3Offset, value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3189 | CONDITIONAL_WRITE_BARRIER( |
| 3190 | heap, this, kInstanceDescriptorsOrBitField3Offset, value, mode); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3191 | } |
| 3192 | |
| 3193 | |
| 3194 | int Map::bit_field3() { |
| 3195 | Object* object = READ_FIELD(this, |
| 3196 | kInstanceDescriptorsOrBitField3Offset); |
| 3197 | if (object->IsSmi()) { |
| 3198 | return Smi::cast(object)->value(); |
| 3199 | } else { |
| 3200 | return DescriptorArray::cast(object)->bit_field3_storage(); |
| 3201 | } |
| 3202 | } |
| 3203 | |
| 3204 | |
| 3205 | void Map::set_bit_field3(int value) { |
| 3206 | ASSERT(Smi::IsValid(value)); |
| 3207 | Object* object = READ_FIELD(this, |
| 3208 | kInstanceDescriptorsOrBitField3Offset); |
| 3209 | if (object->IsSmi()) { |
| 3210 | WRITE_FIELD(this, |
| 3211 | kInstanceDescriptorsOrBitField3Offset, |
| 3212 | Smi::FromInt(value)); |
| 3213 | } else { |
| 3214 | DescriptorArray::cast(object)->set_bit_field3_storage(value); |
| 3215 | } |
| 3216 | } |
| 3217 | |
| 3218 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3219 | FixedArray* Map::unchecked_prototype_transitions() { |
| 3220 | return reinterpret_cast<FixedArray*>( |
| 3221 | READ_FIELD(this, kPrototypeTransitionsOffset)); |
| 3222 | } |
| 3223 | |
| 3224 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3225 | ACCESSORS(Map, code_cache, Object, kCodeCacheOffset) |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 3226 | ACCESSORS(Map, prototype_transitions, FixedArray, kPrototypeTransitionsOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3227 | ACCESSORS(Map, constructor, Object, kConstructorOffset) |
| 3228 | |
| 3229 | ACCESSORS(JSFunction, shared, SharedFunctionInfo, kSharedFunctionInfoOffset) |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3230 | ACCESSORS(JSFunction, literals_or_bindings, FixedArray, kLiteralsOffset) |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3231 | ACCESSORS(JSFunction, |
| 3232 | next_function_link, |
| 3233 | Object, |
| 3234 | kNextFunctionLinkOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3235 | |
| 3236 | ACCESSORS(GlobalObject, builtins, JSBuiltinsObject, kBuiltinsOffset) |
| 3237 | ACCESSORS(GlobalObject, global_context, Context, kGlobalContextOffset) |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3238 | ACCESSORS(GlobalObject, global_receiver, JSObject, kGlobalReceiverOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3239 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3240 | ACCESSORS(JSGlobalProxy, context, Object, kContextOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3241 | |
| 3242 | ACCESSORS(AccessorInfo, getter, Object, kGetterOffset) |
| 3243 | ACCESSORS(AccessorInfo, setter, Object, kSetterOffset) |
| 3244 | ACCESSORS(AccessorInfo, data, Object, kDataOffset) |
| 3245 | ACCESSORS(AccessorInfo, name, Object, kNameOffset) |
| 3246 | ACCESSORS(AccessorInfo, flag, Smi, kFlagOffset) |
| 3247 | |
| 3248 | ACCESSORS(AccessCheckInfo, named_callback, Object, kNamedCallbackOffset) |
| 3249 | ACCESSORS(AccessCheckInfo, indexed_callback, Object, kIndexedCallbackOffset) |
| 3250 | ACCESSORS(AccessCheckInfo, data, Object, kDataOffset) |
| 3251 | |
| 3252 | ACCESSORS(InterceptorInfo, getter, Object, kGetterOffset) |
| 3253 | ACCESSORS(InterceptorInfo, setter, Object, kSetterOffset) |
| 3254 | ACCESSORS(InterceptorInfo, query, Object, kQueryOffset) |
| 3255 | ACCESSORS(InterceptorInfo, deleter, Object, kDeleterOffset) |
| 3256 | ACCESSORS(InterceptorInfo, enumerator, Object, kEnumeratorOffset) |
| 3257 | ACCESSORS(InterceptorInfo, data, Object, kDataOffset) |
| 3258 | |
| 3259 | ACCESSORS(CallHandlerInfo, callback, Object, kCallbackOffset) |
| 3260 | ACCESSORS(CallHandlerInfo, data, Object, kDataOffset) |
| 3261 | |
| 3262 | ACCESSORS(TemplateInfo, tag, Object, kTagOffset) |
| 3263 | ACCESSORS(TemplateInfo, property_list, Object, kPropertyListOffset) |
| 3264 | |
| 3265 | ACCESSORS(FunctionTemplateInfo, serial_number, Object, kSerialNumberOffset) |
| 3266 | ACCESSORS(FunctionTemplateInfo, call_code, Object, kCallCodeOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3267 | ACCESSORS(FunctionTemplateInfo, property_accessors, Object, |
| 3268 | kPropertyAccessorsOffset) |
| 3269 | ACCESSORS(FunctionTemplateInfo, prototype_template, Object, |
| 3270 | kPrototypeTemplateOffset) |
| 3271 | ACCESSORS(FunctionTemplateInfo, parent_template, Object, kParentTemplateOffset) |
| 3272 | ACCESSORS(FunctionTemplateInfo, named_property_handler, Object, |
| 3273 | kNamedPropertyHandlerOffset) |
| 3274 | ACCESSORS(FunctionTemplateInfo, indexed_property_handler, Object, |
| 3275 | kIndexedPropertyHandlerOffset) |
| 3276 | ACCESSORS(FunctionTemplateInfo, instance_template, Object, |
| 3277 | kInstanceTemplateOffset) |
| 3278 | ACCESSORS(FunctionTemplateInfo, class_name, Object, kClassNameOffset) |
| 3279 | ACCESSORS(FunctionTemplateInfo, signature, Object, kSignatureOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3280 | ACCESSORS(FunctionTemplateInfo, instance_call_handler, Object, |
| 3281 | kInstanceCallHandlerOffset) |
| 3282 | ACCESSORS(FunctionTemplateInfo, access_check_info, Object, |
| 3283 | kAccessCheckInfoOffset) |
| 3284 | ACCESSORS(FunctionTemplateInfo, flag, Smi, kFlagOffset) |
| 3285 | |
| 3286 | ACCESSORS(ObjectTemplateInfo, constructor, Object, kConstructorOffset) |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 3287 | ACCESSORS(ObjectTemplateInfo, internal_field_count, Object, |
| 3288 | kInternalFieldCountOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3289 | |
| 3290 | ACCESSORS(SignatureInfo, receiver, Object, kReceiverOffset) |
| 3291 | ACCESSORS(SignatureInfo, args, Object, kArgsOffset) |
| 3292 | |
| 3293 | ACCESSORS(TypeSwitchInfo, types, Object, kTypesOffset) |
| 3294 | |
| 3295 | ACCESSORS(Script, source, Object, kSourceOffset) |
| 3296 | ACCESSORS(Script, name, Object, kNameOffset) |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3297 | ACCESSORS(Script, id, Object, kIdOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3298 | ACCESSORS(Script, line_offset, Smi, kLineOffsetOffset) |
| 3299 | ACCESSORS(Script, column_offset, Smi, kColumnOffsetOffset) |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3300 | ACCESSORS(Script, data, Object, kDataOffset) |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 3301 | ACCESSORS(Script, context_data, Object, kContextOffset) |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3302 | ACCESSORS(Script, wrapper, Foreign, kWrapperOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3303 | ACCESSORS(Script, type, Smi, kTypeOffset) |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 3304 | ACCESSORS(Script, compilation_type, Smi, kCompilationTypeOffset) |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 3305 | ACCESSORS(Script, line_ends, Object, kLineEndsOffset) |
sgjesse@chromium.org | 9818059 | 2009-12-02 08:17:28 +0000 | [diff] [blame] | 3306 | ACCESSORS(Script, eval_from_shared, Object, kEvalFromSharedOffset) |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 3307 | ACCESSORS(Script, eval_from_instructions_offset, Smi, |
| 3308 | kEvalFrominstructionsOffsetOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3309 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3310 | #ifdef ENABLE_DEBUGGER_SUPPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3311 | ACCESSORS(DebugInfo, shared, SharedFunctionInfo, kSharedFunctionInfoIndex) |
| 3312 | ACCESSORS(DebugInfo, original_code, Code, kOriginalCodeIndex) |
| 3313 | ACCESSORS(DebugInfo, code, Code, kPatchedCodeIndex) |
| 3314 | ACCESSORS(DebugInfo, break_points, FixedArray, kBreakPointsStateIndex) |
| 3315 | |
| 3316 | ACCESSORS(BreakPointInfo, code_position, Smi, kCodePositionIndex) |
| 3317 | ACCESSORS(BreakPointInfo, source_position, Smi, kSourcePositionIndex) |
| 3318 | ACCESSORS(BreakPointInfo, statement_position, Smi, kStatementPositionIndex) |
| 3319 | ACCESSORS(BreakPointInfo, break_point_objects, Object, kBreakPointObjectsIndex) |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3320 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3321 | |
| 3322 | ACCESSORS(SharedFunctionInfo, name, Object, kNameOffset) |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3323 | ACCESSORS(SharedFunctionInfo, construct_stub, Code, kConstructStubOffset) |
| 3324 | ACCESSORS(SharedFunctionInfo, initial_map, Object, kInitialMapOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3325 | ACCESSORS(SharedFunctionInfo, instance_class_name, Object, |
| 3326 | kInstanceClassNameOffset) |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 3327 | ACCESSORS(SharedFunctionInfo, function_data, Object, kFunctionDataOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3328 | ACCESSORS(SharedFunctionInfo, script, Object, kScriptOffset) |
| 3329 | ACCESSORS(SharedFunctionInfo, debug_info, Object, kDebugInfoOffset) |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 3330 | ACCESSORS(SharedFunctionInfo, inferred_name, String, kInferredNameOffset) |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 3331 | ACCESSORS(SharedFunctionInfo, this_property_assignments, Object, |
| 3332 | kThisPropertyAssignmentsOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3333 | |
| 3334 | BOOL_ACCESSORS(FunctionTemplateInfo, flag, hidden_prototype, |
| 3335 | kHiddenPrototypeBit) |
| 3336 | BOOL_ACCESSORS(FunctionTemplateInfo, flag, undetectable, kUndetectableBit) |
| 3337 | BOOL_ACCESSORS(FunctionTemplateInfo, flag, needs_access_check, |
| 3338 | kNeedsAccessCheckBit) |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 3339 | BOOL_ACCESSORS(FunctionTemplateInfo, flag, read_only_prototype, |
| 3340 | kReadOnlyPrototypeBit) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3341 | BOOL_ACCESSORS(SharedFunctionInfo, start_position_and_type, is_expression, |
| 3342 | kIsExpressionBit) |
| 3343 | BOOL_ACCESSORS(SharedFunctionInfo, start_position_and_type, is_toplevel, |
| 3344 | kIsTopLevelBit) |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3345 | BOOL_GETTER(SharedFunctionInfo, |
| 3346 | compiler_hints, |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 3347 | has_only_simple_this_property_assignments, |
| 3348 | kHasOnlySimpleThisPropertyAssignments) |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3349 | BOOL_ACCESSORS(SharedFunctionInfo, |
| 3350 | compiler_hints, |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 3351 | allows_lazy_compilation, |
| 3352 | kAllowLazyCompilation) |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3353 | BOOL_ACCESSORS(SharedFunctionInfo, |
| 3354 | compiler_hints, |
| 3355 | uses_arguments, |
| 3356 | kUsesArguments) |
| 3357 | BOOL_ACCESSORS(SharedFunctionInfo, |
| 3358 | compiler_hints, |
| 3359 | has_duplicate_parameters, |
| 3360 | kHasDuplicateParameters) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3361 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 3362 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3363 | #if V8_HOST_ARCH_32_BIT |
| 3364 | SMI_ACCESSORS(SharedFunctionInfo, length, kLengthOffset) |
| 3365 | SMI_ACCESSORS(SharedFunctionInfo, formal_parameter_count, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3366 | kFormalParameterCountOffset) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3367 | SMI_ACCESSORS(SharedFunctionInfo, expected_nof_properties, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3368 | kExpectedNofPropertiesOffset) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3369 | SMI_ACCESSORS(SharedFunctionInfo, num_literals, kNumLiteralsOffset) |
| 3370 | SMI_ACCESSORS(SharedFunctionInfo, start_position_and_type, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3371 | kStartPositionAndTypeOffset) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3372 | SMI_ACCESSORS(SharedFunctionInfo, end_position, kEndPositionOffset) |
| 3373 | SMI_ACCESSORS(SharedFunctionInfo, function_token_position, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3374 | kFunctionTokenPositionOffset) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3375 | SMI_ACCESSORS(SharedFunctionInfo, compiler_hints, |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 3376 | kCompilerHintsOffset) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3377 | SMI_ACCESSORS(SharedFunctionInfo, this_property_assignments_count, |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 3378 | kThisPropertyAssignmentsCountOffset) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3379 | SMI_ACCESSORS(SharedFunctionInfo, opt_count, kOptCountOffset) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3380 | #else |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3381 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3382 | #define PSEUDO_SMI_ACCESSORS_LO(holder, name, offset) \ |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 3383 | STATIC_ASSERT(holder::offset % kPointerSize == 0); \ |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3384 | int holder::name() { \ |
| 3385 | int value = READ_INT_FIELD(this, offset); \ |
| 3386 | ASSERT(kHeapObjectTag == 1); \ |
| 3387 | ASSERT((value & kHeapObjectTag) == 0); \ |
| 3388 | return value >> 1; \ |
| 3389 | } \ |
| 3390 | void holder::set_##name(int value) { \ |
| 3391 | ASSERT(kHeapObjectTag == 1); \ |
| 3392 | ASSERT((value & 0xC0000000) == 0xC0000000 || \ |
| 3393 | (value & 0xC0000000) == 0x000000000); \ |
| 3394 | WRITE_INT_FIELD(this, \ |
| 3395 | offset, \ |
| 3396 | (value << 1) & ~kHeapObjectTag); \ |
| 3397 | } |
| 3398 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 3399 | #define PSEUDO_SMI_ACCESSORS_HI(holder, name, offset) \ |
| 3400 | STATIC_ASSERT(holder::offset % kPointerSize == kIntSize); \ |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3401 | INT_ACCESSORS(holder, name, offset) |
| 3402 | |
| 3403 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3404 | PSEUDO_SMI_ACCESSORS_LO(SharedFunctionInfo, length, kLengthOffset) |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 3405 | PSEUDO_SMI_ACCESSORS_HI(SharedFunctionInfo, |
| 3406 | formal_parameter_count, |
| 3407 | kFormalParameterCountOffset) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3408 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 3409 | PSEUDO_SMI_ACCESSORS_LO(SharedFunctionInfo, |
| 3410 | expected_nof_properties, |
| 3411 | kExpectedNofPropertiesOffset) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3412 | PSEUDO_SMI_ACCESSORS_HI(SharedFunctionInfo, num_literals, kNumLiteralsOffset) |
| 3413 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 3414 | PSEUDO_SMI_ACCESSORS_LO(SharedFunctionInfo, end_position, kEndPositionOffset) |
| 3415 | PSEUDO_SMI_ACCESSORS_HI(SharedFunctionInfo, |
| 3416 | start_position_and_type, |
| 3417 | kStartPositionAndTypeOffset) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3418 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 3419 | PSEUDO_SMI_ACCESSORS_LO(SharedFunctionInfo, |
| 3420 | function_token_position, |
| 3421 | kFunctionTokenPositionOffset) |
| 3422 | PSEUDO_SMI_ACCESSORS_HI(SharedFunctionInfo, |
| 3423 | compiler_hints, |
| 3424 | kCompilerHintsOffset) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3425 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 3426 | PSEUDO_SMI_ACCESSORS_LO(SharedFunctionInfo, |
| 3427 | this_property_assignments_count, |
| 3428 | kThisPropertyAssignmentsCountOffset) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3429 | PSEUDO_SMI_ACCESSORS_HI(SharedFunctionInfo, opt_count, kOptCountOffset) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3430 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3431 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3432 | |
| 3433 | int SharedFunctionInfo::construction_count() { |
| 3434 | return READ_BYTE_FIELD(this, kConstructionCountOffset); |
| 3435 | } |
| 3436 | |
| 3437 | |
| 3438 | void SharedFunctionInfo::set_construction_count(int value) { |
| 3439 | ASSERT(0 <= value && value < 256); |
| 3440 | WRITE_BYTE_FIELD(this, kConstructionCountOffset, static_cast<byte>(value)); |
| 3441 | } |
| 3442 | |
| 3443 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3444 | BOOL_ACCESSORS(SharedFunctionInfo, |
| 3445 | compiler_hints, |
| 3446 | live_objects_may_exist, |
| 3447 | kLiveObjectsMayExist) |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3448 | |
| 3449 | |
| 3450 | bool SharedFunctionInfo::IsInobjectSlackTrackingInProgress() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3451 | return initial_map() != HEAP->undefined_value(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3452 | } |
| 3453 | |
| 3454 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3455 | BOOL_GETTER(SharedFunctionInfo, |
| 3456 | compiler_hints, |
| 3457 | optimization_disabled, |
| 3458 | kOptimizationDisabled) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3459 | |
| 3460 | |
| 3461 | void SharedFunctionInfo::set_optimization_disabled(bool disable) { |
| 3462 | set_compiler_hints(BooleanBit::set(compiler_hints(), |
| 3463 | kOptimizationDisabled, |
| 3464 | disable)); |
| 3465 | // If disabling optimizations we reflect that in the code object so |
| 3466 | // it will not be counted as optimizable code. |
| 3467 | if ((code()->kind() == Code::FUNCTION) && disable) { |
| 3468 | code()->set_optimizable(false); |
| 3469 | } |
| 3470 | } |
| 3471 | |
| 3472 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3473 | StrictModeFlag SharedFunctionInfo::strict_mode_flag() { |
| 3474 | return BooleanBit::get(compiler_hints(), kStrictModeFunction) |
| 3475 | ? kStrictMode : kNonStrictMode; |
| 3476 | } |
| 3477 | |
| 3478 | |
| 3479 | void SharedFunctionInfo::set_strict_mode_flag(StrictModeFlag strict_mode_flag) { |
| 3480 | ASSERT(strict_mode_flag == kStrictMode || |
| 3481 | strict_mode_flag == kNonStrictMode); |
| 3482 | bool value = strict_mode_flag == kStrictMode; |
| 3483 | set_compiler_hints( |
| 3484 | BooleanBit::set(compiler_hints(), kStrictModeFunction, value)); |
| 3485 | } |
| 3486 | |
| 3487 | |
| 3488 | BOOL_GETTER(SharedFunctionInfo, compiler_hints, strict_mode, |
| 3489 | kStrictModeFunction) |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3490 | BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, native, kNative) |
| 3491 | BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, |
| 3492 | name_should_print_as_anonymous, |
| 3493 | kNameShouldPrintAsAnonymous) |
| 3494 | BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, bound, kBoundFunction) |
| 3495 | BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, is_anonymous, kIsAnonymous) |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3496 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3497 | ACCESSORS(CodeCache, default_cache, FixedArray, kDefaultCacheOffset) |
| 3498 | ACCESSORS(CodeCache, normal_type_cache, Object, kNormalTypeCacheOffset) |
| 3499 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 3500 | ACCESSORS(PolymorphicCodeCache, cache, Object, kCacheOffset) |
| 3501 | |
sgjesse@chromium.org | 152a0b0 | 2009-10-07 13:50:16 +0000 | [diff] [blame] | 3502 | bool Script::HasValidSource() { |
| 3503 | Object* src = this->source(); |
| 3504 | if (!src->IsString()) return true; |
| 3505 | String* src_str = String::cast(src); |
| 3506 | if (!StringShape(src_str).IsExternal()) return true; |
| 3507 | if (src_str->IsAsciiRepresentation()) { |
| 3508 | return ExternalAsciiString::cast(src)->resource() != NULL; |
| 3509 | } else if (src_str->IsTwoByteRepresentation()) { |
| 3510 | return ExternalTwoByteString::cast(src)->resource() != NULL; |
| 3511 | } |
| 3512 | return true; |
| 3513 | } |
| 3514 | |
| 3515 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 3516 | void SharedFunctionInfo::DontAdaptArguments() { |
| 3517 | ASSERT(code()->kind() == Code::BUILTIN); |
| 3518 | set_formal_parameter_count(kDontAdaptArgumentsSentinel); |
| 3519 | } |
| 3520 | |
| 3521 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3522 | int SharedFunctionInfo::start_position() { |
| 3523 | return start_position_and_type() >> kStartPositionShift; |
| 3524 | } |
| 3525 | |
| 3526 | |
| 3527 | void SharedFunctionInfo::set_start_position(int start_position) { |
| 3528 | set_start_position_and_type((start_position << kStartPositionShift) |
| 3529 | | (start_position_and_type() & ~kStartPositionMask)); |
| 3530 | } |
| 3531 | |
| 3532 | |
| 3533 | Code* SharedFunctionInfo::code() { |
| 3534 | return Code::cast(READ_FIELD(this, kCodeOffset)); |
| 3535 | } |
| 3536 | |
| 3537 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 3538 | Code* SharedFunctionInfo::unchecked_code() { |
| 3539 | return reinterpret_cast<Code*>(READ_FIELD(this, kCodeOffset)); |
| 3540 | } |
| 3541 | |
| 3542 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3543 | void SharedFunctionInfo::set_code(Code* value, WriteBarrierMode mode) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3544 | WRITE_FIELD(this, kCodeOffset, value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3545 | CONDITIONAL_WRITE_BARRIER(value->GetHeap(), this, kCodeOffset, value, mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3546 | } |
| 3547 | |
| 3548 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame^] | 3549 | ScopeInfo* SharedFunctionInfo::scope_info() { |
| 3550 | return reinterpret_cast<ScopeInfo*>(READ_FIELD(this, kScopeInfoOffset)); |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 3551 | } |
| 3552 | |
| 3553 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame^] | 3554 | void SharedFunctionInfo::set_scope_info(ScopeInfo* value, |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 3555 | WriteBarrierMode mode) { |
| 3556 | WRITE_FIELD(this, kScopeInfoOffset, reinterpret_cast<Object*>(value)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3557 | CONDITIONAL_WRITE_BARRIER(GetHeap(), |
| 3558 | this, |
| 3559 | kScopeInfoOffset, |
| 3560 | reinterpret_cast<Object*>(value), |
| 3561 | mode); |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 3562 | } |
| 3563 | |
| 3564 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3565 | Smi* SharedFunctionInfo::deopt_counter() { |
| 3566 | return reinterpret_cast<Smi*>(READ_FIELD(this, kDeoptCounterOffset)); |
| 3567 | } |
| 3568 | |
| 3569 | |
| 3570 | void SharedFunctionInfo::set_deopt_counter(Smi* value) { |
| 3571 | WRITE_FIELD(this, kDeoptCounterOffset, value); |
| 3572 | } |
| 3573 | |
| 3574 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3575 | bool SharedFunctionInfo::is_compiled() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3576 | return code() != |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3577 | Isolate::Current()->builtins()->builtin(Builtins::kLazyCompile); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3578 | } |
| 3579 | |
| 3580 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 3581 | bool SharedFunctionInfo::IsApiFunction() { |
| 3582 | return function_data()->IsFunctionTemplateInfo(); |
| 3583 | } |
| 3584 | |
| 3585 | |
| 3586 | FunctionTemplateInfo* SharedFunctionInfo::get_api_func_data() { |
| 3587 | ASSERT(IsApiFunction()); |
| 3588 | return FunctionTemplateInfo::cast(function_data()); |
| 3589 | } |
| 3590 | |
| 3591 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3592 | bool SharedFunctionInfo::HasBuiltinFunctionId() { |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3593 | return function_data()->IsSmi(); |
| 3594 | } |
| 3595 | |
| 3596 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3597 | BuiltinFunctionId SharedFunctionInfo::builtin_function_id() { |
| 3598 | ASSERT(HasBuiltinFunctionId()); |
| 3599 | return static_cast<BuiltinFunctionId>(Smi::cast(function_data())->value()); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 3600 | } |
| 3601 | |
| 3602 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 3603 | int SharedFunctionInfo::code_age() { |
| 3604 | return (compiler_hints() >> kCodeAgeShift) & kCodeAgeMask; |
| 3605 | } |
| 3606 | |
| 3607 | |
| 3608 | void SharedFunctionInfo::set_code_age(int code_age) { |
| 3609 | set_compiler_hints(compiler_hints() | |
| 3610 | ((code_age & kCodeAgeMask) << kCodeAgeShift)); |
| 3611 | } |
| 3612 | |
| 3613 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3614 | bool SharedFunctionInfo::has_deoptimization_support() { |
| 3615 | Code* code = this->code(); |
| 3616 | return code->kind() == Code::FUNCTION && code->has_deoptimization_support(); |
| 3617 | } |
| 3618 | |
| 3619 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 3620 | bool JSFunction::IsBuiltin() { |
| 3621 | return context()->global()->IsJSBuiltinsObject(); |
| 3622 | } |
| 3623 | |
| 3624 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3625 | bool JSFunction::NeedsArgumentsAdaption() { |
| 3626 | return shared()->formal_parameter_count() != |
| 3627 | SharedFunctionInfo::kDontAdaptArgumentsSentinel; |
| 3628 | } |
| 3629 | |
| 3630 | |
| 3631 | bool JSFunction::IsOptimized() { |
| 3632 | return code()->kind() == Code::OPTIMIZED_FUNCTION; |
| 3633 | } |
| 3634 | |
| 3635 | |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 3636 | bool JSFunction::IsOptimizable() { |
| 3637 | return code()->kind() == Code::FUNCTION && code()->optimizable(); |
| 3638 | } |
| 3639 | |
| 3640 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3641 | bool JSFunction::IsMarkedForLazyRecompilation() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3642 | return code() == GetIsolate()->builtins()->builtin(Builtins::kLazyRecompile); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3643 | } |
| 3644 | |
| 3645 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3646 | Code* JSFunction::code() { |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 3647 | return Code::cast(unchecked_code()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3648 | } |
| 3649 | |
| 3650 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 3651 | Code* JSFunction::unchecked_code() { |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 3652 | return reinterpret_cast<Code*>( |
| 3653 | Code::GetObjectFromEntryAddress(FIELD_ADDR(this, kCodeEntryOffset))); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 3654 | } |
| 3655 | |
| 3656 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3657 | void JSFunction::set_code(Code* value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3658 | ASSERT(!HEAP->InNewSpace(value)); |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 3659 | Address entry = value->entry(); |
| 3660 | WRITE_INTPTR_FIELD(this, kCodeEntryOffset, reinterpret_cast<intptr_t>(entry)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3661 | GetHeap()->incremental_marking()->RecordWriteOfCodeEntry( |
| 3662 | this, |
| 3663 | HeapObject::RawField(this, kCodeEntryOffset), |
| 3664 | value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3665 | } |
| 3666 | |
| 3667 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3668 | void JSFunction::ReplaceCode(Code* code) { |
| 3669 | bool was_optimized = IsOptimized(); |
| 3670 | bool is_optimized = code->kind() == Code::OPTIMIZED_FUNCTION; |
| 3671 | |
| 3672 | set_code(code); |
| 3673 | |
| 3674 | // Add/remove the function from the list of optimized functions for this |
| 3675 | // context based on the state change. |
| 3676 | if (!was_optimized && is_optimized) { |
| 3677 | context()->global_context()->AddOptimizedFunction(this); |
| 3678 | } |
| 3679 | if (was_optimized && !is_optimized) { |
| 3680 | context()->global_context()->RemoveOptimizedFunction(this); |
| 3681 | } |
| 3682 | } |
| 3683 | |
| 3684 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3685 | Context* JSFunction::context() { |
| 3686 | return Context::cast(READ_FIELD(this, kContextOffset)); |
| 3687 | } |
| 3688 | |
| 3689 | |
| 3690 | Object* JSFunction::unchecked_context() { |
| 3691 | return READ_FIELD(this, kContextOffset); |
| 3692 | } |
| 3693 | |
| 3694 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 3695 | SharedFunctionInfo* JSFunction::unchecked_shared() { |
| 3696 | return reinterpret_cast<SharedFunctionInfo*>( |
| 3697 | READ_FIELD(this, kSharedFunctionInfoOffset)); |
| 3698 | } |
| 3699 | |
| 3700 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3701 | void JSFunction::set_context(Object* value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3702 | ASSERT(value->IsUndefined() || value->IsContext()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3703 | WRITE_FIELD(this, kContextOffset, value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3704 | WRITE_BARRIER(GetHeap(), this, kContextOffset, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3705 | } |
| 3706 | |
| 3707 | ACCESSORS(JSFunction, prototype_or_initial_map, Object, |
| 3708 | kPrototypeOrInitialMapOffset) |
| 3709 | |
| 3710 | |
| 3711 | Map* JSFunction::initial_map() { |
| 3712 | return Map::cast(prototype_or_initial_map()); |
| 3713 | } |
| 3714 | |
| 3715 | |
| 3716 | void JSFunction::set_initial_map(Map* value) { |
| 3717 | set_prototype_or_initial_map(value); |
| 3718 | } |
| 3719 | |
| 3720 | |
| 3721 | bool JSFunction::has_initial_map() { |
| 3722 | return prototype_or_initial_map()->IsMap(); |
| 3723 | } |
| 3724 | |
| 3725 | |
| 3726 | bool JSFunction::has_instance_prototype() { |
| 3727 | return has_initial_map() || !prototype_or_initial_map()->IsTheHole(); |
| 3728 | } |
| 3729 | |
| 3730 | |
| 3731 | bool JSFunction::has_prototype() { |
| 3732 | return map()->has_non_instance_prototype() || has_instance_prototype(); |
| 3733 | } |
| 3734 | |
| 3735 | |
| 3736 | Object* JSFunction::instance_prototype() { |
| 3737 | ASSERT(has_instance_prototype()); |
| 3738 | if (has_initial_map()) return initial_map()->prototype(); |
| 3739 | // When there is no initial map and the prototype is a JSObject, the |
| 3740 | // initial map field is used for the prototype field. |
| 3741 | return prototype_or_initial_map(); |
| 3742 | } |
| 3743 | |
| 3744 | |
| 3745 | Object* JSFunction::prototype() { |
| 3746 | ASSERT(has_prototype()); |
| 3747 | // If the function's prototype property has been set to a non-JSObject |
| 3748 | // value, that value is stored in the constructor field of the map. |
| 3749 | if (map()->has_non_instance_prototype()) return map()->constructor(); |
| 3750 | return instance_prototype(); |
| 3751 | } |
| 3752 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 3753 | bool JSFunction::should_have_prototype() { |
| 3754 | return map()->function_with_prototype(); |
| 3755 | } |
| 3756 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3757 | |
| 3758 | bool JSFunction::is_compiled() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3759 | return code() != GetIsolate()->builtins()->builtin(Builtins::kLazyCompile); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3760 | } |
| 3761 | |
| 3762 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3763 | FixedArray* JSFunction::literals() { |
| 3764 | ASSERT(!shared()->bound()); |
| 3765 | return literals_or_bindings(); |
| 3766 | } |
| 3767 | |
| 3768 | |
| 3769 | void JSFunction::set_literals(FixedArray* literals) { |
| 3770 | ASSERT(!shared()->bound()); |
| 3771 | set_literals_or_bindings(literals); |
| 3772 | } |
| 3773 | |
| 3774 | |
| 3775 | FixedArray* JSFunction::function_bindings() { |
| 3776 | ASSERT(shared()->bound()); |
| 3777 | return literals_or_bindings(); |
| 3778 | } |
| 3779 | |
| 3780 | |
| 3781 | void JSFunction::set_function_bindings(FixedArray* bindings) { |
| 3782 | ASSERT(shared()->bound()); |
| 3783 | // Bound function literal may be initialized to the empty fixed array |
| 3784 | // before the bindings are set. |
| 3785 | ASSERT(bindings == GetHeap()->empty_fixed_array() || |
| 3786 | bindings->map() == GetHeap()->fixed_cow_array_map()); |
| 3787 | set_literals_or_bindings(bindings); |
| 3788 | } |
| 3789 | |
| 3790 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 3791 | int JSFunction::NumberOfLiterals() { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3792 | ASSERT(!shared()->bound()); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 3793 | return literals()->length(); |
| 3794 | } |
| 3795 | |
| 3796 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3797 | Object* JSBuiltinsObject::javascript_builtin(Builtins::JavaScript id) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3798 | ASSERT(id < kJSBuiltinsCount); // id is unsigned. |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 3799 | return READ_FIELD(this, OffsetOfFunctionWithId(id)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3800 | } |
| 3801 | |
| 3802 | |
| 3803 | void JSBuiltinsObject::set_javascript_builtin(Builtins::JavaScript id, |
| 3804 | Object* value) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3805 | ASSERT(id < kJSBuiltinsCount); // id is unsigned. |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 3806 | WRITE_FIELD(this, OffsetOfFunctionWithId(id), value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3807 | WRITE_BARRIER(GetHeap(), this, OffsetOfFunctionWithId(id), value); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 3808 | } |
| 3809 | |
| 3810 | |
| 3811 | Code* JSBuiltinsObject::javascript_builtin_code(Builtins::JavaScript id) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3812 | ASSERT(id < kJSBuiltinsCount); // id is unsigned. |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 3813 | return Code::cast(READ_FIELD(this, OffsetOfCodeWithId(id))); |
| 3814 | } |
| 3815 | |
| 3816 | |
| 3817 | void JSBuiltinsObject::set_javascript_builtin_code(Builtins::JavaScript id, |
| 3818 | Code* value) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3819 | ASSERT(id < kJSBuiltinsCount); // id is unsigned. |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 3820 | WRITE_FIELD(this, OffsetOfCodeWithId(id), value); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3821 | ASSERT(!HEAP->InNewSpace(value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3822 | } |
| 3823 | |
| 3824 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3825 | ACCESSORS(JSProxy, handler, Object, kHandlerOffset) |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3826 | ACCESSORS(JSProxy, hash, Object, kHashOffset) |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 3827 | ACCESSORS(JSFunctionProxy, call_trap, Object, kCallTrapOffset) |
| 3828 | ACCESSORS(JSFunctionProxy, construct_trap, Object, kConstructTrapOffset) |
| 3829 | |
| 3830 | |
| 3831 | void JSProxy::InitializeBody(int object_size, Object* value) { |
| 3832 | ASSERT(!value->IsHeapObject() || !GetHeap()->InNewSpace(value)); |
| 3833 | for (int offset = kHeaderSize; offset < object_size; offset += kPointerSize) { |
| 3834 | WRITE_FIELD(this, offset, value); |
| 3835 | } |
| 3836 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3837 | |
| 3838 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3839 | ACCESSORS(JSSet, table, Object, kTableOffset) |
| 3840 | ACCESSORS(JSMap, table, Object, kTableOffset) |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3841 | ACCESSORS(JSWeakMap, table, Object, kTableOffset) |
| 3842 | ACCESSORS(JSWeakMap, next, Object, kNextOffset) |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3843 | |
| 3844 | |
| 3845 | ObjectHashTable* JSWeakMap::unchecked_table() { |
| 3846 | return reinterpret_cast<ObjectHashTable*>(READ_FIELD(this, kTableOffset)); |
| 3847 | } |
| 3848 | |
| 3849 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame^] | 3850 | Address Foreign::foreign_address() { |
| 3851 | return AddressFrom<Address>(READ_INTPTR_FIELD(this, kForeignAddressOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3852 | } |
| 3853 | |
| 3854 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame^] | 3855 | void Foreign::set_foreign_address(Address value) { |
| 3856 | WRITE_INTPTR_FIELD(this, kForeignAddressOffset, OffsetFrom(value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3857 | } |
| 3858 | |
| 3859 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3860 | ACCESSORS(JSValue, value, Object, kValueOffset) |
| 3861 | |
| 3862 | |
| 3863 | JSValue* JSValue::cast(Object* obj) { |
| 3864 | ASSERT(obj->IsJSValue()); |
| 3865 | ASSERT(HeapObject::cast(obj)->Size() == JSValue::kSize); |
| 3866 | return reinterpret_cast<JSValue*>(obj); |
| 3867 | } |
| 3868 | |
| 3869 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 3870 | ACCESSORS(JSMessageObject, type, String, kTypeOffset) |
| 3871 | ACCESSORS(JSMessageObject, arguments, JSArray, kArgumentsOffset) |
| 3872 | ACCESSORS(JSMessageObject, script, Object, kScriptOffset) |
| 3873 | ACCESSORS(JSMessageObject, stack_trace, Object, kStackTraceOffset) |
| 3874 | ACCESSORS(JSMessageObject, stack_frames, Object, kStackFramesOffset) |
| 3875 | SMI_ACCESSORS(JSMessageObject, start_position, kStartPositionOffset) |
| 3876 | SMI_ACCESSORS(JSMessageObject, end_position, kEndPositionOffset) |
| 3877 | |
| 3878 | |
| 3879 | JSMessageObject* JSMessageObject::cast(Object* obj) { |
| 3880 | ASSERT(obj->IsJSMessageObject()); |
| 3881 | ASSERT(HeapObject::cast(obj)->Size() == JSMessageObject::kSize); |
| 3882 | return reinterpret_cast<JSMessageObject*>(obj); |
| 3883 | } |
| 3884 | |
| 3885 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3886 | INT_ACCESSORS(Code, instruction_size, kInstructionSizeOffset) |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 3887 | ACCESSORS(Code, relocation_info, ByteArray, kRelocationInfoOffset) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3888 | ACCESSORS(Code, deoptimization_data, FixedArray, kDeoptimizationDataOffset) |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3889 | ACCESSORS(Code, next_code_flushing_candidate, |
| 3890 | Object, kNextCodeFlushingCandidateOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3891 | |
| 3892 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3893 | byte* Code::instruction_start() { |
| 3894 | return FIELD_ADDR(this, kHeaderSize); |
| 3895 | } |
| 3896 | |
| 3897 | |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 3898 | byte* Code::instruction_end() { |
| 3899 | return instruction_start() + instruction_size(); |
| 3900 | } |
| 3901 | |
| 3902 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3903 | int Code::body_size() { |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 3904 | return RoundUp(instruction_size(), kObjectAlignment); |
| 3905 | } |
| 3906 | |
| 3907 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3908 | FixedArray* Code::unchecked_deoptimization_data() { |
| 3909 | return reinterpret_cast<FixedArray*>( |
| 3910 | READ_FIELD(this, kDeoptimizationDataOffset)); |
| 3911 | } |
| 3912 | |
| 3913 | |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 3914 | ByteArray* Code::unchecked_relocation_info() { |
| 3915 | return reinterpret_cast<ByteArray*>(READ_FIELD(this, kRelocationInfoOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3916 | } |
| 3917 | |
| 3918 | |
| 3919 | byte* Code::relocation_start() { |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 3920 | return unchecked_relocation_info()->GetDataStartAddress(); |
| 3921 | } |
| 3922 | |
| 3923 | |
| 3924 | int Code::relocation_size() { |
| 3925 | return unchecked_relocation_info()->length(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3926 | } |
| 3927 | |
| 3928 | |
| 3929 | byte* Code::entry() { |
| 3930 | return instruction_start(); |
| 3931 | } |
| 3932 | |
| 3933 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3934 | bool Code::contains(byte* inner_pointer) { |
| 3935 | return (address() <= inner_pointer) && (inner_pointer <= address() + Size()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3936 | } |
| 3937 | |
| 3938 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3939 | ACCESSORS(JSArray, length, Object, kLengthOffset) |
| 3940 | |
| 3941 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 3942 | ACCESSORS(JSRegExp, data, Object, kDataOffset) |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 3943 | |
| 3944 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 3945 | JSRegExp::Type JSRegExp::TypeTag() { |
| 3946 | Object* data = this->data(); |
| 3947 | if (data->IsUndefined()) return JSRegExp::NOT_COMPILED; |
| 3948 | Smi* smi = Smi::cast(FixedArray::cast(data)->get(kTagIndex)); |
| 3949 | return static_cast<JSRegExp::Type>(smi->value()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 3950 | } |
| 3951 | |
| 3952 | |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3953 | JSRegExp::Type JSRegExp::TypeTagUnchecked() { |
| 3954 | Smi* smi = Smi::cast(DataAtUnchecked(kTagIndex)); |
| 3955 | return static_cast<JSRegExp::Type>(smi->value()); |
| 3956 | } |
| 3957 | |
| 3958 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3959 | int JSRegExp::CaptureCount() { |
| 3960 | switch (TypeTag()) { |
| 3961 | case ATOM: |
| 3962 | return 0; |
| 3963 | case IRREGEXP: |
| 3964 | return Smi::cast(DataAt(kIrregexpCaptureCountIndex))->value(); |
| 3965 | default: |
| 3966 | UNREACHABLE(); |
| 3967 | return -1; |
| 3968 | } |
| 3969 | } |
| 3970 | |
| 3971 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 3972 | JSRegExp::Flags JSRegExp::GetFlags() { |
| 3973 | ASSERT(this->data()->IsFixedArray()); |
| 3974 | Object* data = this->data(); |
| 3975 | Smi* smi = Smi::cast(FixedArray::cast(data)->get(kFlagsIndex)); |
| 3976 | return Flags(smi->value()); |
| 3977 | } |
| 3978 | |
| 3979 | |
| 3980 | String* JSRegExp::Pattern() { |
| 3981 | ASSERT(this->data()->IsFixedArray()); |
| 3982 | Object* data = this->data(); |
| 3983 | String* pattern= String::cast(FixedArray::cast(data)->get(kSourceIndex)); |
| 3984 | return pattern; |
| 3985 | } |
| 3986 | |
| 3987 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 3988 | Object* JSRegExp::DataAt(int index) { |
| 3989 | ASSERT(TypeTag() != NOT_COMPILED); |
| 3990 | return FixedArray::cast(data())->get(index); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 3991 | } |
| 3992 | |
| 3993 | |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3994 | Object* JSRegExp::DataAtUnchecked(int index) { |
| 3995 | FixedArray* fa = reinterpret_cast<FixedArray*>(data()); |
| 3996 | int offset = FixedArray::kHeaderSize + index * kPointerSize; |
| 3997 | return READ_FIELD(fa, offset); |
| 3998 | } |
| 3999 | |
| 4000 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4001 | void JSRegExp::SetDataAt(int index, Object* value) { |
| 4002 | ASSERT(TypeTag() != NOT_COMPILED); |
| 4003 | ASSERT(index >= kDataIndex); // Only implementation data can be set this way. |
| 4004 | FixedArray::cast(data())->set(index, value); |
| 4005 | } |
| 4006 | |
| 4007 | |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4008 | void JSRegExp::SetDataAtUnchecked(int index, Object* value, Heap* heap) { |
| 4009 | ASSERT(index >= kDataIndex); // Only implementation data can be set this way. |
| 4010 | FixedArray* fa = reinterpret_cast<FixedArray*>(data()); |
| 4011 | if (value->IsSmi()) { |
| 4012 | fa->set_unchecked(index, Smi::cast(value)); |
| 4013 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4014 | // We only do this during GC, so we don't need to notify the write barrier. |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4015 | fa->set_unchecked(heap, index, value, SKIP_WRITE_BARRIER); |
| 4016 | } |
| 4017 | } |
| 4018 | |
| 4019 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4020 | ElementsKind JSObject::GetElementsKind() { |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4021 | ElementsKind kind = map()->elements_kind(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4022 | #if DEBUG |
| 4023 | FixedArrayBase* fixed_array = |
| 4024 | reinterpret_cast<FixedArrayBase*>(READ_FIELD(this, kElementsOffset)); |
| 4025 | Map* map = fixed_array->map(); |
| 4026 | ASSERT(((kind == FAST_ELEMENTS || kind == FAST_SMI_ONLY_ELEMENTS) && |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4027 | (map == GetHeap()->fixed_array_map() || |
| 4028 | map == GetHeap()->fixed_cow_array_map())) || |
| 4029 | (kind == FAST_DOUBLE_ELEMENTS && |
| 4030 | fixed_array->IsFixedDoubleArray()) || |
| 4031 | (kind == DICTIONARY_ELEMENTS && |
| 4032 | fixed_array->IsFixedArray() && |
| 4033 | fixed_array->IsDictionary()) || |
| 4034 | (kind > DICTIONARY_ELEMENTS)); |
| 4035 | ASSERT((kind != NON_STRICT_ARGUMENTS_ELEMENTS) || |
| 4036 | (elements()->IsFixedArray() && elements()->length() >= 2)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4037 | #endif |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4038 | return kind; |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 4039 | } |
| 4040 | |
| 4041 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 4042 | ElementsAccessor* JSObject::GetElementsAccessor() { |
| 4043 | return ElementsAccessor::ForKind(GetElementsKind()); |
| 4044 | } |
| 4045 | |
| 4046 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4047 | bool JSObject::HasFastElements() { |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 4048 | return GetElementsKind() == FAST_ELEMENTS; |
| 4049 | } |
| 4050 | |
| 4051 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4052 | bool JSObject::HasFastSmiOnlyElements() { |
| 4053 | return GetElementsKind() == FAST_SMI_ONLY_ELEMENTS; |
| 4054 | } |
| 4055 | |
| 4056 | |
| 4057 | bool JSObject::HasFastTypeElements() { |
| 4058 | ElementsKind elements_kind = GetElementsKind(); |
| 4059 | return elements_kind == FAST_SMI_ONLY_ELEMENTS || |
| 4060 | elements_kind == FAST_ELEMENTS; |
| 4061 | } |
| 4062 | |
| 4063 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4064 | bool JSObject::HasFastDoubleElements() { |
| 4065 | return GetElementsKind() == FAST_DOUBLE_ELEMENTS; |
| 4066 | } |
| 4067 | |
| 4068 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 4069 | bool JSObject::HasDictionaryElements() { |
| 4070 | return GetElementsKind() == DICTIONARY_ELEMENTS; |
| 4071 | } |
| 4072 | |
| 4073 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4074 | bool JSObject::HasNonStrictArgumentsElements() { |
| 4075 | return GetElementsKind() == NON_STRICT_ARGUMENTS_ELEMENTS; |
| 4076 | } |
| 4077 | |
| 4078 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4079 | bool JSObject::HasExternalArrayElements() { |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4080 | HeapObject* array = elements(); |
| 4081 | ASSERT(array != NULL); |
| 4082 | return array->IsExternalArray(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4083 | } |
| 4084 | |
| 4085 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4086 | #define EXTERNAL_ELEMENTS_CHECK(name, type) \ |
| 4087 | bool JSObject::HasExternal##name##Elements() { \ |
| 4088 | HeapObject* array = elements(); \ |
| 4089 | ASSERT(array != NULL); \ |
| 4090 | if (!array->IsHeapObject()) \ |
| 4091 | return false; \ |
| 4092 | return array->map()->instance_type() == type; \ |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4093 | } |
| 4094 | |
| 4095 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4096 | EXTERNAL_ELEMENTS_CHECK(Byte, EXTERNAL_BYTE_ARRAY_TYPE) |
| 4097 | EXTERNAL_ELEMENTS_CHECK(UnsignedByte, EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE) |
| 4098 | EXTERNAL_ELEMENTS_CHECK(Short, EXTERNAL_SHORT_ARRAY_TYPE) |
| 4099 | EXTERNAL_ELEMENTS_CHECK(UnsignedShort, |
| 4100 | EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE) |
| 4101 | EXTERNAL_ELEMENTS_CHECK(Int, EXTERNAL_INT_ARRAY_TYPE) |
| 4102 | EXTERNAL_ELEMENTS_CHECK(UnsignedInt, |
| 4103 | EXTERNAL_UNSIGNED_INT_ARRAY_TYPE) |
| 4104 | EXTERNAL_ELEMENTS_CHECK(Float, |
| 4105 | EXTERNAL_FLOAT_ARRAY_TYPE) |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 4106 | EXTERNAL_ELEMENTS_CHECK(Double, |
| 4107 | EXTERNAL_DOUBLE_ARRAY_TYPE) |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4108 | EXTERNAL_ELEMENTS_CHECK(Pixel, EXTERNAL_PIXEL_ARRAY_TYPE) |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4109 | |
| 4110 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4111 | bool JSObject::HasNamedInterceptor() { |
| 4112 | return map()->has_named_interceptor(); |
| 4113 | } |
| 4114 | |
| 4115 | |
| 4116 | bool JSObject::HasIndexedInterceptor() { |
| 4117 | return map()->has_indexed_interceptor(); |
| 4118 | } |
| 4119 | |
| 4120 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4121 | bool JSObject::AllowsSetElementsLength() { |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4122 | bool result = elements()->IsFixedArray() || |
| 4123 | elements()->IsFixedDoubleArray(); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4124 | ASSERT(result == !HasExternalArrayElements()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4125 | return result; |
| 4126 | } |
| 4127 | |
| 4128 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4129 | MaybeObject* JSObject::EnsureWritableFastElements() { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4130 | ASSERT(HasFastTypeElements()); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 4131 | FixedArray* elems = FixedArray::cast(elements()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4132 | Isolate* isolate = GetIsolate(); |
| 4133 | if (elems->map() != isolate->heap()->fixed_cow_array_map()) return elems; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4134 | Object* writable_elems; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4135 | { MaybeObject* maybe_writable_elems = isolate->heap()->CopyFixedArrayWithMap( |
| 4136 | elems, isolate->heap()->fixed_array_map()); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4137 | if (!maybe_writable_elems->ToObject(&writable_elems)) { |
| 4138 | return maybe_writable_elems; |
| 4139 | } |
| 4140 | } |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 4141 | set_elements(FixedArray::cast(writable_elems)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4142 | isolate->counters()->cow_arrays_converted()->Increment(); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 4143 | return writable_elems; |
| 4144 | } |
| 4145 | |
| 4146 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4147 | StringDictionary* JSObject::property_dictionary() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4148 | ASSERT(!HasFastProperties()); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4149 | return StringDictionary::cast(properties()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4150 | } |
| 4151 | |
| 4152 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4153 | NumberDictionary* JSObject::element_dictionary() { |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 4154 | ASSERT(HasDictionaryElements()); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4155 | return NumberDictionary::cast(elements()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4156 | } |
| 4157 | |
| 4158 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4159 | bool String::IsHashFieldComputed(uint32_t field) { |
| 4160 | return (field & kHashNotComputedMask) == 0; |
| 4161 | } |
| 4162 | |
| 4163 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4164 | bool String::HasHashCode() { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4165 | return IsHashFieldComputed(hash_field()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4166 | } |
| 4167 | |
| 4168 | |
| 4169 | uint32_t String::Hash() { |
| 4170 | // Fast case: has hash code already been computed? |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 4171 | uint32_t field = hash_field(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4172 | if (IsHashFieldComputed(field)) return field >> kHashShift; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4173 | // Slow case: compute hash code and set it. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4174 | return ComputeAndSetHash(); |
| 4175 | } |
| 4176 | |
| 4177 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4178 | StringHasher::StringHasher(int length) |
| 4179 | : length_(length), |
| 4180 | raw_running_hash_(0), |
| 4181 | array_index_(0), |
| 4182 | is_array_index_(0 < length_ && length_ <= String::kMaxArrayIndexSize), |
| 4183 | is_first_char_(true), |
| 4184 | is_valid_(true) { } |
| 4185 | |
| 4186 | |
| 4187 | bool StringHasher::has_trivial_hash() { |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 4188 | return length_ > String::kMaxHashCalcLength; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4189 | } |
| 4190 | |
| 4191 | |
| 4192 | void StringHasher::AddCharacter(uc32 c) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4193 | // Use the Jenkins one-at-a-time hash function to update the hash |
| 4194 | // for the given character. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4195 | raw_running_hash_ += c; |
| 4196 | raw_running_hash_ += (raw_running_hash_ << 10); |
| 4197 | raw_running_hash_ ^= (raw_running_hash_ >> 6); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4198 | // Incremental array index computation. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4199 | if (is_array_index_) { |
| 4200 | if (c < '0' || c > '9') { |
| 4201 | is_array_index_ = false; |
| 4202 | } else { |
| 4203 | int d = c - '0'; |
| 4204 | if (is_first_char_) { |
| 4205 | is_first_char_ = false; |
| 4206 | if (c == '0' && length_ > 1) { |
| 4207 | is_array_index_ = false; |
| 4208 | return; |
| 4209 | } |
| 4210 | } |
| 4211 | if (array_index_ > 429496729U - ((d + 2) >> 3)) { |
| 4212 | is_array_index_ = false; |
| 4213 | } else { |
| 4214 | array_index_ = array_index_ * 10 + d; |
| 4215 | } |
| 4216 | } |
| 4217 | } |
| 4218 | } |
| 4219 | |
| 4220 | |
| 4221 | void StringHasher::AddCharacterNoIndex(uc32 c) { |
| 4222 | ASSERT(!is_array_index()); |
| 4223 | raw_running_hash_ += c; |
| 4224 | raw_running_hash_ += (raw_running_hash_ << 10); |
| 4225 | raw_running_hash_ ^= (raw_running_hash_ >> 6); |
| 4226 | } |
| 4227 | |
| 4228 | |
| 4229 | uint32_t StringHasher::GetHash() { |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 4230 | // Get the calculated raw hash value and do some more bit ops to distribute |
| 4231 | // the hash further. Ensure that we never return zero as the hash value. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4232 | uint32_t result = raw_running_hash_; |
| 4233 | result += (result << 3); |
| 4234 | result ^= (result >> 11); |
| 4235 | result += (result << 15); |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 4236 | if (result == 0) { |
| 4237 | result = 27; |
| 4238 | } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4239 | return result; |
| 4240 | } |
| 4241 | |
| 4242 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4243 | template <typename schar> |
| 4244 | uint32_t HashSequentialString(const schar* chars, int length) { |
| 4245 | StringHasher hasher(length); |
| 4246 | if (!hasher.has_trivial_hash()) { |
| 4247 | int i; |
| 4248 | for (i = 0; hasher.is_array_index() && (i < length); i++) { |
| 4249 | hasher.AddCharacter(chars[i]); |
| 4250 | } |
| 4251 | for (; i < length; i++) { |
| 4252 | hasher.AddCharacterNoIndex(chars[i]); |
| 4253 | } |
| 4254 | } |
| 4255 | return hasher.GetHashField(); |
| 4256 | } |
| 4257 | |
| 4258 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4259 | bool String::AsArrayIndex(uint32_t* index) { |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 4260 | uint32_t field = hash_field(); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 4261 | if (IsHashFieldComputed(field) && (field & kIsNotArrayIndexMask)) { |
| 4262 | return false; |
| 4263 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4264 | return SlowAsArrayIndex(index); |
| 4265 | } |
| 4266 | |
| 4267 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4268 | Object* JSReceiver::GetPrototype() { |
| 4269 | return HeapObject::cast(this)->map()->prototype(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4270 | } |
| 4271 | |
| 4272 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4273 | bool JSReceiver::HasProperty(String* name) { |
| 4274 | if (IsJSProxy()) { |
| 4275 | return JSProxy::cast(this)->HasPropertyWithHandler(name); |
| 4276 | } |
| 4277 | return GetPropertyAttribute(name) != ABSENT; |
| 4278 | } |
| 4279 | |
| 4280 | |
| 4281 | bool JSReceiver::HasLocalProperty(String* name) { |
| 4282 | if (IsJSProxy()) { |
| 4283 | return JSProxy::cast(this)->HasPropertyWithHandler(name); |
| 4284 | } |
| 4285 | return GetLocalPropertyAttribute(name) != ABSENT; |
| 4286 | } |
| 4287 | |
| 4288 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4289 | PropertyAttributes JSReceiver::GetPropertyAttribute(String* key) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4290 | return GetPropertyAttributeWithReceiver(this, key); |
| 4291 | } |
| 4292 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4293 | // TODO(504): this may be useful in other places too where JSGlobalProxy |
| 4294 | // is used. |
| 4295 | Object* JSObject::BypassGlobalProxy() { |
| 4296 | if (IsJSGlobalProxy()) { |
| 4297 | Object* proto = GetPrototype(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4298 | if (proto->IsNull()) return GetHeap()->undefined_value(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4299 | ASSERT(proto->IsJSGlobalObject()); |
| 4300 | return proto; |
| 4301 | } |
| 4302 | return this; |
| 4303 | } |
| 4304 | |
| 4305 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4306 | MaybeObject* JSReceiver::GetIdentityHash(CreationFlag flag) { |
| 4307 | return IsJSProxy() |
| 4308 | ? JSProxy::cast(this)->GetIdentityHash(flag) |
| 4309 | : JSObject::cast(this)->GetIdentityHash(flag); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4310 | } |
| 4311 | |
| 4312 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4313 | bool JSReceiver::HasElement(uint32_t index) { |
| 4314 | if (IsJSProxy()) { |
| 4315 | return JSProxy::cast(this)->HasElementWithHandler(index); |
| 4316 | } |
| 4317 | return JSObject::cast(this)->HasElementWithReceiver(this, index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4318 | } |
| 4319 | |
| 4320 | |
| 4321 | bool AccessorInfo::all_can_read() { |
| 4322 | return BooleanBit::get(flag(), kAllCanReadBit); |
| 4323 | } |
| 4324 | |
| 4325 | |
| 4326 | void AccessorInfo::set_all_can_read(bool value) { |
| 4327 | set_flag(BooleanBit::set(flag(), kAllCanReadBit, value)); |
| 4328 | } |
| 4329 | |
| 4330 | |
| 4331 | bool AccessorInfo::all_can_write() { |
| 4332 | return BooleanBit::get(flag(), kAllCanWriteBit); |
| 4333 | } |
| 4334 | |
| 4335 | |
| 4336 | void AccessorInfo::set_all_can_write(bool value) { |
| 4337 | set_flag(BooleanBit::set(flag(), kAllCanWriteBit, value)); |
| 4338 | } |
| 4339 | |
| 4340 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 4341 | bool AccessorInfo::prohibits_overwriting() { |
| 4342 | return BooleanBit::get(flag(), kProhibitsOverwritingBit); |
| 4343 | } |
| 4344 | |
| 4345 | |
| 4346 | void AccessorInfo::set_prohibits_overwriting(bool value) { |
| 4347 | set_flag(BooleanBit::set(flag(), kProhibitsOverwritingBit, value)); |
| 4348 | } |
| 4349 | |
| 4350 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4351 | PropertyAttributes AccessorInfo::property_attributes() { |
| 4352 | return AttributesField::decode(static_cast<uint32_t>(flag()->value())); |
| 4353 | } |
| 4354 | |
| 4355 | |
| 4356 | void AccessorInfo::set_property_attributes(PropertyAttributes attributes) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4357 | set_flag(Smi::FromInt(AttributesField::update(flag()->value(), attributes))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4358 | } |
| 4359 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4360 | |
| 4361 | template<typename Shape, typename Key> |
| 4362 | void Dictionary<Shape, Key>::SetEntry(int entry, |
| 4363 | Object* key, |
| 4364 | Object* value) { |
| 4365 | SetEntry(entry, key, value, PropertyDetails(Smi::FromInt(0))); |
| 4366 | } |
| 4367 | |
| 4368 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4369 | template<typename Shape, typename Key> |
| 4370 | void Dictionary<Shape, Key>::SetEntry(int entry, |
| 4371 | Object* key, |
| 4372 | Object* value, |
| 4373 | PropertyDetails details) { |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 4374 | ASSERT(!key->IsString() || details.IsDeleted() || details.index() > 0); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4375 | int index = HashTable<Shape, Key>::EntryToIndex(entry); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4376 | AssertNoAllocation no_gc; |
| 4377 | WriteBarrierMode mode = FixedArray::GetWriteBarrierMode(no_gc); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4378 | FixedArray::set(index, key, mode); |
| 4379 | FixedArray::set(index+1, value, mode); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4380 | FixedArray::set(index+2, details.AsSmi()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4381 | } |
| 4382 | |
| 4383 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4384 | bool NumberDictionaryShape::IsMatch(uint32_t key, Object* other) { |
| 4385 | ASSERT(other->IsNumber()); |
| 4386 | return key == static_cast<uint32_t>(other->Number()); |
| 4387 | } |
| 4388 | |
| 4389 | |
| 4390 | uint32_t NumberDictionaryShape::Hash(uint32_t key) { |
| 4391 | return ComputeIntegerHash(key); |
| 4392 | } |
| 4393 | |
| 4394 | |
| 4395 | uint32_t NumberDictionaryShape::HashForObject(uint32_t key, Object* other) { |
| 4396 | ASSERT(other->IsNumber()); |
| 4397 | return ComputeIntegerHash(static_cast<uint32_t>(other->Number())); |
| 4398 | } |
| 4399 | |
| 4400 | |
| 4401 | MaybeObject* NumberDictionaryShape::AsObject(uint32_t key) { |
| 4402 | return Isolate::Current()->heap()->NumberFromUint32(key); |
| 4403 | } |
| 4404 | |
| 4405 | |
| 4406 | bool StringDictionaryShape::IsMatch(String* key, Object* other) { |
| 4407 | // We know that all entries in a hash table had their hash keys created. |
| 4408 | // Use that knowledge to have fast failure. |
| 4409 | if (key->Hash() != String::cast(other)->Hash()) return false; |
| 4410 | return key->Equals(String::cast(other)); |
| 4411 | } |
| 4412 | |
| 4413 | |
| 4414 | uint32_t StringDictionaryShape::Hash(String* key) { |
| 4415 | return key->Hash(); |
| 4416 | } |
| 4417 | |
| 4418 | |
| 4419 | uint32_t StringDictionaryShape::HashForObject(String* key, Object* other) { |
| 4420 | return String::cast(other)->Hash(); |
| 4421 | } |
| 4422 | |
| 4423 | |
| 4424 | MaybeObject* StringDictionaryShape::AsObject(String* key) { |
| 4425 | return key; |
| 4426 | } |
| 4427 | |
| 4428 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4429 | template <int entrysize> |
| 4430 | bool ObjectHashTableShape<entrysize>::IsMatch(Object* key, Object* other) { |
| 4431 | return key->SameValue(other); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 4432 | } |
| 4433 | |
| 4434 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4435 | template <int entrysize> |
| 4436 | uint32_t ObjectHashTableShape<entrysize>::Hash(Object* key) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4437 | MaybeObject* maybe_hash = key->GetHash(OMIT_CREATION); |
| 4438 | return Smi::cast(maybe_hash->ToObjectChecked())->value(); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 4439 | } |
| 4440 | |
| 4441 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4442 | template <int entrysize> |
| 4443 | uint32_t ObjectHashTableShape<entrysize>::HashForObject(Object* key, |
| 4444 | Object* other) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4445 | MaybeObject* maybe_hash = other->GetHash(OMIT_CREATION); |
| 4446 | return Smi::cast(maybe_hash->ToObjectChecked())->value(); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 4447 | } |
| 4448 | |
| 4449 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4450 | template <int entrysize> |
| 4451 | MaybeObject* ObjectHashTableShape<entrysize>::AsObject(Object* key) { |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 4452 | return key; |
| 4453 | } |
| 4454 | |
| 4455 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4456 | void Map::ClearCodeCache(Heap* heap) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4457 | // No write barrier is needed since empty_fixed_array is not in new space. |
| 4458 | // Please note this function is used during marking: |
| 4459 | // - MarkCompactCollector::MarkUnmarkedObject |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4460 | ASSERT(!heap->InNewSpace(heap->raw_unchecked_empty_fixed_array())); |
| 4461 | WRITE_FIELD(this, kCodeCacheOffset, heap->raw_unchecked_empty_fixed_array()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4462 | } |
| 4463 | |
| 4464 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 4465 | void JSArray::EnsureSize(int required_size) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4466 | ASSERT(HasFastTypeElements()); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4467 | FixedArray* elts = FixedArray::cast(elements()); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4468 | const int kArraySizeThatFitsComfortablyInNewSpace = 128; |
| 4469 | if (elts->length() < required_size) { |
| 4470 | // Doubling in size would be overkill, but leave some slack to avoid |
| 4471 | // constantly growing. |
| 4472 | Expand(required_size + (required_size >> 3)); |
| 4473 | // It's a performance benefit to keep a frequently used array in new-space. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4474 | } else if (!GetHeap()->new_space()->Contains(elts) && |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4475 | required_size < kArraySizeThatFitsComfortablyInNewSpace) { |
| 4476 | // Expand will allocate a new backing store in new space even if the size |
| 4477 | // we asked for isn't larger than what we had before. |
| 4478 | Expand(required_size); |
| 4479 | } |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 4480 | } |
| 4481 | |
| 4482 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4483 | void JSArray::set_length(Smi* length) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4484 | // Don't need a write barrier for a Smi. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4485 | set_length(static_cast<Object*>(length), SKIP_WRITE_BARRIER); |
| 4486 | } |
| 4487 | |
| 4488 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4489 | MaybeObject* JSArray::SetContent(FixedArray* storage) { |
| 4490 | MaybeObject* maybe_object = EnsureCanContainElements(storage); |
| 4491 | if (maybe_object->IsFailure()) return maybe_object; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4492 | set_length(Smi::FromInt(storage->length())); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4493 | set_elements(storage); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4494 | return this; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4495 | } |
| 4496 | |
| 4497 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4498 | MaybeObject* FixedArray::Copy() { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4499 | if (length() == 0) return this; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4500 | return GetHeap()->CopyFixedArray(this); |
| 4501 | } |
| 4502 | |
| 4503 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4504 | MaybeObject* FixedDoubleArray::Copy() { |
| 4505 | if (length() == 0) return this; |
| 4506 | return GetHeap()->CopyFixedDoubleArray(this); |
| 4507 | } |
| 4508 | |
| 4509 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4510 | Relocatable::Relocatable(Isolate* isolate) { |
| 4511 | ASSERT(isolate == Isolate::Current()); |
| 4512 | isolate_ = isolate; |
| 4513 | prev_ = isolate->relocatable_top(); |
| 4514 | isolate->set_relocatable_top(this); |
| 4515 | } |
| 4516 | |
| 4517 | |
| 4518 | Relocatable::~Relocatable() { |
| 4519 | ASSERT(isolate_ == Isolate::Current()); |
| 4520 | ASSERT_EQ(isolate_->relocatable_top(), this); |
| 4521 | isolate_->set_relocatable_top(prev_); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4522 | } |
| 4523 | |
| 4524 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4525 | int JSObject::BodyDescriptor::SizeOf(Map* map, HeapObject* object) { |
| 4526 | return map->instance_size(); |
| 4527 | } |
| 4528 | |
| 4529 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 4530 | void Foreign::ForeignIterateBody(ObjectVisitor* v) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4531 | v->VisitExternalReference( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame^] | 4532 | reinterpret_cast<Address*>(FIELD_ADDR(this, kForeignAddressOffset))); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4533 | } |
| 4534 | |
| 4535 | |
| 4536 | template<typename StaticVisitor> |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 4537 | void Foreign::ForeignIterateBody() { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4538 | StaticVisitor::VisitExternalReference( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame^] | 4539 | reinterpret_cast<Address*>(FIELD_ADDR(this, kForeignAddressOffset))); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4540 | } |
| 4541 | |
| 4542 | |
| 4543 | void ExternalAsciiString::ExternalAsciiStringIterateBody(ObjectVisitor* v) { |
| 4544 | typedef v8::String::ExternalAsciiStringResource Resource; |
| 4545 | v->VisitExternalAsciiString( |
| 4546 | reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset))); |
| 4547 | } |
| 4548 | |
| 4549 | |
| 4550 | template<typename StaticVisitor> |
| 4551 | void ExternalAsciiString::ExternalAsciiStringIterateBody() { |
| 4552 | typedef v8::String::ExternalAsciiStringResource Resource; |
| 4553 | StaticVisitor::VisitExternalAsciiString( |
| 4554 | reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset))); |
| 4555 | } |
| 4556 | |
| 4557 | |
| 4558 | void ExternalTwoByteString::ExternalTwoByteStringIterateBody(ObjectVisitor* v) { |
| 4559 | typedef v8::String::ExternalStringResource Resource; |
| 4560 | v->VisitExternalTwoByteString( |
| 4561 | reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset))); |
| 4562 | } |
| 4563 | |
| 4564 | |
| 4565 | template<typename StaticVisitor> |
| 4566 | void ExternalTwoByteString::ExternalTwoByteStringIterateBody() { |
| 4567 | typedef v8::String::ExternalStringResource Resource; |
| 4568 | StaticVisitor::VisitExternalTwoByteString( |
| 4569 | reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset))); |
| 4570 | } |
| 4571 | |
| 4572 | #define SLOT_ADDR(obj, offset) \ |
| 4573 | reinterpret_cast<Object**>((obj)->address() + offset) |
| 4574 | |
| 4575 | template<int start_offset, int end_offset, int size> |
| 4576 | void FixedBodyDescriptor<start_offset, end_offset, size>::IterateBody( |
| 4577 | HeapObject* obj, |
| 4578 | ObjectVisitor* v) { |
| 4579 | v->VisitPointers(SLOT_ADDR(obj, start_offset), SLOT_ADDR(obj, end_offset)); |
| 4580 | } |
| 4581 | |
| 4582 | |
| 4583 | template<int start_offset> |
| 4584 | void FlexibleBodyDescriptor<start_offset>::IterateBody(HeapObject* obj, |
| 4585 | int object_size, |
| 4586 | ObjectVisitor* v) { |
| 4587 | v->VisitPointers(SLOT_ADDR(obj, start_offset), SLOT_ADDR(obj, object_size)); |
| 4588 | } |
| 4589 | |
| 4590 | #undef SLOT_ADDR |
| 4591 | |
| 4592 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4593 | #undef CAST_ACCESSOR |
| 4594 | #undef INT_ACCESSORS |
| 4595 | #undef SMI_ACCESSORS |
| 4596 | #undef ACCESSORS |
| 4597 | #undef FIELD_ADDR |
| 4598 | #undef READ_FIELD |
| 4599 | #undef WRITE_FIELD |
| 4600 | #undef WRITE_BARRIER |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4601 | #undef CONDITIONAL_WRITE_BARRIER |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4602 | #undef READ_MEMADDR_FIELD |
| 4603 | #undef WRITE_MEMADDR_FIELD |
| 4604 | #undef READ_DOUBLE_FIELD |
| 4605 | #undef WRITE_DOUBLE_FIELD |
| 4606 | #undef READ_INT_FIELD |
| 4607 | #undef WRITE_INT_FIELD |
| 4608 | #undef READ_SHORT_FIELD |
| 4609 | #undef WRITE_SHORT_FIELD |
| 4610 | #undef READ_BYTE_FIELD |
| 4611 | #undef WRITE_BYTE_FIELD |
| 4612 | |
| 4613 | |
| 4614 | } } // namespace v8::internal |
| 4615 | |
| 4616 | #endif // V8_OBJECTS_INL_H_ |