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