V8 Project
regexp-macro-assembler-tracer.cc
Go to the documentation of this file.
1 // Copyright 2012 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 #include "src/v8.h"
6 
7 #include "src/ast.h"
10 
11 namespace v8 {
12 namespace internal {
13 
15  RegExpMacroAssembler* assembler) :
16  RegExpMacroAssembler(assembler->zone()),
17  assembler_(assembler) {
18  unsigned int type = assembler->Implementation();
19  DCHECK(type < 6);
20  const char* impl_names[] = {"IA32", "ARM", "ARM64",
21  "MIPS", "X64", "X87", "Bytecode"};
22  PrintF("RegExpMacroAssembler%s();\n", impl_names[type]);
23 }
24 
25 
27 }
28 
29 
30 // This is used for printing out debugging information. It makes an integer
31 // that is closely related to the address of an object.
32 static int LabelToInt(Label* label) {
33  return static_cast<int>(reinterpret_cast<intptr_t>(label));
34 }
35 
36 
38  PrintF("label[%08x]: (Bind)\n", LabelToInt(label));
39  assembler_->Bind(label);
40 }
41 
42 
44  PrintF(" AdvanceCurrentPosition(by=%d);\n", by);
46 }
47 
48 
50  PrintF(" CheckGreedyLoop(label[%08x]);\n\n", LabelToInt(label));
52 }
53 
54 
56  PrintF(" PopCurrentPosition();\n");
58 }
59 
60 
62  PrintF(" PushCurrentPosition();\n");
64 }
65 
66 
68  PrintF(" Backtrack();\n");
70 }
71 
72 
74  PrintF(" GoTo(label[%08x]);\n\n", LabelToInt(label));
75  assembler_->GoTo(label);
76 }
77 
78 
80  PrintF(" PushBacktrack(label[%08x]);\n", LabelToInt(label));
81  assembler_->PushBacktrack(label);
82 }
83 
84 
86  bool restart = assembler_->Succeed();
87  PrintF(" Succeed();%s\n", restart ? " [restart for global match]" : "");
88  return restart;
89 }
90 
91 
93  PrintF(" Fail();");
94  assembler_->Fail();
95 }
96 
97 
98 void RegExpMacroAssemblerTracer::PopRegister(int register_index) {
99  PrintF(" PopRegister(register=%d);\n", register_index);
100  assembler_->PopRegister(register_index);
101 }
102 
103 
105  int register_index,
106  StackCheckFlag check_stack_limit) {
107  PrintF(" PushRegister(register=%d, %s);\n",
108  register_index,
109  check_stack_limit ? "check stack limit" : "");
110  assembler_->PushRegister(register_index, check_stack_limit);
111 }
112 
113 
115  PrintF(" AdvanceRegister(register=%d, by=%d);\n", reg, by);
116  assembler_->AdvanceRegister(reg, by);
117 }
118 
119 
121  PrintF(" SetCurrentPositionFromEnd(by=%d);\n", by);
123 }
124 
125 
126 void RegExpMacroAssemblerTracer::SetRegister(int register_index, int to) {
127  PrintF(" SetRegister(register=%d, to=%d);\n", register_index, to);
128  assembler_->SetRegister(register_index, to);
129 }
130 
131 
133  int cp_offset) {
134  PrintF(" WriteCurrentPositionToRegister(register=%d,cp_offset=%d);\n",
135  reg,
136  cp_offset);
138 }
139 
140 
141 void RegExpMacroAssemblerTracer::ClearRegisters(int reg_from, int reg_to) {
142  PrintF(" ClearRegister(from=%d, to=%d);\n", reg_from, reg_to);
143  assembler_->ClearRegisters(reg_from, reg_to);
144 }
145 
146 
148  PrintF(" ReadCurrentPositionFromRegister(register=%d);\n", reg);
150 }
151 
152 
154  PrintF(" WriteStackPointerToRegister(register=%d);\n", reg);
156 }
157 
158 
160  PrintF(" ReadStackPointerFromRegister(register=%d);\n", reg);
162 }
163 
164 
166  Label* on_end_of_input,
167  bool check_bounds,
168  int characters) {
169  const char* check_msg = check_bounds ? "" : " (unchecked)";
170  PrintF(" LoadCurrentCharacter(cp_offset=%d, label[%08x]%s (%d chars));\n",
171  cp_offset,
172  LabelToInt(on_end_of_input),
173  check_msg,
174  characters);
175  assembler_->LoadCurrentCharacter(cp_offset,
176  on_end_of_input,
177  check_bounds,
178  characters);
179 }
180 
181 
183  public:
184  explicit PrintablePrinter(uc16 character) : character_(character) { }
185 
186  const char* operator*() {
187  if (character_ >= ' ' && character_ <= '~') {
188  buffer_[0] = '(';
189  buffer_[1] = static_cast<char>(character_);
190  buffer_[2] = ')';
191  buffer_[3] = '\0';
192  } else {
193  buffer_[0] = '\0';
194  }
195  return &buffer_[0];
196  }
197 
198  private:
200  char buffer_[4];
201 };
202 
203 
205  PrintablePrinter printable(limit);
206  PrintF(" CheckCharacterLT(c=0x%04x%s, label[%08x]);\n",
207  limit,
208  *printable,
209  LabelToInt(on_less));
210  assembler_->CheckCharacterLT(limit, on_less);
211 }
212 
213 
215  Label* on_greater) {
216  PrintablePrinter printable(limit);
217  PrintF(" CheckCharacterGT(c=0x%04x%s, label[%08x]);\n",
218  limit,
219  *printable,
220  LabelToInt(on_greater));
221  assembler_->CheckCharacterGT(limit, on_greater);
222 }
223 
224 
225 void RegExpMacroAssemblerTracer::CheckCharacter(unsigned c, Label* on_equal) {
226  PrintablePrinter printable(c);
227  PrintF(" CheckCharacter(c=0x%04x%s, label[%08x]);\n",
228  c,
229  *printable,
230  LabelToInt(on_equal));
231  assembler_->CheckCharacter(c, on_equal);
232 }
233 
234 
236  PrintF(" CheckAtStart(label[%08x]);\n", LabelToInt(on_at_start));
237  assembler_->CheckAtStart(on_at_start);
238 }
239 
240 
241 void RegExpMacroAssemblerTracer::CheckNotAtStart(Label* on_not_at_start) {
242  PrintF(" CheckNotAtStart(label[%08x]);\n", LabelToInt(on_not_at_start));
243  assembler_->CheckNotAtStart(on_not_at_start);
244 }
245 
246 
248  Label* on_not_equal) {
249  PrintablePrinter printable(c);
250  PrintF(" CheckNotCharacter(c=0x%04x%s, label[%08x]);\n",
251  c,
252  *printable,
253  LabelToInt(on_not_equal));
254  assembler_->CheckNotCharacter(c, on_not_equal);
255 }
256 
257 
259  unsigned c,
260  unsigned mask,
261  Label* on_equal) {
262  PrintablePrinter printable(c);
263  PrintF(" CheckCharacterAfterAnd(c=0x%04x%s, mask=0x%04x, label[%08x]);\n",
264  c,
265  *printable,
266  mask,
267  LabelToInt(on_equal));
268  assembler_->CheckCharacterAfterAnd(c, mask, on_equal);
269 }
270 
271 
273  unsigned c,
274  unsigned mask,
275  Label* on_not_equal) {
276  PrintablePrinter printable(c);
277  PrintF(" CheckNotCharacterAfterAnd(c=0x%04x%s, mask=0x%04x, label[%08x]);\n",
278  c,
279  *printable,
280  mask,
281  LabelToInt(on_not_equal));
282  assembler_->CheckNotCharacterAfterAnd(c, mask, on_not_equal);
283 }
284 
285 
287  uc16 c,
288  uc16 minus,
289  uc16 mask,
290  Label* on_not_equal) {
291  PrintF(" CheckNotCharacterAfterMinusAnd(c=0x%04x, minus=%04x, mask=0x%04x, "
292  "label[%08x]);\n",
293  c,
294  minus,
295  mask,
296  LabelToInt(on_not_equal));
297  assembler_->CheckNotCharacterAfterMinusAnd(c, minus, mask, on_not_equal);
298 }
299 
300 
302  uc16 from,
303  uc16 to,
304  Label* on_not_in_range) {
305  PrintablePrinter printable_from(from);
306  PrintablePrinter printable_to(to);
307  PrintF(" CheckCharacterInRange(from=0x%04x%s, to=0x%04x%s, label[%08x]);\n",
308  from,
309  *printable_from,
310  to,
311  *printable_to,
312  LabelToInt(on_not_in_range));
313  assembler_->CheckCharacterInRange(from, to, on_not_in_range);
314 }
315 
316 
318  uc16 from,
319  uc16 to,
320  Label* on_in_range) {
321  PrintablePrinter printable_from(from);
322  PrintablePrinter printable_to(to);
323  PrintF(
324  " CheckCharacterNotInRange(from=0x%04x%s," " to=%04x%s, label[%08x]);\n",
325  from,
326  *printable_from,
327  to,
328  *printable_to,
329  LabelToInt(on_in_range));
330  assembler_->CheckCharacterNotInRange(from, to, on_in_range);
331 }
332 
333 
335  Handle<ByteArray> table, Label* on_bit_set) {
336  PrintF(" CheckBitInTable(label[%08x] ", LabelToInt(on_bit_set));
337  for (int i = 0; i < kTableSize; i++) {
338  PrintF("%c", table->get(i) != 0 ? 'X' : '.');
339  if (i % 32 == 31 && i != kTableMask) {
340  PrintF("\n ");
341  }
342  }
343  PrintF(");\n");
344  assembler_->CheckBitInTable(table, on_bit_set);
345 }
346 
347 
349  Label* on_no_match) {
350  PrintF(" CheckNotBackReference(register=%d, label[%08x]);\n", start_reg,
351  LabelToInt(on_no_match));
352  assembler_->CheckNotBackReference(start_reg, on_no_match);
353 }
354 
355 
357  int start_reg,
358  Label* on_no_match) {
359  PrintF(" CheckNotBackReferenceIgnoreCase(register=%d, label[%08x]);\n",
360  start_reg, LabelToInt(on_no_match));
361  assembler_->CheckNotBackReferenceIgnoreCase(start_reg, on_no_match);
362 }
363 
364 
366  uc16 type,
367  Label* on_no_match) {
368  bool supported = assembler_->CheckSpecialCharacterClass(type,
369  on_no_match);
370  PrintF(" CheckSpecialCharacterClass(type='%c', label[%08x]): %s;\n",
371  type,
372  LabelToInt(on_no_match),
373  supported ? "true" : "false");
374  return supported;
375 }
376 
377 
379  int comparand, Label* if_lt) {
380  PrintF(" IfRegisterLT(register=%d, number=%d, label[%08x]);\n",
381  register_index, comparand, LabelToInt(if_lt));
382  assembler_->IfRegisterLT(register_index, comparand, if_lt);
383 }
384 
385 
387  Label* if_eq) {
388  PrintF(" IfRegisterEqPos(register=%d, label[%08x]);\n",
389  register_index, LabelToInt(if_eq));
390  assembler_->IfRegisterEqPos(register_index, if_eq);
391 }
392 
393 
395  int comparand, Label* if_ge) {
396  PrintF(" IfRegisterGE(register=%d, number=%d, label[%08x]);\n",
397  register_index, comparand, LabelToInt(if_ge));
398  assembler_->IfRegisterGE(register_index, comparand, if_ge);
399 }
400 
401 
404  return assembler_->Implementation();
405 }
406 
407 
409  PrintF(" GetCode(%s);\n", source->ToCString().get());
410  return assembler_->GetCode(source);
411 }
412 
413 }} // namespace v8::internal
virtual void CheckCharacterAfterAnd(unsigned c, unsigned and_with, Label *on_equal)
virtual void CheckCharacterNotInRange(uc16 from, uc16 to, Label *on_not_in_range)
virtual void CheckNotCharacterAfterMinusAnd(uc16 c, uc16 minus, uc16 and_with, Label *on_not_equal)
virtual Handle< HeapObject > GetCode(Handle< String > source)
virtual void LoadCurrentCharacter(int cp_offset, Label *on_end_of_input, bool check_bounds=true, int characters=1)
virtual void IfRegisterLT(int reg, int comparand, Label *if_lt)
virtual void CheckCharacterLT(uc16 limit, Label *on_less)
virtual void CheckNotBackReferenceIgnoreCase(int start_reg, Label *on_no_match)
virtual void CheckNotBackReference(int start_reg, Label *on_no_match)
virtual void IfRegisterEqPos(int reg, Label *if_eq)
virtual void CheckCharacterInRange(uc16 from, uc16 to, Label *on_in_range)
virtual void CheckNotCharacterAfterAnd(unsigned c, unsigned and_with, Label *on_not_equal)
virtual void CheckCharacter(unsigned c, Label *on_equal)
virtual void CheckCharacterGT(uc16 limit, Label *on_greater)
RegExpMacroAssemblerTracer(RegExpMacroAssembler *assembler)
virtual void WriteCurrentPositionToRegister(int reg, int cp_offset)
virtual void SetRegister(int register_index, int to)
virtual void IfRegisterGE(int reg, int comparand, Label *if_ge)
virtual void CheckNotCharacter(unsigned c, Label *on_not_equal)
virtual void CheckGreedyLoop(Label *on_tos_equals_current_position)
virtual void PushRegister(int register_index, StackCheckFlag check_stack_limit)
virtual void ClearRegisters(int reg_from, int reg_to)
virtual void CheckBitInTable(Handle< ByteArray > table, Label *on_bit_set)
virtual void CheckNotAtStart(Label *on_not_at_start)
virtual bool CheckSpecialCharacterClass(uc16 type, Label *on_no_match)
virtual void LoadCurrentCharacter(int cp_offset, Label *on_end_of_input, bool check_bounds=true, int characters=1)=0
virtual void CheckBitInTable(Handle< ByteArray > table, Label *on_bit_set)=0
virtual void PushRegister(int register_index, StackCheckFlag check_stack_limit)=0
virtual void Bind(Label *label)=0
virtual void PushBacktrack(Label *label)=0
virtual void IfRegisterEqPos(int reg, Label *if_eq)=0
virtual void SetRegister(int register_index, int to)=0
virtual bool CheckSpecialCharacterClass(uc16 type, Label *on_no_match)
virtual void CheckAtStart(Label *on_at_start)=0
virtual void CheckCharacterNotInRange(uc16 from, uc16 to, Label *on_not_in_range)=0
virtual void CheckCharacterAfterAnd(unsigned c, unsigned and_with, Label *on_equal)=0
virtual void CheckCharacterLT(uc16 limit, Label *on_less)=0
virtual void CheckNotCharacterAfterMinusAnd(uc16 c, uc16 minus, uc16 and_with, Label *on_not_equal)=0
virtual void CheckNotBackReference(int start_reg, Label *on_no_match)=0
virtual void SetCurrentPositionFromEnd(int by)=0
virtual void CheckCharacter(unsigned c, Label *on_equal)=0
virtual void ReadCurrentPositionFromRegister(int reg)=0
virtual void CheckCharacterGT(uc16 limit, Label *on_greater)=0
virtual void CheckCharacterInRange(uc16 from, uc16 to, Label *on_in_range)=0
virtual void IfRegisterLT(int reg, int comparand, Label *if_lt)=0
virtual IrregexpImplementation Implementation()=0
virtual void ReadStackPointerFromRegister(int reg)=0
virtual void WriteStackPointerToRegister(int reg)=0
virtual void WriteCurrentPositionToRegister(int reg, int cp_offset)=0
virtual void CheckGreedyLoop(Label *on_tos_equals_current_position)=0
virtual Handle< HeapObject > GetCode(Handle< String > source)=0
virtual void AdvanceCurrentPosition(int by)=0
virtual void PopRegister(int register_index)=0
virtual void CheckNotBackReferenceIgnoreCase(int start_reg, Label *on_no_match)=0
virtual void CheckNotCharacter(unsigned c, Label *on_not_equal)=0
virtual void GoTo(Label *label)=0
virtual void AdvanceRegister(int reg, int by)=0
virtual void ClearRegisters(int reg_from, int reg_to)=0
virtual void IfRegisterGE(int reg, int comparand, Label *if_ge)=0
virtual void CheckNotAtStart(Label *on_not_at_start)=0
virtual void CheckNotCharacterAfterAnd(unsigned c, unsigned and_with, Label *on_not_equal)=0
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 only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the A file to write the raw snapshot bytes to(mksnapshot only)") DEFINE_STRING(raw_context_file
#define DCHECK(condition)
Definition: logging.h:205
void PrintF(const char *format,...)
Definition: utils.cc:80
uint16_t uc16
Definition: globals.h:184
static int LabelToInt(Label *label)
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20