Revision f230a1cf deps/v8/src/objects-inl.h

View differences:

deps/v8/src/objects-inl.h
80 80

  
81 81
#define CAST_ACCESSOR(type)                     \
82 82
  type* type::cast(Object* object) {            \
83
    ASSERT(object->Is##type());                 \
83
    SLOW_ASSERT(object->Is##type());            \
84 84
    return reinterpret_cast<type*>(object);     \
85 85
  }
86 86

  
......
133 133

  
134 134

  
135 135
bool Object::IsFixedArrayBase() {
136
  return IsFixedArray() || IsFixedDoubleArray();
136
  return IsFixedArray() || IsFixedDoubleArray() || IsConstantPoolArray();
137 137
}
138 138

  
139 139

  
......
285 285

  
286 286

  
287 287
MaybeObject* Object::AllocateNewStorageFor(Heap* heap,
288
                                           Representation representation,
289
                                           PretenureFlag tenure) {
288
                                           Representation representation) {
290 289
  if (!FLAG_track_double_fields) return this;
291 290
  if (!representation.IsDouble()) return this;
292 291
  if (IsUninitialized()) {
293
    return heap->AllocateHeapNumber(0, tenure);
292
    return heap->AllocateHeapNumber(0);
294 293
  }
295
  return heap->AllocateHeapNumber(Number(), tenure);
294
  return heap->AllocateHeapNumber(Number());
296 295
}
297 296

  
298 297

  
......
572 571
TYPE_CHECKER(Map, MAP_TYPE)
573 572
TYPE_CHECKER(FixedArray, FIXED_ARRAY_TYPE)
574 573
TYPE_CHECKER(FixedDoubleArray, FIXED_DOUBLE_ARRAY_TYPE)
574
TYPE_CHECKER(ConstantPoolArray, CONSTANT_POOL_ARRAY_TYPE)
575 575

  
576 576

  
577 577
bool Object::IsJSWeakCollection() {
......
1028 1028
#define WRITE_UINT32_FIELD(p, offset, value) \
1029 1029
  (*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset)) = value)
1030 1030

  
1031
#define READ_INT32_FIELD(p, offset) \
1032
  (*reinterpret_cast<int32_t*>(FIELD_ADDR(p, offset)))
1033

  
1034
#define WRITE_INT32_FIELD(p, offset, value) \
1035
  (*reinterpret_cast<int32_t*>(FIELD_ADDR(p, offset)) = value)
1036

  
1031 1037
#define READ_INT64_FIELD(p, offset) \
1032 1038
  (*reinterpret_cast<int64_t*>(FIELD_ADDR(p, offset)))
1033 1039

  
......
1184 1190
Heap* HeapObject::GetHeap() {
1185 1191
  Heap* heap =
1186 1192
      MemoryChunk::FromAddress(reinterpret_cast<Address>(this))->heap();
1187
  ASSERT(heap != NULL);
1193
  SLOW_ASSERT(heap != NULL);
1188 1194
  return heap;
1189 1195
}
1190 1196

  
......
1301 1307

  
1302 1308

  
1303 1309
void JSObject::ValidateElements() {
1304
#if DEBUG
1310
#ifdef ENABLE_SLOW_ASSERTS
1305 1311
  if (FLAG_enable_slow_asserts) {
1306 1312
    ElementsAccessor* accessor = GetElementsAccessor();
1307 1313
    accessor->Validate(this);
......
1323 1329
}
1324 1330

  
1325 1331

  
1332
void AllocationSite::Initialize() {
1333
  SetElementsKind(GetInitialFastElementsKind());
1334
  set_nested_site(Smi::FromInt(0));
1335
  set_dependent_code(DependentCode::cast(GetHeap()->empty_fixed_array()),
1336
                     SKIP_WRITE_BARRIER);
1337
}
1338

  
1339

  
1326 1340
// Heuristic: We only need to create allocation site info if the boilerplate
1327 1341
// elements kind is the initial elements kind.
1328 1342
AllocationSiteMode AllocationSite::GetMode(
......
1535 1549
}
1536 1550

  
1537 1551

  
1538
MaybeObject* JSObject::AllocateStorageForMap(Map* map) {
1539
  ASSERT(this->map()->inobject_properties() == map->inobject_properties());
1540
  ElementsKind obj_kind = this->map()->elements_kind();
1541
  ElementsKind map_kind = map->elements_kind();
1542
  if (map_kind != obj_kind) {
1543
    ElementsKind to_kind = map_kind;
1544
    if (IsMoreGeneralElementsKindTransition(map_kind, obj_kind) ||
1545
        IsDictionaryElementsKind(obj_kind)) {
1546
      to_kind = obj_kind;
1547
    }
1548
    MaybeObject* maybe_obj =
1549
        IsDictionaryElementsKind(to_kind) ? NormalizeElements()
1550
                                          : TransitionElementsKind(to_kind);
1551
    if (maybe_obj->IsFailure()) return maybe_obj;
1552
    MaybeObject* maybe_map = map->AsElementsKind(to_kind);
1553
    if (!maybe_map->To(&map)) return maybe_map;
1554
  }
1555
  int total_size =
1556
      map->NumberOfOwnDescriptors() + map->unused_property_fields();
1557
  int out_of_object = total_size - map->inobject_properties();
1558
  if (out_of_object != properties()->length()) {
1559
    FixedArray* new_properties;
1560
    MaybeObject* maybe_properties = properties()->CopySize(out_of_object);
1561
    if (!maybe_properties->To(&new_properties)) return maybe_properties;
1562
    set_properties(new_properties);
1563
  }
1564
  set_map(map);
1565
  return this;
1566
}
1567

  
1568

  
1569
MaybeObject* JSObject::MigrateInstance() {
1570
  // Converting any field to the most specific type will cause the
1571
  // GeneralizeFieldRepresentation algorithm to create the most general existing
1572
  // transition that matches the object. This achieves what is needed.
1573
  Map* original_map = map();
1574
  MaybeObject* maybe_result = GeneralizeFieldRepresentation(
1575
      0, Representation::None(), ALLOW_AS_CONSTANT);
1576
  JSObject* result;
1577
  if (FLAG_trace_migration && maybe_result->To(&result)) {
1578
    PrintInstanceMigration(stdout, original_map, result->map());
1579
  }
1580
  return maybe_result;
1581
}
1582

  
1583

  
1584
MaybeObject* JSObject::TryMigrateInstance() {
1585
  Map* new_map = map()->CurrentMapForDeprecated();
1586
  if (new_map == NULL) return Smi::FromInt(0);
1587
  Map* original_map = map();
1588
  MaybeObject* maybe_result = MigrateToMap(new_map);
1589
  JSObject* result;
1590
  if (FLAG_trace_migration && maybe_result->To(&result)) {
1591
    PrintInstanceMigration(stdout, original_map, result->map());
1592
  }
1593
  return maybe_result;
1594
}
1595

  
1596

  
1597 1552
Handle<String> JSObject::ExpectedTransitionKey(Handle<Map> map) {
1598 1553
  DisallowHeapAllocation no_gc;
1599 1554
  if (!map->HasTransitionArray()) return Handle<String>::null();
......
1629 1584
}
1630 1585

  
1631 1586

  
1632
int JSObject::LastAddedFieldIndex() {
1633
  Map* map = this->map();
1634
  int last_added = map->LastAdded();
1635
  return map->instance_descriptors()->GetFieldIndex(last_added);
1636
}
1637

  
1638

  
1639 1587
ACCESSORS(Oddball, to_string, String, kToStringOffset)
1640 1588
ACCESSORS(Oddball, to_number, Object, kToNumberOffset)
1641 1589

  
......
1719 1667
    case JS_MESSAGE_OBJECT_TYPE:
1720 1668
      return JSMessageObject::kSize;
1721 1669
    default:
1722
      UNREACHABLE();
1670
      // TODO(jkummerow): Re-enable this. Blink currently hits this
1671
      // from its CustomElementConstructorBuilder.
1672
      // UNREACHABLE();
1723 1673
      return 0;
1724 1674
  }
1725 1675
}
......
1946 1896

  
1947 1897

  
1948 1898
FixedArrayBase* FixedArrayBase::cast(Object* object) {
1949
  ASSERT(object->IsFixedArray() || object->IsFixedDoubleArray());
1899
  ASSERT(object->IsFixedArray() || object->IsFixedDoubleArray() ||
1900
         object->IsConstantPoolArray());
1950 1901
  return reinterpret_cast<FixedArrayBase*>(object);
1951 1902
}
1952 1903

  
1953 1904

  
1954 1905
Object* FixedArray::get(int index) {
1955
  ASSERT(index >= 0 && index < this->length());
1906
  SLOW_ASSERT(index >= 0 && index < this->length());
1956 1907
  return READ_FIELD(this, kHeaderSize + index * kPointerSize);
1957 1908
}
1958 1909

  
......
2045 1996
}
2046 1997

  
2047 1998

  
1999
SMI_ACCESSORS(ConstantPoolArray, first_ptr_index, kFirstPointerIndexOffset)
2000
SMI_ACCESSORS(ConstantPoolArray, first_int32_index, kFirstInt32IndexOffset)
2001

  
2002

  
2003
int ConstantPoolArray::first_int64_index() {
2004
  return 0;
2005
}
2006

  
2007

  
2008
int ConstantPoolArray::count_of_int64_entries() {
2009
  return first_ptr_index();
2010
}
2011

  
2012

  
2013
int ConstantPoolArray::count_of_ptr_entries() {
2014
  return first_int32_index() - first_ptr_index();
2015
}
2016

  
2017

  
2018
int ConstantPoolArray::count_of_int32_entries() {
2019
  return length() - first_int32_index();
2020
}
2021

  
2022

  
2023
void ConstantPoolArray::SetEntryCounts(int number_of_int64_entries,
2024
                                       int number_of_ptr_entries,
2025
                                       int number_of_int32_entries) {
2026
  set_first_ptr_index(number_of_int64_entries);
2027
  set_first_int32_index(number_of_int64_entries + number_of_ptr_entries);
2028
  set_length(number_of_int64_entries + number_of_ptr_entries +
2029
             number_of_int32_entries);
2030
}
2031

  
2032

  
2033
int64_t ConstantPoolArray::get_int64_entry(int index) {
2034
  ASSERT(map() == GetHeap()->constant_pool_array_map());
2035
  ASSERT(index >= 0 && index < first_ptr_index());
2036
  return READ_INT64_FIELD(this, OffsetOfElementAt(index));
2037
}
2038

  
2039
double ConstantPoolArray::get_int64_entry_as_double(int index) {
2040
  STATIC_ASSERT(kDoubleSize == kInt64Size);
2041
  ASSERT(map() == GetHeap()->constant_pool_array_map());
2042
  ASSERT(index >= 0 && index < first_ptr_index());
2043
  return READ_DOUBLE_FIELD(this, OffsetOfElementAt(index));
2044
}
2045

  
2046

  
2047
Object* ConstantPoolArray::get_ptr_entry(int index) {
2048
  ASSERT(map() == GetHeap()->constant_pool_array_map());
2049
  ASSERT(index >= first_ptr_index() && index < first_int32_index());
2050
  return READ_FIELD(this, OffsetOfElementAt(index));
2051
}
2052

  
2053

  
2054
int32_t ConstantPoolArray::get_int32_entry(int index) {
2055
  ASSERT(map() == GetHeap()->constant_pool_array_map());
2056
  ASSERT(index >= first_int32_index() && index < length());
2057
  return READ_INT32_FIELD(this, OffsetOfElementAt(index));
2058
}
2059

  
2060

  
2061
void ConstantPoolArray::set(int index, Object* value) {
2062
  ASSERT(map() == GetHeap()->constant_pool_array_map());
2063
  ASSERT(index >= first_ptr_index() && index < first_int32_index());
2064
  WRITE_FIELD(this, OffsetOfElementAt(index), value);
2065
  WRITE_BARRIER(GetHeap(), this, OffsetOfElementAt(index), value);
2066
}
2067

  
2068

  
2069
void ConstantPoolArray::set(int index, int64_t value) {
2070
  ASSERT(map() == GetHeap()->constant_pool_array_map());
2071
  ASSERT(index >= first_int64_index() && index < first_ptr_index());
2072
  WRITE_INT64_FIELD(this, OffsetOfElementAt(index), value);
2073
}
2074

  
2075

  
2076
void ConstantPoolArray::set(int index, double value) {
2077
  STATIC_ASSERT(kDoubleSize == kInt64Size);
2078
  ASSERT(map() == GetHeap()->constant_pool_array_map());
2079
  ASSERT(index >= first_int64_index() && index < first_ptr_index());
2080
  WRITE_DOUBLE_FIELD(this, OffsetOfElementAt(index), value);
2081
}
2082

  
2083

  
2084
void ConstantPoolArray::set(int index, int32_t value) {
2085
  ASSERT(map() == GetHeap()->constant_pool_array_map());
2086
  ASSERT(index >= this->first_int32_index() && index < length());
2087
  WRITE_INT32_FIELD(this, OffsetOfElementAt(index), value);
2088
}
2089

  
2090

  
2048 2091
WriteBarrierMode HeapObject::GetWriteBarrierMode(
2049 2092
    const DisallowHeapAllocation& promise) {
2050 2093
  Heap* heap = GetHeap();
......
2537 2580

  
2538 2581
CAST_ACCESSOR(FixedArray)
2539 2582
CAST_ACCESSOR(FixedDoubleArray)
2583
CAST_ACCESSOR(ConstantPoolArray)
2540 2584
CAST_ACCESSOR(DescriptorArray)
2541 2585
CAST_ACCESSOR(DeoptimizationInputData)
2542 2586
CAST_ACCESSOR(DeoptimizationOutputData)
......
3432 3476
    return FixedDoubleArray::SizeFor(
3433 3477
        reinterpret_cast<FixedDoubleArray*>(this)->length());
3434 3478
  }
3479
  if (instance_type == CONSTANT_POOL_ARRAY_TYPE) {
3480
    return ConstantPoolArray::SizeFor(
3481
        reinterpret_cast<ConstantPoolArray*>(this)->count_of_int64_entries(),
3482
        reinterpret_cast<ConstantPoolArray*>(this)->count_of_ptr_entries(),
3483
        reinterpret_cast<ConstantPoolArray*>(this)->count_of_int32_entries());
3484
  }
3435 3485
  ASSERT(instance_type == CODE_TYPE);
3436 3486
  return reinterpret_cast<Code*>(this)->CodeSize();
3437 3487
}
......
3808 3858

  
3809 3859

  
3810 3860
int Code::arguments_count() {
3811
  ASSERT(is_call_stub() || is_keyed_call_stub() || kind() == STUB);
3861
  ASSERT(is_call_stub() || is_keyed_call_stub() ||
3862
         kind() == STUB || is_handler());
3812 3863
  return ExtractArgumentsCountFromFlags(flags());
3813 3864
}
3814 3865

  
......
3828 3879

  
3829 3880
int Code::major_key() {
3830 3881
  ASSERT(kind() == STUB ||
3882
         kind() == HANDLER ||
3831 3883
         kind() == BINARY_OP_IC ||
3832 3884
         kind() == COMPARE_IC ||
3833 3885
         kind() == COMPARE_NIL_IC ||
......
3842 3894

  
3843 3895
void Code::set_major_key(int major) {
3844 3896
  ASSERT(kind() == STUB ||
3897
         kind() == HANDLER ||
3845 3898
         kind() == BINARY_OP_IC ||
3846 3899
         kind() == COMPARE_IC ||
3847 3900
         kind() == COMPARE_NIL_IC ||
......
4077 4130
}
4078 4131

  
4079 4132

  
4133
bool Code::is_keyed_stub() {
4134
  return is_keyed_load_stub() || is_keyed_store_stub() || is_keyed_call_stub();
4135
}
4136

  
4137

  
4080 4138
bool Code::is_debug_stub() {
4081 4139
  return ic_state() == DEBUG_STUB;
4082 4140
}
......
4495 4553
ACCESSORS(TypeSwitchInfo, types, Object, kTypesOffset)
4496 4554

  
4497 4555
ACCESSORS(AllocationSite, transition_info, Object, kTransitionInfoOffset)
4556
ACCESSORS(AllocationSite, nested_site, Object, kNestedSiteOffset)
4557
ACCESSORS(AllocationSite, dependent_code, DependentCode,
4558
          kDependentCodeOffset)
4498 4559
ACCESSORS(AllocationSite, weak_next, Object, kWeakNextOffset)
4499 4560
ACCESSORS(AllocationMemento, allocation_site, Object, kAllocationSiteOffset)
4500 4561

  
......
5457 5518
#if DEBUG
5458 5519
  FixedArrayBase* fixed_array =
5459 5520
      reinterpret_cast<FixedArrayBase*>(READ_FIELD(this, kElementsOffset));
5460
  Map* map = fixed_array->map();
5461
  ASSERT((IsFastSmiOrObjectElementsKind(kind) &&
5462
          (map == GetHeap()->fixed_array_map() ||
5463
           map == GetHeap()->fixed_cow_array_map())) ||
5464
         (IsFastDoubleElementsKind(kind) &&
5465
          (fixed_array->IsFixedDoubleArray() ||
5466
           fixed_array == GetHeap()->empty_fixed_array())) ||
5467
         (kind == DICTIONARY_ELEMENTS &&
5521

  
5522
  // If a GC was caused while constructing this object, the elements
5523
  // pointer may point to a one pointer filler map.
5524
  if (ElementsAreSafeToExamine()) {
5525
    Map* map = fixed_array->map();
5526
    ASSERT((IsFastSmiOrObjectElementsKind(kind) &&
5527
            (map == GetHeap()->fixed_array_map() ||
5528
             map == GetHeap()->fixed_cow_array_map())) ||
5529
           (IsFastDoubleElementsKind(kind) &&
5530
            (fixed_array->IsFixedDoubleArray() ||
5531
             fixed_array == GetHeap()->empty_fixed_array())) ||
5532
           (kind == DICTIONARY_ELEMENTS &&
5468 5533
            fixed_array->IsFixedArray() &&
5469
          fixed_array->IsDictionary()) ||
5470
         (kind > DICTIONARY_ELEMENTS));
5471
  ASSERT((kind != NON_STRICT_ARGUMENTS_ELEMENTS) ||
5472
         (elements()->IsFixedArray() && elements()->length() >= 2));
5534
            fixed_array->IsDictionary()) ||
5535
           (kind > DICTIONARY_ELEMENTS));
5536
    ASSERT((kind != NON_STRICT_ARGUMENTS_ELEMENTS) ||
5537
           (elements()->IsFixedArray() && elements()->length() >= 2));
5538
  }
5473 5539
#endif
5474 5540
  return kind;
5475 5541
}
......
5729 5795
}
5730 5796

  
5731 5797

  
5732
bool JSReceiver::HasProperty(Name* name) {
5733
  if (IsJSProxy()) {
5734
    return JSProxy::cast(this)->HasPropertyWithHandler(name);
5798
bool JSReceiver::HasProperty(Handle<JSReceiver> object,
5799
                             Handle<Name> name) {
5800
  if (object->IsJSProxy()) {
5801
    Handle<JSProxy> proxy = Handle<JSProxy>::cast(object);
5802
    return JSProxy::HasPropertyWithHandler(proxy, name);
5735 5803
  }
5736
  return GetPropertyAttribute(name) != ABSENT;
5804
  return object->GetPropertyAttribute(*name) != ABSENT;
5737 5805
}
5738 5806

  
5739 5807

  
5740
bool JSReceiver::HasLocalProperty(Name* name) {
5741
  if (IsJSProxy()) {
5742
    return JSProxy::cast(this)->HasPropertyWithHandler(name);
5808
bool JSReceiver::HasLocalProperty(Handle<JSReceiver> object,
5809
                                  Handle<Name> name) {
5810
  if (object->IsJSProxy()) {
5811
    Handle<JSProxy> proxy = Handle<JSProxy>::cast(object);
5812
    return JSProxy::HasPropertyWithHandler(proxy, name);
5743 5813
  }
5744
  return GetLocalPropertyAttribute(name) != ABSENT;
5814
  return object->GetLocalPropertyAttribute(*name) != ABSENT;
5745 5815
}
5746 5816

  
5747 5817

  
......
5783 5853
}
5784 5854

  
5785 5855

  
5786
bool JSReceiver::HasElement(uint32_t index) {
5787
  if (IsJSProxy()) {
5788
    return JSProxy::cast(this)->HasElementWithHandler(index);
5856
bool JSReceiver::HasElement(Handle<JSReceiver> object, uint32_t index) {
5857
  if (object->IsJSProxy()) {
5858
    Handle<JSProxy> proxy = Handle<JSProxy>::cast(object);
5859
    return JSProxy::HasElementWithHandler(proxy, index);
5789 5860
  }
5790
  return JSObject::cast(this)->GetElementAttributeWithReceiver(
5791
      this, index, true) != ABSENT;
5861
  return Handle<JSObject>::cast(object)->GetElementAttributeWithReceiver(
5862
      *object, index, true) != ABSENT;
5792 5863
}
5793 5864

  
5794 5865

  
5795
bool JSReceiver::HasLocalElement(uint32_t index) {
5796
  if (IsJSProxy()) {
5797
    return JSProxy::cast(this)->HasElementWithHandler(index);
5866
bool JSReceiver::HasLocalElement(Handle<JSReceiver> object, uint32_t index) {
5867
  if (object->IsJSProxy()) {
5868
    Handle<JSProxy> proxy = Handle<JSProxy>::cast(object);
5869
    return JSProxy::HasElementWithHandler(proxy, index);
5798 5870
  }
5799
  return JSObject::cast(this)->GetElementAttributeWithReceiver(
5800
      this, index, false) != ABSENT;
5871
  return Handle<JSObject>::cast(object)->GetElementAttributeWithReceiver(
5872
      *object, index, false) != ABSENT;
5801 5873
}
5802 5874

  
5803 5875

  
......
5964 6036

  
5965 6037

  
5966 6038
MaybeObject* NameDictionaryShape::AsObject(Heap* heap, Name* key) {
6039
  ASSERT(key->IsUniqueName());
5967 6040
  return key;
5968 6041
}
5969 6042

  
......
5996 6069
}
5997 6070

  
5998 6071

  
6072
template <int entrysize>
6073
bool WeakHashTableShape<entrysize>::IsMatch(Object* key, Object* other) {
6074
  return key->SameValue(other);
6075
}
6076

  
6077

  
6078
template <int entrysize>
6079
uint32_t WeakHashTableShape<entrysize>::Hash(Object* key) {
6080
  intptr_t hash = reinterpret_cast<intptr_t>(key);
6081
  return (uint32_t)(hash & 0xFFFFFFFF);
6082
}
6083

  
6084

  
6085
template <int entrysize>
6086
uint32_t WeakHashTableShape<entrysize>::HashForObject(Object* key,
6087
                                                      Object* other) {
6088
  intptr_t hash = reinterpret_cast<intptr_t>(other);
6089
  return (uint32_t)(hash & 0xFFFFFFFF);
6090
}
6091

  
6092

  
6093
template <int entrysize>
6094
MaybeObject* WeakHashTableShape<entrysize>::AsObject(Heap* heap,
6095
                                                    Object* key) {
6096
  return key;
6097
}
6098

  
6099

  
5999 6100
void Map::ClearCodeCache(Heap* heap) {
6000 6101
  // No write barrier is needed since empty_fixed_array is not in new space.
6001 6102
  // Please note this function is used during marking:
......
6065 6166
}
6066 6167

  
6067 6168

  
6169
MaybeObject* ConstantPoolArray::Copy() {
6170
  if (length() == 0) return this;
6171
  return GetHeap()->CopyConstantPoolArray(this);
6172
}
6173

  
6174

  
6068 6175
void TypeFeedbackCells::SetAstId(int index, TypeFeedbackId id) {
6069 6176
  set(1 + index * 2, Smi::FromInt(id.ToInt()));
6070 6177
}

Also available in: Unified diff