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

Side by Side Diff: src/interface.h

Issue 11093074: Get rid of static module allocation, do it in code. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed last comments; added other back-ends Created 8 years, 1 month 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/ia32/macro-assembler-ia32.h ('k') | src/interface.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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 *ok = !IsModule() && (IsConst() || !IsFrozen()); 101 *ok = !IsModule() && (IsConst() || !IsFrozen());
102 if (*ok) Chase()->flags_ |= VALUE + CONST; 102 if (*ok) Chase()->flags_ |= VALUE + CONST;
103 } 103 }
104 104
105 // Determine this interface to be a module interface. 105 // Determine this interface to be a module interface.
106 void MakeModule(bool* ok) { 106 void MakeModule(bool* ok) {
107 *ok = !IsValue(); 107 *ok = !IsValue();
108 if (*ok) Chase()->flags_ |= MODULE; 108 if (*ok) Chase()->flags_ |= MODULE;
109 } 109 }
110 110
111 // Set associated instance object.
112 void MakeSingleton(Handle<JSModule> instance, bool* ok) {
113 *ok = IsModule() && Chase()->instance_.is_null();
114 if (*ok) Chase()->instance_ = instance;
115 }
116
117 // Do not allow any further refinements, directly or through unification. 111 // Do not allow any further refinements, directly or through unification.
118 void Freeze(bool* ok) { 112 void Freeze(bool* ok) {
119 *ok = IsValue() || IsModule(); 113 *ok = IsValue() || IsModule();
120 if (*ok) Chase()->flags_ |= FROZEN; 114 if (*ok) Chase()->flags_ |= FROZEN;
121 } 115 }
122 116
117 // Assign an index.
118 void Allocate(int index) {
119 ASSERT(IsModule() && IsFrozen() && Chase()->index_ == -1);
120 Chase()->index_ = index;
121 }
122
123 // --------------------------------------------------------------------------- 123 // ---------------------------------------------------------------------------
124 // Accessors. 124 // Accessors.
125 125
126 // Check whether this is still a fully undetermined type. 126 // Check whether this is still a fully undetermined type.
127 bool IsUnknown() { return Chase()->flags_ == NONE; } 127 bool IsUnknown() { return Chase()->flags_ == NONE; }
128 128
129 // Check whether this is a value type. 129 // Check whether this is a value type.
130 bool IsValue() { return Chase()->flags_ & VALUE; } 130 bool IsValue() { return Chase()->flags_ & VALUE; }
131 131
132 // Check whether this is a constant type. 132 // Check whether this is a constant type.
133 bool IsConst() { return Chase()->flags_ & CONST; } 133 bool IsConst() { return Chase()->flags_ & CONST; }
134 134
135 // Check whether this is a module type. 135 // Check whether this is a module type.
136 bool IsModule() { return Chase()->flags_ & MODULE; } 136 bool IsModule() { return Chase()->flags_ & MODULE; }
137 137
138 // Check whether this is closed (i.e. fully determined). 138 // Check whether this is closed (i.e. fully determined).
139 bool IsFrozen() { return Chase()->flags_ & FROZEN; } 139 bool IsFrozen() { return Chase()->flags_ & FROZEN; }
140 140
141 Handle<JSModule> Instance() { return Chase()->instance_; } 141 bool IsUnified(Interface* that) {
142 return Chase() == that->Chase()
143 || (this->IsValue() == that->IsValue() &&
144 this->IsConst() == that->IsConst());
145 }
146
147 int Length() {
148 ASSERT(IsModule() && IsFrozen());
149 ZoneHashMap* exports = Chase()->exports_;
150 return exports ? exports->occupancy() : 0;
151 }
152
153 // The context slot in the hosting global context pointing to this module.
154 int Index() {
155 ASSERT(IsModule() && IsFrozen());
156 return Chase()->index_;
157 }
142 158
143 // Look up an exported name. Returns NULL if not (yet) defined. 159 // Look up an exported name. Returns NULL if not (yet) defined.
144 Interface* Lookup(Handle<String> name, Zone* zone); 160 Interface* Lookup(Handle<String> name, Zone* zone);
145 161
146 // --------------------------------------------------------------------------- 162 // ---------------------------------------------------------------------------
147 // Iterators. 163 // Iterators.
148 164
149 // Use like: 165 // Use like:
150 // for (auto it = interface->iterator(); !it.done(); it.Advance()) { 166 // for (auto it = interface->iterator(); !it.done(); it.Advance()) {
151 // ... it.name() ... it.interface() ... 167 // ... it.name() ... it.interface() ...
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 NONE = 0, 203 NONE = 0,
188 VALUE = 1, // This type describes a value 204 VALUE = 1, // This type describes a value
189 CONST = 2, // This type describes a constant 205 CONST = 2, // This type describes a constant
190 MODULE = 4, // This type describes a module 206 MODULE = 4, // This type describes a module
191 FROZEN = 8 // This type is fully determined 207 FROZEN = 8 // This type is fully determined
192 }; 208 };
193 209
194 int flags_; 210 int flags_;
195 Interface* forward_; // Unification link 211 Interface* forward_; // Unification link
196 ZoneHashMap* exports_; // Module exports and their types (allocated lazily) 212 ZoneHashMap* exports_; // Module exports and their types (allocated lazily)
197 Handle<JSModule> instance_; 213 int index_;
198 214
199 explicit Interface(int flags) 215 explicit Interface(int flags)
200 : flags_(flags), 216 : flags_(flags),
201 forward_(NULL), 217 forward_(NULL),
202 exports_(NULL) { 218 exports_(NULL),
219 index_(-1) {
203 #ifdef DEBUG 220 #ifdef DEBUG
204 if (FLAG_print_interface_details) 221 if (FLAG_print_interface_details)
205 PrintF("# Creating %p\n", static_cast<void*>(this)); 222 PrintF("# Creating %p\n", static_cast<void*>(this));
206 #endif 223 #endif
207 } 224 }
208 225
209 Interface* Chase() { 226 Interface* Chase() {
210 Interface* result = this; 227 Interface* result = this;
211 while (result->forward_ != NULL) result = result->forward_; 228 while (result->forward_ != NULL) result = result->forward_;
212 if (result != this) forward_ = result; // On-the-fly path compression. 229 if (result != this) forward_ = result; // On-the-fly path compression.
213 return result; 230 return result;
214 } 231 }
215 232
216 void DoAdd(void* name, uint32_t hash, Interface* interface, Zone* zone, 233 void DoAdd(void* name, uint32_t hash, Interface* interface, Zone* zone,
217 bool* ok); 234 bool* ok);
218 void DoUnify(Interface* that, bool* ok, Zone* zone); 235 void DoUnify(Interface* that, bool* ok, Zone* zone);
219 }; 236 };
220 237
221 } } // namespace v8::internal 238 } } // namespace v8::internal
222 239
223 #endif // V8_INTERFACE_H_ 240 #endif // V8_INTERFACE_H_
OLDNEW
« no previous file with comments | « src/ia32/macro-assembler-ia32.h ('k') | src/interface.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698