Index: src/objects.h |
diff --git a/src/objects.h b/src/objects.h |
index 3187467b380a9cde1d4355ea007238fb1075e317..021ad4cc76fcad76c3e847d6804120fdd3c5068f 100644 |
--- a/src/objects.h |
+++ b/src/objects.h |
@@ -78,7 +78,7 @@ |
// - MapCache |
// - Context |
// - JSFunctionResultCache |
-// - SerializedScopeInfo |
+// - ScopeInfo |
// - FixedDoubleArray |
// - ExternalArray |
// - ExternalPixelArray |
@@ -814,7 +814,7 @@ class MaybeObject BASE_EMBEDDED { |
V(FixedDoubleArray) \ |
V(Context) \ |
V(GlobalContext) \ |
- V(SerializedScopeInfo) \ |
+ V(ScopeInfo) \ |
V(JSFunction) \ |
V(Code) \ |
V(Oddball) \ |
@@ -3098,13 +3098,19 @@ class JSFunctionResultCache: public FixedArray { |
}; |
+// ScopeInfo represents information about different scopes of a source |
+// program and the allocation of the scope's variables. Scope information |
+// is stored in a compressed form in ScopeInfo objects and is used |
+// at runtime (stack dumps, deoptimization, etc.). |
+ |
// This object provides quick access to scope info details for runtime |
-// routines w/o the need to explicitly create a ScopeInfo object. |
-class SerializedScopeInfo : public FixedArray { |
+// routines. |
+class ScopeInfo : public FixedArray { |
public : |
- static SerializedScopeInfo* cast(Object* object) { |
- ASSERT(object->IsSerializedScopeInfo()); |
- return reinterpret_cast<SerializedScopeInfo*>(object); |
+ |
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
|
+ 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.
|
+ ASSERT(object->IsScopeInfo()); |
+ return reinterpret_cast<ScopeInfo*>(object); |
} |
// Return the type of this scope. |
@@ -3116,18 +3122,57 @@ class SerializedScopeInfo : public FixedArray { |
// Is this scope a strict mode scope? |
bool IsStrictMode(); |
- // Return the number of stack slots for code. |
+ // Does this scope make a non-strict eval call? |
+ bool CallsNonStrictEval() { |
+ return CallsEval() && !IsStrictMode(); |
+ } |
+ |
+ // Return the total number of locals allocated on the stack and in the |
+ // context. This includes the parameters that are allocated in the context. |
+ int NumberOfLocals(); |
+ |
+ // Return the number of stack slots for code. This number consists of two |
+ // parts: |
+ // 1. One stack slot per stack allocated local. |
+ // 2. One stack slot for the function name if it is stack allocated. |
int NumberOfStackSlots(); |
- // Return the number of context slots for code. |
+ // Return the number of context slots for code if a context is allocated. This |
+ // number consists of three parts: |
+ // 1. Size of fixed header for every context: Context::MIN_CONTEXT_SLOTS |
+ // 2. One context slot per context allocated local. |
+ // 3. One context slot for the function name if it is context allocated. |
+ // Parameters allocated in the context count as context allocated locals. If |
+ // no contexts are allocated for this scope NumberOfContextSlots returns 0. |
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
|
- // Return if this has context slots besides MIN_CONTEXT_SLOTS; |
+ // Is this scope the scope of a named function expression? |
+ bool HasFunctionName(); |
+ |
+ // Return if this has context allocated locals. |
bool HasHeapAllocatedLocals(); |
// Return if contexts are allocated for this scope. |
bool HasContext(); |
+ // Return the function_name if present. |
+ 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.
|
+ |
+ // Return the name of the given parameter. |
+ Handle<String> parameter_name(int var); |
+ |
+ // Return the name of the given local. |
+ Handle<String> local_name(int var); |
+ |
+ // Return the name of the given stack local. |
+ Handle<String> stack_local_name(int var); |
+ |
+ // Return the name of the given context local. |
+ Handle<String> context_local_name(int var); |
+ |
+ // Return the mode of the given context local. |
+ VariableMode context_local_mode(int var); |
+ |
// Lookup support for serialized scope info. Returns the |
// the stack slot index for a given slot name if the slot is |
// present; otherwise returns a value < 0. The name must be a symbol |
@@ -3139,7 +3184,7 @@ class SerializedScopeInfo : public FixedArray { |
// returns a value < 0. The name must be a symbol (canonicalized). |
// If the slot is present and mode != NULL, sets *mode to the corresponding |
// mode for that variable. |
- int ContextSlotIndex(String* name, VariableMode* mode); |
+ 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.
|
// Lookup support for serialized scope info. Returns the |
// parameter index for a given parameter name if the parameter is present; |
@@ -3152,17 +3197,95 @@ class SerializedScopeInfo : public FixedArray { |
// must be a symbol (canonicalized). |
int FunctionContextSlotIndex(String* name, VariableMode* mode); |
- static Handle<SerializedScopeInfo> Create(Scope* scope); |
+ static Handle<ScopeInfo> Create(Scope* scope); |
// Serializes empty scope info. |
- static SerializedScopeInfo* Empty(); |
+ static ScopeInfo* Empty(); |
- private: |
- Object** ContextEntriesAddr(); |
+#ifdef DEBUG |
+ void Print(); |
+#endif |
+ |
+#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
|
+ V(FLAGS_INDEX, flags, 0) \ |
+ V(NUM_PARAMETERS_INDEX, num_parameters, 0) \ |
+ V(NUM_STACK_LOCALS_INDEX, num_stack_locals, 0) \ |
+ V(NUM_CONTEXT_LOCALS_INDEX, num_context_locals, 0) |
+ |
+#define SCOPE_INFO_NUMERIC_FIELD_ACCESSORS(index, name, default) \ |
+ void set_##name(int value) { \ |
+ set(index, Smi::FromInt(value)); \ |
+ } \ |
+ int name() { \ |
+ if (length() > 0) { \ |
+ return Smi::cast(get(index))->value(); \ |
+ } else { \ |
+ return default; \ |
+ } \ |
+ } |
+ SCOPE_INFO_NUMERIC_FIELDS(SCOPE_INFO_NUMERIC_FIELD_ACCESSORS) |
+#undef SCOPE_INFO_NUMERIC_FIELD_ACCESSORS |
- Object** ParameterEntriesAddr(); |
+ // Layout description of the fixed part of a ScopeInfo. |
+ 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.
|
+ FLAGS_INDEX, |
+ // The number of parameters for the function. |
+ NUM_PARAMETERS_INDEX, |
+ // The number of non-parameter variables allocated on the stack. |
+ NUM_STACK_LOCALS_INDEX, |
+ // The number of non-parameter and parameter variables |
+ // allocated in the context. |
+ NUM_CONTEXT_LOCALS_INDEX, |
+ // Beginning of variable sized part of ScopeInfo. |
+ VARIABLE_PART_INDEX |
+ }; |
+ |
+ // The layout of the variable part of a ScopeInfo is as follows: |
+ // 1. ParameterEntries: |
+ // This part stores the names of the parameters for function scopes. One |
+ // slot is used per parameter, so in total this part occupies |
+ // num_parameters() slots in the array. For other scopes than function |
+ // scopes num_parameters() is 0. |
+ // 2. StackLocalEntries: |
+ // Contains the names of local variables that are allocated on the stack, |
+ // in increasing order of the stack slot index. One slot is used per |
+ // stack local, so in total this part occupies num_stack_locals() slots |
+ // in the array. |
+ // 3. ContextLocalNameEntries: |
+ // Contains the names of local variables and parameters that are allocated |
+ // in the context. They are stored in increasing order of the context slot |
+ // index starting with Context::MIN_CONTEXT_SLOTS. One slot is used per |
+ // context local, so in total this part occupies num_context_locals() |
+ // slots in the array. |
+ // 4. ContextLocalModeEntries: |
+ // Contains the variable modes corresponding to the context locals in |
+ // ContextLocalNameEntries. One slot is used per context local, so in total |
+ // this part occupies num_context_locals() slots in the array. |
+ // 5. FunctionNameEntryIndex: |
+ // If the scope belongs to a named function expression this part contains |
+ // information about the function variable. It always occupies two array |
+ // slots: a. The name of the function variable. |
+ // b. The context or stack slot index for the variable. |
+ int ParameterEntriesIndex(); |
+ int StackLocalEntriesIndex(); |
+ int ContextLocalNameEntriesIndex(); |
+ int ContextLocalModeEntriesIndex(); |
+ int FunctionNameEntryIndex(); |
+ |
+ // Location of the function variable for named function expressions. |
+ enum FunctionVariableInfo { |
+ NONE, // No function name present. |
+ STACK, // Function |
+ CONTEXT, |
+ UNUSED |
+ }; |
- Object** StackSlotEntriesAddr(); |
+ // Properties of scopes. |
+ class TypeField: public BitField<ScopeType, 0, 3> {}; |
+ class CallsEvalField: public BitField<bool, 3, 1> {}; |
+ class StrictModeField: public BitField<bool, 4, 1> {}; |
+ class FunctionVariableField: public BitField<FunctionVariableInfo, 5, 2> {}; |
+ class FunctionVariableMode: public BitField<VariableMode, 7, 3> {}; |
}; |
@@ -4685,7 +4808,7 @@ class SharedFunctionInfo: public HeapObject { |
DECL_ACCESSORS(code, Code) |
// [scope_info]: Scope info. |
- DECL_ACCESSORS(scope_info, SerializedScopeInfo) |
+ DECL_ACCESSORS(scope_info, ScopeInfo) |
// [construct stub]: Code stub for constructing instances of this function. |
DECL_ACCESSORS(construct_stub, Code) |