OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 |
Kevin Millikin (Chromium)
2011/11/02 16:31:19
Presubmit check is not going to like this extra bl
Steven
2011/11/02 18:52:59
tools/presubmit.py didn't complain. Maybe it shoul
Kevin Millikin (Chromium)
2011/11/03 09:18:37
I'm pretty sure the one from Chromium's depot_tool
| |
3106 ASSERT(object->IsSerializedScopeInfo()); | 3111 static ScopeInfo* cast(Object* object) { |
Kevin Millikin (Chromium)
2011/11/02 16:31:19
We normally do this this way:
in objects.h:
stat
Steven
2011/11/02 18:52:59
Done.
| |
3107 return reinterpret_cast<SerializedScopeInfo*>(object); | 3112 ASSERT(object->IsScopeInfo()); |
3113 return reinterpret_cast<ScopeInfo*>(object); | |
3108 } | 3114 } |
3109 | 3115 |
3110 // Return the type of this scope. | 3116 // Return the type of this scope. |
3111 ScopeType Type(); | 3117 ScopeType Type(); |
3112 | 3118 |
3113 // Does this scope call eval? | 3119 // Does this scope call eval? |
3114 bool CallsEval(); | 3120 bool CallsEval(); |
3115 | 3121 |
3116 // Is this scope a strict mode scope? | 3122 // Is this scope a strict mode scope? |
3117 bool IsStrictMode(); | 3123 bool IsStrictMode(); |
3118 | 3124 |
3119 // Return the number of stack slots for code. | 3125 // Does this scope make a non-strict eval call? |
3126 bool CallsNonStrictEval() { | |
3127 return CallsEval() && !IsStrictMode(); | |
3128 } | |
3129 | |
3130 // Return the total number of locals allocated on the stack and in the | |
3131 // context. This includes the parameters that are allocated in the context. | |
3132 int NumberOfLocals(); | |
3133 | |
3134 // Return the number of stack slots for code. This number consists of two | |
3135 // parts: | |
3136 // 1. One stack slot per stack allocated local. | |
3137 // 2. One stack slot for the function name if it is stack allocated. | |
3120 int NumberOfStackSlots(); | 3138 int NumberOfStackSlots(); |
3121 | 3139 |
3122 // Return the number of context slots for code. | 3140 // Return the number of context slots for code if a context is allocated. This |
3141 // number consists of three parts: | |
3142 // 1. Size of fixed header for every context: Context::MIN_CONTEXT_SLOTS | |
3143 // 2. One context slot per context allocated local. | |
3144 // 3. One context slot for the function name if it is context allocated. | |
3145 // Parameters allocated in the context count as context allocated locals. If | |
3146 // no contexts are allocated for this scope NumberOfContextSlots returns 0. | |
3123 int NumberOfContextSlots(); | 3147 int NumberOfContextSlots(); |
Kevin Millikin (Chromium)
2011/11/02 16:31:19
I've always found it a bit confusing to count the
Steven
2011/11/02 18:52:59
Renamed it to ContextLength.
On 2011/11/02 16:31:1
| |
3124 | 3148 |
3125 // Return if this has context slots besides MIN_CONTEXT_SLOTS; | 3149 // Is this scope the scope of a named function expression? |
3150 bool HasFunctionName(); | |
3151 | |
3152 // Return if this has context allocated locals. | |
3126 bool HasHeapAllocatedLocals(); | 3153 bool HasHeapAllocatedLocals(); |
3127 | 3154 |
3128 // Return if contexts are allocated for this scope. | 3155 // Return if contexts are allocated for this scope. |
3129 bool HasContext(); | 3156 bool HasContext(); |
3130 | 3157 |
3158 // Return the function_name if present. | |
3159 Handle<String> function_name(); | |
Kevin Millikin (Chromium)
2011/11/02 16:31:19
There's a strange mix of hacker_style and CamelCas
Steven
2011/11/02 18:52:59
Done.
| |
3160 | |
3161 // Return the name of the given parameter. | |
3162 Handle<String> parameter_name(int var); | |
3163 | |
3164 // Return the name of the given local. | |
3165 Handle<String> local_name(int var); | |
3166 | |
3167 // Return the name of the given stack local. | |
3168 Handle<String> stack_local_name(int var); | |
3169 | |
3170 // Return the name of the given context local. | |
3171 Handle<String> context_local_name(int var); | |
3172 | |
3173 // Return the mode of the given context local. | |
3174 VariableMode context_local_mode(int var); | |
3175 | |
3131 // Lookup support for serialized scope info. Returns the | 3176 // Lookup support for serialized scope info. Returns the |
3132 // the stack slot index for a given slot name if the slot is | 3177 // 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 | 3178 // present; otherwise returns a value < 0. The name must be a symbol |
3134 // (canonicalized). | 3179 // (canonicalized). |
3135 int StackSlotIndex(String* name); | 3180 int StackSlotIndex(String* name); |
3136 | 3181 |
3137 // Lookup support for serialized scope info. Returns the | 3182 // Lookup support for serialized scope info. Returns the |
3138 // context slot index for a given slot name if the slot is present; otherwise | 3183 // 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). | 3184 // 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 | 3185 // If the slot is present and mode != NULL, sets *mode to the corresponding |
3141 // mode for that variable. | 3186 // mode for that variable. |
3142 int ContextSlotIndex(String* name, VariableMode* mode); | 3187 int ContextSlotIndex(String* name, VariableMode* mode = NULL); |
Kevin Millikin (Chromium)
2011/11/02 16:31:19
I'm not thrilled with the default parameter. It d
Steven
2011/11/02 18:52:59
Done.
| |
3143 | 3188 |
3144 // Lookup support for serialized scope info. Returns the | 3189 // Lookup support for serialized scope info. Returns the |
3145 // parameter index for a given parameter name if the parameter is present; | 3190 // 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). | 3191 // otherwise returns a value < 0. The name must be a symbol (canonicalized). |
3147 int ParameterIndex(String* name); | 3192 int ParameterIndex(String* name); |
3148 | 3193 |
3149 // Lookup support for serialized scope info. Returns the | 3194 // Lookup support for serialized scope info. Returns the |
3150 // function context slot index if the function name is present (named | 3195 // function context slot index if the function name is present (named |
3151 // function expressions, only), otherwise returns a value < 0. The name | 3196 // function expressions, only), otherwise returns a value < 0. The name |
3152 // must be a symbol (canonicalized). | 3197 // must be a symbol (canonicalized). |
3153 int FunctionContextSlotIndex(String* name, VariableMode* mode); | 3198 int FunctionContextSlotIndex(String* name, VariableMode* mode); |
3154 | 3199 |
3155 static Handle<SerializedScopeInfo> Create(Scope* scope); | 3200 static Handle<ScopeInfo> Create(Scope* scope); |
3156 | 3201 |
3157 // Serializes empty scope info. | 3202 // Serializes empty scope info. |
3158 static SerializedScopeInfo* Empty(); | 3203 static ScopeInfo* Empty(); |
3159 | 3204 |
3160 private: | 3205 #ifdef DEBUG |
3161 Object** ContextEntriesAddr(); | 3206 void Print(); |
3207 #endif | |
3162 | 3208 |
3163 Object** ParameterEntriesAddr(); | 3209 #define SCOPE_INFO_NUMERIC_FIELDS(V) \ |
Kevin Millikin (Chromium)
2011/11/02 16:31:19
OK to use a macro to generate these, but there's n
Steven
2011/11/02 18:52:59
Kept the higher order macro but now it generates t
| |
3210 V(FLAGS_INDEX, flags, 0) \ | |
3211 V(NUM_PARAMETERS_INDEX, num_parameters, 0) \ | |
3212 V(NUM_STACK_LOCALS_INDEX, num_stack_locals, 0) \ | |
3213 V(NUM_CONTEXT_LOCALS_INDEX, num_context_locals, 0) | |
3164 | 3214 |
3165 Object** StackSlotEntriesAddr(); | 3215 #define SCOPE_INFO_NUMERIC_FIELD_ACCESSORS(index, name, default) \ |
3216 void set_##name(int value) { \ | |
3217 set(index, Smi::FromInt(value)); \ | |
3218 } \ | |
3219 int name() { \ | |
3220 if (length() > 0) { \ | |
3221 return Smi::cast(get(index))->value(); \ | |
3222 } else { \ | |
3223 return default; \ | |
3224 } \ | |
3225 } | |
3226 SCOPE_INFO_NUMERIC_FIELDS(SCOPE_INFO_NUMERIC_FIELD_ACCESSORS) | |
3227 #undef SCOPE_INFO_NUMERIC_FIELD_ACCESSORS | |
3228 | |
3229 // Layout description of the fixed part of a ScopeInfo. | |
3230 enum { | |
Kevin Millikin (Chromium)
2011/11/02 16:31:19
Or, you could keep the higher-order macro, and use
Steven
2011/11/02 18:52:59
Done.
| |
3231 FLAGS_INDEX, | |
3232 // The number of parameters for the function. | |
3233 NUM_PARAMETERS_INDEX, | |
3234 // The number of non-parameter variables allocated on the stack. | |
3235 NUM_STACK_LOCALS_INDEX, | |
3236 // The number of non-parameter and parameter variables | |
3237 // allocated in the context. | |
3238 NUM_CONTEXT_LOCALS_INDEX, | |
3239 // Beginning of variable sized part of ScopeInfo. | |
3240 VARIABLE_PART_INDEX | |
3241 }; | |
3242 | |
3243 // The layout of the variable part of a ScopeInfo is as follows: | |
3244 // 1. ParameterEntries: | |
3245 // This part stores the names of the parameters for function scopes. One | |
3246 // slot is used per parameter, so in total this part occupies | |
3247 // num_parameters() slots in the array. For other scopes than function | |
3248 // scopes num_parameters() is 0. | |
3249 // 2. StackLocalEntries: | |
3250 // Contains the names of local variables that are allocated on the stack, | |
3251 // in increasing order of the stack slot index. One slot is used per | |
3252 // stack local, so in total this part occupies num_stack_locals() slots | |
3253 // in the array. | |
3254 // 3. ContextLocalNameEntries: | |
3255 // Contains the names of local variables and parameters that are allocated | |
3256 // in the context. They are stored in increasing order of the context slot | |
3257 // index starting with Context::MIN_CONTEXT_SLOTS. One slot is used per | |
3258 // context local, so in total this part occupies num_context_locals() | |
3259 // slots in the array. | |
3260 // 4. ContextLocalModeEntries: | |
3261 // Contains the variable modes corresponding to the context locals in | |
3262 // ContextLocalNameEntries. One slot is used per context local, so in total | |
3263 // this part occupies num_context_locals() slots in the array. | |
3264 // 5. FunctionNameEntryIndex: | |
3265 // If the scope belongs to a named function expression this part contains | |
3266 // information about the function variable. It always occupies two array | |
3267 // slots: a. The name of the function variable. | |
3268 // b. The context or stack slot index for the variable. | |
3269 int ParameterEntriesIndex(); | |
3270 int StackLocalEntriesIndex(); | |
3271 int ContextLocalNameEntriesIndex(); | |
3272 int ContextLocalModeEntriesIndex(); | |
3273 int FunctionNameEntryIndex(); | |
3274 | |
3275 // Location of the function variable for named function expressions. | |
3276 enum FunctionVariableInfo { | |
3277 NONE, // No function name present. | |
3278 STACK, // Function | |
3279 CONTEXT, | |
3280 UNUSED | |
3281 }; | |
3282 | |
3283 // Properties of scopes. | |
3284 class TypeField: public BitField<ScopeType, 0, 3> {}; | |
3285 class CallsEvalField: public BitField<bool, 3, 1> {}; | |
3286 class StrictModeField: public BitField<bool, 4, 1> {}; | |
3287 class FunctionVariableField: public BitField<FunctionVariableInfo, 5, 2> {}; | |
3288 class FunctionVariableMode: public BitField<VariableMode, 7, 3> {}; | |
3166 }; | 3289 }; |
3167 | 3290 |
3168 | 3291 |
3169 // The cache for maps used by normalized (dictionary mode) objects. | 3292 // The cache for maps used by normalized (dictionary mode) objects. |
3170 // Such maps do not have property descriptors, so a typical program | 3293 // Such maps do not have property descriptors, so a typical program |
3171 // needs very limited number of distinct normalized maps. | 3294 // needs very limited number of distinct normalized maps. |
3172 class NormalizedMapCache: public FixedArray { | 3295 class NormalizedMapCache: public FixedArray { |
3173 public: | 3296 public: |
3174 static const int kEntries = 64; | 3297 static const int kEntries = 64; |
3175 | 3298 |
(...skipping 1502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4678 // shared by multiple instances of the function. | 4801 // shared by multiple instances of the function. |
4679 class SharedFunctionInfo: public HeapObject { | 4802 class SharedFunctionInfo: public HeapObject { |
4680 public: | 4803 public: |
4681 // [name]: Function name. | 4804 // [name]: Function name. |
4682 DECL_ACCESSORS(name, Object) | 4805 DECL_ACCESSORS(name, Object) |
4683 | 4806 |
4684 // [code]: Function code. | 4807 // [code]: Function code. |
4685 DECL_ACCESSORS(code, Code) | 4808 DECL_ACCESSORS(code, Code) |
4686 | 4809 |
4687 // [scope_info]: Scope info. | 4810 // [scope_info]: Scope info. |
4688 DECL_ACCESSORS(scope_info, SerializedScopeInfo) | 4811 DECL_ACCESSORS(scope_info, ScopeInfo) |
4689 | 4812 |
4690 // [construct stub]: Code stub for constructing instances of this function. | 4813 // [construct stub]: Code stub for constructing instances of this function. |
4691 DECL_ACCESSORS(construct_stub, Code) | 4814 DECL_ACCESSORS(construct_stub, Code) |
4692 | 4815 |
4693 inline Code* unchecked_code(); | 4816 inline Code* unchecked_code(); |
4694 | 4817 |
4695 // Returns if this function has been compiled to native code yet. | 4818 // Returns if this function has been compiled to native code yet. |
4696 inline bool is_compiled(); | 4819 inline bool is_compiled(); |
4697 | 4820 |
4698 // [length]: The function length - usually the number of declared parameters. | 4821 // [length]: The function length - usually the number of declared parameters. |
(...skipping 3107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7806 } else { | 7929 } else { |
7807 value &= ~(1 << bit_position); | 7930 value &= ~(1 << bit_position); |
7808 } | 7931 } |
7809 return value; | 7932 return value; |
7810 } | 7933 } |
7811 }; | 7934 }; |
7812 | 7935 |
7813 } } // namespace v8::internal | 7936 } } // namespace v8::internal |
7814 | 7937 |
7815 #endif // V8_OBJECTS_H_ | 7938 #endif // V8_OBJECTS_H_ |
OLD | NEW |