v8  3.11.10(node0.8.26)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
preparse-data.cc
Go to the documentation of this file.
1 // Copyright 2010 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 "../include/v8stdint.h"
29 
30 #include "preparse-data-format.h"
31 #include "preparse-data.h"
32 
33 #include "checks.h"
34 #include "globals.h"
35 #include "hashmap.h"
36 
37 namespace v8 {
38 namespace internal {
39 
40 // ----------------------------------------------------------------------------
41 // FunctionLoggingParserRecorder
42 
44  : function_store_(0),
45  is_recording_(true),
46  pause_count_(0) {
56 #ifdef DEBUG
57  prev_start_ = -1;
58 #endif
59 }
60 
61 
63  int end_pos,
64  const char* message,
65  const char* arg_opt) {
66  if (has_error()) return;
70  function_store_.Add(start_pos);
72  function_store_.Add(end_pos);
74  function_store_.Add((arg_opt == NULL) ? 0 : 1);
76  WriteString(CStrVector(message));
77  if (arg_opt != NULL) WriteString(CStrVector(arg_opt));
78  is_recording_ = false;
79 }
80 
81 
83  function_store_.Add(str.length());
84  for (int i = 0; i < str.length(); i++) {
85  function_store_.Add(str[i]);
86  }
87 }
88 
89 // ----------------------------------------------------------------------------
90 // PartialParserRecorder - Record both function entries and symbols.
91 
93  int function_size = function_store_.size();
94  int total_size = PreparseDataConstants::kHeaderSize + function_size;
95  Vector<unsigned> data = Vector<unsigned>::New(total_size);
98  memcpy(data.start(), preamble_, sizeof(preamble_));
99  int symbol_start = PreparseDataConstants::kHeaderSize + function_size;
100  if (function_size > 0) {
102  symbol_start));
103  }
104  return data;
105 }
106 
107 
108 // ----------------------------------------------------------------------------
109 // CompleteParserRecorder - Record both function entries and symbols.
110 
113  literal_chars_(0),
114  symbol_store_(0),
115  symbol_keys_(0),
116  symbol_table_(vector_compare),
117  symbol_id_(0) {
118 }
119 
120 
121 void CompleteParserRecorder::LogSymbol(int start,
122  int hash,
123  bool is_ascii,
124  Vector<const byte> literal_bytes) {
125  Key key = { is_ascii, literal_bytes };
126  HashMap::Entry* entry = symbol_table_.Lookup(&key, hash, true);
127  int id = static_cast<int>(reinterpret_cast<intptr_t>(entry->value));
128  if (id == 0) {
129  // Copy literal contents for later comparison.
130  key.literal_bytes =
131  Vector<const byte>::cast(literal_chars_.AddBlock(literal_bytes));
132  // Put (symbol_id_ + 1) into entry and increment it.
133  id = ++symbol_id_;
134  entry->value = reinterpret_cast<void*>(id);
135  Vector<Key> symbol = symbol_keys_.AddBlock(1, key);
136  entry->key = &symbol[0];
137  }
138  WriteNumber(id - 1);
139 }
140 
141 
143  int function_size = function_store_.size();
144  // Add terminator to symbols, then pad to unsigned size.
145  int symbol_size = symbol_store_.size();
146  int padding = sizeof(unsigned) - (symbol_size % sizeof(unsigned));
147  symbol_store_.AddBlock(padding, PreparseDataConstants::kNumberTerminator);
148  symbol_size += padding;
149  int total_size = PreparseDataConstants::kHeaderSize + function_size
150  + (symbol_size / sizeof(unsigned));
151  Vector<unsigned> data = Vector<unsigned>::New(total_size);
154  memcpy(data.start(), preamble_, sizeof(preamble_));
155  int symbol_start = PreparseDataConstants::kHeaderSize + function_size;
156  if (function_size > 0) {
158  symbol_start));
159  }
160  if (!has_error()) {
161  symbol_store_.WriteTo(
162  Vector<byte>::cast(data.SubVector(symbol_start, total_size)));
163  }
164  return data;
165 }
166 
167 
168 void CompleteParserRecorder::WriteNumber(int number) {
169  ASSERT(number >= 0);
170 
171  int mask = (1 << 28) - 1;
172  for (int i = 28; i > 0; i -= 7) {
173  if (number > mask) {
174  symbol_store_.Add(static_cast<byte>(number >> i) | 0x80u);
175  number &= mask;
176  }
177  mask >>= 7;
178  }
179  symbol_store_.Add(static_cast<byte>(number));
180 }
181 
182 
183 } } // namespace v8::internal.
Vector< T > SubVector(int from, int to)
Definition: utils.h:375
void Add(T value)
Definition: utils.h:565
#define ASSERT(condition)
Definition: checks.h:270
virtual Vector< unsigned > ExtractData()
virtual void LogMessage(int start, int end, const char *message, const char *argument_opt)
Vector< T > AddBlock(int size, T initial_value)
Definition: utils.h:578
T * start() const
Definition: utils.h:389
STATIC_ASSERT((FixedDoubleArray::kHeaderSize &kDoubleAlignmentMask)==0)
void WriteString(Vector< const char > str)
Entry * Lookup(void *key, uint32_t hash, bool insert, AllocationPolicy allocator=AllocationPolicy())
Definition: hashmap.h:130
int length() const
Definition: utils.h:383
unsigned preamble_[PreparseDataConstants::kHeaderSize]
static Vector< T > New(int length)
Definition: utils.h:369
Vector< const char > CStrVector(const char *data)
Definition: utils.h:525
virtual Vector< unsigned > ExtractData()
static Vector< T > cast(Vector< S > input)
Definition: utils.h:444
static const unsigned char kNumberTerminator
#define ASSERT_EQ(v1, v2)
Definition: checks.h:271
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 trace on stack replacement optimize closures functions with arguments object optimize functions containing for in loops profiler considers IC stability primitive functions trigger their own optimization re try self optimization if it failed insert an interrupt check at function exit execution budget before interrupt is triggered call count before self optimization self_optimization count_based_interrupts weighted_back_edges trace_opt 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 enable use of ARMv7 instructions if enable use of MIPS FPU instructions if NULL
Definition: flags.cc:274
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 true
Definition: flags.cc:157
void WriteTo(Vector< T > destination)
Definition: utils.h:612
virtual void Reset()
Definition: utils-inl.h:37