Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame^] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 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_MACRO_ASSEMBLER_IA32_H_ |
| 29 | #define V8_IA32_MACRO_ASSEMBLER_IA32_H_ |
| 30 | |
| 31 | #include "assembler.h" |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 32 | #include "type-info.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 33 | |
| 34 | namespace v8 { |
| 35 | namespace internal { |
| 36 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 37 | // Flags used for the AllocateInNewSpace functions. |
| 38 | enum AllocationFlags { |
| 39 | // No special flags. |
| 40 | NO_ALLOCATION_FLAGS = 0, |
| 41 | // Return the pointer to the allocated already tagged as a heap object. |
| 42 | TAG_OBJECT = 1 << 0, |
| 43 | // The content of the result register already contains the allocation top in |
| 44 | // new space. |
| 45 | RESULT_CONTAINS_TOP = 1 << 1 |
| 46 | }; |
| 47 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 48 | // Convenience for platform-independent signatures. We do not normally |
| 49 | // distinguish memory operands from other operands on ia32. |
| 50 | typedef Operand MemOperand; |
| 51 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 52 | // Forward declaration. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 53 | class PostCallGenerator; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 54 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 55 | // MacroAssembler implements a collection of frequently used macros. |
| 56 | class MacroAssembler: public Assembler { |
| 57 | public: |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame^] | 58 | // The isolate parameter can be NULL if the macro assembler should |
| 59 | // not use isolate-dependent functionality. In this case, it's the |
| 60 | // responsibility of the caller to never invoke such function on the |
| 61 | // macro assembler. |
| 62 | MacroAssembler(Isolate* isolate, void* buffer, int size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 63 | |
| 64 | // --------------------------------------------------------------------------- |
| 65 | // GC Support |
| 66 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 67 | // For page containing |object| mark region covering |addr| dirty. |
| 68 | // RecordWriteHelper only works if the object is not in new |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 69 | // space. |
| 70 | void RecordWriteHelper(Register object, |
| 71 | Register addr, |
| 72 | Register scratch); |
| 73 | |
| 74 | // Check if object is in new space. |
| 75 | // scratch can be object itself, but it will be clobbered. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 76 | template <typename LabelType> |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 77 | void InNewSpace(Register object, |
| 78 | Register scratch, |
| 79 | Condition cc, // equal for new space, not_equal otherwise. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 80 | LabelType* branch); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 81 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 82 | // For page containing |object| mark region covering [object+offset] |
| 83 | // dirty. |object| is the object being stored into, |value| is the |
| 84 | // object being stored. If offset is zero, then the scratch register |
| 85 | // contains the array index into the elements array represented as a |
| 86 | // Smi. All registers are clobbered by the operation. RecordWrite |
| 87 | // filters out smis so it does not update the write barrier if the |
| 88 | // value is a smi. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 89 | void RecordWrite(Register object, |
| 90 | int offset, |
| 91 | Register value, |
| 92 | Register scratch); |
| 93 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 94 | // For page containing |object| mark region covering |address| |
| 95 | // dirty. |object| is the object being stored into, |value| is the |
| 96 | // object being stored. All registers are clobbered by the |
| 97 | // operation. RecordWrite filters out smis so it does not update the |
| 98 | // write barrier if the value is a smi. |
| 99 | void RecordWrite(Register object, |
| 100 | Register address, |
| 101 | Register value); |
| 102 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 103 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 104 | // --------------------------------------------------------------------------- |
| 105 | // Debugger Support |
| 106 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 107 | void DebugBreak(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 108 | #endif |
| 109 | |
| 110 | // --------------------------------------------------------------------------- |
| 111 | // Activation frames |
| 112 | |
| 113 | void EnterInternalFrame() { EnterFrame(StackFrame::INTERNAL); } |
| 114 | void LeaveInternalFrame() { LeaveFrame(StackFrame::INTERNAL); } |
| 115 | |
| 116 | void EnterConstructFrame() { EnterFrame(StackFrame::CONSTRUCT); } |
| 117 | void LeaveConstructFrame() { LeaveFrame(StackFrame::CONSTRUCT); } |
| 118 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 119 | // Enter specific kind of exit frame. Expects the number of |
| 120 | // arguments in register eax and sets up the number of arguments in |
| 121 | // register edi and the pointer to the first argument in register |
| 122 | // esi. |
| 123 | void EnterExitFrame(bool save_doubles); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 124 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 125 | void EnterApiExitFrame(int argc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 126 | |
| 127 | // Leave the current exit frame. Expects the return value in |
| 128 | // register eax:edx (untouched) and the pointer to the first |
| 129 | // argument in register esi. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 130 | void LeaveExitFrame(bool save_doubles); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 131 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 132 | // Leave the current exit frame. Expects the return value in |
| 133 | // register eax (untouched). |
| 134 | void LeaveApiExitFrame(); |
| 135 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 136 | // Find the function context up the context chain. |
| 137 | void LoadContext(Register dst, int context_chain_length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 138 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 139 | // Load the global function with the given index. |
| 140 | void LoadGlobalFunction(int index, Register function); |
| 141 | |
| 142 | // Load the initial map from the global function. The registers |
| 143 | // function and map can be the same. |
| 144 | void LoadGlobalFunctionInitialMap(Register function, Register map); |
| 145 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 146 | // Push and pop the registers that can hold pointers. |
| 147 | void PushSafepointRegisters() { pushad(); } |
| 148 | void PopSafepointRegisters() { popad(); } |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 149 | // Store the value in register/immediate src in the safepoint |
| 150 | // register stack slot for register dst. |
| 151 | void StoreToSafepointRegisterSlot(Register dst, Register src); |
| 152 | void StoreToSafepointRegisterSlot(Register dst, Immediate src); |
| 153 | void LoadFromSafepointRegisterSlot(Register dst, Register src); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 154 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 155 | // --------------------------------------------------------------------------- |
| 156 | // JavaScript invokes |
| 157 | |
| 158 | // Invoke the JavaScript function code by either calling or jumping. |
| 159 | void InvokeCode(const Operand& code, |
| 160 | const ParameterCount& expected, |
| 161 | const ParameterCount& actual, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 162 | InvokeFlag flag, |
| 163 | PostCallGenerator* post_call_generator = NULL); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 164 | |
| 165 | void InvokeCode(Handle<Code> code, |
| 166 | const ParameterCount& expected, |
| 167 | const ParameterCount& actual, |
| 168 | RelocInfo::Mode rmode, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 169 | InvokeFlag flag, |
| 170 | PostCallGenerator* post_call_generator = NULL); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 171 | |
| 172 | // Invoke the JavaScript function in the given register. Changes the |
| 173 | // current context to the context in the function before invoking. |
| 174 | void InvokeFunction(Register function, |
| 175 | const ParameterCount& actual, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 176 | InvokeFlag flag, |
| 177 | PostCallGenerator* post_call_generator = NULL); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 178 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 179 | void InvokeFunction(JSFunction* function, |
| 180 | const ParameterCount& actual, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 181 | InvokeFlag flag, |
| 182 | PostCallGenerator* post_call_generator = NULL); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 183 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 184 | // Invoke specified builtin JavaScript function. Adds an entry to |
| 185 | // the unresolved list if the name does not resolve. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 186 | void InvokeBuiltin(Builtins::JavaScript id, |
| 187 | InvokeFlag flag, |
| 188 | PostCallGenerator* post_call_generator = NULL); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 189 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 190 | // Store the function for the given builtin in the target register. |
| 191 | void GetBuiltinFunction(Register target, Builtins::JavaScript id); |
| 192 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 193 | // Store the code object for the given builtin in the target register. |
| 194 | void GetBuiltinEntry(Register target, Builtins::JavaScript id); |
| 195 | |
| 196 | // Expression support |
| 197 | void Set(Register dst, const Immediate& x); |
| 198 | void Set(const Operand& dst, const Immediate& x); |
| 199 | |
| 200 | // Compare object type for heap object. |
| 201 | // Incoming register is heap_object and outgoing register is map. |
| 202 | void CmpObjectType(Register heap_object, InstanceType type, Register map); |
| 203 | |
| 204 | // Compare instance type for map. |
| 205 | void CmpInstanceType(Register map, InstanceType type); |
| 206 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 207 | // Check if the map of an object is equal to a specified map and |
| 208 | // branch to label if not. Skip the smi check if not required |
| 209 | // (object is known to be a heap object) |
| 210 | void CheckMap(Register obj, |
| 211 | Handle<Map> map, |
| 212 | Label* fail, |
| 213 | bool is_heap_object); |
| 214 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 215 | // Check if the object in register heap_object is a string. Afterwards the |
| 216 | // register map contains the object map and the register instance_type |
| 217 | // contains the instance_type. The registers map and instance_type can be the |
| 218 | // same in which case it contains the instance type afterwards. Either of the |
| 219 | // registers map and instance_type can be the same as heap_object. |
| 220 | Condition IsObjectStringType(Register heap_object, |
| 221 | Register map, |
| 222 | Register instance_type); |
| 223 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 224 | // Check if a heap object's type is in the JSObject range, not including |
| 225 | // JSFunction. The object's map will be loaded in the map register. |
| 226 | // Any or all of the three registers may be the same. |
| 227 | // The contents of the scratch register will always be overwritten. |
| 228 | void IsObjectJSObjectType(Register heap_object, |
| 229 | Register map, |
| 230 | Register scratch, |
| 231 | Label* fail); |
| 232 | |
| 233 | // The contents of the scratch register will be overwritten. |
| 234 | void IsInstanceJSObjectType(Register map, Register scratch, Label* fail); |
| 235 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 236 | // FCmp is similar to integer cmp, but requires unsigned |
| 237 | // jcc instructions (je, ja, jae, jb, jbe, je, and jz). |
| 238 | void FCmp(); |
| 239 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 240 | // Smi tagging support. |
| 241 | void SmiTag(Register reg) { |
| 242 | ASSERT(kSmiTag == 0); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 243 | ASSERT(kSmiTagSize == 1); |
| 244 | add(reg, Operand(reg)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 245 | } |
| 246 | void SmiUntag(Register reg) { |
| 247 | sar(reg, kSmiTagSize); |
| 248 | } |
| 249 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 250 | // Modifies the register even if it does not contain a Smi! |
| 251 | void SmiUntag(Register reg, TypeInfo info, Label* non_smi) { |
| 252 | ASSERT(kSmiTagSize == 1); |
| 253 | sar(reg, kSmiTagSize); |
| 254 | if (info.IsSmi()) { |
| 255 | ASSERT(kSmiTag == 0); |
| 256 | j(carry, non_smi); |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | // Modifies the register even if it does not contain a Smi! |
| 261 | void SmiUntag(Register reg, Label* is_smi) { |
| 262 | ASSERT(kSmiTagSize == 1); |
| 263 | sar(reg, kSmiTagSize); |
| 264 | ASSERT(kSmiTag == 0); |
| 265 | j(not_carry, is_smi); |
| 266 | } |
| 267 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 268 | // Jump the register contains a smi. |
| 269 | inline void JumpIfSmi(Register value, Label* smi_label) { |
| 270 | test(value, Immediate(kSmiTagMask)); |
| 271 | j(zero, smi_label, not_taken); |
| 272 | } |
| 273 | // Jump if register contain a non-smi. |
| 274 | inline void JumpIfNotSmi(Register value, Label* not_smi_label) { |
| 275 | test(value, Immediate(kSmiTagMask)); |
| 276 | j(not_zero, not_smi_label, not_taken); |
| 277 | } |
| 278 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 279 | // Assumes input is a heap object. |
| 280 | void JumpIfNotNumber(Register reg, TypeInfo info, Label* on_not_number); |
| 281 | |
| 282 | // Assumes input is a heap number. Jumps on things out of range. Also jumps |
| 283 | // on the min negative int32. Ignores frational parts. |
| 284 | void ConvertToInt32(Register dst, |
| 285 | Register src, // Can be the same as dst. |
| 286 | Register scratch, // Can be no_reg or dst, but not src. |
| 287 | TypeInfo info, |
| 288 | Label* on_not_int32); |
| 289 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 290 | void LoadPowerOf2(XMMRegister dst, Register scratch, int power); |
| 291 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 292 | // Abort execution if argument is not a number. Used in debug code. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 293 | void AbortIfNotNumber(Register object); |
| 294 | |
| 295 | // Abort execution if argument is not a smi. Used in debug code. |
| 296 | void AbortIfNotSmi(Register object); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 297 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 298 | // Abort execution if argument is a smi. Used in debug code. |
| 299 | void AbortIfSmi(Register object); |
| 300 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 301 | // Abort execution if argument is a string. Used in debug code. |
| 302 | void AbortIfNotString(Register object); |
| 303 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 304 | // --------------------------------------------------------------------------- |
| 305 | // Exception handling |
| 306 | |
| 307 | // Push a new try handler and link into try handler chain. The return |
| 308 | // address must be pushed before calling this helper. |
| 309 | void PushTryHandler(CodeLocation try_location, HandlerType type); |
| 310 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 311 | // Unlink the stack handler on top of the stack from the try handler chain. |
| 312 | void PopTryHandler(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 313 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 314 | // Activate the top handler in the try hander chain. |
| 315 | void Throw(Register value); |
| 316 | |
| 317 | void ThrowUncatchable(UncatchableExceptionType type, Register value); |
| 318 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 319 | // --------------------------------------------------------------------------- |
| 320 | // Inline caching support |
| 321 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 322 | // Generate code for checking access rights - used for security checks |
| 323 | // on access to global objects across environments. The holder register |
| 324 | // is left untouched, but the scratch register is clobbered. |
| 325 | void CheckAccessGlobalProxy(Register holder_reg, |
| 326 | Register scratch, |
| 327 | Label* miss); |
| 328 | |
| 329 | |
| 330 | // --------------------------------------------------------------------------- |
| 331 | // Allocation support |
| 332 | |
| 333 | // Allocate an object in new space. If the new space is exhausted control |
| 334 | // continues at the gc_required label. The allocated object is returned in |
| 335 | // result and end of the new object is returned in result_end. The register |
| 336 | // scratch can be passed as no_reg in which case an additional object |
| 337 | // reference will be added to the reloc info. The returned pointers in result |
| 338 | // and result_end have not yet been tagged as heap objects. If |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 339 | // result_contains_top_on_entry is true the content of result is known to be |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 340 | // the allocation top on entry (could be result_end from a previous call to |
| 341 | // AllocateInNewSpace). If result_contains_top_on_entry is true scratch |
| 342 | // should be no_reg as it is never used. |
| 343 | void AllocateInNewSpace(int object_size, |
| 344 | Register result, |
| 345 | Register result_end, |
| 346 | Register scratch, |
| 347 | Label* gc_required, |
| 348 | AllocationFlags flags); |
| 349 | |
| 350 | void AllocateInNewSpace(int header_size, |
| 351 | ScaleFactor element_size, |
| 352 | Register element_count, |
| 353 | Register result, |
| 354 | Register result_end, |
| 355 | Register scratch, |
| 356 | Label* gc_required, |
| 357 | AllocationFlags flags); |
| 358 | |
| 359 | void AllocateInNewSpace(Register object_size, |
| 360 | Register result, |
| 361 | Register result_end, |
| 362 | Register scratch, |
| 363 | Label* gc_required, |
| 364 | AllocationFlags flags); |
| 365 | |
| 366 | // Undo allocation in new space. The object passed and objects allocated after |
| 367 | // it will no longer be allocated. Make sure that no pointers are left to the |
| 368 | // object(s) no longer allocated as they would be invalid when allocation is |
| 369 | // un-done. |
| 370 | void UndoAllocationInNewSpace(Register object); |
| 371 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 372 | // Allocate a heap number in new space with undefined value. The |
| 373 | // register scratch2 can be passed as no_reg; the others must be |
| 374 | // valid registers. Returns tagged pointer in result register, or |
| 375 | // jumps to gc_required if new space is full. |
| 376 | void AllocateHeapNumber(Register result, |
| 377 | Register scratch1, |
| 378 | Register scratch2, |
| 379 | Label* gc_required); |
| 380 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 381 | // Allocate a sequential string. All the header fields of the string object |
| 382 | // are initialized. |
| 383 | void AllocateTwoByteString(Register result, |
| 384 | Register length, |
| 385 | Register scratch1, |
| 386 | Register scratch2, |
| 387 | Register scratch3, |
| 388 | Label* gc_required); |
| 389 | void AllocateAsciiString(Register result, |
| 390 | Register length, |
| 391 | Register scratch1, |
| 392 | Register scratch2, |
| 393 | Register scratch3, |
| 394 | Label* gc_required); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 395 | void AllocateAsciiString(Register result, |
| 396 | int length, |
| 397 | Register scratch1, |
| 398 | Register scratch2, |
| 399 | Label* gc_required); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 400 | |
| 401 | // Allocate a raw cons string object. Only the map field of the result is |
| 402 | // initialized. |
| 403 | void AllocateConsString(Register result, |
| 404 | Register scratch1, |
| 405 | Register scratch2, |
| 406 | Label* gc_required); |
| 407 | void AllocateAsciiConsString(Register result, |
| 408 | Register scratch1, |
| 409 | Register scratch2, |
| 410 | Label* gc_required); |
| 411 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 412 | // Copy memory, byte-by-byte, from source to destination. Not optimized for |
| 413 | // long or aligned copies. |
| 414 | // The contents of index and scratch are destroyed. |
| 415 | void CopyBytes(Register source, |
| 416 | Register destination, |
| 417 | Register length, |
| 418 | Register scratch); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 419 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 420 | // --------------------------------------------------------------------------- |
| 421 | // Support functions. |
| 422 | |
| 423 | // Check if result is zero and op is negative. |
| 424 | void NegativeZeroTest(Register result, Register op, Label* then_label); |
| 425 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 426 | // Check if result is zero and any of op1 and op2 are negative. |
| 427 | // Register scratch is destroyed, and it must be different from op2. |
| 428 | void NegativeZeroTest(Register result, Register op1, Register op2, |
| 429 | Register scratch, Label* then_label); |
| 430 | |
| 431 | // Try to get function prototype of a function and puts the value in |
| 432 | // the result register. Checks that the function really is a |
| 433 | // function and jumps to the miss label if the fast checks fail. The |
| 434 | // function register will be untouched; the other registers may be |
| 435 | // clobbered. |
| 436 | void TryGetFunctionPrototype(Register function, |
| 437 | Register result, |
| 438 | Register scratch, |
| 439 | Label* miss); |
| 440 | |
| 441 | // Generates code for reporting that an illegal operation has |
| 442 | // occurred. |
| 443 | void IllegalOperation(int num_arguments); |
| 444 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 445 | // Picks out an array index from the hash field. |
| 446 | // Register use: |
| 447 | // hash - holds the index's hash. Clobbered. |
| 448 | // index - holds the overwritten index on exit. |
| 449 | void IndexFromHash(Register hash, Register index); |
| 450 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 451 | // --------------------------------------------------------------------------- |
| 452 | // Runtime calls |
| 453 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 454 | // Call a code stub. Generate the code if necessary. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 455 | void CallStub(CodeStub* stub); |
| 456 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 457 | // Call a code stub and return the code object called. Try to generate |
| 458 | // the code if necessary. Do not perform a GC but instead return a retry |
| 459 | // after GC failure. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 460 | MUST_USE_RESULT MaybeObject* TryCallStub(CodeStub* stub); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 461 | |
| 462 | // Tail call a code stub (jump). Generate the code if necessary. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 463 | void TailCallStub(CodeStub* stub); |
| 464 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 465 | // Tail call a code stub (jump) and return the code object called. Try to |
| 466 | // generate the code if necessary. Do not perform a GC but instead return |
| 467 | // a retry after GC failure. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 468 | MUST_USE_RESULT MaybeObject* TryTailCallStub(CodeStub* stub); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 469 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 470 | // Return from a code stub after popping its arguments. |
| 471 | void StubReturn(int argc); |
| 472 | |
| 473 | // Call a runtime routine. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 474 | void CallRuntime(const Runtime::Function* f, int num_arguments); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 475 | void CallRuntimeSaveDoubles(Runtime::FunctionId id); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 476 | |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 477 | // Call a runtime function, returning the CodeStub object called. |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 478 | // Try to generate the stub code if necessary. Do not perform a GC |
| 479 | // but instead return a retry after GC failure. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 480 | MUST_USE_RESULT MaybeObject* TryCallRuntime(const Runtime::Function* f, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 481 | int num_arguments); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 482 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 483 | // Convenience function: Same as above, but takes the fid instead. |
| 484 | void CallRuntime(Runtime::FunctionId id, int num_arguments); |
| 485 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 486 | // Convenience function: Same as above, but takes the fid instead. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 487 | MUST_USE_RESULT MaybeObject* TryCallRuntime(Runtime::FunctionId id, |
| 488 | int num_arguments); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 489 | |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 490 | // Convenience function: call an external reference. |
| 491 | void CallExternalReference(ExternalReference ref, int num_arguments); |
| 492 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 493 | // Tail call of a runtime routine (jump). |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 494 | // Like JumpToExternalReference, but also takes care of passing the number |
| 495 | // of parameters. |
| 496 | void TailCallExternalReference(const ExternalReference& ext, |
| 497 | int num_arguments, |
| 498 | int result_size); |
| 499 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 500 | // Tail call of a runtime routine (jump). Try to generate the code if |
| 501 | // necessary. Do not perform a GC but instead return a retry after GC failure. |
| 502 | MUST_USE_RESULT MaybeObject* TryTailCallExternalReference( |
| 503 | const ExternalReference& ext, int num_arguments, int result_size); |
| 504 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 505 | // Convenience function: tail call a runtime routine (jump). |
| 506 | void TailCallRuntime(Runtime::FunctionId fid, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 507 | int num_arguments, |
| 508 | int result_size); |
| 509 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 510 | // Convenience function: tail call a runtime routine (jump). Try to generate |
| 511 | // the code if necessary. Do not perform a GC but instead return a retry after |
| 512 | // GC failure. |
| 513 | MUST_USE_RESULT MaybeObject* TryTailCallRuntime(Runtime::FunctionId fid, |
| 514 | int num_arguments, |
| 515 | int result_size); |
| 516 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 517 | // Before calling a C-function from generated code, align arguments on stack. |
| 518 | // After aligning the frame, arguments must be stored in esp[0], esp[4], |
| 519 | // etc., not pushed. The argument count assumes all arguments are word sized. |
| 520 | // Some compilers/platforms require the stack to be aligned when calling |
| 521 | // C++ code. |
| 522 | // Needs a scratch register to do some arithmetic. This register will be |
| 523 | // trashed. |
| 524 | void PrepareCallCFunction(int num_arguments, Register scratch); |
| 525 | |
| 526 | // Calls a C function and cleans up the space for arguments allocated |
| 527 | // by PrepareCallCFunction. The called function is not allowed to trigger a |
| 528 | // garbage collection, since that might move the code and invalidate the |
| 529 | // return address (unless this is somehow accounted for by the called |
| 530 | // function). |
| 531 | void CallCFunction(ExternalReference function, int num_arguments); |
| 532 | void CallCFunction(Register function, int num_arguments); |
| 533 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 534 | // Prepares stack to put arguments (aligns and so on). Reserves |
| 535 | // space for return value if needed (assumes the return value is a handle). |
| 536 | // Uses callee-saved esi to restore stack state after call. Arguments must be |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 537 | // stored in ApiParameterOperand(0), ApiParameterOperand(1) etc. Saves |
| 538 | // context (esi). |
| 539 | void PrepareCallApiFunction(int argc, Register scratch); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 540 | |
Russell Brenner | 90bac25 | 2010-11-18 13:33:46 -0800 | [diff] [blame] | 541 | // Calls an API function. Allocates HandleScope, extracts |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 542 | // returned value from handle and propagates exceptions. |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 543 | // Clobbers ebx, edi and caller-save registers. Restores context. |
| 544 | // On return removes stack_space * kPointerSize (GCed). |
| 545 | MaybeObject* TryCallApiFunctionAndReturn(ApiFunction* function, |
| 546 | int stack_space); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 547 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 548 | // Jump to a runtime routine. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 549 | void JumpToExternalReference(const ExternalReference& ext); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 550 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 551 | MaybeObject* TryJumpToExternalReference(const ExternalReference& ext); |
| 552 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 553 | |
| 554 | // --------------------------------------------------------------------------- |
| 555 | // Utilities |
| 556 | |
| 557 | void Ret(); |
| 558 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 559 | // Return and drop arguments from stack, where the number of arguments |
| 560 | // may be bigger than 2^16 - 1. Requires a scratch register. |
| 561 | void Ret(int bytes_dropped, Register scratch); |
| 562 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 563 | // Emit code to discard a non-negative number of pointer-sized elements |
| 564 | // from the stack, clobbering only the esp register. |
| 565 | void Drop(int element_count); |
| 566 | |
| 567 | void Call(Label* target) { call(target); } |
| 568 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 569 | // Emit call to the code we are currently generating. |
| 570 | void CallSelf() { |
| 571 | Handle<Code> self(reinterpret_cast<Code**>(CodeObject().location())); |
| 572 | call(self, RelocInfo::CODE_TARGET); |
| 573 | } |
| 574 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 575 | // Move if the registers are not identical. |
| 576 | void Move(Register target, Register source); |
| 577 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 578 | void Move(Register target, Handle<Object> value); |
| 579 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame^] | 580 | Handle<Object> CodeObject() { |
| 581 | ASSERT(!code_object_.is_null()); |
| 582 | return code_object_; |
| 583 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 584 | |
| 585 | |
| 586 | // --------------------------------------------------------------------------- |
| 587 | // StatsCounter support |
| 588 | |
| 589 | void SetCounter(StatsCounter* counter, int value); |
| 590 | void IncrementCounter(StatsCounter* counter, int value); |
| 591 | void DecrementCounter(StatsCounter* counter, int value); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 592 | void IncrementCounter(Condition cc, StatsCounter* counter, int value); |
| 593 | void DecrementCounter(Condition cc, StatsCounter* counter, int value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 594 | |
| 595 | |
| 596 | // --------------------------------------------------------------------------- |
| 597 | // Debugging |
| 598 | |
| 599 | // Calls Abort(msg) if the condition cc is not satisfied. |
| 600 | // Use --debug_code to enable. |
| 601 | void Assert(Condition cc, const char* msg); |
| 602 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 603 | void AssertFastElements(Register elements); |
| 604 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 605 | // Like Assert(), but always enabled. |
| 606 | void Check(Condition cc, const char* msg); |
| 607 | |
| 608 | // Print a message to stdout and abort execution. |
| 609 | void Abort(const char* msg); |
| 610 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 611 | // Check that the stack is aligned. |
| 612 | void CheckStackAlignment(); |
| 613 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 614 | // Verify restrictions about code generated in stubs. |
| 615 | void set_generating_stub(bool value) { generating_stub_ = value; } |
| 616 | bool generating_stub() { return generating_stub_; } |
| 617 | void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; } |
| 618 | bool allow_stub_calls() { return allow_stub_calls_; } |
| 619 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 620 | // --------------------------------------------------------------------------- |
| 621 | // String utilities. |
| 622 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 623 | // Check whether the instance type represents a flat ascii string. Jump to the |
| 624 | // label if not. If the instance type can be scratched specify same register |
| 625 | // for both instance type and scratch. |
| 626 | void JumpIfInstanceTypeIsNotSequentialAscii(Register instance_type, |
| 627 | Register scratch, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 628 | Label* on_not_flat_ascii_string); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 629 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 630 | // Checks if both objects are sequential ASCII strings, and jumps to label |
| 631 | // if either is not. |
| 632 | void JumpIfNotBothSequentialAsciiStrings(Register object1, |
| 633 | Register object2, |
| 634 | Register scratch1, |
| 635 | Register scratch2, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 636 | Label* on_not_flat_ascii_strings); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 637 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame^] | 638 | static int SafepointRegisterStackIndex(Register reg) { |
| 639 | return SafepointRegisterStackIndex(reg.code()); |
| 640 | } |
| 641 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 642 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 643 | bool generating_stub_; |
| 644 | bool allow_stub_calls_; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 645 | // This handle will be patched with the code object on installation. |
| 646 | Handle<Object> code_object_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 647 | |
| 648 | // Helper functions for generating invokes. |
| 649 | void InvokePrologue(const ParameterCount& expected, |
| 650 | const ParameterCount& actual, |
| 651 | Handle<Code> code_constant, |
| 652 | const Operand& code_operand, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 653 | NearLabel* done, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 654 | InvokeFlag flag, |
| 655 | PostCallGenerator* post_call_generator = NULL); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 656 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 657 | // Activation support. |
| 658 | void EnterFrame(StackFrame::Type type); |
| 659 | void LeaveFrame(StackFrame::Type type); |
| 660 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 661 | void EnterExitFramePrologue(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 662 | void EnterExitFrameEpilogue(int argc, bool save_doubles); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 663 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 664 | void LeaveExitFrameEpilogue(); |
| 665 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 666 | // Allocation support helpers. |
| 667 | void LoadAllocationTopHelper(Register result, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 668 | Register scratch, |
| 669 | AllocationFlags flags); |
| 670 | void UpdateAllocationTopHelper(Register result_end, Register scratch); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 671 | |
| 672 | // Helper for PopHandleScope. Allowed to perform a GC and returns |
| 673 | // NULL if gc_allowed. Does not perform a GC if !gc_allowed, and |
| 674 | // possibly returns a failure object indicating an allocation failure. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 675 | MUST_USE_RESULT MaybeObject* PopHandleScopeHelper(Register saved, |
| 676 | Register scratch, |
| 677 | bool gc_allowed); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 678 | |
| 679 | |
| 680 | // Compute memory operands for safepoint stack slots. |
| 681 | Operand SafepointRegisterSlot(Register reg); |
| 682 | static int SafepointRegisterStackIndex(int reg_code); |
| 683 | |
| 684 | // Needs access to SafepointRegisterStackIndex for optimized frame |
| 685 | // traversal. |
| 686 | friend class OptimizedFrame; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 687 | }; |
| 688 | |
| 689 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 690 | template <typename LabelType> |
| 691 | void MacroAssembler::InNewSpace(Register object, |
| 692 | Register scratch, |
| 693 | Condition cc, |
| 694 | LabelType* branch) { |
| 695 | ASSERT(cc == equal || cc == not_equal); |
| 696 | if (Serializer::enabled()) { |
| 697 | // Can't do arithmetic on external references if it might get serialized. |
| 698 | mov(scratch, Operand(object)); |
| 699 | // The mask isn't really an address. We load it as an external reference in |
| 700 | // case the size of the new space is different between the snapshot maker |
| 701 | // and the running system. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 702 | and_(Operand(scratch), |
| 703 | Immediate(ExternalReference::new_space_mask(isolate()))); |
| 704 | cmp(Operand(scratch), |
| 705 | Immediate(ExternalReference::new_space_start(isolate()))); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 706 | j(cc, branch); |
| 707 | } else { |
| 708 | int32_t new_space_start = reinterpret_cast<int32_t>( |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 709 | ExternalReference::new_space_start(isolate()).address()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 710 | lea(scratch, Operand(object, -new_space_start)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 711 | and_(scratch, isolate()->heap()->NewSpaceMask()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 712 | j(cc, branch); |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 717 | // The code patcher is used to patch (typically) small parts of code e.g. for |
| 718 | // debugging and other types of instrumentation. When using the code patcher |
| 719 | // the exact number of bytes specified must be emitted. Is not legal to emit |
| 720 | // relocation information. If any of these constraints are violated it causes |
| 721 | // an assertion. |
| 722 | class CodePatcher { |
| 723 | public: |
| 724 | CodePatcher(byte* address, int size); |
| 725 | virtual ~CodePatcher(); |
| 726 | |
| 727 | // Macro assembler to emit code. |
| 728 | MacroAssembler* masm() { return &masm_; } |
| 729 | |
| 730 | private: |
| 731 | byte* address_; // The address of the code being patched. |
| 732 | int size_; // Number of bytes of the expected patch size. |
| 733 | MacroAssembler masm_; // Macro assembler used to generate the code. |
| 734 | }; |
| 735 | |
| 736 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 737 | // Helper class for generating code or data associated with the code |
| 738 | // right after a call instruction. As an example this can be used to |
| 739 | // generate safepoint data after calls for crankshaft. |
| 740 | class PostCallGenerator { |
| 741 | public: |
| 742 | PostCallGenerator() { } |
| 743 | virtual ~PostCallGenerator() { } |
| 744 | virtual void Generate() = 0; |
| 745 | }; |
| 746 | |
| 747 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 748 | // ----------------------------------------------------------------------------- |
| 749 | // Static helper functions. |
| 750 | |
| 751 | // Generate an Operand for loading a field from an object. |
| 752 | static inline Operand FieldOperand(Register object, int offset) { |
| 753 | return Operand(object, offset - kHeapObjectTag); |
| 754 | } |
| 755 | |
| 756 | |
| 757 | // Generate an Operand for loading an indexed field from an object. |
| 758 | static inline Operand FieldOperand(Register object, |
| 759 | Register index, |
| 760 | ScaleFactor scale, |
| 761 | int offset) { |
| 762 | return Operand(object, index, scale, offset - kHeapObjectTag); |
| 763 | } |
| 764 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 765 | |
| 766 | static inline Operand ContextOperand(Register context, int index) { |
| 767 | return Operand(context, Context::SlotOffset(index)); |
| 768 | } |
| 769 | |
| 770 | |
| 771 | static inline Operand GlobalObjectOperand() { |
| 772 | return ContextOperand(esi, Context::GLOBAL_INDEX); |
| 773 | } |
| 774 | |
| 775 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 776 | // Generates an Operand for saving parameters after PrepareCallApiFunction. |
| 777 | Operand ApiParameterOperand(int index); |
| 778 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 779 | |
| 780 | #ifdef GENERATED_CODE_COVERAGE |
| 781 | extern void LogGeneratedCodeCoverage(const char* file_line); |
| 782 | #define CODE_COVERAGE_STRINGIFY(x) #x |
| 783 | #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x) |
| 784 | #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__) |
| 785 | #define ACCESS_MASM(masm) { \ |
| 786 | byte* ia32_coverage_function = \ |
| 787 | reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \ |
| 788 | masm->pushfd(); \ |
| 789 | masm->pushad(); \ |
| 790 | masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \ |
| 791 | masm->call(ia32_coverage_function, RelocInfo::RUNTIME_ENTRY); \ |
| 792 | masm->pop(eax); \ |
| 793 | masm->popad(); \ |
| 794 | masm->popfd(); \ |
| 795 | } \ |
| 796 | masm-> |
| 797 | #else |
| 798 | #define ACCESS_MASM(masm) masm-> |
| 799 | #endif |
| 800 | |
| 801 | |
| 802 | } } // namespace v8::internal |
| 803 | |
| 804 | #endif // V8_IA32_MACRO_ASSEMBLER_IA32_H_ |