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