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
regexp-macro-assembler-ia32.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_IA32_REGEXP_MACRO_ASSEMBLER_IA32_H_
29 #define V8_IA32_REGEXP_MACRO_ASSEMBLER_IA32_H_
30 
31 #include "ia32/assembler-ia32.h"
33 #include "macro-assembler.h"
34 
35 namespace v8 {
36 namespace internal {
37 
38 #ifndef V8_INTERPRETED_REGEXP
40  public:
41  RegExpMacroAssemblerIA32(Mode mode, int registers_to_save, Zone* zone);
42  virtual ~RegExpMacroAssemblerIA32();
43  virtual int stack_limit_slack();
44  virtual void AdvanceCurrentPosition(int by);
45  virtual void AdvanceRegister(int reg, int by);
46  virtual void Backtrack();
47  virtual void Bind(Label* label);
48  virtual void CheckAtStart(Label* on_at_start);
49  virtual void CheckCharacter(uint32_t c, Label* on_equal);
50  virtual void CheckCharacterAfterAnd(uint32_t c,
51  uint32_t mask,
52  Label* on_equal);
53  virtual void CheckCharacterGT(uc16 limit, Label* on_greater);
54  virtual void CheckCharacterLT(uc16 limit, Label* on_less);
55  // A "greedy loop" is a loop that is both greedy and with a simple
56  // body. It has a particularly simple implementation.
57  virtual void CheckGreedyLoop(Label* on_tos_equals_current_position);
58  virtual void CheckNotAtStart(Label* on_not_at_start);
59  virtual void CheckNotBackReference(int start_reg, Label* on_no_match);
60  virtual void CheckNotBackReferenceIgnoreCase(int start_reg,
61  Label* on_no_match);
62  virtual void CheckNotCharacter(uint32_t c, Label* on_not_equal);
63  virtual void CheckNotCharacterAfterAnd(uint32_t c,
64  uint32_t mask,
65  Label* on_not_equal);
66  virtual void CheckNotCharacterAfterMinusAnd(uc16 c,
67  uc16 minus,
68  uc16 mask,
69  Label* on_not_equal);
70  virtual void CheckCharacterInRange(uc16 from,
71  uc16 to,
72  Label* on_in_range);
73  virtual void CheckCharacterNotInRange(uc16 from,
74  uc16 to,
75  Label* on_not_in_range);
76  virtual void CheckBitInTable(Handle<ByteArray> table, Label* on_bit_set);
77 
78  // Checks whether the given offset from the current position is before
79  // the end of the string.
80  virtual void CheckPosition(int cp_offset, Label* on_outside_input);
81  virtual bool CheckSpecialCharacterClass(uc16 type, Label* on_no_match);
82  virtual void Fail();
84  virtual void GoTo(Label* label);
85  virtual void IfRegisterGE(int reg, int comparand, Label* if_ge);
86  virtual void IfRegisterLT(int reg, int comparand, Label* if_lt);
87  virtual void IfRegisterEqPos(int reg, Label* if_eq);
89  virtual void LoadCurrentCharacter(int cp_offset,
90  Label* on_end_of_input,
91  bool check_bounds = true,
92  int characters = 1);
93  virtual void PopCurrentPosition();
94  virtual void PopRegister(int register_index);
95  virtual void PushBacktrack(Label* label);
96  virtual void PushCurrentPosition();
97  virtual void PushRegister(int register_index,
98  StackCheckFlag check_stack_limit);
99  virtual void ReadCurrentPositionFromRegister(int reg);
100  virtual void ReadStackPointerFromRegister(int reg);
101  virtual void SetCurrentPositionFromEnd(int by);
102  virtual void SetRegister(int register_index, int to);
103  virtual bool Succeed();
104  virtual void WriteCurrentPositionToRegister(int reg, int cp_offset);
105  virtual void ClearRegisters(int reg_from, int reg_to);
106  virtual void WriteStackPointerToRegister(int reg);
107 
108  // Called from RegExp if the stack-guard is triggered.
109  // If the code object is relocated, the return address is fixed before
110  // returning.
111  static int CheckStackGuardState(Address* return_address,
112  Code* re_code,
113  Address re_frame);
114 
115  private:
116  // Offsets from ebp of function parameters and stored registers.
117  static const int kFramePointer = 0;
118  // Above the frame pointer - function parameters and return address.
119  static const int kReturn_eip = kFramePointer + kPointerSize;
120  static const int kFrameAlign = kReturn_eip + kPointerSize;
121  // Parameters.
122  static const int kInputString = kFrameAlign;
123  static const int kStartIndex = kInputString + kPointerSize;
124  static const int kInputStart = kStartIndex + kPointerSize;
125  static const int kInputEnd = kInputStart + kPointerSize;
126  static const int kRegisterOutput = kInputEnd + kPointerSize;
127  // For the case of global regular expression, we have room to store at least
128  // one set of capture results. For the case of non-global regexp, we ignore
129  // this value.
130  static const int kNumOutputRegisters = kRegisterOutput + kPointerSize;
131  static const int kStackHighEnd = kNumOutputRegisters + kPointerSize;
132  static const int kDirectCall = kStackHighEnd + kPointerSize;
133  static const int kIsolate = kDirectCall + kPointerSize;
134  // Below the frame pointer - local stack variables.
135  // When adding local variables remember to push space for them in
136  // the frame in GetCode.
137  static const int kBackup_esi = kFramePointer - kPointerSize;
138  static const int kBackup_edi = kBackup_esi - kPointerSize;
139  static const int kBackup_ebx = kBackup_edi - kPointerSize;
140  static const int kSuccessfulCaptures = kBackup_ebx - kPointerSize;
141  static const int kInputStartMinusOne = kSuccessfulCaptures - kPointerSize;
142  // First register address. Following registers are below it on the stack.
143  static const int kRegisterZero = kInputStartMinusOne - kPointerSize;
144 
145  // Initial size of code buffer.
146  static const size_t kRegExpCodeSize = 1024;
147 
148  // Load a number of characters at the given offset from the
149  // current position, into the current-character register.
150  void LoadCurrentCharacterUnchecked(int cp_offset, int character_count);
151 
152  // Check whether preemption has been requested.
153  void CheckPreemption();
154 
155  // Check whether we are exceeding the stack limit on the backtrack stack.
156  void CheckStackLimit();
157 
158  // Generate a call to CheckStackGuardState.
159  void CallCheckStackGuardState(Register scratch);
160 
161  // The ebp-relative location of a regexp register.
162  Operand register_location(int register_index);
163 
164  // The register containing the current character after LoadCurrentCharacter.
165  inline Register current_character() { return edx; }
166 
167  // The register containing the backtrack stack top. Provides a meaningful
168  // name to the register.
169  inline Register backtrack_stackpointer() { return ecx; }
170 
171  // Byte size of chars in the string to match (decided by the Mode argument)
172  inline int char_size() { return static_cast<int>(mode_); }
173 
174  // Equivalent to a conditional branch to the label, unless the label
175  // is NULL, in which case it is a conditional Backtrack.
176  void BranchOrBacktrack(Condition condition, Label* to);
177 
178  // Call and return internally in the generated code in a way that
179  // is GC-safe (i.e., doesn't leave absolute code addresses on the stack)
180  inline void SafeCall(Label* to);
181  inline void SafeReturn();
182  inline void SafeCallTarget(Label* name);
183 
184  // Pushes the value of a register on the backtrack stack. Decrements the
185  // stack pointer (ecx) by a word size and stores the register's value there.
186  inline void Push(Register source);
187 
188  // Pushes a value on the backtrack stack. Decrements the stack pointer (ecx)
189  // by a word size and stores the value there.
190  inline void Push(Immediate value);
191 
192  // Pops a value from the backtrack stack. Reads the word at the stack pointer
193  // (ecx) and increments it by a word size.
194  inline void Pop(Register target);
195 
196  Isolate* isolate() const { return masm_->isolate(); }
197 
198  MacroAssembler* masm_;
199 
200  // Which mode to generate code for (ASCII or UC16).
201  Mode mode_;
202 
203  // One greater than maximal register index actually used.
204  int num_registers_;
205 
206  // Number of registers to output at the end (the saved registers
207  // are always 0..num_saved_registers_-1)
208  int num_saved_registers_;
209 
210  // Labels used internally.
211  Label entry_label_;
212  Label start_label_;
213  Label success_label_;
214  Label backtrack_label_;
215  Label exit_label_;
216  Label check_preempt_label_;
217  Label stack_overflow_label_;
218 };
219 #endif // V8_INTERPRETED_REGEXP
220 
221 }} // namespace v8::internal
222 
223 #endif // V8_IA32_REGEXP_MACRO_ASSEMBLER_IA32_H_
byte * Address
Definition: globals.h:186
virtual void IfRegisterEqPos(int reg, Label *if_eq)
virtual bool CheckSpecialCharacterClass(uc16 type, Label *on_no_match)
Isolate * isolate() const
Definition: assembler.h:62
virtual void LoadCurrentCharacter(int cp_offset, Label *on_end_of_input, bool check_bounds=true, int characters=1)
virtual void SetCurrentPositionFromEnd(int by)
virtual void CheckCharacterLT(uc16 limit, Label *on_less)
virtual void AdvanceRegister(int reg, int by)
virtual void CheckNotCharacter(uint32_t c, Label *on_not_equal)
virtual Handle< HeapObject > GetCode(Handle< String > source)
virtual void IfRegisterLT(int reg, int comparand, Label *if_lt)
virtual void CheckPosition(int cp_offset, Label *on_outside_input)
virtual void SetRegister(int register_index, int to)
virtual void CheckGreedyLoop(Label *on_tos_equals_current_position)
virtual void CheckNotBackReferenceIgnoreCase(int start_reg, Label *on_no_match)
virtual void CheckCharacter(uint32_t c, Label *on_equal)
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 mode(MIPS only)") DEFINE_string(expose_natives_as
RegExpMacroAssemblerIA32(Mode mode, int registers_to_save, Zone *zone)
virtual void IfRegisterGE(int reg, int comparand, Label *if_ge)
virtual void CheckCharacterGT(uc16 limit, Label *on_greater)
const int kPointerSize
Definition: globals.h:268
const Register ecx
virtual void AdvanceCurrentPosition(int by)
virtual void CheckNotBackReference(int start_reg, Label *on_no_match)
virtual void PushBacktrack(Label *label)
virtual void CheckCharacterInRange(uc16 from, uc16 to, Label *on_in_range)
virtual void ReadCurrentPositionFromRegister(int reg)
static int CheckStackGuardState(Address *return_address, Code *re_code, Address re_frame)
virtual void GoTo(Label *label)
virtual void CheckNotCharacterAfterMinusAnd(uc16 c, uc16 minus, uc16 mask, Label *on_not_equal)
virtual void ReadStackPointerFromRegister(int reg)
virtual void WriteCurrentPositionToRegister(int reg, int cp_offset)
virtual void CheckBitInTable(Handle< ByteArray > table, Label *on_bit_set)
uint16_t uc16
Definition: globals.h:309
virtual void PopRegister(int register_index)
virtual void PushRegister(int register_index, StackCheckFlag check_stack_limit)
virtual void CheckCharacterAfterAnd(uint32_t c, uint32_t mask, Label *on_equal)
virtual void ClearRegisters(int reg_from, int reg_to)
const Register edx
virtual void CheckCharacterNotInRange(uc16 from, uc16 to, Label *on_not_in_range)
virtual IrregexpImplementation Implementation()
virtual void CheckNotCharacterAfterAnd(uint32_t c, uint32_t mask, Label *on_not_equal)
virtual void CheckAtStart(Label *on_at_start)
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
virtual void Bind(Label *label)
virtual void CheckNotAtStart(Label *on_not_at_start)
virtual void WriteStackPointerToRegister(int reg)