Removed IsTransitionType predicate.
With the upcoming changes to CALLBACKS properties, a predicate on the transition
type alone doesn't make sense anymore: For CALLBACKS one has to look into the
property's value to decide, and there is even the possibility of having a an
accessor function *and* a transition in the same property.
I am not completely happy with some parts of this CL, because they contain
redundant code, but given the various representations we currently have for
property type/value pairs, I can see no easy way around that. Perhaps one can
improve this a bit in a different CL, the current diversity really, really hurts
productivity...
As a bonus, this CL includes a few minor things:
* CaseClause::RecordTypeFeedback has been cleaned up and it handles the
NULL_DESCRIPTOR case correctly now. Under some (very unlikely) circumstances,
we previously missed some opportunities for monomorphic calls. In general, it
is rather unfortunate that NULL_DESCRIPTOR "shines through", it is just a
hack for the inability to remove a descriptor entry during GC, something
callers shouldn't have to be aware of.
* DescriptorArray::CopyInsert has been cleaned up a bit, preparing it for later
CALLBACKS-related changes.
* LookupResult::Print is now more informative for CONSTANT_TRANSITION.
Review URL: https://chromiumcodereview.appspot.com/9320066
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10600 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-02-03 13:37:13 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2008-07-03 15:10:15 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#ifndef V8_PROPERTY_H_
|
|
|
|
#define V8_PROPERTY_H_
|
|
|
|
|
2011-05-06 06:50:20 +00:00
|
|
|
#include "allocation.h"
|
2012-07-05 13:54:20 +00:00
|
|
|
#include "transitions.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:
|
2013-03-04 15:00:57 +00:00
|
|
|
MUST_USE_RESULT MaybeObject* KeyToUniqueName() {
|
|
|
|
if (!key_->IsUniqueName()) {
|
|
|
|
MaybeObject* maybe_result = HEAP->InternalizeString(String::cast(key_));
|
2012-03-06 09:19:25 +00:00
|
|
|
if (!maybe_result->To(&key_)) return maybe_result;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
return key_;
|
|
|
|
}
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
Name* GetKey() { return key_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
Object* GetValue() { return value_; }
|
|
|
|
PropertyDetails GetDetails() { return details_; }
|
|
|
|
|
2010-12-20 10:38:19 +00:00
|
|
|
#ifdef OBJECT_PRINT
|
|
|
|
void Print(FILE* out);
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
|
|
|
|
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:
|
2013-03-04 15:00:57 +00:00
|
|
|
Name* key_;
|
2008-07-03 15:10:15 +00:00
|
|
|
Object* value_;
|
|
|
|
PropertyDetails details_;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Descriptor() : details_(Smi::FromInt(0)) {}
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
void Init(Name* key, Object* value, PropertyDetails details) {
|
2008-07-03 15:10:15 +00:00
|
|
|
key_ = key;
|
|
|
|
value_ = value;
|
|
|
|
details_ = details;
|
|
|
|
}
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
Descriptor(Name* key, Object* value, PropertyDetails details)
|
2008-07-03 15:10:15 +00:00
|
|
|
: key_(key),
|
|
|
|
value_(value),
|
|
|
|
details_(details) { }
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
Descriptor(Name* key,
|
2008-07-03 15:10:15 +00:00
|
|
|
Object* value,
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class FieldDescriptor: public Descriptor {
|
|
|
|
public:
|
2013-03-04 15:00:57 +00:00
|
|
|
FieldDescriptor(Name* key,
|
2008-07-03 15:10:15 +00:00
|
|
|
int field_index,
|
|
|
|
PropertyAttributes attributes,
|
2013-05-07 13:09:23 +00:00
|
|
|
Representation representation)
|
2013-05-31 19:11:09 +00:00
|
|
|
: Descriptor(key, Smi::FromInt(0), attributes,
|
|
|
|
FIELD, representation, field_index) {}
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ConstantFunctionDescriptor: public Descriptor {
|
|
|
|
public:
|
2013-03-04 15:00:57 +00:00
|
|
|
ConstantFunctionDescriptor(Name* key,
|
2008-07-03 15:10:15 +00:00
|
|
|
JSFunction* function,
|
2013-05-07 13:09:23 +00:00
|
|
|
PropertyAttributes attributes)
|
|
|
|
: Descriptor(key, function, attributes, CONSTANT_FUNCTION,
|
|
|
|
Representation::Tagged()) {}
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class CallbacksDescriptor: public Descriptor {
|
|
|
|
public:
|
2013-03-04 15:00:57 +00:00
|
|
|
CallbacksDescriptor(Name* key,
|
2011-05-19 11:47:34 +00:00
|
|
|
Object* foreign,
|
2013-05-07 13:09:23 +00:00
|
|
|
PropertyAttributes attributes)
|
2013-04-26 15:30:41 +00:00
|
|
|
: Descriptor(key, foreign, attributes, CALLBACKS,
|
2013-05-07 13:09:23 +00:00
|
|
|
Representation::Tagged()) {}
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-11-13 11:07:04 +00:00
|
|
|
// Holds a property index value distinguishing if it is a field index or an
|
|
|
|
// index inside the object header.
|
|
|
|
class PropertyIndex {
|
|
|
|
public:
|
|
|
|
static PropertyIndex NewFieldIndex(int index) {
|
|
|
|
return PropertyIndex(index, false);
|
|
|
|
}
|
|
|
|
static PropertyIndex NewHeaderIndex(int index) {
|
|
|
|
return PropertyIndex(index, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_field_index() { return (index_ & kHeaderIndexBit) == 0; }
|
|
|
|
bool is_header_index() { return (index_ & kHeaderIndexBit) != 0; }
|
|
|
|
|
|
|
|
int field_index() {
|
|
|
|
ASSERT(is_field_index());
|
|
|
|
return value();
|
|
|
|
}
|
|
|
|
int header_index() {
|
|
|
|
ASSERT(is_header_index());
|
|
|
|
return value();
|
|
|
|
}
|
|
|
|
|
2013-03-04 14:03:27 +00:00
|
|
|
bool is_inobject(Handle<JSObject> holder) {
|
|
|
|
if (is_header_index()) return true;
|
|
|
|
return field_index() < holder->map()->inobject_properties();
|
|
|
|
}
|
|
|
|
|
|
|
|
int translate(Handle<JSObject> holder) {
|
|
|
|
if (is_header_index()) return header_index();
|
|
|
|
int index = field_index() - holder->map()->inobject_properties();
|
|
|
|
if (index >= 0) return index;
|
|
|
|
return index + holder->map()->instance_size() / kPointerSize;
|
|
|
|
}
|
|
|
|
|
2012-11-13 11:07:04 +00:00
|
|
|
private:
|
|
|
|
static const int kHeaderIndexBit = 1 << 31;
|
|
|
|
static const int kIndexMask = ~kHeaderIndexBit;
|
|
|
|
|
|
|
|
int value() { return index_ & kIndexMask; }
|
|
|
|
|
|
|
|
PropertyIndex(int index, bool is_header_based)
|
|
|
|
: index_(index | (is_header_based ? kHeaderIndexBit : 0)) {
|
|
|
|
ASSERT(index <= kIndexMask);
|
|
|
|
}
|
|
|
|
|
|
|
|
int index_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
class LookupResult BASE_EMBEDDED {
|
|
|
|
public:
|
2011-10-18 11:18:55 +00:00
|
|
|
explicit LookupResult(Isolate* isolate)
|
|
|
|
: isolate_(isolate),
|
|
|
|
next_(isolate->top_lookup_result()),
|
|
|
|
lookup_type_(NOT_FOUND),
|
|
|
|
holder_(NULL),
|
2008-07-03 15:10:15 +00:00
|
|
|
cacheable_(true),
|
2013-04-26 15:30:41 +00:00
|
|
|
details_(NONE, NONEXISTENT, Representation::None()) {
|
2011-10-18 11:18:55 +00:00
|
|
|
isolate->SetTopLookupResult(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
~LookupResult() {
|
2013-02-27 13:22:29 +00:00
|
|
|
ASSERT(isolate()->top_lookup_result() == this);
|
|
|
|
isolate()->SetTopLookupResult(next_);
|
2011-10-18 11:18:55 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-02-27 13:22:29 +00:00
|
|
|
Isolate* isolate() const { return isolate_; }
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void DescriptorResult(JSObject* holder, PropertyDetails details, int number) {
|
|
|
|
lookup_type_ = DESCRIPTOR_TYPE;
|
|
|
|
holder_ = holder;
|
|
|
|
details_ = details;
|
|
|
|
number_ = number;
|
|
|
|
}
|
|
|
|
|
2013-04-26 15:30:41 +00:00
|
|
|
bool CanHoldValue(Handle<Object> value) {
|
2013-06-06 14:21:35 +00:00
|
|
|
if (IsNormal()) return true;
|
|
|
|
ASSERT(!IsTransition());
|
2013-04-26 15:30:41 +00:00
|
|
|
return value->FitsRepresentation(details_.representation());
|
|
|
|
}
|
|
|
|
|
2012-07-05 13:54:20 +00:00
|
|
|
void TransitionResult(JSObject* holder, int number) {
|
|
|
|
lookup_type_ = TRANSITION_TYPE;
|
2013-04-26 15:30:41 +00:00
|
|
|
details_ = PropertyDetails(NONE, TRANSITION, Representation::None());
|
2012-07-05 13:54:20 +00:00
|
|
|
holder_ = holder;
|
|
|
|
number_ = number;
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void DictionaryResult(JSObject* holder, int entry) {
|
|
|
|
lookup_type_ = DICTIONARY_TYPE;
|
|
|
|
holder_ = holder;
|
|
|
|
details_ = holder->property_dictionary()->DetailsAt(entry);
|
|
|
|
number_ = entry;
|
|
|
|
}
|
|
|
|
|
2011-09-16 13:38:30 +00:00
|
|
|
void HandlerResult(JSProxy* proxy) {
|
2011-05-16 16:33:58 +00:00
|
|
|
lookup_type_ = HANDLER_TYPE;
|
2011-09-16 13:38:30 +00:00
|
|
|
holder_ = proxy;
|
2013-04-26 15:30:41 +00:00
|
|
|
details_ = PropertyDetails(NONE, HANDLER, Representation::None());
|
2011-07-13 11:57:15 +00:00
|
|
|
cacheable_ = false;
|
2011-05-16 16:33:58 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void InterceptorResult(JSObject* holder) {
|
|
|
|
lookup_type_ = INTERCEPTOR_TYPE;
|
|
|
|
holder_ = holder;
|
2013-04-26 15:30:41 +00:00
|
|
|
details_ = PropertyDetails(NONE, INTERCEPTOR, Representation::None());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NotFound() {
|
|
|
|
lookup_type_ = NOT_FOUND;
|
2013-04-26 15:30:41 +00:00
|
|
|
details_ = PropertyDetails(NONE, NONEXISTENT, Representation::None());
|
2011-10-18 11:18:55 +00:00
|
|
|
holder_ = NULL;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
JSObject* holder() {
|
2010-02-18 15:10:35 +00:00
|
|
|
ASSERT(IsFound());
|
2011-09-16 13:38:30 +00:00
|
|
|
return JSObject::cast(holder_);
|
|
|
|
}
|
|
|
|
|
|
|
|
JSProxy* proxy() {
|
|
|
|
ASSERT(IsFound());
|
|
|
|
return JSProxy::cast(holder_);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PropertyType type() {
|
2010-02-18 15:10:35 +00:00
|
|
|
ASSERT(IsFound());
|
2008-07-03 15:10:15 +00:00
|
|
|
return details_.type();
|
|
|
|
}
|
|
|
|
|
2013-04-26 15:30:41 +00:00
|
|
|
Representation representation() {
|
|
|
|
ASSERT(IsFound());
|
2013-05-08 15:02:08 +00:00
|
|
|
ASSERT(!IsTransition());
|
|
|
|
ASSERT(details_.type() != NONEXISTENT);
|
2013-04-26 15:30:41 +00:00
|
|
|
return details_.representation();
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
PropertyAttributes GetAttributes() {
|
2012-07-05 13:54:20 +00:00
|
|
|
ASSERT(!IsTransition());
|
2010-02-18 15:10:35 +00:00
|
|
|
ASSERT(IsFound());
|
2012-07-05 13:54:20 +00:00
|
|
|
ASSERT(details_.type() != NONEXISTENT);
|
2008-07-03 15:10:15 +00:00
|
|
|
return details_.attributes();
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyDetails GetPropertyDetails() {
|
2012-07-05 13:54:20 +00:00
|
|
|
ASSERT(!IsTransition());
|
2008-07-03 15:10:15 +00:00
|
|
|
return details_;
|
|
|
|
}
|
|
|
|
|
2012-06-21 15:32:52 +00:00
|
|
|
bool IsFastPropertyType() {
|
|
|
|
ASSERT(IsFound());
|
2012-07-05 13:54:20 +00:00
|
|
|
return IsTransition() || type() != NORMAL;
|
2012-06-21 15:32:52 +00:00
|
|
|
}
|
|
|
|
|
2012-07-05 13:54:20 +00:00
|
|
|
// Property callbacks does not include transitions to callbacks.
|
|
|
|
bool IsPropertyCallbacks() {
|
|
|
|
ASSERT(!(details_.type() == CALLBACKS && !IsFound()));
|
|
|
|
return details_.type() == CALLBACKS;
|
2012-06-21 15:32:52 +00:00
|
|
|
}
|
|
|
|
|
2012-07-05 13:54:20 +00:00
|
|
|
bool IsReadOnly() {
|
|
|
|
ASSERT(IsFound());
|
|
|
|
ASSERT(!IsTransition());
|
|
|
|
ASSERT(details_.type() != NONEXISTENT);
|
|
|
|
return details_.IsReadOnly();
|
2012-06-21 15:32:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IsField() {
|
|
|
|
ASSERT(!(details_.type() == FIELD && !IsFound()));
|
|
|
|
return details_.type() == FIELD;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsNormal() {
|
|
|
|
ASSERT(!(details_.type() == NORMAL && !IsFound()));
|
|
|
|
return details_.type() == NORMAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsConstantFunction() {
|
|
|
|
ASSERT(!(details_.type() == CONSTANT_FUNCTION && !IsFound()));
|
|
|
|
return details_.type() == CONSTANT_FUNCTION;
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
bool IsDontDelete() { return details_.IsDontDelete(); }
|
|
|
|
bool IsDontEnum() { return details_.IsDontEnum(); }
|
2010-02-18 15:10:35 +00:00
|
|
|
bool IsFound() { return lookup_type_ != NOT_FOUND; }
|
2012-07-05 13:54:20 +00:00
|
|
|
bool IsTransition() { return lookup_type_ == TRANSITION_TYPE; }
|
2011-05-16 16:33:58 +00:00
|
|
|
bool IsHandler() { return lookup_type_ == HANDLER_TYPE; }
|
2012-06-21 15:32:52 +00:00
|
|
|
bool IsInterceptor() { return lookup_type_ == INTERCEPTOR_TYPE; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-03-02 14:03:59 +00:00
|
|
|
// Is the result is a property excluding transitions and the null descriptor?
|
2008-07-03 15:10:15 +00:00
|
|
|
bool IsProperty() {
|
2012-07-05 13:54:20 +00:00
|
|
|
return IsFound() && !IsTransition();
|
2010-02-18 15:10:35 +00:00
|
|
|
}
|
|
|
|
|
2012-12-13 09:31:44 +00:00
|
|
|
bool IsDataProperty() {
|
|
|
|
switch (type()) {
|
|
|
|
case FIELD:
|
|
|
|
case NORMAL:
|
|
|
|
case CONSTANT_FUNCTION:
|
|
|
|
return true;
|
|
|
|
case CALLBACKS: {
|
|
|
|
Object* callback = GetCallbackObject();
|
|
|
|
return callback->IsAccessorInfo() || callback->IsForeign();
|
|
|
|
}
|
|
|
|
case HANDLER:
|
|
|
|
case INTERCEPTOR:
|
|
|
|
case TRANSITION:
|
|
|
|
case NONEXISTENT:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
bool IsCacheable() { return cacheable_; }
|
|
|
|
void DisallowCaching() { cacheable_ = false; }
|
|
|
|
|
2009-04-24 08:13:09 +00:00
|
|
|
Object* GetLazyValue() {
|
|
|
|
switch (type()) {
|
|
|
|
case FIELD:
|
2013-05-08 15:02:08 +00:00
|
|
|
return holder()->RawFastPropertyAt(GetFieldIndex().field_index());
|
2009-06-30 10:05:36 +00:00
|
|
|
case NORMAL: {
|
|
|
|
Object* value;
|
|
|
|
value = holder()->property_dictionary()->ValueAt(GetDictionaryEntry());
|
2009-07-01 11:44:37 +00:00
|
|
|
if (holder()->IsGlobalObject()) {
|
2009-06-30 10:05:36 +00:00
|
|
|
value = JSGlobalPropertyCell::cast(value)->value();
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
2009-04-24 08:13:09 +00:00
|
|
|
case CONSTANT_FUNCTION:
|
|
|
|
return GetConstantFunction();
|
2012-12-13 09:31:44 +00:00
|
|
|
case CALLBACKS:
|
|
|
|
case HANDLER:
|
|
|
|
case INTERCEPTOR:
|
|
|
|
case TRANSITION:
|
|
|
|
case NONEXISTENT:
|
2013-02-27 13:22:29 +00:00
|
|
|
return isolate()->heap()->the_hole_value();
|
2009-04-24 08:13:09 +00:00
|
|
|
}
|
2012-12-13 09:31:44 +00:00
|
|
|
UNREACHABLE();
|
|
|
|
return NULL;
|
2009-04-24 08:13:09 +00:00
|
|
|
}
|
|
|
|
|
2013-03-25 12:55:27 +00:00
|
|
|
Map* GetTransitionTarget(Map* map) {
|
2012-07-05 13:54:20 +00:00
|
|
|
ASSERT(IsTransition());
|
2013-03-25 12:55:27 +00:00
|
|
|
TransitionArray* transitions = map->transitions();
|
2012-07-16 14:02:50 +00:00
|
|
|
return transitions->GetTarget(number_);
|
2012-07-05 13:54:20 +00:00
|
|
|
}
|
|
|
|
|
2013-03-25 12:55:27 +00:00
|
|
|
Map* GetTransitionTarget() {
|
|
|
|
return GetTransitionTarget(holder()->map());
|
|
|
|
}
|
|
|
|
|
2012-07-05 13:54:20 +00:00
|
|
|
PropertyDetails GetTransitionDetails(Map* map) {
|
|
|
|
ASSERT(IsTransition());
|
|
|
|
TransitionArray* transitions = map->transitions();
|
|
|
|
return transitions->GetTargetDetails(number_);
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyDetails GetTransitionDetails() {
|
|
|
|
return GetTransitionDetails(holder()->map());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsTransitionToField(Map* map) {
|
|
|
|
return IsTransition() && GetTransitionDetails(map).type() == FIELD;
|
|
|
|
}
|
|
|
|
|
2013-06-13 15:01:25 +00:00
|
|
|
bool IsTransitionToConstantFunction(Map* map) {
|
|
|
|
return IsTransition() &&
|
|
|
|
GetTransitionDetails(map).type() == CONSTANT_FUNCTION;
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Map* GetTransitionMap() {
|
2012-07-05 13:54:20 +00:00
|
|
|
ASSERT(IsTransition());
|
2008-07-03 15:10:15 +00:00
|
|
|
return Map::cast(GetValue());
|
|
|
|
}
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
Map* GetTransitionMapFromMap(Map* map) {
|
2012-07-05 13:54:20 +00:00
|
|
|
ASSERT(IsTransition());
|
2012-07-16 14:02:50 +00:00
|
|
|
return map->transitions()->GetTarget(number_);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
2012-07-12 16:36:10 +00:00
|
|
|
int GetTransitionIndex() {
|
|
|
|
ASSERT(IsTransition());
|
|
|
|
return number_;
|
|
|
|
}
|
|
|
|
|
2012-07-18 09:20:57 +00:00
|
|
|
int GetDescriptorIndex() {
|
|
|
|
ASSERT(lookup_type_ == DESCRIPTOR_TYPE);
|
|
|
|
return number_;
|
|
|
|
}
|
|
|
|
|
2012-11-13 11:07:04 +00:00
|
|
|
PropertyIndex GetFieldIndex() {
|
2008-07-03 15:10:15 +00:00
|
|
|
ASSERT(lookup_type_ == DESCRIPTOR_TYPE);
|
2012-06-21 15:32:52 +00:00
|
|
|
ASSERT(IsField());
|
2013-05-31 19:11:09 +00:00
|
|
|
return PropertyIndex::NewFieldIndex(GetFieldIndexFromMap(holder()->map()));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
int GetLocalFieldIndexFromMap(Map* map) {
|
2012-06-21 15:32:52 +00:00
|
|
|
ASSERT(IsField());
|
2013-05-31 19:11:09 +00:00
|
|
|
return GetFieldIndexFromMap(map) - map->inobject_properties();
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
int GetDictionaryEntry() {
|
|
|
|
ASSERT(lookup_type_ == DICTIONARY_TYPE);
|
|
|
|
return number_;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSFunction* GetConstantFunction() {
|
|
|
|
ASSERT(type() == CONSTANT_FUNCTION);
|
|
|
|
return JSFunction::cast(GetValue());
|
|
|
|
}
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
JSFunction* GetConstantFunctionFromMap(Map* map) {
|
|
|
|
ASSERT(type() == CONSTANT_FUNCTION);
|
2012-07-06 08:11:10 +00:00
|
|
|
return JSFunction::cast(GetValueFromMap(map));
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Object* GetCallbackObject() {
|
2013-02-26 10:46:00 +00:00
|
|
|
ASSERT(type() == CALLBACKS && !IsTransition());
|
2012-07-16 14:02:50 +00:00
|
|
|
return GetValue();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2010-12-20 10:38:19 +00:00
|
|
|
#ifdef OBJECT_PRINT
|
|
|
|
void Print(FILE* out);
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
Object* GetValue() {
|
|
|
|
if (lookup_type_ == DESCRIPTOR_TYPE) {
|
2012-07-06 08:11:10 +00:00
|
|
|
return GetValueFromMap(holder()->map());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
// In the dictionary case, the data is held in the value field.
|
|
|
|
ASSERT(lookup_type_ == DICTIONARY_TYPE);
|
2009-06-30 10:05:36 +00:00
|
|
|
return holder()->GetNormalizedProperty(this);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2012-07-06 08:11:10 +00:00
|
|
|
Object* GetValueFromMap(Map* map) const {
|
|
|
|
ASSERT(lookup_type_ == DESCRIPTOR_TYPE);
|
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
|
|
|
ASSERT(number_ < map->NumberOfOwnDescriptors());
|
2012-07-06 08:11:10 +00:00
|
|
|
return map->instance_descriptors()->GetValue(number_);
|
|
|
|
}
|
|
|
|
|
2013-05-31 19:11:09 +00:00
|
|
|
int GetFieldIndexFromMap(Map* map) const {
|
|
|
|
ASSERT(lookup_type_ == DESCRIPTOR_TYPE);
|
|
|
|
ASSERT(number_ < map->NumberOfOwnDescriptors());
|
|
|
|
return map->instance_descriptors()->GetFieldIndex(number_);
|
|
|
|
}
|
|
|
|
|
2011-10-18 11:18:55 +00:00
|
|
|
void Iterate(ObjectVisitor* visitor);
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
2011-10-18 11:18:55 +00:00
|
|
|
Isolate* isolate_;
|
|
|
|
LookupResult* next_;
|
|
|
|
|
2011-05-16 16:33:58 +00:00
|
|
|
// Where did we find the result;
|
|
|
|
enum {
|
|
|
|
NOT_FOUND,
|
|
|
|
DESCRIPTOR_TYPE,
|
2012-07-05 13:54:20 +00:00
|
|
|
TRANSITION_TYPE,
|
2011-05-16 16:33:58 +00:00
|
|
|
DICTIONARY_TYPE,
|
|
|
|
HANDLER_TYPE,
|
2013-02-26 10:46:00 +00:00
|
|
|
INTERCEPTOR_TYPE
|
2011-05-16 16:33:58 +00:00
|
|
|
} lookup_type_;
|
|
|
|
|
2011-09-16 13:38:30 +00:00
|
|
|
JSReceiver* holder_;
|
2008-07-03 15:10:15 +00:00
|
|
|
int number_;
|
|
|
|
bool cacheable_;
|
|
|
|
PropertyDetails details_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif // V8_PROPERTY_H_
|