Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: src/property-details.h

Issue 14146005: Track representations of fields (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add test for tracking fields Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/property.h ('k') | src/runtime.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 CALLBACKS = 3, 69 CALLBACKS = 3,
70 // Only in lookup results, not in descriptors. 70 // Only in lookup results, not in descriptors.
71 HANDLER = 4, 71 HANDLER = 4,
72 INTERCEPTOR = 5, 72 INTERCEPTOR = 5,
73 TRANSITION = 6, 73 TRANSITION = 6,
74 // Only used as a marker in LookupResult. 74 // Only used as a marker in LookupResult.
75 NONEXISTENT = 7 75 NONEXISTENT = 7
76 }; 76 };
77 77
78 78
79 class Representation {
80 public:
81 enum Kind {
82 kNone,
83 kSmi,
84 kInteger32,
85 kDouble,
86 kTagged,
87 kExternal,
88 kNumRepresentations
89 };
90
91 Representation() : kind_(kNone) { }
92
93 static Representation None() { return Representation(kNone); }
94 static Representation Tagged() { return Representation(kTagged); }
95 static Representation Smi() { return Representation(kSmi); }
96 static Representation Integer32() { return Representation(kInteger32); }
97 static Representation Double() { return Representation(kDouble); }
98 static Representation External() { return Representation(kExternal); }
99
100 static Representation FromKind(Kind kind) { return Representation(kind); }
101
102 bool Equals(const Representation& other) {
103 return kind_ == other.kind_;
104 }
105
106 bool is_more_general_than(const Representation& other) {
107 ASSERT(kind_ != kExternal);
108 ASSERT(other.kind_ != kExternal);
109 return kind_ > other.kind_;
110 }
111
112 Representation generalize(Representation other) {
113 if (is_more_general_than(other)) {
114 return *this;
115 } else {
116 return other;
117 }
118 }
119
120 Kind kind() const { return static_cast<Kind>(kind_); }
121 bool IsNone() const { return kind_ == kNone; }
122 bool IsTagged() const { return kind_ == kTagged; }
123 bool IsSmi() const { return kind_ == kSmi; }
124 bool IsInteger32() const { return kind_ == kInteger32; }
125 bool IsDouble() const { return kind_ == kDouble; }
126 bool IsExternal() const { return kind_ == kExternal; }
127 bool IsSpecialization() const {
128 return kind_ == kInteger32 || kind_ == kDouble;
129 }
130 const char* Mnemonic() const;
131
132 private:
133 explicit Representation(Kind k) : kind_(k) { }
134
135 // Make sure kind fits in int8.
136 STATIC_ASSERT(kNumRepresentations <= (1 << kBitsPerByte));
137
138 int8_t kind_;
139 };
140
141
79 // PropertyDetails captures type and attributes for a property. 142 // PropertyDetails captures type and attributes for a property.
80 // They are used both in property dictionaries and instance descriptors. 143 // They are used both in property dictionaries and instance descriptors.
81 class PropertyDetails BASE_EMBEDDED { 144 class PropertyDetails BASE_EMBEDDED {
82 public: 145 public:
83 PropertyDetails(PropertyAttributes attributes, 146 PropertyDetails(PropertyAttributes attributes,
84 PropertyType type, 147 PropertyType type,
148 Representation representation,
85 int index = 0) { 149 int index = 0) {
86 value_ = TypeField::encode(type) 150 value_ = TypeField::encode(type)
87 | AttributesField::encode(attributes) 151 | AttributesField::encode(attributes)
152 | RepresentationField::encode(EncodeRepresentation(representation))
88 | DictionaryStorageField::encode(index); 153 | DictionaryStorageField::encode(index);
89 154
90 ASSERT(type == this->type()); 155 ASSERT(type == this->type());
91 ASSERT(attributes == this->attributes()); 156 ASSERT(attributes == this->attributes());
92 ASSERT(index == this->dictionary_index()); 157 if (representation.IsNone()) {
158 ASSERT(index == this->dictionary_index());
159 } else {
160 ASSERT(index == this->descriptor_index());
161 }
93 } 162 }
94 163
95 int pointer() { return DescriptorPointer::decode(value_); } 164 int pointer() { return DescriptorPointer::decode(value_); }
96 165
97 PropertyDetails set_pointer(int i) { return PropertyDetails(value_, i); } 166 PropertyDetails set_pointer(int i) { return PropertyDetails(value_, i); }
98 167
168 PropertyDetails CopyWithRepresentation(Representation representation) {
169 return PropertyDetails(value_, representation);
170 }
171
99 // Conversion for storing details as Object*. 172 // Conversion for storing details as Object*.
100 explicit inline PropertyDetails(Smi* smi); 173 explicit inline PropertyDetails(Smi* smi);
101 inline Smi* AsSmi(); 174 inline Smi* AsSmi();
102 175
176 static uint8_t EncodeRepresentation(Representation representation) {
177 ASSERT(representation.kind() <= Representation::kTagged);
178 if (representation.kind() < Representation::kInteger32) {
179 return representation.kind();
180 } else {
181 return representation.kind() - 1;
182 }
183 }
184
185 static Representation DecodeRepresentation(uint32_t bits) {
186 ASSERT(bits <= Representation::kTagged);
187 if (bits >= Representation::kInteger32) bits += 1;
188 return Representation::FromKind(static_cast<Representation::Kind>(bits));
189 }
190
103 PropertyType type() { return TypeField::decode(value_); } 191 PropertyType type() { return TypeField::decode(value_); }
104 192
105 PropertyAttributes attributes() const { 193 PropertyAttributes attributes() const {
106 return AttributesField::decode(value_); 194 return AttributesField::decode(value_);
107 } 195 }
108 196
109 int dictionary_index() { 197 int dictionary_index() {
110 return DictionaryStorageField::decode(value_); 198 return DictionaryStorageField::decode(value_);
111 } 199 }
112 200
113 int descriptor_index() { 201 int descriptor_index() {
114 return DescriptorStorageField::decode(value_); 202 return DescriptorStorageField::decode(value_);
115 } 203 }
116 204
205 Representation representation() {
206 return DecodeRepresentation(RepresentationField::decode(value_));
207 }
208
117 inline PropertyDetails AsDeleted(); 209 inline PropertyDetails AsDeleted();
118 210
119 static bool IsValidIndex(int index) { 211 static bool IsValidIndex(int index) {
120 return DictionaryStorageField::is_valid(index); 212 return DictionaryStorageField::is_valid(index);
121 } 213 }
122 214
123 bool IsReadOnly() const { return (attributes() & READ_ONLY) != 0; } 215 bool IsReadOnly() const { return (attributes() & READ_ONLY) != 0; }
124 bool IsDontDelete() const { return (attributes() & DONT_DELETE) != 0; } 216 bool IsDontDelete() const { return (attributes() & DONT_DELETE) != 0; }
125 bool IsDontEnum() const { return (attributes() & DONT_ENUM) != 0; } 217 bool IsDontEnum() const { return (attributes() & DONT_ENUM) != 0; }
126 bool IsDeleted() const { return DeletedField::decode(value_) != 0;} 218 bool IsDeleted() const { return DeletedField::decode(value_) != 0;}
127 219
128 // Bit fields in value_ (type, shift, size). Must be public so the 220 // Bit fields in value_ (type, shift, size). Must be public so the
129 // constants can be embedded in generated code. 221 // constants can be embedded in generated code.
130 class TypeField: public BitField<PropertyType, 0, 3> {}; 222 class TypeField: public BitField<PropertyType, 0, 3> {};
131 class AttributesField: public BitField<PropertyAttributes, 3, 3> {}; 223 class AttributesField: public BitField<PropertyAttributes, 3, 3> {};
132 class DeletedField: public BitField<uint32_t, 6, 1> {}; 224 class DeletedField: public BitField<uint32_t, 6, 1> {};
133 class DictionaryStorageField: public BitField<uint32_t, 7, 24> {}; 225 class DictionaryStorageField: public BitField<uint32_t, 7, 24> {};
134 class DescriptorStorageField: public BitField<uint32_t, 7, 11> {}; 226 class DescriptorStorageField: public BitField<uint32_t, 7, 11> {};
135 class DescriptorPointer: public BitField<uint32_t, 18, 11> {}; 227 class DescriptorPointer: public BitField<uint32_t, 18, 11> {};
228 class RepresentationField: public BitField<uint32_t, 29, 2> {};
136 229
137 static const int kInitialIndex = 1; 230 static const int kInitialIndex = 1;
138 231
139 private: 232 private:
140 PropertyDetails(int value, int pointer) { 233 PropertyDetails(int value, int pointer) {
141 value_ = DescriptorPointer::update(value, pointer); 234 value_ = DescriptorPointer::update(value, pointer);
235 }
236 PropertyDetails(int value, Representation representation) {
237 value_ = RepresentationField::update(
238 value, EncodeRepresentation(representation));
142 } 239 }
143 240
144 uint32_t value_; 241 uint32_t value_;
145 }; 242 };
146 243
147 } } // namespace v8::internal 244 } } // namespace v8::internal
148 245
149 #endif // V8_PROPERTY_DETAILS_H_ 246 #endif // V8_PROPERTY_DETAILS_H_
OLDNEW
« no previous file with comments | « src/property.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698