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

Side by Side Diff: src/objects.h

Issue 8352039: Cleanup ScopeInfo and SerializedScopeInfo. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Converted ScopeInfo accessors to CamelCase. Created 9 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
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // - FixedArray 71 // - FixedArray
72 // - DescriptorArray 72 // - DescriptorArray
73 // - HashTable 73 // - HashTable
74 // - Dictionary 74 // - Dictionary
75 // - SymbolTable 75 // - SymbolTable
76 // - CompilationCacheTable 76 // - CompilationCacheTable
77 // - CodeCacheHashTable 77 // - CodeCacheHashTable
78 // - MapCache 78 // - MapCache
79 // - Context 79 // - Context
80 // - JSFunctionResultCache 80 // - JSFunctionResultCache
81 // - SerializedScopeInfo 81 // - ScopeInfo
82 // - FixedDoubleArray 82 // - FixedDoubleArray
83 // - ExternalArray 83 // - ExternalArray
84 // - ExternalPixelArray 84 // - ExternalPixelArray
85 // - ExternalByteArray 85 // - ExternalByteArray
86 // - ExternalUnsignedByteArray 86 // - ExternalUnsignedByteArray
87 // - ExternalShortArray 87 // - ExternalShortArray
88 // - ExternalUnsignedShortArray 88 // - ExternalUnsignedShortArray
89 // - ExternalIntArray 89 // - ExternalIntArray
90 // - ExternalUnsignedIntArray 90 // - ExternalUnsignedIntArray
91 // - ExternalFloatArray 91 // - ExternalFloatArray
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 V(JSObject) \ 807 V(JSObject) \
808 V(JSContextExtensionObject) \ 808 V(JSContextExtensionObject) \
809 V(Map) \ 809 V(Map) \
810 V(DescriptorArray) \ 810 V(DescriptorArray) \
811 V(DeoptimizationInputData) \ 811 V(DeoptimizationInputData) \
812 V(DeoptimizationOutputData) \ 812 V(DeoptimizationOutputData) \
813 V(FixedArray) \ 813 V(FixedArray) \
814 V(FixedDoubleArray) \ 814 V(FixedDoubleArray) \
815 V(Context) \ 815 V(Context) \
816 V(GlobalContext) \ 816 V(GlobalContext) \
817 V(SerializedScopeInfo) \ 817 V(ScopeInfo) \
818 V(JSFunction) \ 818 V(JSFunction) \
819 V(Code) \ 819 V(Code) \
820 V(Oddball) \ 820 V(Oddball) \
821 V(SharedFunctionInfo) \ 821 V(SharedFunctionInfo) \
822 V(JSValue) \ 822 V(JSValue) \
823 V(JSMessageObject) \ 823 V(JSMessageObject) \
824 V(StringWrapper) \ 824 V(StringWrapper) \
825 V(Foreign) \ 825 V(Foreign) \
826 V(Boolean) \ 826 V(Boolean) \
827 V(JSArray) \ 827 V(JSArray) \
(...skipping 2263 matching lines...) Expand 10 before | Expand all | Expand 10 after
3091 3091
3092 // Casting 3092 // Casting
3093 static inline JSFunctionResultCache* cast(Object* obj); 3093 static inline JSFunctionResultCache* cast(Object* obj);
3094 3094
3095 #ifdef DEBUG 3095 #ifdef DEBUG
3096 void JSFunctionResultCacheVerify(); 3096 void JSFunctionResultCacheVerify();
3097 #endif 3097 #endif
3098 }; 3098 };
3099 3099
3100 3100
3101 // ScopeInfo represents information about different scopes of a source
3102 // program and the allocation of the scope's variables. Scope information
3103 // is stored in a compressed form in ScopeInfo objects and is used
3104 // at runtime (stack dumps, deoptimization, etc.).
3105
3101 // This object provides quick access to scope info details for runtime 3106 // This object provides quick access to scope info details for runtime
3102 // routines w/o the need to explicitly create a ScopeInfo object. 3107 // routines.
3103 class SerializedScopeInfo : public FixedArray { 3108 class ScopeInfo : public FixedArray {
3104 public : 3109 public :
3105 static SerializedScopeInfo* cast(Object* object) { 3110 static inline ScopeInfo* cast(Object* object);
3106 ASSERT(object->IsSerializedScopeInfo());
3107 return reinterpret_cast<SerializedScopeInfo*>(object);
3108 }
3109 3111
3110 // Return the type of this scope. 3112 // Return the type of this scope.
3111 ScopeType Type(); 3113 ScopeType Type();
3112 3114
3113 // Does this scope call eval? 3115 // Does this scope call eval?
3114 bool CallsEval(); 3116 bool CallsEval();
3115 3117
3116 // Is this scope a strict mode scope? 3118 // Is this scope a strict mode scope?
3117 bool IsStrictMode(); 3119 bool IsStrictMode();
3118 3120
3119 // Return the number of stack slots for code. 3121 // Does this scope make a non-strict eval call?
3122 bool CallsNonStrictEval() {
3123 return CallsEval() && !IsStrictMode();
3124 }
3125
3126 // Return the total number of locals allocated on the stack and in the
3127 // context. This includes the parameters that are allocated in the context.
3128 int NumberOfLocals();
3129
3130 // Return the number of stack slots for code. This number consists of two
3131 // parts:
3132 // 1. One stack slot per stack allocated local.
3133 // 2. One stack slot for the function name if it is stack allocated.
3120 int NumberOfStackSlots(); 3134 int NumberOfStackSlots();
3121 3135
3122 // Return the number of context slots for code. 3136 // Return the number of context slots for code if a context is allocated. This
3123 int NumberOfContextSlots(); 3137 // number consists of three parts:
3138 // 1. Size of fixed header for every context: Context::MIN_CONTEXT_SLOTS
3139 // 2. One context slot per context allocated local.
3140 // 3. One context slot for the function name if it is context allocated.
3141 // Parameters allocated in the context count as context allocated locals. If
3142 // no contexts are allocated for this scope ContextLength returns 0.
3143 int ContextLength();
3124 3144
3125 // Return if this has context slots besides MIN_CONTEXT_SLOTS; 3145 // Is this scope the scope of a named function expression?
3146 bool HasFunctionName();
3147
3148 // Return if this has context allocated locals.
3126 bool HasHeapAllocatedLocals(); 3149 bool HasHeapAllocatedLocals();
3127 3150
3128 // Return if contexts are allocated for this scope. 3151 // Return if contexts are allocated for this scope.
3129 bool HasContext(); 3152 bool HasContext();
3130 3153
3154 // Return the function_name if present.
3155 String* FunctionName();
3156
3157 // Return the name of the given parameter.
3158 String* ParameterName(int var);
3159
3160 // Return the name of the given local.
3161 String* LocalName(int var);
3162
3163 // Return the name of the given stack local.
3164 String* StackLocalName(int var);
3165
3166 // Return the name of the given context local.
3167 String* ContextLocalName(int var);
3168
3169 // Return the mode of the given context local.
3170 VariableMode ContextLocalMode(int var);
3171
3131 // Lookup support for serialized scope info. Returns the 3172 // Lookup support for serialized scope info. Returns the
3132 // the stack slot index for a given slot name if the slot is 3173 // the stack slot index for a given slot name if the slot is
3133 // present; otherwise returns a value < 0. The name must be a symbol 3174 // present; otherwise returns a value < 0. The name must be a symbol
3134 // (canonicalized). 3175 // (canonicalized).
3135 int StackSlotIndex(String* name); 3176 int StackSlotIndex(String* name);
3136 3177
3137 // Lookup support for serialized scope info. Returns the 3178 // Lookup support for serialized scope info. Returns the
3138 // context slot index for a given slot name if the slot is present; otherwise 3179 // context slot index for a given slot name if the slot is present; otherwise
3139 // returns a value < 0. The name must be a symbol (canonicalized). 3180 // returns a value < 0. The name must be a symbol (canonicalized).
3140 // If the slot is present and mode != NULL, sets *mode to the corresponding 3181 // If the slot is present and mode != NULL, sets *mode to the corresponding
3141 // mode for that variable. 3182 // mode for that variable.
3142 int ContextSlotIndex(String* name, VariableMode* mode); 3183 int ContextSlotIndex(String* name, VariableMode* mode);
3143 3184
3144 // Lookup support for serialized scope info. Returns the 3185 // Lookup support for serialized scope info. Returns the
3145 // parameter index for a given parameter name if the parameter is present; 3186 // parameter index for a given parameter name if the parameter is present;
3146 // otherwise returns a value < 0. The name must be a symbol (canonicalized). 3187 // otherwise returns a value < 0. The name must be a symbol (canonicalized).
3147 int ParameterIndex(String* name); 3188 int ParameterIndex(String* name);
3148 3189
3149 // Lookup support for serialized scope info. Returns the 3190 // Lookup support for serialized scope info. Returns the
3150 // function context slot index if the function name is present (named 3191 // function context slot index if the function name is present (named
3151 // function expressions, only), otherwise returns a value < 0. The name 3192 // function expressions, only), otherwise returns a value < 0. The name
3152 // must be a symbol (canonicalized). 3193 // must be a symbol (canonicalized).
3153 int FunctionContextSlotIndex(String* name, VariableMode* mode); 3194 int FunctionContextSlotIndex(String* name, VariableMode* mode);
3154 3195
3155 static Handle<SerializedScopeInfo> Create(Scope* scope); 3196 static Handle<ScopeInfo> Create(Scope* scope);
3156 3197
3157 // Serializes empty scope info. 3198 // Serializes empty scope info.
3158 static SerializedScopeInfo* Empty(); 3199 static ScopeInfo* Empty();
3200
3201 #ifdef DEBUG
3202 void Print();
3203 #endif
3204
3205 // The layout of the static part of a ScopeInfo is as follows. Each entry is
3206 // numeric and occupies one array slot.
3207 // 1. A set of properties of the scope
3208 // 2. The number of parameters. This only applies to function scopes. For
3209 // non-function scopes this is 0.
3210 // 3. The number of non-parameter variables allocated on the stack.
3211 // 4. The number of non-parameter and parameter variables allocated in the
3212 // context.
3213 #define FOR_EACH_NUMERIC_FIELD(V) \
3214 V(Flags) \
3215 V(NumParameters) \
3216 V(NumStackLocals) \
3217 V(NumContextLocals)
3218
3219 #define FIELD_ACCESSORS(name) \
3220 void Set##name(int value) { \
3221 set(k##name, Smi::FromInt(value)); \
3222 } \
3223 int name() { \
3224 if (length() > 0) { \
3225 return Smi::cast(get(k##name))->value(); \
3226 } else { \
3227 return 0; \
3228 } \
3229 }
3230 FOR_EACH_NUMERIC_FIELD(FIELD_ACCESSORS)
3231 #undef FIELD_ACCESSORS
3159 3232
3160 private: 3233 private:
3161 Object** ContextEntriesAddr(); 3234 enum {
3235 #define DECL_INDEX(name) k##name,
3236 FOR_EACH_NUMERIC_FIELD(DECL_INDEX)
3237 #undef DECL_INDEX
3238 #undef FOR_EACH_NUMERIC_FIELD
3239 kVariablePartIndex
3240 };
3162 3241
3163 Object** ParameterEntriesAddr(); 3242 // The layout of the variable part of a ScopeInfo is as follows:
3243 // 1. ParameterEntries:
3244 // This part stores the names of the parameters for function scopes. One
3245 // slot is used per parameter, so in total this part occupies
3246 // NumParameters() slots in the array. For other scopes than function
3247 // scopes NumParameters() is 0.
3248 // 2. StackLocalEntries:
3249 // Contains the names of local variables that are allocated on the stack,
3250 // in increasing order of the stack slot index. One slot is used per
3251 // stack local, so in total this part occupies NumStackLocals() slots
3252 // in the array.
3253 // 3. ContextLocalNameEntries:
3254 // Contains the names of local variables and parameters that are allocated
3255 // in the context. They are stored in increasing order of the context slot
3256 // index starting with Context::MIN_CONTEXT_SLOTS. One slot is used per
3257 // context local, so in total this part occupies NumContextLocals()
3258 // slots in the array.
3259 // 4. ContextLocalModeEntries:
3260 // Contains the variable modes corresponding to the context locals in
3261 // ContextLocalNameEntries. One slot is used per context local, so in total
3262 // this part occupies NumContextLocals() slots in the array.
3263 // 5. FunctionNameEntryIndex:
3264 // If the scope belongs to a named function expression this part contains
3265 // information about the function variable. It always occupies two array
3266 // slots: a. The name of the function variable.
3267 // b. The context or stack slot index for the variable.
3268 int ParameterEntriesIndex();
3269 int StackLocalEntriesIndex();
3270 int ContextLocalNameEntriesIndex();
3271 int ContextLocalModeEntriesIndex();
3272 int FunctionNameEntryIndex();
3164 3273
3165 Object** StackSlotEntriesAddr(); 3274 // Location of the function variable for named function expressions.
3275 enum FunctionVariableInfo {
3276 NONE, // No function name present.
3277 STACK, // Function
3278 CONTEXT,
3279 UNUSED
3280 };
3281
3282 // Properties of scopes.
3283 class TypeField: public BitField<ScopeType, 0, 3> {};
3284 class CallsEvalField: public BitField<bool, 3, 1> {};
3285 class StrictModeField: public BitField<bool, 4, 1> {};
3286 class FunctionVariableField: public BitField<FunctionVariableInfo, 5, 2> {};
3287 class FunctionVariableMode: public BitField<VariableMode, 7, 3> {};
3166 }; 3288 };
3167 3289
3168 3290
3169 // The cache for maps used by normalized (dictionary mode) objects. 3291 // The cache for maps used by normalized (dictionary mode) objects.
3170 // Such maps do not have property descriptors, so a typical program 3292 // Such maps do not have property descriptors, so a typical program
3171 // needs very limited number of distinct normalized maps. 3293 // needs very limited number of distinct normalized maps.
3172 class NormalizedMapCache: public FixedArray { 3294 class NormalizedMapCache: public FixedArray {
3173 public: 3295 public:
3174 static const int kEntries = 64; 3296 static const int kEntries = 64;
3175 3297
(...skipping 1502 matching lines...) Expand 10 before | Expand all | Expand 10 after
4678 // shared by multiple instances of the function. 4800 // shared by multiple instances of the function.
4679 class SharedFunctionInfo: public HeapObject { 4801 class SharedFunctionInfo: public HeapObject {
4680 public: 4802 public:
4681 // [name]: Function name. 4803 // [name]: Function name.
4682 DECL_ACCESSORS(name, Object) 4804 DECL_ACCESSORS(name, Object)
4683 4805
4684 // [code]: Function code. 4806 // [code]: Function code.
4685 DECL_ACCESSORS(code, Code) 4807 DECL_ACCESSORS(code, Code)
4686 4808
4687 // [scope_info]: Scope info. 4809 // [scope_info]: Scope info.
4688 DECL_ACCESSORS(scope_info, SerializedScopeInfo) 4810 DECL_ACCESSORS(scope_info, ScopeInfo)
4689 4811
4690 // [construct stub]: Code stub for constructing instances of this function. 4812 // [construct stub]: Code stub for constructing instances of this function.
4691 DECL_ACCESSORS(construct_stub, Code) 4813 DECL_ACCESSORS(construct_stub, Code)
4692 4814
4693 inline Code* unchecked_code(); 4815 inline Code* unchecked_code();
4694 4816
4695 // Returns if this function has been compiled to native code yet. 4817 // Returns if this function has been compiled to native code yet.
4696 inline bool is_compiled(); 4818 inline bool is_compiled();
4697 4819
4698 // [length]: The function length - usually the number of declared parameters. 4820 // [length]: The function length - usually the number of declared parameters.
(...skipping 3107 matching lines...) Expand 10 before | Expand all | Expand 10 after
7806 } else { 7928 } else {
7807 value &= ~(1 << bit_position); 7929 value &= ~(1 << bit_position);
7808 } 7930 }
7809 return value; 7931 return value;
7810 } 7932 }
7811 }; 7933 };
7812 7934
7813 } } // namespace v8::internal 7935 } } // namespace v8::internal
7814 7936
7815 #endif // V8_OBJECTS_H_ 7937 #endif // V8_OBJECTS_H_
OLDNEW
« src/frames.cc ('K') | « src/liveedit.cc ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698