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