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
preparse-data.h
Go to the documentation of this file.
1 // Copyright 2011 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_PREPARSE_DATA_H_
29 #define V8_PREPARSE_DATA_H_
30 
31 #include "allocation.h"
32 #include "hashmap.h"
33 #include "utils-inl.h"
34 
35 namespace v8 {
36 namespace internal {
37 
38 
39 // Abstract interface for preparse data recorder.
41  public:
43  virtual ~ParserRecorder() { }
44 
45  // Logs the scope and some details of a function literal in the source.
46  virtual void LogFunction(int start,
47  int end,
48  int literals,
49  int properties,
50  StrictMode strict_mode) = 0;
51 
52  // Logs an error message and marks the log as containing an error.
53  // Further logging will be ignored, and ExtractData will return a vector
54  // representing the error only.
55  virtual void LogMessage(int start,
56  int end,
57  const char* message,
58  const char* argument_opt) = 0;
59 
60  // Logs a symbol creation of a literal or identifier.
62  // The following functions are only callable on CompleteParserRecorder
63  // and are guarded by calls to ShouldLogSymbols.
64  virtual void LogOneByteSymbol(int start, Vector<const uint8_t> literal) {
65  UNREACHABLE();
66  }
67  virtual void LogTwoByteSymbol(int start, Vector<const uint16_t> literal) {
68  UNREACHABLE();
69  }
70  virtual void PauseRecording() { UNREACHABLE(); }
71  virtual void ResumeRecording() { UNREACHABLE(); }
72 
73  protected:
75 
76  private:
77  DISALLOW_COPY_AND_ASSIGN(ParserRecorder);
78 };
79 
80 
82  public:
83  SingletonLogger() : has_error_(false), start_(-1), end_(-1) { }
84  virtual ~SingletonLogger() { }
85 
86  void Reset() { has_error_ = false; }
87 
88  virtual void LogFunction(int start,
89  int end,
90  int literals,
91  int properties,
93  ASSERT(!has_error_);
94  start_ = start;
95  end_ = end;
96  literals_ = literals;
97  properties_ = properties;
98  strict_mode_ = strict_mode;
99  };
100 
101  // Logs an error message and marks the log as containing an error.
102  // Further logging will be ignored, and ExtractData will return a vector
103  // representing the error only.
104  virtual void LogMessage(int start,
105  int end,
106  const char* message,
107  const char* argument_opt) {
108  if (has_error_) return;
109  has_error_ = true;
110  start_ = start;
111  end_ = end;
112  message_ = message;
113  argument_opt_ = argument_opt;
114  }
115 
116  bool has_error() { return has_error_; }
117 
118  int start() { return start_; }
119  int end() { return end_; }
120  int literals() {
121  ASSERT(!has_error_);
122  return literals_;
123  }
124  int properties() {
125  ASSERT(!has_error_);
126  return properties_;
127  }
129  ASSERT(!has_error_);
130  return strict_mode_;
131  }
132  const char* message() {
133  ASSERT(has_error_);
134  return message_;
135  }
136  const char* argument_opt() {
137  ASSERT(has_error_);
138  return argument_opt_;
139  }
140 
141  private:
142  bool has_error_;
143  int start_;
144  int end_;
145  // For function entries.
146  int literals_;
147  int properties_;
148  StrictMode strict_mode_;
149  // For error messages.
150  const char* message_;
151  const char* argument_opt_;
152 };
153 
154 
156  public:
157  struct Key {
160  };
161 
164 
165  virtual void LogFunction(int start,
166  int end,
167  int literals,
168  int properties,
169  StrictMode strict_mode) {
170  function_store_.Add(start);
171  function_store_.Add(end);
172  function_store_.Add(literals);
173  function_store_.Add(properties);
174  function_store_.Add(strict_mode);
175  }
176 
177  // Logs an error message and marks the log as containing an error.
178  // Further logging will be ignored, and ExtractData will return a vector
179  // representing the error only.
180  virtual void LogMessage(int start,
181  int end,
182  const char* message,
183  const char* argument_opt);
184 
185  virtual void PauseRecording() {
187  should_log_symbols_ = false;
188  }
189 
190  virtual void ResumeRecording() {
192  should_log_symbols_ = !has_error();
193  }
194 
195  virtual void LogOneByteSymbol(int start, Vector<const uint8_t> literal);
196  virtual void LogTwoByteSymbol(int start, Vector<const uint16_t> literal);
198 
199  private:
200  bool has_error() {
201  return static_cast<bool>(preamble_[PreparseDataConstants::kHasErrorOffset]);
202  }
203 
204  void WriteString(Vector<const char> str);
205 
206  // For testing. Defined in test-parsing.cc.
208 
209  void LogSymbol(int start,
210  int hash,
211  bool is_one_byte,
212  Vector<const byte> literal);
213 
214  // Write a non-negative number to the symbol store.
215  void WriteNumber(int number);
216 
217  Collector<unsigned> function_store_;
218  unsigned preamble_[PreparseDataConstants::kHeaderSize];
219 
220 #ifdef DEBUG
221  int prev_start_;
222 #endif
223 
224  Collector<byte> literal_chars_;
225  Collector<byte> symbol_store_;
226  Collector<Key> symbol_keys_;
227  HashMap string_table_;
228  int symbol_id_;
229 };
230 
231 
232 } } // namespace v8::internal.
233 
234 #endif // V8_PREPARSE_DATA_H_
virtual void LogFunction(int start, int end, int literals, int properties, StrictMode strict_mode)
Definition: preparse-data.h:88
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 message
Definition: flags.cc:665
void Add(T value)
Definition: utils.h:622
#define ASSERT(condition)
Definition: checks.h:329
virtual void LogTwoByteSymbol(int start, Vector< const uint16_t > literal)
Definition: preparse-data.h:67
virtual void LogOneByteSymbol(int start, Vector< const uint8_t > literal)
#define UNREACHABLE()
Definition: checks.h:52
virtual void LogFunction(int start, int end, int literals, int properties, StrictMode strict_mode)
virtual void LogTwoByteSymbol(int start, Vector< const uint16_t > literal)
virtual void LogFunction(int start, int end, int literals, int properties, StrictMode strict_mode)=0
virtual void ResumeRecording()
Definition: preparse-data.h:71
virtual void LogMessage(int start, int end, const char *message, const char *argument_opt)
virtual void LogMessage(int start, int end, const char *message, const char *argument_opt)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric literals(0o77, 0b11)") DEFINE_bool(harmony_strings
virtual void LogOneByteSymbol(int start, Vector< const uint8_t > literal)
Definition: preparse-data.h:64
virtual void LogMessage(int start, int end, const char *message, const char *argument_opt)=0