~ubuntu-branches/ubuntu/precise/nodejs/precise

« back to all changes in this revision

Viewing changes to deps/v8/src/scopeinfo.h

  • Committer: Bazaar Package Importer
  • Author(s): Jérémy Lal
  • Date: 2010-08-20 11:49:04 UTC
  • mfrom: (7.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20100820114904-lz22w6fkth7yh179
Tags: 0.2.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
// Scope information represents information about a functions's
38
38
// scopes (currently only one, because we don't do any inlining)
39
39
// and the allocation of the scope's variables. Scope information
40
 
// is stored in a compressed form with Code objects and is used
 
40
// is stored in a compressed form in FixedArray objects and is used
41
41
// at runtime (stack dumps, deoptimization, etc.).
42
42
//
43
43
// Historical note: In other VMs built by this team, ScopeInfo was
54
54
  // Create a ScopeInfo instance from a scope.
55
55
  explicit ScopeInfo(Scope* scope);
56
56
 
57
 
  // Create a ScopeInfo instance from a Code object.
58
 
  explicit ScopeInfo(Code* code);
59
 
 
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.
63
 
  //
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);
68
 
 
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);
73
 
 
 
57
  // Create a ScopeInfo instance from SerializedScopeInfo.
 
58
  explicit ScopeInfo(SerializedScopeInfo* data);
 
59
 
 
60
  // Creates a SerializedScopeInfo holding the serialized scope info.
 
61
  Handle<SerializedScopeInfo> Serialize();
74
62
 
75
63
  // --------------------------------------------------------------------------
76
64
  // Lookup
95
83
  int NumberOfLocals() const;
96
84
 
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
100
 
  // object.
101
 
  //
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.
 
86
  // Debugging support
 
87
 
 
88
#ifdef DEBUG
 
89
  void Print();
 
90
#endif
 
91
 
 
92
 private:
 
93
  Handle<String> function_name_;
 
94
  bool calls_eval_;
 
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_;
 
99
};
 
100
 
 
101
 
 
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 {
 
105
 public :
 
106
 
 
107
  static SerializedScopeInfo* cast(Object* object) {
 
108
    ASSERT(object->IsFixedArray());
 
109
    return reinterpret_cast<SerializedScopeInfo*>(object);
 
110
  }
105
111
 
106
112
  // Does this scope call eval.
107
 
  static bool CallsEval(Code* code);
 
113
  bool CallsEval();
108
114
 
109
115
  // Return the number of stack slots for code.
110
 
  static int NumberOfStackSlots(Code* code);
 
116
  int NumberOfStackSlots();
111
117
 
112
118
  // Return the number of context slots for code.
113
 
  static int NumberOfContextSlots(Code* code);
114
 
 
115
 
  // Lookup support for scope info embedded in Code objects. Returns
 
119
  int NumberOfContextSlots();
 
120
 
 
121
  // Return if this has context slots besides MIN_CONTEXT_SLOTS;
 
122
  bool HasHeapAllocatedLocals();
 
123
 
 
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);
120
129
 
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);
127
136
 
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);
132
141
 
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);
138
 
 
139
 
  // --------------------------------------------------------------------------
140
 
  // Debugging support
141
 
 
142
 
#ifdef DEBUG
143
 
  void Print();
144
 
#endif
 
146
  int FunctionContextSlotIndex(String* name);
 
147
 
 
148
  static Handle<SerializedScopeInfo> Create(Scope* scope);
 
149
 
 
150
  // Serializes empty scope info.
 
151
  static SerializedScopeInfo* Empty();
145
152
 
146
153
 private:
147
 
  Handle<String> function_name_;
148
 
  bool calls_eval_;
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_;
153
 
};
154
 
 
155
 
class ZoneScopeInfo: public ScopeInfo<ZoneListAllocationPolicy> {
156
 
 public:
157
 
  // Create a ZoneScopeInfo instance from a scope.
158
 
  explicit ZoneScopeInfo(Scope* scope)
159
 
      : ScopeInfo<ZoneListAllocationPolicy>(scope) {}
160
 
 
161
 
  // Create a ZoneScopeInfo instance from a Code object.
162
 
  explicit ZoneScopeInfo(Code* code)
163
 
      :  ScopeInfo<ZoneListAllocationPolicy>(code) {}
164
 
};
165
 
 
166
 
 
167
 
// Cache for mapping (code, property name) into context slot index.
 
154
 
 
155
  inline Object** ContextEntriesAddr();
 
156
 
 
157
  inline Object** ParameterEntriesAddr();
 
158
 
 
159
  inline Object** StackSlotEntriesAddr();
 
160
};
 
161
 
 
162
 
 
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 {
172
168
 public:
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,
176
172
                    String* name,
177
173
                    Variable::Mode* mode);
178
174
 
179
175
  // Update an element in the cache.
180
 
  static void Update(Code* code,
 
176
  static void Update(Object* data,
181
177
                     String* name,
182
178
                     Variable::Mode mode,
183
179
                     int slot_index);
187
183
 
188
184
  static const int kNotFound = -2;
189
185
 private:
190
 
  inline static int Hash(Code* code, String* name);
 
186
  inline static int Hash(Object* data, String* name);
191
187
 
192
188
#ifdef DEBUG
193
 
  static void ValidateEntry(Code* code,
 
189
  static void ValidateEntry(Object* data,
194
190
                            String* name,
195
191
                            Variable::Mode mode,
196
192
                            int slot_index);
198
194
 
199
195
  static const int kLength = 256;
200
196
  struct Key {
201
 
    Code* code;
 
197
    Object* data;
202
198
    String* name;
203
199
  };
204
200