v8  3.14.5(node0.10.28)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
interface.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef V8_INTERFACE_H_
29 #define V8_INTERFACE_H_
30 
31 #include "zone-inl.h" // For operator new.
32 
33 namespace v8 {
34 namespace internal {
35 
36 
37 // This class implements the following abstract grammar of interfaces
38 // (i.e. module types):
39 // interface ::= UNDETERMINED | VALUE | CONST | MODULE(exports)
40 // exports ::= {name : interface, ...}
41 // A frozen type is one that is fully determined. Unification does not
42 // allow to turn non-const values into const, or adding additional exports to
43 // frozen interfaces. Otherwise, unifying modules merges their exports.
44 // Undetermined types are unification variables that can be unified freely.
45 // There is a natural subsort lattice that reflects the increase of knowledge:
46 //
47 // undetermined
48 // // | \\ .
49 // value (frozen) module
50 // // \\ / \ //
51 // const fr.value fr.module
52 // \\ /
53 // fr.const
54 //
55 // where the bold lines are the only transitions allowed.
56 
57 class Interface : public ZoneObject {
58  public:
59  // ---------------------------------------------------------------------------
60  // Factory methods.
61 
62  static Interface* NewUnknown(Zone* zone) {
63  return new(zone) Interface(NONE);
64  }
65 
66  static Interface* NewValue() {
67  static Interface value_interface(VALUE + FROZEN); // Cached.
68  return &value_interface;
69  }
70 
71  static Interface* NewConst() {
72  static Interface value_interface(VALUE + CONST + FROZEN); // Cached.
73  return &value_interface;
74  }
75 
76  static Interface* NewModule(Zone* zone) {
77  return new(zone) Interface(MODULE);
78  }
79 
80  // ---------------------------------------------------------------------------
81  // Mutators.
82 
83  // Add a name to the list of exports. If it already exists, unify with
84  // interface, otherwise insert unless this is closed.
85  void Add(Handle<String> name, Interface* interface, Zone* zone, bool* ok) {
86  DoAdd(name.location(), name->Hash(), interface, zone, ok);
87  }
88 
89  // Unify with another interface. If successful, both interface objects will
90  // represent the same type, and changes to one are reflected in the other.
91  void Unify(Interface* that, Zone* zone, bool* ok);
92 
93  // Determine this interface to be a value interface.
94  void MakeValue(bool* ok) {
95  *ok = !IsModule();
96  if (*ok) Chase()->flags_ |= VALUE;
97  }
98 
99  // Determine this interface to be an immutable interface.
100  void MakeConst(bool* ok) {
101  *ok = !IsModule() && (IsConst() || !IsFrozen());
102  if (*ok) Chase()->flags_ |= VALUE + CONST;
103  }
104 
105  // Determine this interface to be a module interface.
106  void MakeModule(bool* ok) {
107  *ok = !IsValue();
108  if (*ok) Chase()->flags_ |= MODULE;
109  }
110 
111  // Set associated instance object.
112  void MakeSingleton(Handle<JSModule> instance, bool* ok) {
113  *ok = IsModule() && Chase()->instance_.is_null();
114  if (*ok) Chase()->instance_ = instance;
115  }
116 
117  // Do not allow any further refinements, directly or through unification.
118  void Freeze(bool* ok) {
119  *ok = IsValue() || IsModule();
120  if (*ok) Chase()->flags_ |= FROZEN;
121  }
122 
123  // ---------------------------------------------------------------------------
124  // Accessors.
125 
126  // Check whether this is still a fully undetermined type.
127  bool IsUnknown() { return Chase()->flags_ == NONE; }
128 
129  // Check whether this is a value type.
130  bool IsValue() { return Chase()->flags_ & VALUE; }
131 
132  // Check whether this is a constant type.
133  bool IsConst() { return Chase()->flags_ & CONST; }
134 
135  // Check whether this is a module type.
136  bool IsModule() { return Chase()->flags_ & MODULE; }
137 
138  // Check whether this is closed (i.e. fully determined).
139  bool IsFrozen() { return Chase()->flags_ & FROZEN; }
140 
141  Handle<JSModule> Instance() { return Chase()->instance_; }
142 
143  // Look up an exported name. Returns NULL if not (yet) defined.
144  Interface* Lookup(Handle<String> name, Zone* zone);
145 
146  // ---------------------------------------------------------------------------
147  // Iterators.
148 
149  // Use like:
150  // for (auto it = interface->iterator(); !it.done(); it.Advance()) {
151  // ... it.name() ... it.interface() ...
152  // }
153  class Iterator {
154  public:
155  bool done() const { return entry_ == NULL; }
157  ASSERT(!done());
158  return Handle<String>(*static_cast<String**>(entry_->key));
159  }
160  Interface* interface() const {
161  ASSERT(!done());
162  return static_cast<Interface*>(entry_->value);
163  }
164  void Advance() { entry_ = exports_->Next(entry_); }
165 
166  private:
167  friend class Interface;
168  explicit Iterator(const ZoneHashMap* exports)
169  : exports_(exports), entry_(exports ? exports->Start() : NULL) {}
170 
171  const ZoneHashMap* exports_;
172  ZoneHashMap::Entry* entry_;
173  };
174 
175  Iterator iterator() const { return Iterator(this->exports_); }
176 
177  // ---------------------------------------------------------------------------
178  // Debugging.
179 #ifdef DEBUG
180  void Print(int n = 0); // n = indentation; n < 0 => don't print recursively
181 #endif
182 
183  // ---------------------------------------------------------------------------
184  // Implementation.
185  private:
186  enum Flags { // All flags are monotonic
187  NONE = 0,
188  VALUE = 1, // This type describes a value
189  CONST = 2, // This type describes a constant
190  MODULE = 4, // This type describes a module
191  FROZEN = 8 // This type is fully determined
192  };
193 
194  int flags_;
195  Interface* forward_; // Unification link
196  ZoneHashMap* exports_; // Module exports and their types (allocated lazily)
197  Handle<JSModule> instance_;
198 
199  explicit Interface(int flags)
200  : flags_(flags),
201  forward_(NULL),
202  exports_(NULL) {
203 #ifdef DEBUG
204  if (FLAG_print_interface_details)
205  PrintF("# Creating %p\n", static_cast<void*>(this));
206 #endif
207  }
208 
209  Interface* Chase() {
210  Interface* result = this;
211  while (result->forward_ != NULL) result = result->forward_;
212  if (result != this) forward_ = result; // On-the-fly path compression.
213  return result;
214  }
215 
216  void DoAdd(void* name, uint32_t hash, Interface* interface, Zone* zone,
217  bool* ok);
218  void DoUnify(Interface* that, bool* ok, Zone* zone);
219 };
220 
221 } } // namespace v8::internal
222 
223 #endif // V8_INTERFACE_H_
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if expose natives in global object expose gc extension number of stack frames to capture disable builtin natives files print a stack trace if an assertion failure occurs use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations prepare for turning on always opt minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions automatically set the debug break flag when debugger commands are in the queue always cause a debug break before aborting maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print more details following each garbage collection print amount of external allocated memory after each time it is adjusted flush code that we expect not to use again before full gc do incremental marking steps track object counts and memory usage use caching Perform compaction on every full GC Never perform compaction on full GC testing only Compact code space on full incremental collections Default seed for initializing random allows verbose printing trace parsing and preparsing Check icache flushes in ARM and MIPS simulator Stack alingment in bytes in print stack trace when throwing exceptions randomize hashes to avoid predictable hash Fixed seed to use to hash property activate a timer that switches between V8 threads testing_bool_flag float flag Seed used for threading test randomness A filename with extra code to be included in the Print usage including on console Map counters to a file Enable debugger compile events enable GDBJIT interface(disables compacting GC)") DEFINE_bool(gdbjit_full
Handle< String > name() const
Definition: interface.h:156
void PrintF(const char *format,...)
Definition: v8utils.cc:40
static Interface * NewModule(Zone *zone)
Definition: interface.h:76
Interface * interface() const
Definition: interface.h:160
Interface * Lookup(Handle< String > name, Zone *zone)
Definition: interface.cc:44
#define ASSERT(condition)
Definition: checks.h:270
v8::Handle< v8::Value > Print(const v8::Arguments &args)
void Unify(Interface *that, Zone *zone, bool *ok)
Definition: interface.cc:119
void MakeSingleton(Handle< JSModule > instance, bool *ok)
Definition: interface.h:112
Iterator iterator() const
Definition: interface.h:175
static Interface * NewValue()
Definition: interface.h:66
T ** location() const
Definition: handles.h:75
static Interface * NewUnknown(Zone *zone)
Definition: interface.h:62
void MakeValue(bool *ok)
Definition: interface.h:94
Definition: v8.h:105
static Interface * NewConst()
Definition: interface.h:71
void MakeModule(bool *ok)
Definition: interface.h:106
void Add(Handle< String > name, Interface *interface, Zone *zone, bool *ok)
Definition: interface.h:85
Handle< JSModule > Instance()
Definition: interface.h:141
void Freeze(bool *ok)
Definition: interface.h:118
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if NULL
Definition: flags.cc:301
void MakeConst(bool *ok)
Definition: interface.h:100
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if expose natives in global object expose gc extension number of stack frames to capture disable builtin natives files print a stack trace if an assertion failure occurs use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations prepare for turning on always opt minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions automatically set the debug break flag when debugger commands are in the queue always cause a debug break before aborting maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print more details following each garbage collection print amount of external allocated memory after each time it is adjusted flush code that we expect not to use again before full gc do incremental marking steps track object counts and memory usage use caching Perform compaction on every full GC Never perform compaction on full GC testing only Compact code space on full incremental collections Default seed for initializing random allows verbose printing trace parsing and preparsing Check icache flushes in ARM and MIPS simulator Stack alingment in bytes in print stack trace when throwing exceptions randomize hashes to avoid predictable hash Fixed seed to use to hash property activate a timer that switches between V8 threads testing_bool_flag float flag Seed used for threading test randomness A filename with extra code to be included in the Print usage including flags
Definition: flags.cc:495
TemplateHashMapImpl< ZoneAllocationPolicy > ZoneHashMap
Definition: zone.h:269
Entry * Next(Entry *p) const
Definition: hashmap.h:243