54
54
// Create a ScopeInfo instance from a scope.
55
55
explicit ScopeInfo(Scope* scope);
57
// Create a ScopeInfo instance from a Code object.
58
explicit ScopeInfo(Code* code);
60
// Write the ScopeInfo data into a Code object, and returns the
61
// amount of space that was needed. If no Code object is provided
62
// (NULL handle), Serialize() only returns the amount of space needed.
64
// This operations requires that the Code object has the correct amount
65
// of space for the ScopeInfo data; otherwise the operation fails (fatal
66
// error). Any existing scope info in the Code object is simply overwritten.
67
int Serialize(Code* code);
69
// Garbage collection support for scope info embedded in Code objects.
70
// This code is in ScopeInfo because only here we should have to know
71
// about the encoding.
72
static void IterateScopeInfo(Code* code, ObjectVisitor* v);
57
// Create a ScopeInfo instance from SerializedScopeInfo.
58
explicit ScopeInfo(SerializedScopeInfo* data);
60
// Creates a SerializedScopeInfo holding the serialized scope info.
61
Handle<SerializedScopeInfo> Serialize();
75
63
// --------------------------------------------------------------------------
95
83
int NumberOfLocals() const;
97
85
// --------------------------------------------------------------------------
98
// The following functions provide quick access to scope info details
99
// for runtime routines w/o the need to explicitly create a ScopeInfo
102
// ScopeInfo is the only class which should have to know about the
103
// encoding of it's information in a Code object, which is why these
104
// functions are in this class.
93
Handle<String> function_name_;
95
List<Handle<String>, Allocator > parameters_;
96
List<Handle<String>, Allocator > stack_slots_;
97
List<Handle<String>, Allocator > context_slots_;
98
List<Variable::Mode, Allocator > context_modes_;
102
// This object provides quick access to scope info details for runtime
103
// routines w/o the need to explicitly create a ScopeInfo object.
104
class SerializedScopeInfo : public FixedArray {
107
static SerializedScopeInfo* cast(Object* object) {
108
ASSERT(object->IsFixedArray());
109
return reinterpret_cast<SerializedScopeInfo*>(object);
106
112
// Does this scope call eval.
107
static bool CallsEval(Code* code);
109
115
// Return the number of stack slots for code.
110
static int NumberOfStackSlots(Code* code);
116
int NumberOfStackSlots();
112
118
// Return the number of context slots for code.
113
static int NumberOfContextSlots(Code* code);
115
// Lookup support for scope info embedded in Code objects. Returns
119
int NumberOfContextSlots();
121
// Return if this has context slots besides MIN_CONTEXT_SLOTS;
122
bool HasHeapAllocatedLocals();
124
// Lookup support for serialized scope info. Returns the
116
125
// the stack slot index for a given slot name if the slot is
117
126
// present; otherwise returns a value < 0. The name must be a symbol
118
127
// (canonicalized).
119
static int StackSlotIndex(Code* code, String* name);
128
int StackSlotIndex(String* name);
121
// Lookup support for scope info embedded in Code objects. Returns the
130
// Lookup support for serialized scope info. Returns the
122
131
// context slot index for a given slot name if the slot is present; otherwise
123
132
// returns a value < 0. The name must be a symbol (canonicalized).
124
133
// If the slot is present and mode != NULL, sets *mode to the corresponding
125
134
// mode for that variable.
126
static int ContextSlotIndex(Code* code, String* name, Variable::Mode* mode);
135
int ContextSlotIndex(String* name, Variable::Mode* mode);
128
// Lookup support for scope info embedded in Code objects. Returns the
137
// Lookup support for serialized scope info. Returns the
129
138
// parameter index for a given parameter name if the parameter is present;
130
139
// otherwise returns a value < 0. The name must be a symbol (canonicalized).
131
static int ParameterIndex(Code* code, String* name);
140
int ParameterIndex(String* name);
133
// Lookup support for scope info embedded in Code objects. Returns the
142
// Lookup support for serialized scope info. Returns the
134
143
// function context slot index if the function name is present (named
135
144
// function expressions, only), otherwise returns a value < 0. The name
136
145
// must be a symbol (canonicalized).
137
static int FunctionContextSlotIndex(Code* code, String* name);
139
// --------------------------------------------------------------------------
146
int FunctionContextSlotIndex(String* name);
148
static Handle<SerializedScopeInfo> Create(Scope* scope);
150
// Serializes empty scope info.
151
static SerializedScopeInfo* Empty();
147
Handle<String> function_name_;
149
List<Handle<String>, Allocator > parameters_;
150
List<Handle<String>, Allocator > stack_slots_;
151
List<Handle<String>, Allocator > context_slots_;
152
List<Variable::Mode, Allocator > context_modes_;
155
class ZoneScopeInfo: public ScopeInfo<ZoneListAllocationPolicy> {
157
// Create a ZoneScopeInfo instance from a scope.
158
explicit ZoneScopeInfo(Scope* scope)
159
: ScopeInfo<ZoneListAllocationPolicy>(scope) {}
161
// Create a ZoneScopeInfo instance from a Code object.
162
explicit ZoneScopeInfo(Code* code)
163
: ScopeInfo<ZoneListAllocationPolicy>(code) {}
167
// Cache for mapping (code, property name) into context slot index.
155
inline Object** ContextEntriesAddr();
157
inline Object** ParameterEntriesAddr();
159
inline Object** StackSlotEntriesAddr();
163
// Cache for mapping (data, property name) into context slot index.
168
164
// The cache contains both positive and negative results.
169
165
// Slot index equals -1 means the property is absent.
170
166
// Cleared at startup and prior to mark sweep collection.
171
167
class ContextSlotCache {
173
// Lookup context slot index for (code, name).
169
// Lookup context slot index for (data, name).
174
170
// If absent, kNotFound is returned.
175
static int Lookup(Code* code,
171
static int Lookup(Object* data,
177
173
Variable::Mode* mode);
179
175
// Update an element in the cache.
180
static void Update(Code* code,
176
static void Update(Object* data,
182
178
Variable::Mode mode,