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