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.
|
2011-11-08 10:43:25 +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_DETAILS_H_
|
|
|
|
#define V8_PROPERTY_DETAILS_H_
|
|
|
|
|
|
|
|
#include "../include/v8.h"
|
|
|
|
#include "allocation.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
// Ecma-262 3rd 8.6.1
|
|
|
|
enum PropertyAttributes {
|
|
|
|
NONE = v8::None,
|
|
|
|
READ_ONLY = v8::ReadOnly,
|
|
|
|
DONT_ENUM = v8::DontEnum,
|
|
|
|
DONT_DELETE = v8::DontDelete,
|
Get rid of static module allocation, do it in code.
Modules now have their own local scope, represented by their own context.
Module instance objects have an accessor for every export that forwards
access to the respective slot from the module's context. (Exports that are
modules themselves, however, are simple data properties.)
All modules have a _hosting_ scope/context, which (currently) is the
(innermost) enclosing global scope. To deal with recursion, nested modules
are hosted by the same scope as global ones.
For every (global or nested) module literal, the hosting context has an
internal slot that points directly to the respective module context. This
enables quick access to (statically resolved) module members by 2-dimensional
access through the hosting context. For example,
module A {
let x;
module B { let y; }
}
module C { let z; }
allocates contexts as follows:
[header| .A | .B | .C | A | C ] (global)
| | |
| | +-- [header| z ] (module)
| |
| +------- [header| y ] (module)
|
+------------ [header| x | B ] (module)
Here, .A, .B, .C are the internal slots pointing to the hosted module
contexts, whereas A, B, C hold the actual instance objects (note that every
module context also points to the respective instance object through its
extension slot in the header).
To deal with arbitrary recursion and aliases between modules,
they are created and initialized in several stages. Each stage applies to
all modules in the hosting global scope, including nested ones.
1. Allocate: for each module _literal_, allocate the module contexts and
respective instance object and wire them up. This happens in the
PushModuleContext runtime function, as generated by AllocateModules
(invoked by VisitDeclarations in the hosting scope).
2. Bind: for each module _declaration_ (i.e. literals as well as aliases),
assign the respective instance object to respective local variables. This
happens in VisitModuleDeclaration, and uses the instance objects created
in the previous stage.
For each module _literal_, this phase also constructs a module descriptor
for the next stage. This happens in VisitModuleLiteral.
3. Populate: invoke the DeclareModules runtime function to populate each
_instance_ object with accessors for it exports. This is generated by
DeclareModules (invoked by VisitDeclarations in the hosting scope again),
and uses the descriptors generated in the previous stage.
4. Initialize: execute the module bodies (and other code) in sequence. This
happens by the separate statements generated for module bodies. To reenter
the module scopes properly, the parser inserted ModuleStatements.
R=mstarzinger@chromium.org,svenpanne@chromium.org
BUG=
Review URL: https://codereview.chromium.org/11093074
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13033 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-11-22 10:25:22 +00:00
|
|
|
|
2013-05-23 07:05:58 +00:00
|
|
|
SEALED = DONT_DELETE,
|
Get rid of static module allocation, do it in code.
Modules now have their own local scope, represented by their own context.
Module instance objects have an accessor for every export that forwards
access to the respective slot from the module's context. (Exports that are
modules themselves, however, are simple data properties.)
All modules have a _hosting_ scope/context, which (currently) is the
(innermost) enclosing global scope. To deal with recursion, nested modules
are hosted by the same scope as global ones.
For every (global or nested) module literal, the hosting context has an
internal slot that points directly to the respective module context. This
enables quick access to (statically resolved) module members by 2-dimensional
access through the hosting context. For example,
module A {
let x;
module B { let y; }
}
module C { let z; }
allocates contexts as follows:
[header| .A | .B | .C | A | C ] (global)
| | |
| | +-- [header| z ] (module)
| |
| +------- [header| y ] (module)
|
+------------ [header| x | B ] (module)
Here, .A, .B, .C are the internal slots pointing to the hosted module
contexts, whereas A, B, C hold the actual instance objects (note that every
module context also points to the respective instance object through its
extension slot in the header).
To deal with arbitrary recursion and aliases between modules,
they are created and initialized in several stages. Each stage applies to
all modules in the hosting global scope, including nested ones.
1. Allocate: for each module _literal_, allocate the module contexts and
respective instance object and wire them up. This happens in the
PushModuleContext runtime function, as generated by AllocateModules
(invoked by VisitDeclarations in the hosting scope).
2. Bind: for each module _declaration_ (i.e. literals as well as aliases),
assign the respective instance object to respective local variables. This
happens in VisitModuleDeclaration, and uses the instance objects created
in the previous stage.
For each module _literal_, this phase also constructs a module descriptor
for the next stage. This happens in VisitModuleLiteral.
3. Populate: invoke the DeclareModules runtime function to populate each
_instance_ object with accessors for it exports. This is generated by
DeclareModules (invoked by VisitDeclarations in the hosting scope again),
and uses the descriptors generated in the previous stage.
4. Initialize: execute the module bodies (and other code) in sequence. This
happens by the separate statements generated for module bodies. To reenter
the module scopes properly, the parser inserted ModuleStatements.
R=mstarzinger@chromium.org,svenpanne@chromium.org
BUG=
Review URL: https://codereview.chromium.org/11093074
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13033 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-11-22 10:25:22 +00:00
|
|
|
FROZEN = SEALED | READ_ONLY,
|
|
|
|
|
2013-03-06 13:55:21 +00:00
|
|
|
SYMBOLIC = 8, // Used to filter symbol names
|
|
|
|
DONT_SHOW = DONT_ENUM | SYMBOLIC,
|
2011-11-08 10:43:25 +00:00
|
|
|
ABSENT = 16 // Used in runtime to indicate a property is absent.
|
|
|
|
// ABSENT can never be stored in or returned from a descriptor's attributes
|
|
|
|
// bitfield. It is only used as a return value meaning the attributes of
|
|
|
|
// a non-existent property.
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
class Smi;
|
2013-07-05 09:26:22 +00:00
|
|
|
class Type;
|
|
|
|
class TypeInfo;
|
2011-11-08 10:43:25 +00:00
|
|
|
|
|
|
|
// Type of properties.
|
|
|
|
// Order of properties is significant.
|
|
|
|
// Must fit in the BitField PropertyDetails::TypeField.
|
|
|
|
// A copy of this is in mirror-debugger.js.
|
|
|
|
enum PropertyType {
|
2012-07-05 13:54:20 +00:00
|
|
|
// Only in slow mode.
|
|
|
|
NORMAL = 0,
|
|
|
|
// Only in fast mode.
|
|
|
|
FIELD = 1,
|
|
|
|
CONSTANT_FUNCTION = 2,
|
2011-11-08 10:43:25 +00:00
|
|
|
CALLBACKS = 3,
|
2012-07-05 13:54:20 +00:00
|
|
|
// Only in lookup results, not in descriptors.
|
|
|
|
HANDLER = 4,
|
|
|
|
INTERCEPTOR = 5,
|
|
|
|
TRANSITION = 6,
|
2012-06-25 13:10:54 +00:00
|
|
|
// Only used as a marker in LookupResult.
|
2012-07-05 13:54:20 +00:00
|
|
|
NONEXISTENT = 7
|
2011-11-08 10:43:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-04-26 15:30:41 +00:00
|
|
|
class Representation {
|
|
|
|
public:
|
|
|
|
enum Kind {
|
|
|
|
kNone,
|
|
|
|
kSmi,
|
|
|
|
kInteger32,
|
|
|
|
kDouble,
|
2013-05-10 17:17:50 +00:00
|
|
|
kHeapObject,
|
2013-04-26 15:30:41 +00:00
|
|
|
kTagged,
|
|
|
|
kExternal,
|
|
|
|
kNumRepresentations
|
|
|
|
};
|
|
|
|
|
|
|
|
Representation() : kind_(kNone) { }
|
|
|
|
|
|
|
|
static Representation None() { return Representation(kNone); }
|
|
|
|
static Representation Tagged() { return Representation(kTagged); }
|
|
|
|
static Representation Smi() { return Representation(kSmi); }
|
|
|
|
static Representation Integer32() { return Representation(kInteger32); }
|
|
|
|
static Representation Double() { return Representation(kDouble); }
|
2013-05-10 17:17:50 +00:00
|
|
|
static Representation HeapObject() { return Representation(kHeapObject); }
|
2013-04-26 15:30:41 +00:00
|
|
|
static Representation External() { return Representation(kExternal); }
|
|
|
|
|
|
|
|
static Representation FromKind(Kind kind) { return Representation(kind); }
|
|
|
|
|
2013-07-05 09:26:22 +00:00
|
|
|
// TODO(rossberg): this should die eventually.
|
|
|
|
static Representation FromType(TypeInfo info);
|
|
|
|
static Representation FromType(Handle<Type> type);
|
|
|
|
|
2013-05-02 15:41:02 +00:00
|
|
|
bool Equals(const Representation& other) const {
|
2013-04-26 15:30:41 +00:00
|
|
|
return kind_ == other.kind_;
|
|
|
|
}
|
|
|
|
|
2013-05-07 10:32:23 +00:00
|
|
|
bool IsCompatibleForLoad(const Representation& other) const {
|
|
|
|
return (IsDouble() && other.IsDouble()) ||
|
|
|
|
(!IsDouble() && !other.IsDouble());
|
|
|
|
}
|
|
|
|
|
2013-06-14 14:16:03 +00:00
|
|
|
bool IsCompatibleForStore(const Representation& other) const {
|
|
|
|
return Equals(other);
|
|
|
|
}
|
|
|
|
|
2013-05-02 15:41:02 +00:00
|
|
|
bool is_more_general_than(const Representation& other) const {
|
2013-04-26 15:30:41 +00:00
|
|
|
ASSERT(kind_ != kExternal);
|
|
|
|
ASSERT(other.kind_ != kExternal);
|
2013-06-06 14:21:35 +00:00
|
|
|
if (IsHeapObject()) return other.IsDouble() || other.IsNone();
|
2013-04-26 15:30:41 +00:00
|
|
|
return kind_ > other.kind_;
|
|
|
|
}
|
|
|
|
|
2013-05-02 15:41:02 +00:00
|
|
|
bool fits_into(const Representation& other) const {
|
|
|
|
return other.is_more_general_than(*this) || other.Equals(*this);
|
|
|
|
}
|
|
|
|
|
2013-04-26 15:30:41 +00:00
|
|
|
Representation generalize(Representation other) {
|
2013-05-10 17:17:50 +00:00
|
|
|
if (other.fits_into(*this)) return *this;
|
|
|
|
if (other.is_more_general_than(*this)) return other;
|
|
|
|
return Representation::Tagged();
|
2013-04-26 15:30:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Kind kind() const { return static_cast<Kind>(kind_); }
|
|
|
|
bool IsNone() const { return kind_ == kNone; }
|
|
|
|
bool IsTagged() const { return kind_ == kTagged; }
|
|
|
|
bool IsSmi() const { return kind_ == kSmi; }
|
2013-05-23 08:32:07 +00:00
|
|
|
bool IsSmiOrTagged() const { return IsSmi() || IsTagged(); }
|
2013-04-26 15:30:41 +00:00
|
|
|
bool IsInteger32() const { return kind_ == kInteger32; }
|
2013-05-27 08:43:58 +00:00
|
|
|
bool IsSmiOrInteger32() const { return IsSmi() || IsInteger32(); }
|
2013-04-26 15:30:41 +00:00
|
|
|
bool IsDouble() const { return kind_ == kDouble; }
|
2013-05-10 17:17:50 +00:00
|
|
|
bool IsHeapObject() const { return kind_ == kHeapObject; }
|
2013-04-26 15:30:41 +00:00
|
|
|
bool IsExternal() const { return kind_ == kExternal; }
|
|
|
|
bool IsSpecialization() const {
|
|
|
|
return kind_ == kInteger32 || kind_ == kDouble;
|
|
|
|
}
|
|
|
|
const char* Mnemonic() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
explicit Representation(Kind k) : kind_(k) { }
|
|
|
|
|
|
|
|
// Make sure kind fits in int8.
|
|
|
|
STATIC_ASSERT(kNumRepresentations <= (1 << kBitsPerByte));
|
|
|
|
|
|
|
|
int8_t kind_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-11-08 10:43:25 +00:00
|
|
|
// PropertyDetails captures type and attributes for a property.
|
|
|
|
// They are used both in property dictionaries and instance descriptors.
|
|
|
|
class PropertyDetails BASE_EMBEDDED {
|
|
|
|
public:
|
|
|
|
PropertyDetails(PropertyAttributes attributes,
|
|
|
|
PropertyType type,
|
2013-05-07 13:09:23 +00:00
|
|
|
int index) {
|
2011-11-08 10:43:25 +00:00
|
|
|
value_ = TypeField::encode(type)
|
|
|
|
| AttributesField::encode(attributes)
|
2012-08-27 13:47:34 +00:00
|
|
|
| DictionaryStorageField::encode(index);
|
2011-11-08 10:43:25 +00:00
|
|
|
|
|
|
|
ASSERT(type == this->type());
|
|
|
|
ASSERT(attributes == this->attributes());
|
2013-05-07 13:09:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PropertyDetails(PropertyAttributes attributes,
|
|
|
|
PropertyType type,
|
2013-05-31 19:11:09 +00:00
|
|
|
Representation representation,
|
|
|
|
int field_index = 0) {
|
2013-05-07 13:09:23 +00:00
|
|
|
value_ = TypeField::encode(type)
|
|
|
|
| AttributesField::encode(attributes)
|
2013-05-31 19:11:09 +00:00
|
|
|
| RepresentationField::encode(EncodeRepresentation(representation))
|
|
|
|
| FieldIndexField::encode(field_index);
|
2011-11-08 10:43:25 +00:00
|
|
|
}
|
|
|
|
|
2012-08-27 13:47:34 +00:00
|
|
|
int pointer() { return DescriptorPointer::decode(value_); }
|
|
|
|
|
|
|
|
PropertyDetails set_pointer(int i) { return PropertyDetails(value_, i); }
|
|
|
|
|
2013-04-26 15:30:41 +00:00
|
|
|
PropertyDetails CopyWithRepresentation(Representation representation) {
|
|
|
|
return PropertyDetails(value_, representation);
|
|
|
|
}
|
2013-05-23 07:05:58 +00:00
|
|
|
PropertyDetails CopyAddAttributes(PropertyAttributes new_attributes) {
|
|
|
|
new_attributes =
|
|
|
|
static_cast<PropertyAttributes>(attributes() | new_attributes);
|
|
|
|
return PropertyDetails(value_, new_attributes);
|
|
|
|
}
|
2013-04-26 15:30:41 +00:00
|
|
|
|
2011-11-08 10:43:25 +00:00
|
|
|
// Conversion for storing details as Object*.
|
|
|
|
explicit inline PropertyDetails(Smi* smi);
|
|
|
|
inline Smi* AsSmi();
|
|
|
|
|
2013-04-26 15:30:41 +00:00
|
|
|
static uint8_t EncodeRepresentation(Representation representation) {
|
2013-05-07 13:09:23 +00:00
|
|
|
return representation.kind();
|
2013-04-26 15:30:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static Representation DecodeRepresentation(uint32_t bits) {
|
|
|
|
return Representation::FromKind(static_cast<Representation::Kind>(bits));
|
|
|
|
}
|
|
|
|
|
2011-11-08 10:43:25 +00:00
|
|
|
PropertyType type() { return TypeField::decode(value_); }
|
|
|
|
|
2012-10-11 10:52:58 +00:00
|
|
|
PropertyAttributes attributes() const {
|
|
|
|
return AttributesField::decode(value_);
|
|
|
|
}
|
2011-11-08 10:43:25 +00:00
|
|
|
|
2012-08-27 13:47:34 +00:00
|
|
|
int dictionary_index() {
|
|
|
|
return DictionaryStorageField::decode(value_);
|
|
|
|
}
|
|
|
|
|
2013-04-26 15:30:41 +00:00
|
|
|
Representation representation() {
|
2013-06-06 14:21:35 +00:00
|
|
|
ASSERT(type() != NORMAL);
|
2013-04-26 15:30:41 +00:00
|
|
|
return DecodeRepresentation(RepresentationField::decode(value_));
|
|
|
|
}
|
|
|
|
|
2013-05-31 19:11:09 +00:00
|
|
|
int field_index() {
|
|
|
|
return FieldIndexField::decode(value_);
|
|
|
|
}
|
|
|
|
|
2011-11-08 10:43:25 +00:00
|
|
|
inline PropertyDetails AsDeleted();
|
|
|
|
|
|
|
|
static bool IsValidIndex(int index) {
|
2012-08-27 13:47:34 +00:00
|
|
|
return DictionaryStorageField::is_valid(index);
|
2011-11-08 10:43:25 +00:00
|
|
|
}
|
|
|
|
|
2012-10-11 10:52:58 +00:00
|
|
|
bool IsReadOnly() const { return (attributes() & READ_ONLY) != 0; }
|
|
|
|
bool IsDontDelete() const { return (attributes() & DONT_DELETE) != 0; }
|
|
|
|
bool IsDontEnum() const { return (attributes() & DONT_ENUM) != 0; }
|
|
|
|
bool IsDeleted() const { return DeletedField::decode(value_) != 0;}
|
2011-11-08 10:43:25 +00:00
|
|
|
|
|
|
|
// Bit fields in value_ (type, shift, size). Must be public so the
|
|
|
|
// constants can be embedded in generated code.
|
2012-08-27 13:47:34 +00:00
|
|
|
class TypeField: public BitField<PropertyType, 0, 3> {};
|
|
|
|
class AttributesField: public BitField<PropertyAttributes, 3, 3> {};
|
2013-05-31 19:11:09 +00:00
|
|
|
|
|
|
|
// Bit fields for normalized objects.
|
2012-08-27 13:47:34 +00:00
|
|
|
class DeletedField: public BitField<uint32_t, 6, 1> {};
|
|
|
|
class DictionaryStorageField: public BitField<uint32_t, 7, 24> {};
|
2013-05-31 19:11:09 +00:00
|
|
|
|
|
|
|
// Bit fields for fast objects.
|
|
|
|
class DescriptorPointer: public BitField<uint32_t, 6, 11> {};
|
|
|
|
class RepresentationField: public BitField<uint32_t, 17, 3> {};
|
|
|
|
class FieldIndexField: public BitField<uint32_t, 20, 11> {};
|
2011-11-08 10:43:25 +00:00
|
|
|
|
|
|
|
static const int kInitialIndex = 1;
|
|
|
|
|
|
|
|
private:
|
2012-08-27 13:47:34 +00:00
|
|
|
PropertyDetails(int value, int pointer) {
|
2013-04-26 15:30:41 +00:00
|
|
|
value_ = DescriptorPointer::update(value, pointer);
|
|
|
|
}
|
|
|
|
PropertyDetails(int value, Representation representation) {
|
|
|
|
value_ = RepresentationField::update(
|
|
|
|
value, EncodeRepresentation(representation));
|
2012-08-27 13:47:34 +00:00
|
|
|
}
|
2013-05-23 07:05:58 +00:00
|
|
|
PropertyDetails(int value, PropertyAttributes attributes) {
|
|
|
|
value_ = AttributesField::update(value, attributes);
|
|
|
|
}
|
2012-08-27 13:47:34 +00:00
|
|
|
|
2011-11-08 10:43:25 +00:00
|
|
|
uint32_t value_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif // V8_PROPERTY_DETAILS_H_
|