2014-04-01 11:16:13 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
#ifndef V8_PROPERTY_H_
|
|
|
|
#define V8_PROPERTY_H_
|
|
|
|
|
2014-09-30 10:29:32 +00:00
|
|
|
#include <iosfwd>
|
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/factory.h"
|
2014-06-10 14:01:08 +00:00
|
|
|
#include "src/field-index.h"
|
2014-06-20 08:40:11 +00:00
|
|
|
#include "src/isolate.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/types.h"
|
2011-05-06 06:50:20 +00:00
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Abstraction for elements in instance-descriptor arrays.
|
|
|
|
//
|
|
|
|
// Each descriptor has a key, property attributes, property type,
|
|
|
|
// property index (in the actual instance-descriptor array) and
|
|
|
|
// optionally a piece of data.
|
|
|
|
class Descriptor BASE_EMBEDDED {
|
|
|
|
public:
|
2014-04-09 14:26:32 +00:00
|
|
|
void KeyToUniqueName() {
|
2013-03-04 15:00:57 +00:00
|
|
|
if (!key_->IsUniqueName()) {
|
2014-04-09 14:26:32 +00:00
|
|
|
key_ = key_->GetIsolate()->factory()->InternalizeString(
|
|
|
|
Handle<String>::cast(key_));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-07 09:57:29 +00:00
|
|
|
Handle<Name> GetKey() const { return key_; }
|
|
|
|
Handle<Object> GetValue() const { return value_; }
|
|
|
|
PropertyDetails GetDetails() const { return details_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
Sharing of descriptor arrays.
This CL adds multiple things:
Transition arrays do not directly point at their descriptor array anymore, but rather do so via an indirect pointer (a JSGlobalPropertyCell).
An ownership bit is added to maps indicating whether it owns its own descriptor array or not.
Maps owning a descriptor array can pass on ownership if a transition from that map is generated; but only if the descriptor array stays exactly the same; or if a descriptor is added.
Maps that don't have ownership get ownership back if their direct child to which ownership was passed is cleared in ClearNonLiveTransitions.
To detect which descriptors in an array are valid, each map knows its own NumberOfOwnDescriptors. Since the descriptors are sorted in order of addition, if we search and find a descriptor with index bigger than this number, it is not valid for the given map.
We currently still build up an enumeration cache (although this may disappear). The enumeration cache is always built for the entire descriptor array, even if not all descriptors are owned by the map. Once a descriptor array has an enumeration cache for a given map; this invariant will always be true, even if the descriptor array was extended. The extended array will inherit the enumeration cache from the smaller descriptor array. If a map with more descriptors needs an enumeration cache, it's EnumLength will still be set to invalid, so it will have to recompute the enumeration cache. This new cache will also be valid for smaller maps since they have their own enumlength; and use this to loop over the cache. If the EnumLength is still invalid, but there is already a cache present that is big enough; we just initialize the EnumLength field for the map.
When we apply ClearNonLiveTransitions and descriptor ownership is passed back to a parent map, the descriptor array is trimmed in-place and resorted. At the same time, the enumeration cache is trimmed in-place.
Only transition arrays contain descriptor arrays. If we transition to a map and pass ownership of the descriptor array along, the child map will not store the descriptor array it owns. Rather its parent will keep the pointer. So for every leaf-map, we find the descriptor array by following the back pointer, reading out the transition array, and fetching the descriptor array from the JSGlobalPropertyCell. If a map has a transition array, we fetch it from there. If a map has undefined as its back-pointer and has no transition array; it is considered to have an empty descriptor array.
When we modify properties, we cannot share the descriptor array. To accommodate this, the child map will get its own transition array; even if there are not necessarily any transitions leaving from the child map. This is necessary since it's the only way to store its own descriptor array.
Review URL: https://chromiumcodereview.appspot.com/10909007
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12492 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-09-12 16:43:57 +00:00
|
|
|
void SetSortedKeyIndex(int index) { details_ = details_.set_pointer(index); }
|
2012-08-27 13:47:34 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
2014-04-09 14:26:32 +00:00
|
|
|
Handle<Name> key_;
|
|
|
|
Handle<Object> value_;
|
2008-07-03 15:10:15 +00:00
|
|
|
PropertyDetails details_;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Descriptor() : details_(Smi::FromInt(0)) {}
|
|
|
|
|
2014-04-09 14:26:32 +00:00
|
|
|
void Init(Handle<Name> key, Handle<Object> value, PropertyDetails details) {
|
2008-07-03 15:10:15 +00:00
|
|
|
key_ = key;
|
|
|
|
value_ = value;
|
|
|
|
details_ = details;
|
|
|
|
}
|
|
|
|
|
2014-04-09 14:26:32 +00:00
|
|
|
Descriptor(Handle<Name> key, Handle<Object> value, PropertyDetails details)
|
2008-07-03 15:10:15 +00:00
|
|
|
: key_(key),
|
|
|
|
value_(value),
|
|
|
|
details_(details) { }
|
|
|
|
|
2014-04-09 14:26:32 +00:00
|
|
|
Descriptor(Handle<Name> key,
|
|
|
|
Handle<Object> value,
|
2008-07-03 15:10:15 +00:00
|
|
|
PropertyAttributes attributes,
|
|
|
|
PropertyType type,
|
2013-05-31 19:11:09 +00:00
|
|
|
Representation representation,
|
|
|
|
int field_index = 0)
|
2008-07-03 15:10:15 +00:00
|
|
|
: key_(key),
|
|
|
|
value_(value),
|
2013-05-31 19:11:09 +00:00
|
|
|
details_(attributes, type, representation, field_index) { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
friend class DescriptorArray;
|
2014-04-28 11:09:07 +00:00
|
|
|
friend class Map;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-30 10:29:32 +00:00
|
|
|
std::ostream& operator<<(std::ostream& os, const Descriptor& d);
|
2014-07-07 09:57:29 +00:00
|
|
|
|
|
|
|
|
2015-04-20 13:08:11 +00:00
|
|
|
class DataDescriptor final : public Descriptor {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2015-01-19 17:49:13 +00:00
|
|
|
DataDescriptor(Handle<Name> key, int field_index,
|
|
|
|
PropertyAttributes attributes, Representation representation)
|
2016-01-26 15:03:40 +00:00
|
|
|
: Descriptor(key, FieldType::Any(key->GetIsolate()), attributes, DATA,
|
2015-01-19 17:49:13 +00:00
|
|
|
representation, field_index) {}
|
2015-03-23 11:20:38 +00:00
|
|
|
// The field type is either a simple type or a map wrapped in a weak cell.
|
|
|
|
DataDescriptor(Handle<Name> key, int field_index,
|
|
|
|
Handle<Object> wrapped_field_type,
|
2015-01-19 17:49:13 +00:00
|
|
|
PropertyAttributes attributes, Representation representation)
|
2015-03-23 11:20:38 +00:00
|
|
|
: Descriptor(key, wrapped_field_type, attributes, DATA, representation,
|
|
|
|
field_index) {
|
|
|
|
DCHECK(wrapped_field_type->IsSmi() || wrapped_field_type->IsWeakCell());
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-04-20 13:08:11 +00:00
|
|
|
class DataConstantDescriptor final : public Descriptor {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2015-01-19 17:49:13 +00:00
|
|
|
DataConstantDescriptor(Handle<Name> key, Handle<Object> value,
|
|
|
|
PropertyAttributes attributes)
|
|
|
|
: Descriptor(key, value, attributes, DATA_CONSTANT,
|
2013-07-24 12:34:50 +00:00
|
|
|
value->OptimalRepresentation()) {}
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-04-20 13:08:11 +00:00
|
|
|
class AccessorConstantDescriptor final : public Descriptor {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2015-01-19 17:49:13 +00:00
|
|
|
AccessorConstantDescriptor(Handle<Name> key, Handle<Object> foreign,
|
|
|
|
PropertyAttributes attributes)
|
|
|
|
: Descriptor(key, foreign, attributes, ACCESSOR_CONSTANT,
|
2013-05-07 13:09:23 +00:00
|
|
|
Representation::Tagged()) {}
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-09-30 13:46:56 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
#endif // V8_PROPERTY_H_
|