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

Side by Side Diff: src/contexts.h

Issue 10832342: Rename "global context" to "native context", (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 4 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') | src/heap.h » ('J')
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 89
90 // Heap-allocated activation contexts. 90 // Heap-allocated activation contexts.
91 // 91 //
92 // Contexts are implemented as FixedArray objects; the Context 92 // Contexts are implemented as FixedArray objects; the Context
93 // class is a convenience interface casted on a FixedArray object. 93 // class is a convenience interface casted on a FixedArray object.
94 // 94 //
95 // Note: Context must have no virtual functions and Context objects 95 // Note: Context must have no virtual functions and Context objects
96 // must always be allocated via Heap::AllocateContext() or 96 // must always be allocated via Heap::AllocateContext() or
97 // Factory::NewContext. 97 // Factory::NewContext.
98 98
99 #define GLOBAL_CONTEXT_FIELDS(V) \ 99 #define NATIVE_CONTEXT_FIELDS(V) \
100 V(GLOBAL_PROXY_INDEX, JSObject, global_proxy_object) \ 100 V(GLOBAL_PROXY_INDEX, JSObject, global_proxy_object) \
101 V(SECURITY_TOKEN_INDEX, Object, security_token) \ 101 V(SECURITY_TOKEN_INDEX, Object, security_token) \
102 V(BOOLEAN_FUNCTION_INDEX, JSFunction, boolean_function) \ 102 V(BOOLEAN_FUNCTION_INDEX, JSFunction, boolean_function) \
103 V(NUMBER_FUNCTION_INDEX, JSFunction, number_function) \ 103 V(NUMBER_FUNCTION_INDEX, JSFunction, number_function) \
104 V(STRING_FUNCTION_INDEX, JSFunction, string_function) \ 104 V(STRING_FUNCTION_INDEX, JSFunction, string_function) \
105 V(STRING_FUNCTION_PROTOTYPE_MAP_INDEX, Map, string_function_prototype_map) \ 105 V(STRING_FUNCTION_PROTOTYPE_MAP_INDEX, Map, string_function_prototype_map) \
106 V(OBJECT_FUNCTION_INDEX, JSFunction, object_function) \ 106 V(OBJECT_FUNCTION_INDEX, JSFunction, object_function) \
107 V(INTERNAL_ARRAY_FUNCTION_INDEX, JSFunction, internal_array_function) \ 107 V(INTERNAL_ARRAY_FUNCTION_INDEX, JSFunction, internal_array_function) \
108 V(ARRAY_FUNCTION_INDEX, JSFunction, array_function) \ 108 V(ARRAY_FUNCTION_INDEX, JSFunction, array_function) \
109 V(JS_ARRAY_MAPS_INDEX, Object, js_array_maps) \ 109 V(JS_ARRAY_MAPS_INDEX, Object, js_array_maps) \
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // For block contexts, contains the respective ScopeInfo. 193 // For block contexts, contains the respective ScopeInfo.
194 // For module contexts, points back to the respective JSModule. 194 // For module contexts, points back to the respective JSModule.
195 // 195 //
196 // [ global ] A pointer to the global object. Provided for quick 196 // [ global ] A pointer to the global object. Provided for quick
197 // access to the global object from inside the code (since 197 // access to the global object from inside the code (since
198 // we always have a context pointer). 198 // we always have a context pointer).
199 // 199 //
200 // In addition, function contexts may have statically allocated context slots 200 // In addition, function contexts may have statically allocated context slots
201 // to store local variables/functions that are accessed from inner functions 201 // to store local variables/functions that are accessed from inner functions
202 // (via static context addresses) or through 'eval' (dynamic context lookups). 202 // (via static context addresses) or through 'eval' (dynamic context lookups).
203 // Finally, the global context contains additional slots for fast access to 203 // Finally, the native context contains additional slots for fast access to
204 // global properties. 204 // native properties.
205 205
206 class Context: public FixedArray { 206 class Context: public FixedArray {
207 public: 207 public:
208 // Conversions. 208 // Conversions.
209 static Context* cast(Object* context) { 209 static Context* cast(Object* context) {
210 ASSERT(context->IsContext()); 210 ASSERT(context->IsContext());
211 return reinterpret_cast<Context*>(context); 211 return reinterpret_cast<Context*>(context);
212 } 212 }
213 213
214 // The default context slot layout; indices are FixedArray slot indices. 214 // The default context slot layout; indices are FixedArray slot indices.
215 enum { 215 enum {
216 // These slots are in all contexts. 216 // These slots are in all contexts.
217 CLOSURE_INDEX, 217 CLOSURE_INDEX,
218 PREVIOUS_INDEX, 218 PREVIOUS_INDEX,
219 // The extension slot is used for either the global object (in global 219 // The extension slot is used for either the global object (in global
220 // contexts), eval extension object (function contexts), subject of with 220 // contexts), eval extension object (function contexts), subject of with
221 // (with contexts), or the variable name (catch contexts), the serialized 221 // (with contexts), or the variable name (catch contexts), the serialized
222 // scope info (block contexts), or the module instance (module contexts). 222 // scope info (block contexts), or the module instance (module contexts).
223 EXTENSION_INDEX, 223 EXTENSION_INDEX,
224 GLOBAL_INDEX, 224 GLOBAL_INDEX,
225 MIN_CONTEXT_SLOTS, 225 MIN_CONTEXT_SLOTS,
226 226
227 // This slot holds the thrown value in catch contexts. 227 // This slot holds the thrown value in catch contexts.
228 THROWN_OBJECT_INDEX = MIN_CONTEXT_SLOTS, 228 THROWN_OBJECT_INDEX = MIN_CONTEXT_SLOTS,
229 229
230 // These slots are only in global contexts. 230 // These slots are only in native contexts.
231 GLOBAL_PROXY_INDEX = MIN_CONTEXT_SLOTS, 231 GLOBAL_PROXY_INDEX = MIN_CONTEXT_SLOTS,
232 SECURITY_TOKEN_INDEX, 232 SECURITY_TOKEN_INDEX,
233 ARGUMENTS_BOILERPLATE_INDEX, 233 ARGUMENTS_BOILERPLATE_INDEX,
234 ALIASED_ARGUMENTS_BOILERPLATE_INDEX, 234 ALIASED_ARGUMENTS_BOILERPLATE_INDEX,
235 STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX, 235 STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX,
236 REGEXP_RESULT_MAP_INDEX, 236 REGEXP_RESULT_MAP_INDEX,
237 FUNCTION_MAP_INDEX, 237 FUNCTION_MAP_INDEX,
238 STRICT_MODE_FUNCTION_MAP_INDEX, 238 STRICT_MODE_FUNCTION_MAP_INDEX,
239 FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX, 239 FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX,
240 STRICT_MODE_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX, 240 STRICT_MODE_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 PROXY_ENUMERATE, 287 PROXY_ENUMERATE,
288 RANDOM_SEED_INDEX, 288 RANDOM_SEED_INDEX,
289 289
290 // Properties from here are treated as weak references by the full GC. 290 // Properties from here are treated as weak references by the full GC.
291 // Scavenge treats them as strong references. 291 // Scavenge treats them as strong references.
292 OPTIMIZED_FUNCTIONS_LIST, // Weak. 292 OPTIMIZED_FUNCTIONS_LIST, // Weak.
293 MAP_CACHE_INDEX, // Weak. 293 MAP_CACHE_INDEX, // Weak.
294 NEXT_CONTEXT_LINK, // Weak. 294 NEXT_CONTEXT_LINK, // Weak.
295 295
296 // Total number of slots. 296 // Total number of slots.
297 GLOBAL_CONTEXT_SLOTS, 297 NATIVE_CONTEXT_SLOTS,
298 298
299 FIRST_WEAK_SLOT = OPTIMIZED_FUNCTIONS_LIST 299 FIRST_WEAK_SLOT = OPTIMIZED_FUNCTIONS_LIST
300 }; 300 };
301 301
302 // Direct slot access. 302 // Direct slot access.
303 JSFunction* closure() { return JSFunction::cast(get(CLOSURE_INDEX)); } 303 JSFunction* closure() { return JSFunction::cast(get(CLOSURE_INDEX)); }
304 void set_closure(JSFunction* closure) { set(CLOSURE_INDEX, closure); } 304 void set_closure(JSFunction* closure) { set(CLOSURE_INDEX, closure); }
305 305
306 Context* previous() { 306 Context* previous() {
307 Object* result = unchecked_previous(); 307 Object* result = unchecked_previous();
(...skipping 20 matching lines...) Expand all
328 } 328 }
329 void set_global(GlobalObject* global) { set(GLOBAL_INDEX, global); } 329 void set_global(GlobalObject* global) { set(GLOBAL_INDEX, global); }
330 330
331 // Returns a JSGlobalProxy object or null. 331 // Returns a JSGlobalProxy object or null.
332 JSObject* global_proxy(); 332 JSObject* global_proxy();
333 void set_global_proxy(JSObject* global); 333 void set_global_proxy(JSObject* global);
334 334
335 // The builtins object. 335 // The builtins object.
336 JSBuiltinsObject* builtins(); 336 JSBuiltinsObject* builtins();
337 337
338 // Compute the global context by traversing the context chain. 338 // Compute the native context by traversing the context chain.
339 Context* global_context(); 339 Context* native_context();
340 340
341 // Predicates for context types. IsGlobalContext is defined on Object 341 // Predicates for context types. IsNativeContext is defined on Object
342 // because we frequently have to know if arbitrary objects are global 342 // because we frequently have to know if arbitrary objects are natives
343 // contexts. 343 // contexts.
344 bool IsFunctionContext() { 344 bool IsFunctionContext() {
345 Map* map = this->map(); 345 Map* map = this->map();
346 return map == map->GetHeap()->function_context_map(); 346 return map == map->GetHeap()->function_context_map();
347 } 347 }
348 bool IsCatchContext() { 348 bool IsCatchContext() {
349 Map* map = this->map(); 349 Map* map = this->map();
350 return map == map->GetHeap()->catch_context_map(); 350 return map == map->GetHeap()->catch_context_map();
351 } 351 }
352 bool IsWithContext() { 352 bool IsWithContext() {
353 Map* map = this->map(); 353 Map* map = this->map();
354 return map == map->GetHeap()->with_context_map(); 354 return map == map->GetHeap()->with_context_map();
355 } 355 }
356 bool IsBlockContext() { 356 bool IsBlockContext() {
357 Map* map = this->map(); 357 Map* map = this->map();
358 return map == map->GetHeap()->block_context_map(); 358 return map == map->GetHeap()->block_context_map();
359 } 359 }
360 bool IsModuleContext() { 360 bool IsModuleContext() {
361 Map* map = this->map(); 361 Map* map = this->map();
362 return map == map->GetHeap()->module_context_map(); 362 return map == map->GetHeap()->module_context_map();
363 } 363 }
364 364
365 // Tells whether the global context is marked with out of memory. 365 // Tells whether the native context is marked with out of memory.
366 inline bool has_out_of_memory(); 366 inline bool has_out_of_memory();
367 367
368 // Mark the global context with out of memory. 368 // Mark the native context with out of memory.
369 inline void mark_out_of_memory(); 369 inline void mark_out_of_memory();
370 370
371 // A global context hold a list of all functions which have been optimized. 371 // A native context hold a list of all functions which have been optimized.
372 void AddOptimizedFunction(JSFunction* function); 372 void AddOptimizedFunction(JSFunction* function);
373 void RemoveOptimizedFunction(JSFunction* function); 373 void RemoveOptimizedFunction(JSFunction* function);
374 Object* OptimizedFunctionsListHead(); 374 Object* OptimizedFunctionsListHead();
375 void ClearOptimizedFunctions(); 375 void ClearOptimizedFunctions();
376 376
377 #define GLOBAL_CONTEXT_FIELD_ACCESSORS(index, type, name) \ 377 #define NATIVE_CONTEXT_FIELD_ACCESSORS(index, type, name) \
378 void set_##name(type* value) { \ 378 void set_##name(type* value) { \
379 ASSERT(IsGlobalContext()); \ 379 ASSERT(IsNativeContext()); \
380 set(index, value); \ 380 set(index, value); \
381 } \ 381 } \
382 type* name() { \ 382 type* name() { \
383 ASSERT(IsGlobalContext()); \ 383 ASSERT(IsNativeContext()); \
384 return type::cast(get(index)); \ 384 return type::cast(get(index)); \
385 } 385 }
386 GLOBAL_CONTEXT_FIELDS(GLOBAL_CONTEXT_FIELD_ACCESSORS) 386 NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSORS)
387 #undef GLOBAL_CONTEXT_FIELD_ACCESSORS 387 #undef NATIVE_CONTEXT_FIELD_ACCESSORS
388 388
389 // Lookup the slot called name, starting with the current context. 389 // Lookup the slot called name, starting with the current context.
390 // There are three possibilities: 390 // There are three possibilities:
391 // 391 //
392 // 1) result->IsContext(): 392 // 1) result->IsContext():
393 // The binding was found in a context. *index is always the 393 // The binding was found in a context. *index is always the
394 // non-negative slot index. *attributes is NONE for var and let 394 // non-negative slot index. *attributes is NONE for var and let
395 // declarations, READ_ONLY for const declarations (never ABSENT). 395 // declarations, READ_ONLY for const declarations (never ABSENT).
396 // 396 //
397 // 2) result->IsJSObject(): 397 // 2) result->IsJSObject():
398 // The binding was found as a named property in a context extension 398 // The binding was found as a named property in a context extension
399 // object (i.e., was introduced via eval), as a property on the subject 399 // object (i.e., was introduced via eval), as a property on the subject
400 // of with, or as a property of the global object. *index is -1 and 400 // of with, or as a property of the global object. *index is -1 and
401 // *attributes is not ABSENT. 401 // *attributes is not ABSENT.
402 // 402 //
403 // 3) result.is_null(): 403 // 3) result.is_null():
404 // There was no binding found, *index is always -1 and *attributes is 404 // There was no binding found, *index is always -1 and *attributes is
405 // always ABSENT. 405 // always ABSENT.
406 Handle<Object> Lookup(Handle<String> name, 406 Handle<Object> Lookup(Handle<String> name,
407 ContextLookupFlags flags, 407 ContextLookupFlags flags,
408 int* index, 408 int* index,
409 PropertyAttributes* attributes, 409 PropertyAttributes* attributes,
410 BindingFlags* binding_flags); 410 BindingFlags* binding_flags);
411 411
412 // Code generation support. 412 // Code generation support.
413 static int SlotOffset(int index) { 413 static int SlotOffset(int index) {
414 return kHeaderSize + index * kPointerSize - kHeapObjectTag; 414 return kHeaderSize + index * kPointerSize - kHeapObjectTag;
415 } 415 }
416 416
417 static const int kSize = kHeaderSize + GLOBAL_CONTEXT_SLOTS * kPointerSize; 417 static const int kSize =
Michael Starzinger 2012/08/16 16:33:56 Should still fit into one line.
rossberg 2012/08/17 08:40:32 Done.
418 kHeaderSize + NATIVE_CONTEXT_SLOTS * kPointerSize;
418 419
419 // GC support. 420 // GC support.
420 typedef FixedBodyDescriptor< 421 typedef FixedBodyDescriptor<
421 kHeaderSize, kSize, kSize> ScavengeBodyDescriptor; 422 kHeaderSize, kSize, kSize> ScavengeBodyDescriptor;
422 423
423 typedef FixedBodyDescriptor< 424 typedef FixedBodyDescriptor<
424 kHeaderSize, 425 kHeaderSize,
425 kHeaderSize + FIRST_WEAK_SLOT * kPointerSize, 426 kHeaderSize + FIRST_WEAK_SLOT * kPointerSize,
426 kSize> MarkCompactBodyDescriptor; 427 kSize> MarkCompactBodyDescriptor;
427 428
428 private: 429 private:
429 // Unchecked access to the slots. 430 // Unchecked access to the slots.
430 Object* unchecked_previous() { return get(PREVIOUS_INDEX); } 431 Object* unchecked_previous() { return get(PREVIOUS_INDEX); }
431 432
432 #ifdef DEBUG 433 #ifdef DEBUG
433 // Bootstrapping-aware type checks. 434 // Bootstrapping-aware type checks.
434 static bool IsBootstrappingOrValidParentContext(Object* object, Context* kid); 435 static bool IsBootstrappingOrValidParentContext(Object* object, Context* kid);
435 static bool IsBootstrappingOrGlobalObject(Object* object); 436 static bool IsBootstrappingOrGlobalObject(Object* object);
436 #endif 437 #endif
437 }; 438 };
438 439
439 } } // namespace v8::internal 440 } } // namespace v8::internal
440 441
441 #endif // V8_CONTEXTS_H_ 442 #endif // V8_CONTEXTS_H_
OLDNEW
« no previous file with comments | « src/compiler.cc ('k') | src/contexts.cc » ('j') | src/heap.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698