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