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

Side by Side Diff: src/contexts.h

Issue 7348008: Merge up to 8597 to experimental/gc from the bleeding edge. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: '' Created 9 years, 5 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/compiler.cc ('k') | src/contexts.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 V(STRICT_MODE_FUNCTION_MAP_INDEX, Map, strict_mode_function_map) \ 81 V(STRICT_MODE_FUNCTION_MAP_INDEX, Map, strict_mode_function_map) \
82 V(FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX, Map, function_without_prototype_map) \ 82 V(FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX, Map, function_without_prototype_map) \
83 V(STRICT_MODE_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX, Map, \ 83 V(STRICT_MODE_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX, Map, \
84 strict_mode_function_without_prototype_map) \ 84 strict_mode_function_without_prototype_map) \
85 V(FUNCTION_INSTANCE_MAP_INDEX, Map, function_instance_map) \ 85 V(FUNCTION_INSTANCE_MAP_INDEX, Map, function_instance_map) \
86 V(STRICT_MODE_FUNCTION_INSTANCE_MAP_INDEX, Map, \ 86 V(STRICT_MODE_FUNCTION_INSTANCE_MAP_INDEX, Map, \
87 strict_mode_function_instance_map) \ 87 strict_mode_function_instance_map) \
88 V(JS_ARRAY_MAP_INDEX, Map, js_array_map)\ 88 V(JS_ARRAY_MAP_INDEX, Map, js_array_map)\
89 V(REGEXP_RESULT_MAP_INDEX, Map, regexp_result_map)\ 89 V(REGEXP_RESULT_MAP_INDEX, Map, regexp_result_map)\
90 V(ARGUMENTS_BOILERPLATE_INDEX, JSObject, arguments_boilerplate) \ 90 V(ARGUMENTS_BOILERPLATE_INDEX, JSObject, arguments_boilerplate) \
91 V(ALIASED_ARGUMENTS_BOILERPLATE_INDEX, JSObject, \
92 aliased_arguments_boilerplate) \
91 V(STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX, JSObject, \ 93 V(STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX, JSObject, \
92 strict_mode_arguments_boilerplate) \ 94 strict_mode_arguments_boilerplate) \
93 V(MESSAGE_LISTENERS_INDEX, JSObject, message_listeners) \ 95 V(MESSAGE_LISTENERS_INDEX, JSObject, message_listeners) \
94 V(MAKE_MESSAGE_FUN_INDEX, JSFunction, make_message_fun) \ 96 V(MAKE_MESSAGE_FUN_INDEX, JSFunction, make_message_fun) \
95 V(GET_STACK_TRACE_LINE_INDEX, JSFunction, get_stack_trace_line_fun) \ 97 V(GET_STACK_TRACE_LINE_INDEX, JSFunction, get_stack_trace_line_fun) \
96 V(CONFIGURE_GLOBAL_INDEX, JSFunction, configure_global_fun) \ 98 V(CONFIGURE_GLOBAL_INDEX, JSFunction, configure_global_fun) \
97 V(FUNCTION_CACHE_INDEX, JSObject, function_cache) \ 99 V(FUNCTION_CACHE_INDEX, JSObject, function_cache) \
98 V(JSFUNCTION_RESULT_CACHES_INDEX, FixedArray, jsfunction_result_caches) \ 100 V(JSFUNCTION_RESULT_CACHES_INDEX, FixedArray, jsfunction_result_caches) \
99 V(NORMALIZED_MAP_CACHE_INDEX, NormalizedMapCache, normalized_map_cache) \ 101 V(NORMALIZED_MAP_CACHE_INDEX, NormalizedMapCache, normalized_map_cache) \
100 V(RUNTIME_CONTEXT_INDEX, Context, runtime_context) \ 102 V(RUNTIME_CONTEXT_INDEX, Context, runtime_context) \
101 V(CALL_AS_FUNCTION_DELEGATE_INDEX, JSFunction, call_as_function_delegate) \ 103 V(CALL_AS_FUNCTION_DELEGATE_INDEX, JSFunction, call_as_function_delegate) \
102 V(CALL_AS_CONSTRUCTOR_DELEGATE_INDEX, JSFunction, \ 104 V(CALL_AS_CONSTRUCTOR_DELEGATE_INDEX, JSFunction, \
103 call_as_constructor_delegate) \ 105 call_as_constructor_delegate) \
104 V(SCRIPT_FUNCTION_INDEX, JSFunction, script_function) \ 106 V(SCRIPT_FUNCTION_INDEX, JSFunction, script_function) \
105 V(OPAQUE_REFERENCE_FUNCTION_INDEX, JSFunction, opaque_reference_function) \ 107 V(OPAQUE_REFERENCE_FUNCTION_INDEX, JSFunction, opaque_reference_function) \
106 V(CONTEXT_EXTENSION_FUNCTION_INDEX, JSFunction, context_extension_function) \ 108 V(CONTEXT_EXTENSION_FUNCTION_INDEX, JSFunction, context_extension_function) \
107 V(OUT_OF_MEMORY_INDEX, Object, out_of_memory) \ 109 V(OUT_OF_MEMORY_INDEX, Object, out_of_memory) \
108 V(MAP_CACHE_INDEX, Object, map_cache) \ 110 V(MAP_CACHE_INDEX, Object, map_cache) \
109 V(CONTEXT_DATA_INDEX, Object, data) \ 111 V(CONTEXT_DATA_INDEX, Object, data) \
110 V(ALLOW_CODE_GEN_FROM_STRINGS_INDEX, Object, allow_code_gen_from_strings) \ 112 V(ALLOW_CODE_GEN_FROM_STRINGS_INDEX, Object, allow_code_gen_from_strings) \
111 V(DERIVED_GET_TRAP_INDEX, JSFunction, derived_get_trap) 113 V(DERIVED_GET_TRAP_INDEX, JSFunction, derived_get_trap) \
114 V(DERIVED_SET_TRAP_INDEX, JSFunction, derived_set_trap)
112 115
113 // JSFunctions are pairs (context, function code), sometimes also called 116 // JSFunctions are pairs (context, function code), sometimes also called
114 // closures. A Context object is used to represent function contexts and 117 // closures. A Context object is used to represent function contexts and
115 // dynamically pushed 'with' contexts (or 'scopes' in ECMA-262 speak). 118 // dynamically pushed 'with' contexts (or 'scopes' in ECMA-262 speak).
116 // 119 //
117 // At runtime, the contexts build a stack in parallel to the execution 120 // At runtime, the contexts build a stack in parallel to the execution
118 // stack, with the top-most context being the current context. All contexts 121 // stack, with the top-most context being the current context. All contexts
119 // have the following slots: 122 // have the following slots:
120 // 123 //
121 // [ closure ] This is the current function. It is the same for all 124 // [ closure ] This is the current function. It is the same for all
122 // contexts inside a function. It provides access to the 125 // contexts inside a function. It provides access to the
123 // incoming context (i.e., the outer context, which may 126 // incoming context (i.e., the outer context, which may
124 // or may not become the current function's context), and 127 // or may not become the current function's context), and
125 // it provides access to the functions code and thus it's 128 // it provides access to the functions code and thus it's
126 // scope information, which in turn contains the names of 129 // scope information, which in turn contains the names of
127 // statically allocated context slots. The names are needed 130 // statically allocated context slots. The names are needed
128 // for dynamic lookups in the presence of 'with' or 'eval'. 131 // for dynamic lookups in the presence of 'with' or 'eval'.
129 // 132 //
130 // [ fcontext ] A pointer to the innermost enclosing function context.
131 // It is the same for all contexts *allocated* inside a
132 // function, and the function context's fcontext points
133 // to itself. It is only needed for fast access of the
134 // function context (used for declarations, and static
135 // context slot access).
136 //
137 // [ previous ] A pointer to the previous context. It is NULL for 133 // [ previous ] A pointer to the previous context. It is NULL for
138 // function contexts, and non-NULL for 'with' contexts. 134 // function contexts, and non-NULL for 'with' contexts.
139 // Used to implement the 'with' statement. 135 // Used to implement the 'with' statement.
140 // 136 //
141 // [ extension ] A pointer to an extension JSObject, or NULL. Used to 137 // [ extension ] A pointer to an extension JSObject, or NULL. Used to
142 // implement 'with' statements and dynamic declarations 138 // implement 'with' statements and dynamic declarations
143 // (through 'eval'). The object in a 'with' statement is 139 // (through 'eval'). The object in a 'with' statement is
144 // stored in the extension slot of a 'with' context. 140 // stored in the extension slot of a 'with' context.
145 // Dynamically declared variables/functions are also added 141 // Dynamically declared variables/functions are also added
146 // to lazily allocated extension object. Context::Lookup 142 // to lazily allocated extension object. Context::Lookup
147 // searches the extension object for properties. 143 // searches the extension object for properties.
148 // 144 //
149 // [ global ] A pointer to the global object. Provided for quick 145 // [ global ] A pointer to the global object. Provided for quick
150 // access to the global object from inside the code (since 146 // access to the global object from inside the code (since
151 // we always have a context pointer). 147 // we always have a context pointer).
152 // 148 //
153 // In addition, function contexts may have statically allocated context slots 149 // In addition, function contexts may have statically allocated context slots
154 // to store local variables/functions that are accessed from inner functions 150 // to store local variables/functions that are accessed from inner functions
155 // (via static context addresses) or through 'eval' (dynamic context lookups). 151 // (via static context addresses) or through 'eval' (dynamic context lookups).
156 // Finally, the global context contains additional slots for fast access to 152 // Finally, the global context contains additional slots for fast access to
157 // global properties. 153 // global properties.
158 //
159 // We may be able to simplify the implementation:
160 //
161 // - We may be able to get rid of 'fcontext': We can always use the fact that
162 // previous == NULL for function contexts and so we can search for them. They
163 // are only needed when doing dynamic declarations, and the context chains
164 // tend to be very very short (depth of nesting of 'with' statements). At
165 // the moment we also use it in generated code for context slot accesses -
166 // and there we don't want a loop because of code bloat - but we may not
167 // need it there after all (see comment in codegen_*.cc).
168 //
169 // - If we cannot get rid of fcontext, consider making 'previous' never NULL
170 // except for the global context. This could simplify Context::Lookup.
171 154
172 class Context: public FixedArray { 155 class Context: public FixedArray {
173 public: 156 public:
174 // Conversions. 157 // Conversions.
175 static Context* cast(Object* context) { 158 static Context* cast(Object* context) {
176 ASSERT(context->IsContext()); 159 ASSERT(context->IsContext());
177 return reinterpret_cast<Context*>(context); 160 return reinterpret_cast<Context*>(context);
178 } 161 }
179 162
180 // The default context slot layout; indices are FixedArray slot indices. 163 // The default context slot layout; indices are FixedArray slot indices.
181 enum { 164 enum {
182 // These slots are in all contexts. 165 // These slots are in all contexts.
183 CLOSURE_INDEX, 166 CLOSURE_INDEX,
184 FCONTEXT_INDEX,
185 PREVIOUS_INDEX, 167 PREVIOUS_INDEX,
168 // The extension slot is used for either the global object (in global
169 // contexts), eval extension object (function contexts), subject of with
170 // (with contexts), or the variable name (catch contexts).
186 EXTENSION_INDEX, 171 EXTENSION_INDEX,
187 GLOBAL_INDEX, 172 GLOBAL_INDEX,
188 MIN_CONTEXT_SLOTS, 173 MIN_CONTEXT_SLOTS,
189 174
175 // This slot holds the thrown value in catch contexts.
176 THROWN_OBJECT_INDEX = MIN_CONTEXT_SLOTS,
177
190 // These slots are only in global contexts. 178 // These slots are only in global contexts.
191 GLOBAL_PROXY_INDEX = MIN_CONTEXT_SLOTS, 179 GLOBAL_PROXY_INDEX = MIN_CONTEXT_SLOTS,
192 SECURITY_TOKEN_INDEX, 180 SECURITY_TOKEN_INDEX,
193 ARGUMENTS_BOILERPLATE_INDEX, 181 ARGUMENTS_BOILERPLATE_INDEX,
182 ALIASED_ARGUMENTS_BOILERPLATE_INDEX,
194 STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX, 183 STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX,
195 JS_ARRAY_MAP_INDEX, 184 JS_ARRAY_MAP_INDEX,
196 REGEXP_RESULT_MAP_INDEX, 185 REGEXP_RESULT_MAP_INDEX,
197 FUNCTION_MAP_INDEX, 186 FUNCTION_MAP_INDEX,
198 STRICT_MODE_FUNCTION_MAP_INDEX, 187 STRICT_MODE_FUNCTION_MAP_INDEX,
199 FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX, 188 FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX,
200 STRICT_MODE_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX, 189 STRICT_MODE_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX,
201 FUNCTION_INSTANCE_MAP_INDEX, 190 FUNCTION_INSTANCE_MAP_INDEX,
202 STRICT_MODE_FUNCTION_INSTANCE_MAP_INDEX, 191 STRICT_MODE_FUNCTION_INSTANCE_MAP_INDEX,
203 INITIAL_OBJECT_PROTOTYPE_INDEX, 192 INITIAL_OBJECT_PROTOTYPE_INDEX,
(...skipping 25 matching lines...) Expand all
229 FUNCTION_CACHE_INDEX, 218 FUNCTION_CACHE_INDEX,
230 JSFUNCTION_RESULT_CACHES_INDEX, 219 JSFUNCTION_RESULT_CACHES_INDEX,
231 NORMALIZED_MAP_CACHE_INDEX, 220 NORMALIZED_MAP_CACHE_INDEX,
232 RUNTIME_CONTEXT_INDEX, 221 RUNTIME_CONTEXT_INDEX,
233 CALL_AS_FUNCTION_DELEGATE_INDEX, 222 CALL_AS_FUNCTION_DELEGATE_INDEX,
234 CALL_AS_CONSTRUCTOR_DELEGATE_INDEX, 223 CALL_AS_CONSTRUCTOR_DELEGATE_INDEX,
235 SCRIPT_FUNCTION_INDEX, 224 SCRIPT_FUNCTION_INDEX,
236 OPAQUE_REFERENCE_FUNCTION_INDEX, 225 OPAQUE_REFERENCE_FUNCTION_INDEX,
237 CONTEXT_EXTENSION_FUNCTION_INDEX, 226 CONTEXT_EXTENSION_FUNCTION_INDEX,
238 OUT_OF_MEMORY_INDEX, 227 OUT_OF_MEMORY_INDEX,
239 MAP_CACHE_INDEX,
240 CONTEXT_DATA_INDEX, 228 CONTEXT_DATA_INDEX,
241 ALLOW_CODE_GEN_FROM_STRINGS_INDEX, 229 ALLOW_CODE_GEN_FROM_STRINGS_INDEX,
242 DERIVED_GET_TRAP_INDEX, 230 DERIVED_GET_TRAP_INDEX,
231 DERIVED_SET_TRAP_INDEX,
243 232
244 // Properties from here are treated as weak references by the full GC. 233 // Properties from here are treated as weak references by the full GC.
245 // Scavenge treats them as strong references. 234 // Scavenge treats them as strong references.
246 OPTIMIZED_FUNCTIONS_LIST, // Weak. 235 OPTIMIZED_FUNCTIONS_LIST, // Weak.
236 MAP_CACHE_INDEX, // Weak.
247 NEXT_CONTEXT_LINK, // Weak. 237 NEXT_CONTEXT_LINK, // Weak.
248 238
249 // Total number of slots. 239 // Total number of slots.
250 GLOBAL_CONTEXT_SLOTS, 240 GLOBAL_CONTEXT_SLOTS,
251 241
252 FIRST_WEAK_SLOT = OPTIMIZED_FUNCTIONS_LIST 242 FIRST_WEAK_SLOT = OPTIMIZED_FUNCTIONS_LIST
253 }; 243 };
254 244
255 // Direct slot access. 245 // Direct slot access.
256 JSFunction* closure() { return JSFunction::cast(get(CLOSURE_INDEX)); } 246 JSFunction* closure() { return JSFunction::cast(get(CLOSURE_INDEX)); }
257 void set_closure(JSFunction* closure) { set(CLOSURE_INDEX, closure); } 247 void set_closure(JSFunction* closure) { set(CLOSURE_INDEX, closure); }
258 248
259 Context* fcontext() { return Context::cast(get(FCONTEXT_INDEX)); }
260 void set_fcontext(Context* context) { set(FCONTEXT_INDEX, context); }
261
262 Context* previous() { 249 Context* previous() {
263 Object* result = unchecked_previous(); 250 Object* result = unchecked_previous();
264 ASSERT(IsBootstrappingOrContext(result)); 251 ASSERT(IsBootstrappingOrContext(result));
265 return reinterpret_cast<Context*>(result); 252 return reinterpret_cast<Context*>(result);
266 } 253 }
267 void set_previous(Context* context) { set(PREVIOUS_INDEX, context); } 254 void set_previous(Context* context) { set(PREVIOUS_INDEX, context); }
268 255
269 bool has_extension() { return unchecked_extension() != NULL; } 256 bool has_extension() { return extension() != NULL; }
270 JSObject* extension() { return JSObject::cast(unchecked_extension()); } 257 Object* extension() { return get(EXTENSION_INDEX); }
271 void set_extension(JSObject* object) { set(EXTENSION_INDEX, object); } 258 void set_extension(Object* object) { set(EXTENSION_INDEX, object); }
259
260 // Get the context where var declarations will be hoisted to, which
261 // may be the context itself.
262 Context* declaration_context();
272 263
273 GlobalObject* global() { 264 GlobalObject* global() {
274 Object* result = get(GLOBAL_INDEX); 265 Object* result = get(GLOBAL_INDEX);
275 ASSERT(IsBootstrappingOrGlobalObject(result)); 266 ASSERT(IsBootstrappingOrGlobalObject(result));
276 return reinterpret_cast<GlobalObject*>(result); 267 return reinterpret_cast<GlobalObject*>(result);
277 } 268 }
278 void set_global(GlobalObject* global) { set(GLOBAL_INDEX, global); } 269 void set_global(GlobalObject* global) { set(GLOBAL_INDEX, global); }
279 270
280 // Returns a JSGlobalProxy object or null. 271 // Returns a JSGlobalProxy object or null.
281 JSObject* global_proxy(); 272 JSObject* global_proxy();
282 void set_global_proxy(JSObject* global); 273 void set_global_proxy(JSObject* global);
283 274
284 // The builtins object. 275 // The builtins object.
285 JSBuiltinsObject* builtins(); 276 JSBuiltinsObject* builtins();
286 277
287 // Compute the global context by traversing the context chain. 278 // Compute the global context by traversing the context chain.
288 Context* global_context(); 279 Context* global_context();
289 280
290 // Tells if this is a function context (as opposed to a 'with' context). 281 // Predicates for context types. IsGlobalContext is defined on Object
291 bool is_function_context() { return unchecked_previous() == NULL; } 282 // because we frequently have to know if arbitrary objects are global
283 // contexts.
284 bool IsFunctionContext() {
285 Map* map = this->map();
286 return map == map->GetHeap()->function_context_map();
287 }
288 bool IsCatchContext() {
289 Map* map = this->map();
290 return map == map->GetHeap()->catch_context_map();
291 }
292 bool IsWithContext() {
293 Map* map = this->map();
294 return map == map->GetHeap()->with_context_map();
295 }
292 296
293 // Tells whether the global context is marked with out of memory. 297 // Tells whether the global context is marked with out of memory.
294 inline bool has_out_of_memory(); 298 inline bool has_out_of_memory();
295 299
296 // Mark the global context with out of memory. 300 // Mark the global context with out of memory.
297 inline void mark_out_of_memory(); 301 inline void mark_out_of_memory();
298 302
299 // The exception holder is the object used as a with object in 303 // The exception holder is the object used as a with object in
300 // the implementation of a catch block. 304 // the implementation of a catch block.
301 bool is_exception_holder(Object* object) { 305 bool is_exception_holder(Object* object) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 kHeaderSize, kSize, kSize> ScavengeBodyDescriptor; 374 kHeaderSize, kSize, kSize> ScavengeBodyDescriptor;
371 375
372 typedef FixedBodyDescriptor< 376 typedef FixedBodyDescriptor<
373 kHeaderSize, 377 kHeaderSize,
374 kHeaderSize + FIRST_WEAK_SLOT * kPointerSize, 378 kHeaderSize + FIRST_WEAK_SLOT * kPointerSize,
375 kSize> MarkCompactBodyDescriptor; 379 kSize> MarkCompactBodyDescriptor;
376 380
377 private: 381 private:
378 // Unchecked access to the slots. 382 // Unchecked access to the slots.
379 Object* unchecked_previous() { return get(PREVIOUS_INDEX); } 383 Object* unchecked_previous() { return get(PREVIOUS_INDEX); }
380 Object* unchecked_extension() { return get(EXTENSION_INDEX); }
381 384
382 #ifdef DEBUG 385 #ifdef DEBUG
383 // Bootstrapping-aware type checks. 386 // Bootstrapping-aware type checks.
384 static bool IsBootstrappingOrContext(Object* object); 387 static bool IsBootstrappingOrContext(Object* object);
385 static bool IsBootstrappingOrGlobalObject(Object* object); 388 static bool IsBootstrappingOrGlobalObject(Object* object);
386 #endif 389 #endif
387 }; 390 };
388 391
389 } } // namespace v8::internal 392 } } // namespace v8::internal
390 393
391 #endif // V8_CONTEXTS_H_ 394 #endif // V8_CONTEXTS_H_
OLDNEW
« no previous file with comments | « src/compiler.cc ('k') | src/contexts.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698