v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
interface.cc
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 #include "v8.h"
29 
30 #include "interface.h"
31 
32 namespace v8 {
33 namespace internal {
34 
35 static bool Match(void* key1, void* key2) {
36  String* name1 = *static_cast<String**>(key1);
37  String* name2 = *static_cast<String**>(key2);
38  ASSERT(name1->IsInternalizedString());
39  ASSERT(name2->IsInternalizedString());
40  return name1 == name2;
41 }
42 
43 
45  ASSERT(IsModule());
46  ZoneHashMap* map = Chase()->exports_;
47  if (map == NULL) return NULL;
48  ZoneAllocationPolicy allocator(zone);
49  ZoneHashMap::Entry* p = map->Lookup(name.location(), name->Hash(), false,
50  allocator);
51  if (p == NULL) return NULL;
52  ASSERT(*static_cast<String**>(p->key) == *name);
53  ASSERT(p->value != NULL);
54  return static_cast<Interface*>(p->value);
55 }
56 
57 
58 #ifdef DEBUG
59 // Current nesting depth for debug output.
60 class Nesting {
61  public:
62  Nesting() { current_ += 2; }
63  ~Nesting() { current_ -= 2; }
64  static int current() { return current_; }
65  private:
66  static int current_;
67 };
68 
69 int Nesting::current_ = 0;
70 #endif
71 
72 
73 void Interface::DoAdd(
74  void* name, uint32_t hash, Interface* interface, Zone* zone, bool* ok) {
75  MakeModule(ok);
76  if (!*ok) return;
77 
78 #ifdef DEBUG
79  if (FLAG_print_interface_details) {
80  PrintF("%*s# Adding...\n", Nesting::current(), "");
81  PrintF("%*sthis = ", Nesting::current(), "");
82  this->Print(Nesting::current());
83  PrintF("%*s%s : ", Nesting::current(), "",
84  (*static_cast<String**>(name))->ToAsciiArray());
85  interface->Print(Nesting::current());
86  }
87 #endif
88 
89  ZoneHashMap** map = &Chase()->exports_;
90  ZoneAllocationPolicy allocator(zone);
91 
92  if (*map == NULL) {
93  *map = new(zone->New(sizeof(ZoneHashMap)))
95  }
96 
97  ZoneHashMap::Entry* p = (*map)->Lookup(name, hash, !IsFrozen(), allocator);
98  if (p == NULL) {
99  // This didn't have name but was frozen already, that's an error.
100  *ok = false;
101  } else if (p->value == NULL) {
102  p->value = interface;
103  } else {
104 #ifdef DEBUG
105  Nesting nested;
106 #endif
107  static_cast<Interface*>(p->value)->Unify(interface, zone, ok);
108  }
109 
110 #ifdef DEBUG
111  if (FLAG_print_interface_details) {
112  PrintF("%*sthis' = ", Nesting::current(), "");
113  this->Print(Nesting::current());
114  PrintF("%*s# Added.\n", Nesting::current(), "");
115  }
116 #endif
117 }
118 
119 
120 void Interface::Unify(Interface* that, Zone* zone, bool* ok) {
121  if (this->forward_) return this->Chase()->Unify(that, zone, ok);
122  if (that->forward_) return this->Unify(that->Chase(), zone, ok);
123  ASSERT(this->forward_ == NULL);
124  ASSERT(that->forward_ == NULL);
125 
126  *ok = true;
127  if (this == that) return;
128  if (this->IsValue()) {
129  that->MakeValue(ok);
130  if (*ok && this->IsConst()) that->MakeConst(ok);
131  return;
132  }
133  if (that->IsValue()) {
134  this->MakeValue(ok);
135  if (*ok && that->IsConst()) this->MakeConst(ok);
136  return;
137  }
138 
139 #ifdef DEBUG
140  if (FLAG_print_interface_details) {
141  PrintF("%*s# Unifying...\n", Nesting::current(), "");
142  PrintF("%*sthis = ", Nesting::current(), "");
143  this->Print(Nesting::current());
144  PrintF("%*sthat = ", Nesting::current(), "");
145  that->Print(Nesting::current());
146  }
147 #endif
148 
149  // Merge the smaller interface into the larger, for performance.
150  if (this->exports_ != NULL && (that->exports_ == NULL ||
151  this->exports_->occupancy() >= that->exports_->occupancy())) {
152  this->DoUnify(that, ok, zone);
153  } else {
154  that->DoUnify(this, ok, zone);
155  }
156 
157 #ifdef DEBUG
158  if (FLAG_print_interface_details) {
159  PrintF("%*sthis' = ", Nesting::current(), "");
160  this->Print(Nesting::current());
161  PrintF("%*sthat' = ", Nesting::current(), "");
162  that->Print(Nesting::current());
163  PrintF("%*s# Unified.\n", Nesting::current(), "");
164  }
165 #endif
166 }
167 
168 
169 void Interface::DoUnify(Interface* that, bool* ok, Zone* zone) {
170  ASSERT(this->forward_ == NULL);
171  ASSERT(that->forward_ == NULL);
172  ASSERT(!this->IsValue());
173  ASSERT(!that->IsValue());
174  ASSERT(this->index_ == -1);
175  ASSERT(that->index_ == -1);
176  ASSERT(*ok);
177 
178 #ifdef DEBUG
179  Nesting nested;
180 #endif
181 
182  // Try to merge all members from that into this.
183  ZoneHashMap* map = that->exports_;
184  if (map != NULL) {
185  for (ZoneHashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) {
186  this->DoAdd(p->key, p->hash, static_cast<Interface*>(p->value), zone, ok);
187  if (!*ok) return;
188  }
189  }
190 
191  // If the new interface is larger than that's, then there were members in
192  // 'this' which 'that' didn't have. If 'that' was frozen that is an error.
193  int this_size = this->exports_ == NULL ? 0 : this->exports_->occupancy();
194  int that_size = map == NULL ? 0 : map->occupancy();
195  if (that->IsFrozen() && this_size > that_size) {
196  *ok = false;
197  return;
198  }
199 
200  // Merge interfaces.
201  this->flags_ |= that->flags_;
202  that->forward_ = this;
203 }
204 
205 
206 #ifdef DEBUG
207 void Interface::Print(int n) {
208  int n0 = n > 0 ? n : 0;
209 
210  if (FLAG_print_interface_details) {
211  PrintF("%p", static_cast<void*>(this));
212  for (Interface* link = this->forward_; link != NULL; link = link->forward_)
213  PrintF("->%p", static_cast<void*>(link));
214  PrintF(" ");
215  }
216 
217  if (IsUnknown()) {
218  PrintF("unknown\n");
219  } else if (IsConst()) {
220  PrintF("const\n");
221  } else if (IsValue()) {
222  PrintF("value\n");
223  } else if (IsModule()) {
224  PrintF("module %d %s{", Index(), IsFrozen() ? "" : "(unresolved) ");
225  ZoneHashMap* map = Chase()->exports_;
226  if (map == NULL || map->occupancy() == 0) {
227  PrintF("}\n");
228  } else if (n < 0 || n0 >= 2 * FLAG_print_interface_depth) {
229  // Avoid infinite recursion on cyclic types.
230  PrintF("...}\n");
231  } else {
232  PrintF("\n");
233  for (ZoneHashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) {
234  String* name = *static_cast<String**>(p->key);
235  Interface* interface = static_cast<Interface*>(p->value);
236  PrintF("%*s%s : ", n0 + 2, "", name->ToAsciiArray());
237  interface->Print(n0 + 2);
238  }
239  PrintF("%*s}\n", n0, "");
240  }
241  }
242 }
243 #endif
244 
245 } } // namespace v8::internal
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
Definition: flags.cc:269
uint16_t current_
void PrintF(const char *format,...)
Definition: v8utils.cc:40
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf map
Definition: flags.cc:350
Interface * Lookup(Handle< String > name, Zone *zone)
Definition: interface.cc:44
#define ASSERT(condition)
Definition: checks.h:329
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization 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 VFP3 instructions if available enable use of NEON instructions if 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 d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long expose natives in global object expose freeBuffer extension expose gc extension under the specified name expose externalize string extension number of stack frames to capture disable builtin natives files print name of functions for which code is generated use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations always try to OSR functions trace optimize function deoptimization minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions trace debugging JSON request response trace out of bounds accesses to external arrays trace_js_array_abuse automatically set the debug break flag when debugger commands are in the queue abort by crashing 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 statistics of the maximum memory committed for the heap in only print modified registers Don t break for ASM_UNIMPLEMENTED_BREAK macros print stack trace when an illegal exception is thrown randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot testing_bool_flag testing_int_flag string flag tmp file in which to serialize heap Print the time it takes to lazily compile hydrogen code stubs concurrent_recompilation concurrent_sweeping Print usage including on console Map counters to a file Enable debugger compile events enable GDBJIT interface(disables compacting GC)") DEFINE_bool(gdbjit_full
void Unify(Interface *that, Zone *zone, bool *ok)
Definition: interface.cc:120
uint32_t occupancy() const
Definition: hashmap.h:83
Entry * Lookup(void *key, uint32_t hash, bool insert, AllocationPolicy allocator=AllocationPolicy())
Definition: hashmap.h:131
void MakeValue(bool *ok)
Definition: interface.h:94
void MakeModule(bool *ok)
Definition: interface.h:106
void Print(const v8::FunctionCallbackInfo< v8::Value > &args)
void MakeConst(bool *ok)
Definition: interface.h:100
TemplateHashMapImpl< ZoneAllocationPolicy > ZoneHashMap
Definition: zone.h:267
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization 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 VFP3 instructions if available enable use of NEON instructions if 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 d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long expose natives in global object expose freeBuffer extension expose gc extension under the specified name expose externalize string extension number of stack frames to capture disable builtin natives files print name of functions for which code is generated use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations always try to OSR functions trace optimize function deoptimization minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions trace debugging JSON request response trace out of bounds accesses to external arrays trace_js_array_abuse automatically set the debug break flag when debugger commands are in the queue abort by crashing 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 statistics of the maximum memory committed for the heap in name
Definition: flags.cc:505
Entry * Next(Entry *p) const
Definition: hashmap.h:243