V8 Project
scopeinfo.h
Go to the documentation of this file.
1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_SCOPEINFO_H_
6 #define V8_SCOPEINFO_H_
7 
8 #include "src/allocation.h"
9 #include "src/variables.h"
10 #include "src/zone-inl.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 // Cache for mapping (data, property name) into context slot index.
16 // The cache contains both positive and negative results.
17 // Slot index equals -1 means the property is absent.
18 // Cleared at startup and prior to mark sweep collection.
20  public:
21  // Lookup context slot index for (data, name).
22  // If absent, kNotFound is returned.
23  int Lookup(Object* data, String* name, VariableMode* mode,
24  InitializationFlag* init_flag,
25  MaybeAssignedFlag* maybe_assigned_flag);
26 
27  // Update an element in the cache.
29  InitializationFlag init_flag,
30  MaybeAssignedFlag maybe_assigned_flag, int slot_index);
31 
32  // Clear the cache.
33  void Clear();
34 
35  static const int kNotFound = -2;
36 
37  private:
39  for (int i = 0; i < kLength; ++i) {
40  keys_[i].data = NULL;
41  keys_[i].name = NULL;
42  values_[i] = kNotFound;
43  }
44  }
45 
46  inline static int Hash(Object* data, String* name);
47 
48 #ifdef DEBUG
49  void ValidateEntry(Handle<Object> data, Handle<String> name,
51  MaybeAssignedFlag maybe_assigned_flag, int slot_index);
52 #endif
53 
54  static const int kLength = 256;
55  struct Key {
58  };
59 
60  struct Value {
64  DCHECK(InitField::is_valid(init_flag));
68  InitField::encode(init_flag) |
70  DCHECK(mode == this->mode());
71  DCHECK(init_flag == this->initialization_flag());
72  DCHECK(maybe_assigned_flag == this->maybe_assigned_flag());
73  DCHECK(index == this->index());
74  }
75 
76  explicit inline Value(uint32_t value) : value_(value) {}
77 
78  uint32_t raw() { return value_; }
79 
81 
83  return InitField::decode(value_);
84  }
85 
88  }
89 
90  int index() { return IndexField::decode(value_); }
91 
92  // Bit fields in value_ (type, shift, size). Must be public so the
93  // constants can be embedded in generated code.
94  class ModeField : public BitField<VariableMode, 0, 4> {};
95  class InitField : public BitField<InitializationFlag, 4, 1> {};
96  class MaybeAssignedField : public BitField<MaybeAssignedFlag, 5, 1> {};
97  class IndexField : public BitField<int, 6, 32 - 6> {};
98 
99  private:
101  };
102 
105 
106  friend class Isolate;
108 };
109 
110 
111 
112 
113 //---------------------------------------------------------------------------
114 // Auxiliary class used for the description of module instances.
115 // Used by Runtime_DeclareModules.
116 
117 class ModuleInfo: public FixedArray {
118  public:
119  static ModuleInfo* cast(Object* description) {
120  return static_cast<ModuleInfo*>(FixedArray::cast(description));
121  }
122 
123  static Handle<ModuleInfo> Create(
124  Isolate* isolate, Interface* interface, Scope* scope);
125 
126  // Index of module's context in host context.
127  int host_index() { return Smi::cast(get(HOST_OFFSET))->value(); }
128 
129  // Name, mode, and index of the i-th export, respectively.
130  // For value exports, the index is the slot of the value in the module
131  // context, for exported modules it is the slot index of the
132  // referred module's context in the host context.
133  // TODO(rossberg): This format cannot yet handle exports of modules declared
134  // in earlier scripts.
135  String* name(int i) { return String::cast(get(name_offset(i))); }
137  return static_cast<VariableMode>(Smi::cast(get(mode_offset(i)))->value());
138  }
139  int index(int i) { return Smi::cast(get(index_offset(i)))->value(); }
140 
141  int length() { return (FixedArray::length() - HEADER_SIZE) / ITEM_SIZE; }
142 
143  private:
144  // The internal format is: Index, (Name, VariableMode, Index)*
145  enum {
152  };
153  inline int name_offset(int i) { return NAME_OFFSET + i * ITEM_SIZE; }
154  inline int mode_offset(int i) { return MODE_OFFSET + i * ITEM_SIZE; }
155  inline int index_offset(int i) { return INDEX_OFFSET + i * ITEM_SIZE; }
156 
157  static Handle<ModuleInfo> Allocate(Isolate* isolate, int length) {
159  isolate->factory()->NewFixedArray(HEADER_SIZE + ITEM_SIZE * length));
160  }
162  void set_name(int i, String* name) { set(name_offset(i), name); }
165  }
166  void set_index(int i, int index) {
168  }
169 };
170 
171 
172 } } // namespace v8::internal
173 
174 #endif // V8_SCOPEINFO_H_
static bool is_valid(T value)
Definition: utils.h:212
static U encode(T value)
Definition: utils.h:217
static T decode(U value)
Definition: utils.h:228
static int Hash(Object *data, String *name)
Definition: scopeinfo.cc:422
int Lookup(Object *data, String *name, VariableMode *mode, InitializationFlag *init_flag, MaybeAssignedFlag *maybe_assigned_flag)
Definition: scopeinfo.cc:430
static const int kNotFound
Definition: scopeinfo.h:35
static const int kLength
Definition: scopeinfo.h:54
uint32_t values_[kLength]
Definition: scopeinfo.h:104
DISALLOW_COPY_AND_ASSIGN(ContextSlotCache)
void Update(Handle< Object > data, Handle< String > name, VariableMode mode, InitializationFlag init_flag, MaybeAssignedFlag maybe_assigned_flag, int slot_index)
Definition: scopeinfo.cc:447
Object * get(int index)
Definition: objects-inl.h:2165
void set(int index, Object *value)
Definition: objects-inl.h:2190
static Handle< T > cast(Handle< S > that)
Definition: handles.h:116
Factory * factory()
Definition: isolate.h:982
static Handle< ModuleInfo > Create(Isolate *isolate, Interface *interface, Scope *scope)
Definition: scopeinfo.cc:549
VariableMode mode(int i)
Definition: scopeinfo.h:136
void set_mode(int i, VariableMode mode)
Definition: scopeinfo.h:163
static ModuleInfo * cast(Object *description)
Definition: scopeinfo.h:119
void set_name(int i, String *name)
Definition: scopeinfo.h:162
String * name(int i)
Definition: scopeinfo.h:135
void set_host_index(int index)
Definition: scopeinfo.h:161
void set_index(int i, int index)
Definition: scopeinfo.h:166
static Handle< ModuleInfo > Allocate(Isolate *isolate, int length)
Definition: scopeinfo.h:157
static Smi * FromInt(int value)
Definition: objects-inl.h:1321
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in name
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long mode(MIPS only)") DEFINE_BOOL(enable_always_align_csp
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
#define DCHECK(condition)
Definition: logging.h:205
InitializationFlag
Definition: globals.h:751
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20
MaybeAssignedFlag maybe_assigned_flag()
Definition: scopeinfo.h:86
InitializationFlag initialization_flag()
Definition: scopeinfo.h:82
Value(VariableMode mode, InitializationFlag init_flag, MaybeAssignedFlag maybe_assigned_flag, int index)
Definition: scopeinfo.h:61