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