Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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 | #if V8_TARGET_ARCH_X87 |
| 8 | |
| 9 | #include "src/base/bits.h" |
| 10 | #include "src/bootstrapper.h" |
| 11 | #include "src/code-stubs.h" |
| 12 | #include "src/codegen.h" |
| 13 | #include "src/ic/handler-compiler.h" |
| 14 | #include "src/ic/ic.h" |
| 15 | #include "src/isolate.h" |
| 16 | #include "src/jsregexp.h" |
| 17 | #include "src/regexp-macro-assembler.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 18 | #include "src/runtime/runtime.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 19 | |
| 20 | namespace v8 { |
| 21 | namespace internal { |
| 22 | |
| 23 | |
| 24 | static void InitializeArrayConstructorDescriptor( |
| 25 | Isolate* isolate, CodeStubDescriptor* descriptor, |
| 26 | int constant_stack_parameter_count) { |
| 27 | // register state |
| 28 | // eax -- number of arguments |
| 29 | // edi -- function |
| 30 | // ebx -- allocation site with elements kind |
| 31 | Address deopt_handler = Runtime::FunctionForId( |
| 32 | Runtime::kArrayConstructor)->entry; |
| 33 | |
| 34 | if (constant_stack_parameter_count == 0) { |
| 35 | descriptor->Initialize(deopt_handler, constant_stack_parameter_count, |
| 36 | JS_FUNCTION_STUB_MODE); |
| 37 | } else { |
| 38 | descriptor->Initialize(eax, deopt_handler, constant_stack_parameter_count, |
| 39 | JS_FUNCTION_STUB_MODE, PASS_ARGUMENTS); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | |
| 44 | static void InitializeInternalArrayConstructorDescriptor( |
| 45 | Isolate* isolate, CodeStubDescriptor* descriptor, |
| 46 | int constant_stack_parameter_count) { |
| 47 | // register state |
| 48 | // eax -- number of arguments |
| 49 | // edi -- constructor function |
| 50 | Address deopt_handler = Runtime::FunctionForId( |
| 51 | Runtime::kInternalArrayConstructor)->entry; |
| 52 | |
| 53 | if (constant_stack_parameter_count == 0) { |
| 54 | descriptor->Initialize(deopt_handler, constant_stack_parameter_count, |
| 55 | JS_FUNCTION_STUB_MODE); |
| 56 | } else { |
| 57 | descriptor->Initialize(eax, deopt_handler, constant_stack_parameter_count, |
| 58 | JS_FUNCTION_STUB_MODE, PASS_ARGUMENTS); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | |
| 63 | void ArrayNoArgumentConstructorStub::InitializeDescriptor( |
| 64 | CodeStubDescriptor* descriptor) { |
| 65 | InitializeArrayConstructorDescriptor(isolate(), descriptor, 0); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | void ArraySingleArgumentConstructorStub::InitializeDescriptor( |
| 70 | CodeStubDescriptor* descriptor) { |
| 71 | InitializeArrayConstructorDescriptor(isolate(), descriptor, 1); |
| 72 | } |
| 73 | |
| 74 | |
| 75 | void ArrayNArgumentsConstructorStub::InitializeDescriptor( |
| 76 | CodeStubDescriptor* descriptor) { |
| 77 | InitializeArrayConstructorDescriptor(isolate(), descriptor, -1); |
| 78 | } |
| 79 | |
| 80 | |
| 81 | void InternalArrayNoArgumentConstructorStub::InitializeDescriptor( |
| 82 | CodeStubDescriptor* descriptor) { |
| 83 | InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 0); |
| 84 | } |
| 85 | |
| 86 | |
| 87 | void InternalArraySingleArgumentConstructorStub::InitializeDescriptor( |
| 88 | CodeStubDescriptor* descriptor) { |
| 89 | InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, 1); |
| 90 | } |
| 91 | |
| 92 | |
| 93 | void InternalArrayNArgumentsConstructorStub::InitializeDescriptor( |
| 94 | CodeStubDescriptor* descriptor) { |
| 95 | InitializeInternalArrayConstructorDescriptor(isolate(), descriptor, -1); |
| 96 | } |
| 97 | |
| 98 | |
| 99 | #define __ ACCESS_MASM(masm) |
| 100 | |
| 101 | |
| 102 | void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm, |
| 103 | ExternalReference miss) { |
| 104 | // Update the static counter each time a new code stub is generated. |
| 105 | isolate()->counters()->code_stubs()->Increment(); |
| 106 | |
| 107 | CallInterfaceDescriptor descriptor = GetCallInterfaceDescriptor(); |
| 108 | int param_count = descriptor.GetEnvironmentParameterCount(); |
| 109 | { |
| 110 | // Call the runtime system in a fresh internal frame. |
| 111 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 112 | DCHECK(param_count == 0 || |
| 113 | eax.is(descriptor.GetEnvironmentParameterRegister(param_count - 1))); |
| 114 | // Push arguments |
| 115 | for (int i = 0; i < param_count; ++i) { |
| 116 | __ push(descriptor.GetEnvironmentParameterRegister(i)); |
| 117 | } |
| 118 | __ CallExternalReference(miss, param_count); |
| 119 | } |
| 120 | |
| 121 | __ ret(0); |
| 122 | } |
| 123 | |
| 124 | |
| 125 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 126 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 127 | // store the registers in any particular way, but we do have to store and |
| 128 | // restore them. |
| 129 | __ pushad(); |
| 130 | if (save_doubles()) { |
| 131 | // Save FPU stat in m108byte. |
| 132 | __ sub(esp, Immediate(108)); |
| 133 | __ fnsave(Operand(esp, 0)); |
| 134 | } |
| 135 | const int argument_count = 1; |
| 136 | |
| 137 | AllowExternalCallThatCantCauseGC scope(masm); |
| 138 | __ PrepareCallCFunction(argument_count, ecx); |
| 139 | __ mov(Operand(esp, 0 * kPointerSize), |
| 140 | Immediate(ExternalReference::isolate_address(isolate()))); |
| 141 | __ CallCFunction( |
| 142 | ExternalReference::store_buffer_overflow_function(isolate()), |
| 143 | argument_count); |
| 144 | if (save_doubles()) { |
| 145 | // Restore FPU stat in m108byte. |
| 146 | __ frstor(Operand(esp, 0)); |
| 147 | __ add(esp, Immediate(108)); |
| 148 | } |
| 149 | __ popad(); |
| 150 | __ ret(0); |
| 151 | } |
| 152 | |
| 153 | |
| 154 | class FloatingPointHelper : public AllStatic { |
| 155 | public: |
| 156 | enum ArgLocation { |
| 157 | ARGS_ON_STACK, |
| 158 | ARGS_IN_REGISTERS |
| 159 | }; |
| 160 | |
| 161 | // Code pattern for loading a floating point value. Input value must |
| 162 | // be either a smi or a heap number object (fp value). Requirements: |
| 163 | // operand in register number. Returns operand as floating point number |
| 164 | // on FPU stack. |
| 165 | static void LoadFloatOperand(MacroAssembler* masm, Register number); |
| 166 | |
| 167 | // Test if operands are smi or number objects (fp). Requirements: |
| 168 | // operand_1 in eax, operand_2 in edx; falls through on float |
| 169 | // operands, jumps to the non_float label otherwise. |
| 170 | static void CheckFloatOperands(MacroAssembler* masm, |
| 171 | Label* non_float, |
| 172 | Register scratch); |
| 173 | }; |
| 174 | |
| 175 | |
| 176 | void DoubleToIStub::Generate(MacroAssembler* masm) { |
| 177 | Register input_reg = this->source(); |
| 178 | Register final_result_reg = this->destination(); |
| 179 | DCHECK(is_truncating()); |
| 180 | |
| 181 | Label check_negative, process_64_bits, done, done_no_stash; |
| 182 | |
| 183 | int double_offset = offset(); |
| 184 | |
| 185 | // Account for return address and saved regs if input is esp. |
| 186 | if (input_reg.is(esp)) double_offset += 3 * kPointerSize; |
| 187 | |
| 188 | MemOperand mantissa_operand(MemOperand(input_reg, double_offset)); |
| 189 | MemOperand exponent_operand(MemOperand(input_reg, |
| 190 | double_offset + kDoubleSize / 2)); |
| 191 | |
| 192 | Register scratch1; |
| 193 | { |
| 194 | Register scratch_candidates[3] = { ebx, edx, edi }; |
| 195 | for (int i = 0; i < 3; i++) { |
| 196 | scratch1 = scratch_candidates[i]; |
| 197 | if (!final_result_reg.is(scratch1) && !input_reg.is(scratch1)) break; |
| 198 | } |
| 199 | } |
| 200 | // Since we must use ecx for shifts below, use some other register (eax) |
| 201 | // to calculate the result if ecx is the requested return register. |
| 202 | Register result_reg = final_result_reg.is(ecx) ? eax : final_result_reg; |
| 203 | // Save ecx if it isn't the return register and therefore volatile, or if it |
| 204 | // is the return register, then save the temp register we use in its stead for |
| 205 | // the result. |
| 206 | Register save_reg = final_result_reg.is(ecx) ? eax : ecx; |
| 207 | __ push(scratch1); |
| 208 | __ push(save_reg); |
| 209 | |
| 210 | bool stash_exponent_copy = !input_reg.is(esp); |
| 211 | __ mov(scratch1, mantissa_operand); |
| 212 | __ mov(ecx, exponent_operand); |
| 213 | if (stash_exponent_copy) __ push(ecx); |
| 214 | |
| 215 | __ and_(ecx, HeapNumber::kExponentMask); |
| 216 | __ shr(ecx, HeapNumber::kExponentShift); |
| 217 | __ lea(result_reg, MemOperand(ecx, -HeapNumber::kExponentBias)); |
| 218 | __ cmp(result_reg, Immediate(HeapNumber::kMantissaBits)); |
| 219 | __ j(below, &process_64_bits); |
| 220 | |
| 221 | // Result is entirely in lower 32-bits of mantissa |
| 222 | int delta = HeapNumber::kExponentBias + Double::kPhysicalSignificandSize; |
| 223 | __ sub(ecx, Immediate(delta)); |
| 224 | __ xor_(result_reg, result_reg); |
| 225 | __ cmp(ecx, Immediate(31)); |
| 226 | __ j(above, &done); |
| 227 | __ shl_cl(scratch1); |
| 228 | __ jmp(&check_negative); |
| 229 | |
| 230 | __ bind(&process_64_bits); |
| 231 | // Result must be extracted from shifted 32-bit mantissa |
| 232 | __ sub(ecx, Immediate(delta)); |
| 233 | __ neg(ecx); |
| 234 | if (stash_exponent_copy) { |
| 235 | __ mov(result_reg, MemOperand(esp, 0)); |
| 236 | } else { |
| 237 | __ mov(result_reg, exponent_operand); |
| 238 | } |
| 239 | __ and_(result_reg, |
| 240 | Immediate(static_cast<uint32_t>(Double::kSignificandMask >> 32))); |
| 241 | __ add(result_reg, |
| 242 | Immediate(static_cast<uint32_t>(Double::kHiddenBit >> 32))); |
| 243 | __ shrd(result_reg, scratch1); |
| 244 | __ shr_cl(result_reg); |
| 245 | __ test(ecx, Immediate(32)); |
| 246 | { |
| 247 | Label skip_mov; |
| 248 | __ j(equal, &skip_mov, Label::kNear); |
| 249 | __ mov(scratch1, result_reg); |
| 250 | __ bind(&skip_mov); |
| 251 | } |
| 252 | |
| 253 | // If the double was negative, negate the integer result. |
| 254 | __ bind(&check_negative); |
| 255 | __ mov(result_reg, scratch1); |
| 256 | __ neg(result_reg); |
| 257 | if (stash_exponent_copy) { |
| 258 | __ cmp(MemOperand(esp, 0), Immediate(0)); |
| 259 | } else { |
| 260 | __ cmp(exponent_operand, Immediate(0)); |
| 261 | } |
| 262 | { |
| 263 | Label skip_mov; |
| 264 | __ j(less_equal, &skip_mov, Label::kNear); |
| 265 | __ mov(result_reg, scratch1); |
| 266 | __ bind(&skip_mov); |
| 267 | } |
| 268 | |
| 269 | // Restore registers |
| 270 | __ bind(&done); |
| 271 | if (stash_exponent_copy) { |
| 272 | __ add(esp, Immediate(kDoubleSize / 2)); |
| 273 | } |
| 274 | __ bind(&done_no_stash); |
| 275 | if (!final_result_reg.is(result_reg)) { |
| 276 | DCHECK(final_result_reg.is(ecx)); |
| 277 | __ mov(final_result_reg, result_reg); |
| 278 | } |
| 279 | __ pop(save_reg); |
| 280 | __ pop(scratch1); |
| 281 | __ ret(0); |
| 282 | } |
| 283 | |
| 284 | |
| 285 | void FloatingPointHelper::LoadFloatOperand(MacroAssembler* masm, |
| 286 | Register number) { |
| 287 | Label load_smi, done; |
| 288 | |
| 289 | __ JumpIfSmi(number, &load_smi, Label::kNear); |
| 290 | __ fld_d(FieldOperand(number, HeapNumber::kValueOffset)); |
| 291 | __ jmp(&done, Label::kNear); |
| 292 | |
| 293 | __ bind(&load_smi); |
| 294 | __ SmiUntag(number); |
| 295 | __ push(number); |
| 296 | __ fild_s(Operand(esp, 0)); |
| 297 | __ pop(number); |
| 298 | |
| 299 | __ bind(&done); |
| 300 | } |
| 301 | |
| 302 | |
| 303 | void FloatingPointHelper::CheckFloatOperands(MacroAssembler* masm, |
| 304 | Label* non_float, |
| 305 | Register scratch) { |
| 306 | Label test_other, done; |
| 307 | // Test if both operands are floats or smi -> scratch=k_is_float; |
| 308 | // Otherwise scratch = k_not_float. |
| 309 | __ JumpIfSmi(edx, &test_other, Label::kNear); |
| 310 | __ mov(scratch, FieldOperand(edx, HeapObject::kMapOffset)); |
| 311 | Factory* factory = masm->isolate()->factory(); |
| 312 | __ cmp(scratch, factory->heap_number_map()); |
| 313 | __ j(not_equal, non_float); // argument in edx is not a number -> NaN |
| 314 | |
| 315 | __ bind(&test_other); |
| 316 | __ JumpIfSmi(eax, &done, Label::kNear); |
| 317 | __ mov(scratch, FieldOperand(eax, HeapObject::kMapOffset)); |
| 318 | __ cmp(scratch, factory->heap_number_map()); |
| 319 | __ j(not_equal, non_float); // argument in eax is not a number -> NaN |
| 320 | |
| 321 | // Fall-through: Both operands are numbers. |
| 322 | __ bind(&done); |
| 323 | } |
| 324 | |
| 325 | |
| 326 | void MathPowStub::Generate(MacroAssembler* masm) { |
| 327 | // No SSE2 support |
| 328 | UNREACHABLE(); |
| 329 | } |
| 330 | |
| 331 | |
| 332 | void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
| 333 | Label miss; |
| 334 | Register receiver = LoadDescriptor::ReceiverRegister(); |
| 335 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 336 | if (FLAG_vector_ics) { |
| 337 | // With careful management, we won't have to save slot and vector on |
| 338 | // the stack. Simply handle the possibly missing case first. |
| 339 | // TODO(mvstanton): this code can be more efficient. |
| 340 | __ cmp(FieldOperand(receiver, JSFunction::kPrototypeOrInitialMapOffset), |
| 341 | Immediate(isolate()->factory()->the_hole_value())); |
| 342 | __ j(equal, &miss); |
| 343 | __ TryGetFunctionPrototype(receiver, eax, ebx, &miss); |
| 344 | __ ret(0); |
| 345 | } else { |
| 346 | NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, eax, |
| 347 | ebx, &miss); |
| 348 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 349 | __ bind(&miss); |
| 350 | PropertyAccessCompiler::TailCallBuiltin( |
| 351 | masm, PropertyAccessCompiler::MissBuiltin(Code::LOAD_IC)); |
| 352 | } |
| 353 | |
| 354 | |
| 355 | void LoadIndexedInterceptorStub::Generate(MacroAssembler* masm) { |
| 356 | // Return address is on the stack. |
| 357 | Label slow; |
| 358 | |
| 359 | Register receiver = LoadDescriptor::ReceiverRegister(); |
| 360 | Register key = LoadDescriptor::NameRegister(); |
| 361 | Register scratch = eax; |
| 362 | DCHECK(!scratch.is(receiver) && !scratch.is(key)); |
| 363 | |
| 364 | // Check that the key is an array index, that is Uint32. |
| 365 | __ test(key, Immediate(kSmiTagMask | kSmiSignMask)); |
| 366 | __ j(not_zero, &slow); |
| 367 | |
| 368 | // Everything is fine, call runtime. |
| 369 | __ pop(scratch); |
| 370 | __ push(receiver); // receiver |
| 371 | __ push(key); // key |
| 372 | __ push(scratch); // return address |
| 373 | |
| 374 | // Perform tail call to the entry. |
| 375 | ExternalReference ref = ExternalReference( |
| 376 | IC_Utility(IC::kLoadElementWithInterceptor), masm->isolate()); |
| 377 | __ TailCallExternalReference(ref, 2, 1); |
| 378 | |
| 379 | __ bind(&slow); |
| 380 | PropertyAccessCompiler::TailCallBuiltin( |
| 381 | masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC)); |
| 382 | } |
| 383 | |
| 384 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 385 | void LoadIndexedStringStub::Generate(MacroAssembler* masm) { |
| 386 | // Return address is on the stack. |
| 387 | Label miss; |
| 388 | |
| 389 | Register receiver = LoadDescriptor::ReceiverRegister(); |
| 390 | Register index = LoadDescriptor::NameRegister(); |
| 391 | Register scratch = edi; |
| 392 | DCHECK(!scratch.is(receiver) && !scratch.is(index)); |
| 393 | Register result = eax; |
| 394 | DCHECK(!result.is(scratch)); |
| 395 | DCHECK(!FLAG_vector_ics || |
| 396 | (!scratch.is(VectorLoadICDescriptor::VectorRegister()) && |
| 397 | result.is(VectorLoadICDescriptor::SlotRegister()))); |
| 398 | |
| 399 | // StringCharAtGenerator doesn't use the result register until it's passed |
| 400 | // the different miss possibilities. If it did, we would have a conflict |
| 401 | // when FLAG_vector_ics is true. |
| 402 | |
| 403 | StringCharAtGenerator char_at_generator(receiver, index, scratch, result, |
| 404 | &miss, // When not a string. |
| 405 | &miss, // When not a number. |
| 406 | &miss, // When index out of range. |
| 407 | STRING_INDEX_IS_ARRAY_INDEX, |
| 408 | RECEIVER_IS_STRING); |
| 409 | char_at_generator.GenerateFast(masm); |
| 410 | __ ret(0); |
| 411 | |
| 412 | StubRuntimeCallHelper call_helper; |
| 413 | char_at_generator.GenerateSlow(masm, call_helper); |
| 414 | |
| 415 | __ bind(&miss); |
| 416 | PropertyAccessCompiler::TailCallBuiltin( |
| 417 | masm, PropertyAccessCompiler::MissBuiltin(Code::KEYED_LOAD_IC)); |
| 418 | } |
| 419 | |
| 420 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 421 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 422 | // The key is in edx and the parameter count is in eax. |
| 423 | DCHECK(edx.is(ArgumentsAccessReadDescriptor::index())); |
| 424 | DCHECK(eax.is(ArgumentsAccessReadDescriptor::parameter_count())); |
| 425 | |
| 426 | // The displacement is used for skipping the frame pointer on the |
| 427 | // stack. It is the offset of the last parameter (if any) relative |
| 428 | // to the frame pointer. |
| 429 | static const int kDisplacement = 1 * kPointerSize; |
| 430 | |
| 431 | // Check that the key is a smi. |
| 432 | Label slow; |
| 433 | __ JumpIfNotSmi(edx, &slow, Label::kNear); |
| 434 | |
| 435 | // Check if the calling frame is an arguments adaptor frame. |
| 436 | Label adaptor; |
| 437 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 438 | __ mov(ecx, Operand(ebx, StandardFrameConstants::kContextOffset)); |
| 439 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 440 | __ j(equal, &adaptor, Label::kNear); |
| 441 | |
| 442 | // Check index against formal parameters count limit passed in |
| 443 | // through register eax. Use unsigned comparison to get negative |
| 444 | // check for free. |
| 445 | __ cmp(edx, eax); |
| 446 | __ j(above_equal, &slow, Label::kNear); |
| 447 | |
| 448 | // Read the argument from the stack and return it. |
| 449 | STATIC_ASSERT(kSmiTagSize == 1); |
| 450 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 451 | __ lea(ebx, Operand(ebp, eax, times_2, 0)); |
| 452 | __ neg(edx); |
| 453 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 454 | __ ret(0); |
| 455 | |
| 456 | // Arguments adaptor case: Check index against actual arguments |
| 457 | // limit found in the arguments adaptor frame. Use unsigned |
| 458 | // comparison to get negative check for free. |
| 459 | __ bind(&adaptor); |
| 460 | __ mov(ecx, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 461 | __ cmp(edx, ecx); |
| 462 | __ j(above_equal, &slow, Label::kNear); |
| 463 | |
| 464 | // Read the argument from the stack and return it. |
| 465 | STATIC_ASSERT(kSmiTagSize == 1); |
| 466 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 467 | __ lea(ebx, Operand(ebx, ecx, times_2, 0)); |
| 468 | __ neg(edx); |
| 469 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 470 | __ ret(0); |
| 471 | |
| 472 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 473 | // by calling the runtime system. |
| 474 | __ bind(&slow); |
| 475 | __ pop(ebx); // Return address. |
| 476 | __ push(edx); |
| 477 | __ push(ebx); |
| 478 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
| 479 | } |
| 480 | |
| 481 | |
| 482 | void ArgumentsAccessStub::GenerateNewSloppySlow(MacroAssembler* masm) { |
| 483 | // esp[0] : return address |
| 484 | // esp[4] : number of parameters |
| 485 | // esp[8] : receiver displacement |
| 486 | // esp[12] : function |
| 487 | |
| 488 | // Check if the calling frame is an arguments adaptor frame. |
| 489 | Label runtime; |
| 490 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 491 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
| 492 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 493 | __ j(not_equal, &runtime, Label::kNear); |
| 494 | |
| 495 | // Patch the arguments.length and the parameters pointer. |
| 496 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 497 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
| 498 | __ lea(edx, Operand(edx, ecx, times_2, |
| 499 | StandardFrameConstants::kCallerSPOffset)); |
| 500 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 501 | |
| 502 | __ bind(&runtime); |
| 503 | __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1); |
| 504 | } |
| 505 | |
| 506 | |
| 507 | void ArgumentsAccessStub::GenerateNewSloppyFast(MacroAssembler* masm) { |
| 508 | // esp[0] : return address |
| 509 | // esp[4] : number of parameters (tagged) |
| 510 | // esp[8] : receiver displacement |
| 511 | // esp[12] : function |
| 512 | |
| 513 | // ebx = parameter count (tagged) |
| 514 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 515 | |
| 516 | // Check if the calling frame is an arguments adaptor frame. |
| 517 | // TODO(rossberg): Factor out some of the bits that are shared with the other |
| 518 | // Generate* functions. |
| 519 | Label runtime; |
| 520 | Label adaptor_frame, try_allocate; |
| 521 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 522 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
| 523 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 524 | __ j(equal, &adaptor_frame, Label::kNear); |
| 525 | |
| 526 | // No adaptor, parameter count = argument count. |
| 527 | __ mov(ecx, ebx); |
| 528 | __ jmp(&try_allocate, Label::kNear); |
| 529 | |
| 530 | // We have an adaptor frame. Patch the parameters pointer. |
| 531 | __ bind(&adaptor_frame); |
| 532 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 533 | __ lea(edx, Operand(edx, ecx, times_2, |
| 534 | StandardFrameConstants::kCallerSPOffset)); |
| 535 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 536 | |
| 537 | // ebx = parameter count (tagged) |
| 538 | // ecx = argument count (smi-tagged) |
| 539 | // esp[4] = parameter count (tagged) |
| 540 | // esp[8] = address of receiver argument |
| 541 | // Compute the mapped parameter count = min(ebx, ecx) in ebx. |
| 542 | __ cmp(ebx, ecx); |
| 543 | __ j(less_equal, &try_allocate, Label::kNear); |
| 544 | __ mov(ebx, ecx); |
| 545 | |
| 546 | __ bind(&try_allocate); |
| 547 | |
| 548 | // Save mapped parameter count. |
| 549 | __ push(ebx); |
| 550 | |
| 551 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 552 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 553 | const int kParameterMapHeaderSize = |
| 554 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 555 | Label no_parameter_map; |
| 556 | __ test(ebx, ebx); |
| 557 | __ j(zero, &no_parameter_map, Label::kNear); |
| 558 | __ lea(ebx, Operand(ebx, times_2, kParameterMapHeaderSize)); |
| 559 | __ bind(&no_parameter_map); |
| 560 | |
| 561 | // 2. Backing store. |
| 562 | __ lea(ebx, Operand(ebx, ecx, times_2, FixedArray::kHeaderSize)); |
| 563 | |
| 564 | // 3. Arguments object. |
| 565 | __ add(ebx, Immediate(Heap::kSloppyArgumentsObjectSize)); |
| 566 | |
| 567 | // Do the allocation of all three objects in one go. |
| 568 | __ Allocate(ebx, eax, edx, edi, &runtime, TAG_OBJECT); |
| 569 | |
| 570 | // eax = address of new object(s) (tagged) |
| 571 | // ecx = argument count (smi-tagged) |
| 572 | // esp[0] = mapped parameter count (tagged) |
| 573 | // esp[8] = parameter count (tagged) |
| 574 | // esp[12] = address of receiver argument |
| 575 | // Get the arguments map from the current native context into edi. |
| 576 | Label has_mapped_parameters, instantiate; |
| 577 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 578 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
| 579 | __ mov(ebx, Operand(esp, 0 * kPointerSize)); |
| 580 | __ test(ebx, ebx); |
| 581 | __ j(not_zero, &has_mapped_parameters, Label::kNear); |
| 582 | __ mov( |
| 583 | edi, |
| 584 | Operand(edi, Context::SlotOffset(Context::SLOPPY_ARGUMENTS_MAP_INDEX))); |
| 585 | __ jmp(&instantiate, Label::kNear); |
| 586 | |
| 587 | __ bind(&has_mapped_parameters); |
| 588 | __ mov( |
| 589 | edi, |
| 590 | Operand(edi, Context::SlotOffset(Context::ALIASED_ARGUMENTS_MAP_INDEX))); |
| 591 | __ bind(&instantiate); |
| 592 | |
| 593 | // eax = address of new object (tagged) |
| 594 | // ebx = mapped parameter count (tagged) |
| 595 | // ecx = argument count (smi-tagged) |
| 596 | // edi = address of arguments map (tagged) |
| 597 | // esp[0] = mapped parameter count (tagged) |
| 598 | // esp[8] = parameter count (tagged) |
| 599 | // esp[12] = address of receiver argument |
| 600 | // Copy the JS object part. |
| 601 | __ mov(FieldOperand(eax, JSObject::kMapOffset), edi); |
| 602 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), |
| 603 | masm->isolate()->factory()->empty_fixed_array()); |
| 604 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), |
| 605 | masm->isolate()->factory()->empty_fixed_array()); |
| 606 | |
| 607 | // Set up the callee in-object property. |
| 608 | STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| 609 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
| 610 | __ AssertNotSmi(edx); |
| 611 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 612 | Heap::kArgumentsCalleeIndex * kPointerSize), |
| 613 | edx); |
| 614 | |
| 615 | // Use the length (smi tagged) and set that as an in-object property too. |
| 616 | __ AssertSmi(ecx); |
| 617 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 618 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 619 | Heap::kArgumentsLengthIndex * kPointerSize), |
| 620 | ecx); |
| 621 | |
| 622 | // Set up the elements pointer in the allocated arguments object. |
| 623 | // If we allocated a parameter map, edi will point there, otherwise to the |
| 624 | // backing store. |
| 625 | __ lea(edi, Operand(eax, Heap::kSloppyArgumentsObjectSize)); |
| 626 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 627 | |
| 628 | // eax = address of new object (tagged) |
| 629 | // ebx = mapped parameter count (tagged) |
| 630 | // ecx = argument count (tagged) |
| 631 | // edi = address of parameter map or backing store (tagged) |
| 632 | // esp[0] = mapped parameter count (tagged) |
| 633 | // esp[8] = parameter count (tagged) |
| 634 | // esp[12] = address of receiver argument |
| 635 | // Free a register. |
| 636 | __ push(eax); |
| 637 | |
| 638 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 639 | Label skip_parameter_map; |
| 640 | __ test(ebx, ebx); |
| 641 | __ j(zero, &skip_parameter_map); |
| 642 | |
| 643 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
| 644 | Immediate(isolate()->factory()->sloppy_arguments_elements_map())); |
| 645 | __ lea(eax, Operand(ebx, reinterpret_cast<intptr_t>(Smi::FromInt(2)))); |
| 646 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), eax); |
| 647 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 0 * kPointerSize), esi); |
| 648 | __ lea(eax, Operand(edi, ebx, times_2, kParameterMapHeaderSize)); |
| 649 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 1 * kPointerSize), eax); |
| 650 | |
| 651 | // Copy the parameter slots and the holes in the arguments. |
| 652 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 653 | // where parameters are stored in reverse order, at |
| 654 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 655 | // The mapped parameter thus need to get indices |
| 656 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 657 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 658 | // We loop from right to left. |
| 659 | Label parameters_loop, parameters_test; |
| 660 | __ push(ecx); |
| 661 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 662 | __ mov(ebx, Immediate(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 663 | __ add(ebx, Operand(esp, 4 * kPointerSize)); |
| 664 | __ sub(ebx, eax); |
| 665 | __ mov(ecx, isolate()->factory()->the_hole_value()); |
| 666 | __ mov(edx, edi); |
| 667 | __ lea(edi, Operand(edi, eax, times_2, kParameterMapHeaderSize)); |
| 668 | // eax = loop variable (tagged) |
| 669 | // ebx = mapping index (tagged) |
| 670 | // ecx = the hole value |
| 671 | // edx = address of parameter map (tagged) |
| 672 | // edi = address of backing store (tagged) |
| 673 | // esp[0] = argument count (tagged) |
| 674 | // esp[4] = address of new object (tagged) |
| 675 | // esp[8] = mapped parameter count (tagged) |
| 676 | // esp[16] = parameter count (tagged) |
| 677 | // esp[20] = address of receiver argument |
| 678 | __ jmp(¶meters_test, Label::kNear); |
| 679 | |
| 680 | __ bind(¶meters_loop); |
| 681 | __ sub(eax, Immediate(Smi::FromInt(1))); |
| 682 | __ mov(FieldOperand(edx, eax, times_2, kParameterMapHeaderSize), ebx); |
| 683 | __ mov(FieldOperand(edi, eax, times_2, FixedArray::kHeaderSize), ecx); |
| 684 | __ add(ebx, Immediate(Smi::FromInt(1))); |
| 685 | __ bind(¶meters_test); |
| 686 | __ test(eax, eax); |
| 687 | __ j(not_zero, ¶meters_loop, Label::kNear); |
| 688 | __ pop(ecx); |
| 689 | |
| 690 | __ bind(&skip_parameter_map); |
| 691 | |
| 692 | // ecx = argument count (tagged) |
| 693 | // edi = address of backing store (tagged) |
| 694 | // esp[0] = address of new object (tagged) |
| 695 | // esp[4] = mapped parameter count (tagged) |
| 696 | // esp[12] = parameter count (tagged) |
| 697 | // esp[16] = address of receiver argument |
| 698 | // Copy arguments header and remaining slots (if there are any). |
| 699 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
| 700 | Immediate(isolate()->factory()->fixed_array_map())); |
| 701 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 702 | |
| 703 | Label arguments_loop, arguments_test; |
| 704 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 705 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
| 706 | __ sub(edx, ebx); // Is there a smarter way to do negative scaling? |
| 707 | __ sub(edx, ebx); |
| 708 | __ jmp(&arguments_test, Label::kNear); |
| 709 | |
| 710 | __ bind(&arguments_loop); |
| 711 | __ sub(edx, Immediate(kPointerSize)); |
| 712 | __ mov(eax, Operand(edx, 0)); |
| 713 | __ mov(FieldOperand(edi, ebx, times_2, FixedArray::kHeaderSize), eax); |
| 714 | __ add(ebx, Immediate(Smi::FromInt(1))); |
| 715 | |
| 716 | __ bind(&arguments_test); |
| 717 | __ cmp(ebx, ecx); |
| 718 | __ j(less, &arguments_loop, Label::kNear); |
| 719 | |
| 720 | // Restore. |
| 721 | __ pop(eax); // Address of arguments object. |
| 722 | __ pop(ebx); // Parameter count. |
| 723 | |
| 724 | // Return and remove the on-stack parameters. |
| 725 | __ ret(3 * kPointerSize); |
| 726 | |
| 727 | // Do the runtime call to allocate the arguments object. |
| 728 | __ bind(&runtime); |
| 729 | __ pop(eax); // Remove saved parameter count. |
| 730 | __ mov(Operand(esp, 1 * kPointerSize), ecx); // Patch argument count. |
| 731 | __ TailCallRuntime(Runtime::kNewSloppyArguments, 3, 1); |
| 732 | } |
| 733 | |
| 734 | |
| 735 | void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
| 736 | // esp[0] : return address |
| 737 | // esp[4] : number of parameters |
| 738 | // esp[8] : receiver displacement |
| 739 | // esp[12] : function |
| 740 | |
| 741 | // Check if the calling frame is an arguments adaptor frame. |
| 742 | Label adaptor_frame, try_allocate, runtime; |
| 743 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 744 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
| 745 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 746 | __ j(equal, &adaptor_frame, Label::kNear); |
| 747 | |
| 748 | // Get the length from the frame. |
| 749 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 750 | __ jmp(&try_allocate, Label::kNear); |
| 751 | |
| 752 | // Patch the arguments.length and the parameters pointer. |
| 753 | __ bind(&adaptor_frame); |
| 754 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 755 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
| 756 | __ lea(edx, Operand(edx, ecx, times_2, |
| 757 | StandardFrameConstants::kCallerSPOffset)); |
| 758 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 759 | |
| 760 | // Try the new space allocation. Start out with computing the size of |
| 761 | // the arguments object and the elements array. |
| 762 | Label add_arguments_object; |
| 763 | __ bind(&try_allocate); |
| 764 | __ test(ecx, ecx); |
| 765 | __ j(zero, &add_arguments_object, Label::kNear); |
| 766 | __ lea(ecx, Operand(ecx, times_2, FixedArray::kHeaderSize)); |
| 767 | __ bind(&add_arguments_object); |
| 768 | __ add(ecx, Immediate(Heap::kStrictArgumentsObjectSize)); |
| 769 | |
| 770 | // Do the allocation of both objects in one go. |
| 771 | __ Allocate(ecx, eax, edx, ebx, &runtime, TAG_OBJECT); |
| 772 | |
| 773 | // Get the arguments map from the current native context. |
| 774 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 775 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
| 776 | const int offset = Context::SlotOffset(Context::STRICT_ARGUMENTS_MAP_INDEX); |
| 777 | __ mov(edi, Operand(edi, offset)); |
| 778 | |
| 779 | __ mov(FieldOperand(eax, JSObject::kMapOffset), edi); |
| 780 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), |
| 781 | masm->isolate()->factory()->empty_fixed_array()); |
| 782 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), |
| 783 | masm->isolate()->factory()->empty_fixed_array()); |
| 784 | |
| 785 | // Get the length (smi tagged) and set that as an in-object property too. |
| 786 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 787 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 788 | __ AssertSmi(ecx); |
| 789 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 790 | Heap::kArgumentsLengthIndex * kPointerSize), |
| 791 | ecx); |
| 792 | |
| 793 | // If there are no actual arguments, we're done. |
| 794 | Label done; |
| 795 | __ test(ecx, ecx); |
| 796 | __ j(zero, &done, Label::kNear); |
| 797 | |
| 798 | // Get the parameters pointer from the stack. |
| 799 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
| 800 | |
| 801 | // Set up the elements pointer in the allocated arguments object and |
| 802 | // initialize the header in the elements fixed array. |
| 803 | __ lea(edi, Operand(eax, Heap::kStrictArgumentsObjectSize)); |
| 804 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 805 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
| 806 | Immediate(isolate()->factory()->fixed_array_map())); |
| 807 | |
| 808 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 809 | // Untag the length for the loop below. |
| 810 | __ SmiUntag(ecx); |
| 811 | |
| 812 | // Copy the fixed array slots. |
| 813 | Label loop; |
| 814 | __ bind(&loop); |
| 815 | __ mov(ebx, Operand(edx, -1 * kPointerSize)); // Skip receiver. |
| 816 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize), ebx); |
| 817 | __ add(edi, Immediate(kPointerSize)); |
| 818 | __ sub(edx, Immediate(kPointerSize)); |
| 819 | __ dec(ecx); |
| 820 | __ j(not_zero, &loop); |
| 821 | |
| 822 | // Return and remove the on-stack parameters. |
| 823 | __ bind(&done); |
| 824 | __ ret(3 * kPointerSize); |
| 825 | |
| 826 | // Do the runtime call to allocate the arguments object. |
| 827 | __ bind(&runtime); |
| 828 | __ TailCallRuntime(Runtime::kNewStrictArguments, 3, 1); |
| 829 | } |
| 830 | |
| 831 | |
| 832 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 833 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 834 | // time or if regexp entry in generated code is turned off runtime switch or |
| 835 | // at compilation. |
| 836 | #ifdef V8_INTERPRETED_REGEXP |
| 837 | __ TailCallRuntime(Runtime::kRegExpExecRT, 4, 1); |
| 838 | #else // V8_INTERPRETED_REGEXP |
| 839 | |
| 840 | // Stack frame on entry. |
| 841 | // esp[0]: return address |
| 842 | // esp[4]: last_match_info (expected JSArray) |
| 843 | // esp[8]: previous index |
| 844 | // esp[12]: subject string |
| 845 | // esp[16]: JSRegExp object |
| 846 | |
| 847 | static const int kLastMatchInfoOffset = 1 * kPointerSize; |
| 848 | static const int kPreviousIndexOffset = 2 * kPointerSize; |
| 849 | static const int kSubjectOffset = 3 * kPointerSize; |
| 850 | static const int kJSRegExpOffset = 4 * kPointerSize; |
| 851 | |
| 852 | Label runtime; |
| 853 | Factory* factory = isolate()->factory(); |
| 854 | |
| 855 | // Ensure that a RegExp stack is allocated. |
| 856 | ExternalReference address_of_regexp_stack_memory_address = |
| 857 | ExternalReference::address_of_regexp_stack_memory_address(isolate()); |
| 858 | ExternalReference address_of_regexp_stack_memory_size = |
| 859 | ExternalReference::address_of_regexp_stack_memory_size(isolate()); |
| 860 | __ mov(ebx, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
| 861 | __ test(ebx, ebx); |
| 862 | __ j(zero, &runtime); |
| 863 | |
| 864 | // Check that the first argument is a JSRegExp object. |
| 865 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 866 | STATIC_ASSERT(kSmiTag == 0); |
| 867 | __ JumpIfSmi(eax, &runtime); |
| 868 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ecx); |
| 869 | __ j(not_equal, &runtime); |
| 870 | |
| 871 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 872 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 873 | if (FLAG_debug_code) { |
| 874 | __ test(ecx, Immediate(kSmiTagMask)); |
| 875 | __ Check(not_zero, kUnexpectedTypeForRegExpDataFixedArrayExpected); |
| 876 | __ CmpObjectType(ecx, FIXED_ARRAY_TYPE, ebx); |
| 877 | __ Check(equal, kUnexpectedTypeForRegExpDataFixedArrayExpected); |
| 878 | } |
| 879 | |
| 880 | // ecx: RegExp data (FixedArray) |
| 881 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 882 | __ mov(ebx, FieldOperand(ecx, JSRegExp::kDataTagOffset)); |
| 883 | __ cmp(ebx, Immediate(Smi::FromInt(JSRegExp::IRREGEXP))); |
| 884 | __ j(not_equal, &runtime); |
| 885 | |
| 886 | // ecx: RegExp data (FixedArray) |
| 887 | // Check that the number of captures fit in the static offsets vector buffer. |
| 888 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 889 | // Check (number_of_captures + 1) * 2 <= offsets vector size |
| 890 | // Or number_of_captures * 2 <= offsets vector size - 2 |
| 891 | // Multiplying by 2 comes for free since edx is smi-tagged. |
| 892 | STATIC_ASSERT(kSmiTag == 0); |
| 893 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
| 894 | STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2); |
| 895 | __ cmp(edx, Isolate::kJSRegexpStaticOffsetsVectorSize - 2); |
| 896 | __ j(above, &runtime); |
| 897 | |
| 898 | // Reset offset for possibly sliced string. |
| 899 | __ Move(edi, Immediate(0)); |
| 900 | __ mov(eax, Operand(esp, kSubjectOffset)); |
| 901 | __ JumpIfSmi(eax, &runtime); |
| 902 | __ mov(edx, eax); // Make a copy of the original subject string. |
| 903 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 904 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 905 | |
| 906 | // eax: subject string |
| 907 | // edx: subject string |
| 908 | // ebx: subject string instance type |
| 909 | // ecx: RegExp data (FixedArray) |
| 910 | // Handle subject string according to its encoding and representation: |
| 911 | // (1) Sequential two byte? If yes, go to (9). |
| 912 | // (2) Sequential one byte? If yes, go to (6). |
| 913 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 914 | // (4) Cons string. If the string is flat, replace subject with first string. |
| 915 | // Otherwise bailout. |
| 916 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 917 | // (5b) Is subject external? If yes, go to (8). |
| 918 | // (6) One byte sequential. Load regexp code for one byte. |
| 919 | // (E) Carry on. |
| 920 | /// [...] |
| 921 | |
| 922 | // Deferred code at the end of the stub: |
| 923 | // (7) Not a long external string? If yes, go to (10). |
| 924 | // (8) External string. Make it, offset-wise, look like a sequential string. |
| 925 | // (8a) Is the external string one byte? If yes, go to (6). |
| 926 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 927 | // (10) Short external string or not a string? If yes, bail out to runtime. |
| 928 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 929 | |
| 930 | Label seq_one_byte_string /* 6 */, seq_two_byte_string /* 9 */, |
| 931 | external_string /* 8 */, check_underlying /* 5a */, |
| 932 | not_seq_nor_cons /* 7 */, check_code /* E */, |
| 933 | not_long_external /* 10 */; |
| 934 | |
| 935 | // (1) Sequential two byte? If yes, go to (9). |
| 936 | __ and_(ebx, kIsNotStringMask | |
| 937 | kStringRepresentationMask | |
| 938 | kStringEncodingMask | |
| 939 | kShortExternalStringMask); |
| 940 | STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0); |
| 941 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 942 | |
| 943 | // (2) Sequential one byte? If yes, go to (6). |
| 944 | // Any other sequential string must be one byte. |
| 945 | __ and_(ebx, Immediate(kIsNotStringMask | |
| 946 | kStringRepresentationMask | |
| 947 | kShortExternalStringMask)); |
| 948 | __ j(zero, &seq_one_byte_string, Label::kNear); // Go to (6). |
| 949 | |
| 950 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 951 | // We check whether the subject string is a cons, since sequential strings |
| 952 | // have already been covered. |
| 953 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 954 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
| 955 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 956 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
| 957 | __ cmp(ebx, Immediate(kExternalStringTag)); |
| 958 | __ j(greater_equal, ¬_seq_nor_cons); // Go to (7). |
| 959 | |
| 960 | // (4) Cons string. Check that it's flat. |
| 961 | // Replace subject with first string and reload instance type. |
| 962 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string()); |
| 963 | __ j(not_equal, &runtime); |
| 964 | __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset)); |
| 965 | __ bind(&check_underlying); |
| 966 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 967 | __ mov(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 968 | |
| 969 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 970 | __ test_b(ebx, kStringRepresentationMask | kStringEncodingMask); |
| 971 | STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0); |
| 972 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 973 | // (5b) Is subject external? If yes, go to (8). |
| 974 | __ test_b(ebx, kStringRepresentationMask); |
| 975 | // The underlying external string is never a short external string. |
| 976 | STATIC_ASSERT(ExternalString::kMaxShortLength < ConsString::kMinLength); |
| 977 | STATIC_ASSERT(ExternalString::kMaxShortLength < SlicedString::kMinLength); |
| 978 | __ j(not_zero, &external_string); // Go to (8). |
| 979 | |
| 980 | // eax: sequential subject string (or look-alike, external string) |
| 981 | // edx: original subject string |
| 982 | // ecx: RegExp data (FixedArray) |
| 983 | // (6) One byte sequential. Load regexp code for one byte. |
| 984 | __ bind(&seq_one_byte_string); |
| 985 | // Load previous index and check range before edx is overwritten. We have |
| 986 | // to use edx instead of eax here because it might have been only made to |
| 987 | // look like a sequential string when it actually is an external string. |
| 988 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 989 | __ JumpIfNotSmi(ebx, &runtime); |
| 990 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 991 | __ j(above_equal, &runtime); |
| 992 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataOneByteCodeOffset)); |
| 993 | __ Move(ecx, Immediate(1)); // Type is one byte. |
| 994 | |
| 995 | // (E) Carry on. String handling is done. |
| 996 | __ bind(&check_code); |
| 997 | // edx: irregexp code |
| 998 | // Check that the irregexp code has been generated for the actual string |
| 999 | // encoding. If it has, the field contains a code object otherwise it contains |
| 1000 | // a smi (code flushing support). |
| 1001 | __ JumpIfSmi(edx, &runtime); |
| 1002 | |
| 1003 | // eax: subject string |
| 1004 | // ebx: previous index (smi) |
| 1005 | // edx: code |
| 1006 | // ecx: encoding of subject string (1 if one_byte, 0 if two_byte); |
| 1007 | // All checks done. Now push arguments for native regexp code. |
| 1008 | Counters* counters = isolate()->counters(); |
| 1009 | __ IncrementCounter(counters->regexp_entry_native(), 1); |
| 1010 | |
| 1011 | // Isolates: note we add an additional parameter here (isolate pointer). |
| 1012 | static const int kRegExpExecuteArguments = 9; |
| 1013 | __ EnterApiExitFrame(kRegExpExecuteArguments); |
| 1014 | |
| 1015 | // Argument 9: Pass current isolate address. |
| 1016 | __ mov(Operand(esp, 8 * kPointerSize), |
| 1017 | Immediate(ExternalReference::isolate_address(isolate()))); |
| 1018 | |
| 1019 | // Argument 8: Indicate that this is a direct call from JavaScript. |
| 1020 | __ mov(Operand(esp, 7 * kPointerSize), Immediate(1)); |
| 1021 | |
| 1022 | // Argument 7: Start (high end) of backtracking stack memory area. |
| 1023 | __ mov(esi, Operand::StaticVariable(address_of_regexp_stack_memory_address)); |
| 1024 | __ add(esi, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
| 1025 | __ mov(Operand(esp, 6 * kPointerSize), esi); |
| 1026 | |
| 1027 | // Argument 6: Set the number of capture registers to zero to force global |
| 1028 | // regexps to behave as non-global. This does not affect non-global regexps. |
| 1029 | __ mov(Operand(esp, 5 * kPointerSize), Immediate(0)); |
| 1030 | |
| 1031 | // Argument 5: static offsets vector buffer. |
| 1032 | __ mov(Operand(esp, 4 * kPointerSize), |
| 1033 | Immediate(ExternalReference::address_of_static_offsets_vector( |
| 1034 | isolate()))); |
| 1035 | |
| 1036 | // Argument 2: Previous index. |
| 1037 | __ SmiUntag(ebx); |
| 1038 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1039 | |
| 1040 | // Argument 1: Original subject string. |
| 1041 | // The original subject is in the previous stack frame. Therefore we have to |
| 1042 | // use ebp, which points exactly to one pointer size below the previous esp. |
| 1043 | // (Because creating a new stack frame pushes the previous ebp onto the stack |
| 1044 | // and thereby moves up esp by one kPointerSize.) |
| 1045 | __ mov(esi, Operand(ebp, kSubjectOffset + kPointerSize)); |
| 1046 | __ mov(Operand(esp, 0 * kPointerSize), esi); |
| 1047 | |
| 1048 | // esi: original subject string |
| 1049 | // eax: underlying subject string |
| 1050 | // ebx: previous index |
| 1051 | // ecx: encoding of subject string (1 if one_byte 0 if two_byte); |
| 1052 | // edx: code |
| 1053 | // Argument 4: End of string data |
| 1054 | // Argument 3: Start of string data |
| 1055 | // Prepare start and end index of the input. |
| 1056 | // Load the length from the original sliced string if that is the case. |
| 1057 | __ mov(esi, FieldOperand(esi, String::kLengthOffset)); |
| 1058 | __ add(esi, edi); // Calculate input end wrt offset. |
| 1059 | __ SmiUntag(edi); |
| 1060 | __ add(ebx, edi); // Calculate input start wrt offset. |
| 1061 | |
| 1062 | // ebx: start index of the input string |
| 1063 | // esi: end index of the input string |
| 1064 | Label setup_two_byte, setup_rest; |
| 1065 | __ test(ecx, ecx); |
| 1066 | __ j(zero, &setup_two_byte, Label::kNear); |
| 1067 | __ SmiUntag(esi); |
| 1068 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqOneByteString::kHeaderSize)); |
| 1069 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| 1070 | __ lea(ecx, FieldOperand(eax, ebx, times_1, SeqOneByteString::kHeaderSize)); |
| 1071 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
| 1072 | __ jmp(&setup_rest, Label::kNear); |
| 1073 | |
| 1074 | __ bind(&setup_two_byte); |
| 1075 | STATIC_ASSERT(kSmiTag == 0); |
| 1076 | STATIC_ASSERT(kSmiTagSize == 1); // esi is smi (powered by 2). |
| 1077 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqTwoByteString::kHeaderSize)); |
| 1078 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| 1079 | __ lea(ecx, FieldOperand(eax, ebx, times_2, SeqTwoByteString::kHeaderSize)); |
| 1080 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
| 1081 | |
| 1082 | __ bind(&setup_rest); |
| 1083 | |
| 1084 | // Locate the code entry and call it. |
| 1085 | __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 1086 | __ call(edx); |
| 1087 | |
| 1088 | // Drop arguments and come back to JS mode. |
| 1089 | __ LeaveApiExitFrame(true); |
| 1090 | |
| 1091 | // Check the result. |
| 1092 | Label success; |
| 1093 | __ cmp(eax, 1); |
| 1094 | // We expect exactly one result since we force the called regexp to behave |
| 1095 | // as non-global. |
| 1096 | __ j(equal, &success); |
| 1097 | Label failure; |
| 1098 | __ cmp(eax, NativeRegExpMacroAssembler::FAILURE); |
| 1099 | __ j(equal, &failure); |
| 1100 | __ cmp(eax, NativeRegExpMacroAssembler::EXCEPTION); |
| 1101 | // If not exception it can only be retry. Handle that in the runtime system. |
| 1102 | __ j(not_equal, &runtime); |
| 1103 | // Result must now be exception. If there is no pending exception already a |
| 1104 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 1105 | // haven't created the exception yet. Handle that in the runtime system. |
| 1106 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
| 1107 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
| 1108 | isolate()); |
| 1109 | __ mov(edx, Immediate(isolate()->factory()->the_hole_value())); |
| 1110 | __ mov(eax, Operand::StaticVariable(pending_exception)); |
| 1111 | __ cmp(edx, eax); |
| 1112 | __ j(equal, &runtime); |
| 1113 | // For exception, throw the exception again. |
| 1114 | |
| 1115 | // Clear the pending exception variable. |
| 1116 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 1117 | |
| 1118 | // Special handling of termination exceptions which are uncatchable |
| 1119 | // by javascript code. |
| 1120 | __ cmp(eax, factory->termination_exception()); |
| 1121 | Label throw_termination_exception; |
| 1122 | __ j(equal, &throw_termination_exception, Label::kNear); |
| 1123 | |
| 1124 | // Handle normal exception by following handler chain. |
| 1125 | __ Throw(eax); |
| 1126 | |
| 1127 | __ bind(&throw_termination_exception); |
| 1128 | __ ThrowUncatchable(eax); |
| 1129 | |
| 1130 | __ bind(&failure); |
| 1131 | // For failure to match, return null. |
| 1132 | __ mov(eax, factory->null_value()); |
| 1133 | __ ret(4 * kPointerSize); |
| 1134 | |
| 1135 | // Load RegExp data. |
| 1136 | __ bind(&success); |
| 1137 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 1138 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 1139 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 1140 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 1141 | STATIC_ASSERT(kSmiTag == 0); |
| 1142 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
| 1143 | __ add(edx, Immediate(2)); // edx was a smi. |
| 1144 | |
| 1145 | // edx: Number of capture registers |
| 1146 | // Load last_match_info which is still known to be a fast case JSArray. |
| 1147 | // Check that the fourth object is a JSArray object. |
| 1148 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 1149 | __ JumpIfSmi(eax, &runtime); |
| 1150 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
| 1151 | __ j(not_equal, &runtime); |
| 1152 | // Check that the JSArray is in fast case. |
| 1153 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
| 1154 | __ mov(eax, FieldOperand(ebx, HeapObject::kMapOffset)); |
| 1155 | __ cmp(eax, factory->fixed_array_map()); |
| 1156 | __ j(not_equal, &runtime); |
| 1157 | // Check that the last match info has space for the capture registers and the |
| 1158 | // additional information. |
| 1159 | __ mov(eax, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 1160 | __ SmiUntag(eax); |
| 1161 | __ sub(eax, Immediate(RegExpImpl::kLastMatchOverhead)); |
| 1162 | __ cmp(edx, eax); |
| 1163 | __ j(greater, &runtime); |
| 1164 | |
| 1165 | // ebx: last_match_info backing store (FixedArray) |
| 1166 | // edx: number of capture registers |
| 1167 | // Store the capture count. |
| 1168 | __ SmiTag(edx); // Number of capture registers to smi. |
| 1169 | __ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx); |
| 1170 | __ SmiUntag(edx); // Number of capture registers back from smi. |
| 1171 | // Store last subject and last input. |
| 1172 | __ mov(eax, Operand(esp, kSubjectOffset)); |
| 1173 | __ mov(ecx, eax); |
| 1174 | __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax); |
| 1175 | __ RecordWriteField(ebx, RegExpImpl::kLastSubjectOffset, eax, edi, |
| 1176 | kDontSaveFPRegs); |
| 1177 | __ mov(eax, ecx); |
| 1178 | __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax); |
| 1179 | __ RecordWriteField(ebx, RegExpImpl::kLastInputOffset, eax, edi, |
| 1180 | kDontSaveFPRegs); |
| 1181 | |
| 1182 | // Get the static offsets vector filled by the native regexp code. |
| 1183 | ExternalReference address_of_static_offsets_vector = |
| 1184 | ExternalReference::address_of_static_offsets_vector(isolate()); |
| 1185 | __ mov(ecx, Immediate(address_of_static_offsets_vector)); |
| 1186 | |
| 1187 | // ebx: last_match_info backing store (FixedArray) |
| 1188 | // ecx: offsets vector |
| 1189 | // edx: number of capture registers |
| 1190 | Label next_capture, done; |
| 1191 | // Capture register counter starts from number of capture registers and |
| 1192 | // counts down until wraping after zero. |
| 1193 | __ bind(&next_capture); |
| 1194 | __ sub(edx, Immediate(1)); |
| 1195 | __ j(negative, &done, Label::kNear); |
| 1196 | // Read the value from the static offsets vector buffer. |
| 1197 | __ mov(edi, Operand(ecx, edx, times_int_size, 0)); |
| 1198 | __ SmiTag(edi); |
| 1199 | // Store the smi value in the last match info. |
| 1200 | __ mov(FieldOperand(ebx, |
| 1201 | edx, |
| 1202 | times_pointer_size, |
| 1203 | RegExpImpl::kFirstCaptureOffset), |
| 1204 | edi); |
| 1205 | __ jmp(&next_capture); |
| 1206 | __ bind(&done); |
| 1207 | |
| 1208 | // Return last match info. |
| 1209 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 1210 | __ ret(4 * kPointerSize); |
| 1211 | |
| 1212 | // Do the runtime call to execute the regexp. |
| 1213 | __ bind(&runtime); |
| 1214 | __ TailCallRuntime(Runtime::kRegExpExecRT, 4, 1); |
| 1215 | |
| 1216 | // Deferred code for string handling. |
| 1217 | // (7) Not a long external string? If yes, go to (10). |
| 1218 | __ bind(¬_seq_nor_cons); |
| 1219 | // Compare flags are still set from (3). |
| 1220 | __ j(greater, ¬_long_external, Label::kNear); // Go to (10). |
| 1221 | |
| 1222 | // (8) External string. Short external strings have been ruled out. |
| 1223 | __ bind(&external_string); |
| 1224 | // Reload instance type. |
| 1225 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 1226 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 1227 | if (FLAG_debug_code) { |
| 1228 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 1229 | // Sequential strings have already been ruled out. |
| 1230 | __ test_b(ebx, kIsIndirectStringMask); |
| 1231 | __ Assert(zero, kExternalStringExpectedButNotFound); |
| 1232 | } |
| 1233 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
| 1234 | // Move the pointer so that offset-wise, it looks like a sequential string. |
| 1235 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
| 1236 | __ sub(eax, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 1237 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 1238 | // (8a) Is the external string one byte? If yes, go to (6). |
| 1239 | __ test_b(ebx, kStringEncodingMask); |
| 1240 | __ j(not_zero, &seq_one_byte_string); // Goto (6). |
| 1241 | |
| 1242 | // eax: sequential subject string (or look-alike, external string) |
| 1243 | // edx: original subject string |
| 1244 | // ecx: RegExp data (FixedArray) |
| 1245 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 1246 | __ bind(&seq_two_byte_string); |
| 1247 | // Load previous index and check range before edx is overwritten. We have |
| 1248 | // to use edx instead of eax here because it might have been only made to |
| 1249 | // look like a sequential string when it actually is an external string. |
| 1250 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 1251 | __ JumpIfNotSmi(ebx, &runtime); |
| 1252 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 1253 | __ j(above_equal, &runtime); |
| 1254 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset)); |
| 1255 | __ Move(ecx, Immediate(0)); // Type is two byte. |
| 1256 | __ jmp(&check_code); // Go to (E). |
| 1257 | |
| 1258 | // (10) Not a string or a short external string? If yes, bail out to runtime. |
| 1259 | __ bind(¬_long_external); |
| 1260 | // Catch non-string subject or short external string. |
| 1261 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 1262 | __ test(ebx, Immediate(kIsNotStringMask | kShortExternalStringTag)); |
| 1263 | __ j(not_zero, &runtime); |
| 1264 | |
| 1265 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 1266 | // Load offset into edi and replace subject string with parent. |
| 1267 | __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 1268 | __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset)); |
| 1269 | __ jmp(&check_underlying); // Go to (5a). |
| 1270 | #endif // V8_INTERPRETED_REGEXP |
| 1271 | } |
| 1272 | |
| 1273 | |
| 1274 | static int NegativeComparisonResult(Condition cc) { |
| 1275 | DCHECK(cc != equal); |
| 1276 | DCHECK((cc == less) || (cc == less_equal) |
| 1277 | || (cc == greater) || (cc == greater_equal)); |
| 1278 | return (cc == greater || cc == greater_equal) ? LESS : GREATER; |
| 1279 | } |
| 1280 | |
| 1281 | |
| 1282 | static void CheckInputType(MacroAssembler* masm, Register input, |
| 1283 | CompareICState::State expected, Label* fail) { |
| 1284 | Label ok; |
| 1285 | if (expected == CompareICState::SMI) { |
| 1286 | __ JumpIfNotSmi(input, fail); |
| 1287 | } else if (expected == CompareICState::NUMBER) { |
| 1288 | __ JumpIfSmi(input, &ok); |
| 1289 | __ cmp(FieldOperand(input, HeapObject::kMapOffset), |
| 1290 | Immediate(masm->isolate()->factory()->heap_number_map())); |
| 1291 | __ j(not_equal, fail); |
| 1292 | } |
| 1293 | // We could be strict about internalized/non-internalized here, but as long as |
| 1294 | // hydrogen doesn't care, the stub doesn't have to care either. |
| 1295 | __ bind(&ok); |
| 1296 | } |
| 1297 | |
| 1298 | |
| 1299 | static void BranchIfNotInternalizedString(MacroAssembler* masm, |
| 1300 | Label* label, |
| 1301 | Register object, |
| 1302 | Register scratch) { |
| 1303 | __ JumpIfSmi(object, label); |
| 1304 | __ mov(scratch, FieldOperand(object, HeapObject::kMapOffset)); |
| 1305 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
| 1306 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 1307 | __ test(scratch, Immediate(kIsNotStringMask | kIsNotInternalizedMask)); |
| 1308 | __ j(not_zero, label); |
| 1309 | } |
| 1310 | |
| 1311 | |
| 1312 | void CompareICStub::GenerateGeneric(MacroAssembler* masm) { |
| 1313 | Label check_unequal_objects; |
| 1314 | Condition cc = GetCondition(); |
| 1315 | |
| 1316 | Label miss; |
| 1317 | CheckInputType(masm, edx, left(), &miss); |
| 1318 | CheckInputType(masm, eax, right(), &miss); |
| 1319 | |
| 1320 | // Compare two smis. |
| 1321 | Label non_smi, smi_done; |
| 1322 | __ mov(ecx, edx); |
| 1323 | __ or_(ecx, eax); |
| 1324 | __ JumpIfNotSmi(ecx, &non_smi, Label::kNear); |
| 1325 | __ sub(edx, eax); // Return on the result of the subtraction. |
| 1326 | __ j(no_overflow, &smi_done, Label::kNear); |
| 1327 | __ not_(edx); // Correct sign in case of overflow. edx is never 0 here. |
| 1328 | __ bind(&smi_done); |
| 1329 | __ mov(eax, edx); |
| 1330 | __ ret(0); |
| 1331 | __ bind(&non_smi); |
| 1332 | |
| 1333 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 1334 | // it is certain that at least one operand isn't a smi. |
| 1335 | |
| 1336 | // Identical objects can be compared fast, but there are some tricky cases |
| 1337 | // for NaN and undefined. |
| 1338 | Label generic_heap_number_comparison; |
| 1339 | { |
| 1340 | Label not_identical; |
| 1341 | __ cmp(eax, edx); |
| 1342 | __ j(not_equal, ¬_identical); |
| 1343 | |
| 1344 | if (cc != equal) { |
| 1345 | // Check for undefined. undefined OP undefined is false even though |
| 1346 | // undefined == undefined. |
| 1347 | Label check_for_nan; |
| 1348 | __ cmp(edx, isolate()->factory()->undefined_value()); |
| 1349 | __ j(not_equal, &check_for_nan, Label::kNear); |
| 1350 | __ Move(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
| 1351 | __ ret(0); |
| 1352 | __ bind(&check_for_nan); |
| 1353 | } |
| 1354 | |
| 1355 | // Test for NaN. Compare heap numbers in a general way, |
| 1356 | // to hanlde NaNs correctly. |
| 1357 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 1358 | Immediate(isolate()->factory()->heap_number_map())); |
| 1359 | __ j(equal, &generic_heap_number_comparison, Label::kNear); |
| 1360 | if (cc != equal) { |
| 1361 | // Call runtime on identical JSObjects. Otherwise return equal. |
| 1362 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 1363 | __ j(above_equal, ¬_identical); |
| 1364 | } |
| 1365 | __ Move(eax, Immediate(Smi::FromInt(EQUAL))); |
| 1366 | __ ret(0); |
| 1367 | |
| 1368 | |
| 1369 | __ bind(¬_identical); |
| 1370 | } |
| 1371 | |
| 1372 | // Strict equality can quickly decide whether objects are equal. |
| 1373 | // Non-strict object equality is slower, so it is handled later in the stub. |
| 1374 | if (cc == equal && strict()) { |
| 1375 | Label slow; // Fallthrough label. |
| 1376 | Label not_smis; |
| 1377 | // If we're doing a strict equality comparison, we don't have to do |
| 1378 | // type conversion, so we generate code to do fast comparison for objects |
| 1379 | // and oddballs. Non-smi numbers and strings still go through the usual |
| 1380 | // slow-case code. |
| 1381 | // If either is a Smi (we know that not both are), then they can only |
| 1382 | // be equal if the other is a HeapNumber. If so, use the slow case. |
| 1383 | STATIC_ASSERT(kSmiTag == 0); |
| 1384 | DCHECK_EQ(0, Smi::FromInt(0)); |
| 1385 | __ mov(ecx, Immediate(kSmiTagMask)); |
| 1386 | __ and_(ecx, eax); |
| 1387 | __ test(ecx, edx); |
| 1388 | __ j(not_zero, ¬_smis, Label::kNear); |
| 1389 | // One operand is a smi. |
| 1390 | |
| 1391 | // Check whether the non-smi is a heap number. |
| 1392 | STATIC_ASSERT(kSmiTagMask == 1); |
| 1393 | // ecx still holds eax & kSmiTag, which is either zero or one. |
| 1394 | __ sub(ecx, Immediate(0x01)); |
| 1395 | __ mov(ebx, edx); |
| 1396 | __ xor_(ebx, eax); |
| 1397 | __ and_(ebx, ecx); // ebx holds either 0 or eax ^ edx. |
| 1398 | __ xor_(ebx, eax); |
| 1399 | // if eax was smi, ebx is now edx, else eax. |
| 1400 | |
| 1401 | // Check if the non-smi operand is a heap number. |
| 1402 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
| 1403 | Immediate(isolate()->factory()->heap_number_map())); |
| 1404 | // If heap number, handle it in the slow case. |
| 1405 | __ j(equal, &slow, Label::kNear); |
| 1406 | // Return non-equal (ebx is not zero) |
| 1407 | __ mov(eax, ebx); |
| 1408 | __ ret(0); |
| 1409 | |
| 1410 | __ bind(¬_smis); |
| 1411 | // If either operand is a JSObject or an oddball value, then they are not |
| 1412 | // equal since their pointers are different |
| 1413 | // There is no test for undetectability in strict equality. |
| 1414 | |
| 1415 | // Get the type of the first operand. |
| 1416 | // If the first object is a JS object, we have done pointer comparison. |
| 1417 | Label first_non_object; |
| 1418 | STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE); |
| 1419 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 1420 | __ j(below, &first_non_object, Label::kNear); |
| 1421 | |
| 1422 | // Return non-zero (eax is not zero) |
| 1423 | Label return_not_equal; |
| 1424 | STATIC_ASSERT(kHeapObjectTag != 0); |
| 1425 | __ bind(&return_not_equal); |
| 1426 | __ ret(0); |
| 1427 | |
| 1428 | __ bind(&first_non_object); |
| 1429 | // Check for oddballs: true, false, null, undefined. |
| 1430 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 1431 | __ j(equal, &return_not_equal); |
| 1432 | |
| 1433 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 1434 | __ j(above_equal, &return_not_equal); |
| 1435 | |
| 1436 | // Check for oddballs: true, false, null, undefined. |
| 1437 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 1438 | __ j(equal, &return_not_equal); |
| 1439 | |
| 1440 | // Fall through to the general case. |
| 1441 | __ bind(&slow); |
| 1442 | } |
| 1443 | |
| 1444 | // Generate the number comparison code. |
| 1445 | Label non_number_comparison; |
| 1446 | Label unordered; |
| 1447 | __ bind(&generic_heap_number_comparison); |
| 1448 | FloatingPointHelper::CheckFloatOperands( |
| 1449 | masm, &non_number_comparison, ebx); |
| 1450 | FloatingPointHelper::LoadFloatOperand(masm, eax); |
| 1451 | FloatingPointHelper::LoadFloatOperand(masm, edx); |
| 1452 | __ FCmp(); |
| 1453 | |
| 1454 | // Don't base result on EFLAGS when a NaN is involved. |
| 1455 | __ j(parity_even, &unordered, Label::kNear); |
| 1456 | |
| 1457 | Label below_label, above_label; |
| 1458 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 1459 | __ j(below, &below_label, Label::kNear); |
| 1460 | __ j(above, &above_label, Label::kNear); |
| 1461 | |
| 1462 | __ Move(eax, Immediate(0)); |
| 1463 | __ ret(0); |
| 1464 | |
| 1465 | __ bind(&below_label); |
| 1466 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 1467 | __ ret(0); |
| 1468 | |
| 1469 | __ bind(&above_label); |
| 1470 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 1471 | __ ret(0); |
| 1472 | |
| 1473 | // If one of the numbers was NaN, then the result is always false. |
| 1474 | // The cc is never not-equal. |
| 1475 | __ bind(&unordered); |
| 1476 | DCHECK(cc != not_equal); |
| 1477 | if (cc == less || cc == less_equal) { |
| 1478 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 1479 | } else { |
| 1480 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 1481 | } |
| 1482 | __ ret(0); |
| 1483 | |
| 1484 | // The number comparison code did not provide a valid result. |
| 1485 | __ bind(&non_number_comparison); |
| 1486 | |
| 1487 | // Fast negative check for internalized-to-internalized equality. |
| 1488 | Label check_for_strings; |
| 1489 | if (cc == equal) { |
| 1490 | BranchIfNotInternalizedString(masm, &check_for_strings, eax, ecx); |
| 1491 | BranchIfNotInternalizedString(masm, &check_for_strings, edx, ecx); |
| 1492 | |
| 1493 | // We've already checked for object identity, so if both operands |
| 1494 | // are internalized they aren't equal. Register eax already holds a |
| 1495 | // non-zero value, which indicates not equal, so just return. |
| 1496 | __ ret(0); |
| 1497 | } |
| 1498 | |
| 1499 | __ bind(&check_for_strings); |
| 1500 | |
| 1501 | __ JumpIfNotBothSequentialOneByteStrings(edx, eax, ecx, ebx, |
| 1502 | &check_unequal_objects); |
| 1503 | |
| 1504 | // Inline comparison of one-byte strings. |
| 1505 | if (cc == equal) { |
| 1506 | StringHelper::GenerateFlatOneByteStringEquals(masm, edx, eax, ecx, ebx); |
| 1507 | } else { |
| 1508 | StringHelper::GenerateCompareFlatOneByteStrings(masm, edx, eax, ecx, ebx, |
| 1509 | edi); |
| 1510 | } |
| 1511 | #ifdef DEBUG |
| 1512 | __ Abort(kUnexpectedFallThroughFromStringComparison); |
| 1513 | #endif |
| 1514 | |
| 1515 | __ bind(&check_unequal_objects); |
| 1516 | if (cc == equal && !strict()) { |
| 1517 | // Non-strict equality. Objects are unequal if |
| 1518 | // they are both JSObjects and not undetectable, |
| 1519 | // and their pointers are different. |
| 1520 | Label not_both_objects; |
| 1521 | Label return_unequal; |
| 1522 | // At most one is a smi, so we can test for smi by adding the two. |
| 1523 | // A smi plus a heap object has the low bit set, a heap object plus |
| 1524 | // a heap object has the low bit clear. |
| 1525 | STATIC_ASSERT(kSmiTag == 0); |
| 1526 | STATIC_ASSERT(kSmiTagMask == 1); |
| 1527 | __ lea(ecx, Operand(eax, edx, times_1, 0)); |
| 1528 | __ test(ecx, Immediate(kSmiTagMask)); |
| 1529 | __ j(not_zero, ¬_both_objects, Label::kNear); |
| 1530 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 1531 | __ j(below, ¬_both_objects, Label::kNear); |
| 1532 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ebx); |
| 1533 | __ j(below, ¬_both_objects, Label::kNear); |
| 1534 | // We do not bail out after this point. Both are JSObjects, and |
| 1535 | // they are equal if and only if both are undetectable. |
| 1536 | // The and of the undetectable flags is 1 if and only if they are equal. |
| 1537 | __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), |
| 1538 | 1 << Map::kIsUndetectable); |
| 1539 | __ j(zero, &return_unequal, Label::kNear); |
| 1540 | __ test_b(FieldOperand(ebx, Map::kBitFieldOffset), |
| 1541 | 1 << Map::kIsUndetectable); |
| 1542 | __ j(zero, &return_unequal, Label::kNear); |
| 1543 | // The objects are both undetectable, so they both compare as the value |
| 1544 | // undefined, and are equal. |
| 1545 | __ Move(eax, Immediate(EQUAL)); |
| 1546 | __ bind(&return_unequal); |
| 1547 | // Return non-equal by returning the non-zero object pointer in eax, |
| 1548 | // or return equal if we fell through to here. |
| 1549 | __ ret(0); // rax, rdx were pushed |
| 1550 | __ bind(¬_both_objects); |
| 1551 | } |
| 1552 | |
| 1553 | // Push arguments below the return address. |
| 1554 | __ pop(ecx); |
| 1555 | __ push(edx); |
| 1556 | __ push(eax); |
| 1557 | |
| 1558 | // Figure out which native to call and setup the arguments. |
| 1559 | Builtins::JavaScript builtin; |
| 1560 | if (cc == equal) { |
| 1561 | builtin = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
| 1562 | } else { |
| 1563 | builtin = Builtins::COMPARE; |
| 1564 | __ push(Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
| 1565 | } |
| 1566 | |
| 1567 | // Restore return address on the stack. |
| 1568 | __ push(ecx); |
| 1569 | |
| 1570 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 1571 | // tagged as a small integer. |
| 1572 | __ InvokeBuiltin(builtin, JUMP_FUNCTION); |
| 1573 | |
| 1574 | __ bind(&miss); |
| 1575 | GenerateMiss(masm); |
| 1576 | } |
| 1577 | |
| 1578 | |
| 1579 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
| 1580 | // Cache the called function in a feedback vector slot. Cache states |
| 1581 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 1582 | // megamorphic. |
| 1583 | // eax : number of arguments to the construct function |
| 1584 | // ebx : Feedback vector |
| 1585 | // edx : slot in feedback vector (Smi) |
| 1586 | // edi : the function to call |
| 1587 | Isolate* isolate = masm->isolate(); |
| 1588 | Label initialize, done, miss, megamorphic, not_array_function; |
| 1589 | |
| 1590 | // Load the cache state into ecx. |
| 1591 | __ mov(ecx, FieldOperand(ebx, edx, times_half_pointer_size, |
| 1592 | FixedArray::kHeaderSize)); |
| 1593 | |
| 1594 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 1595 | // function without changing the state. |
| 1596 | __ cmp(ecx, edi); |
| 1597 | __ j(equal, &done, Label::kFar); |
| 1598 | __ cmp(ecx, Immediate(TypeFeedbackVector::MegamorphicSentinel(isolate))); |
| 1599 | __ j(equal, &done, Label::kFar); |
| 1600 | |
| 1601 | if (!FLAG_pretenuring_call_new) { |
| 1602 | // If we came here, we need to see if we are the array function. |
| 1603 | // If we didn't have a matching function, and we didn't find the megamorph |
| 1604 | // sentinel, then we have in the slot either some other function or an |
| 1605 | // AllocationSite. Do a map check on the object in ecx. |
| 1606 | Handle<Map> allocation_site_map = isolate->factory()->allocation_site_map(); |
| 1607 | __ cmp(FieldOperand(ecx, 0), Immediate(allocation_site_map)); |
| 1608 | __ j(not_equal, &miss); |
| 1609 | |
| 1610 | // Make sure the function is the Array() function |
| 1611 | __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, ecx); |
| 1612 | __ cmp(edi, ecx); |
| 1613 | __ j(not_equal, &megamorphic); |
| 1614 | __ jmp(&done, Label::kFar); |
| 1615 | } |
| 1616 | |
| 1617 | __ bind(&miss); |
| 1618 | |
| 1619 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 1620 | // megamorphic. |
| 1621 | __ cmp(ecx, Immediate(TypeFeedbackVector::UninitializedSentinel(isolate))); |
| 1622 | __ j(equal, &initialize); |
| 1623 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 1624 | // write-barrier is needed. |
| 1625 | __ bind(&megamorphic); |
| 1626 | __ mov( |
| 1627 | FieldOperand(ebx, edx, times_half_pointer_size, FixedArray::kHeaderSize), |
| 1628 | Immediate(TypeFeedbackVector::MegamorphicSentinel(isolate))); |
| 1629 | __ jmp(&done, Label::kFar); |
| 1630 | |
| 1631 | // An uninitialized cache is patched with the function or sentinel to |
| 1632 | // indicate the ElementsKind if function is the Array constructor. |
| 1633 | __ bind(&initialize); |
| 1634 | if (!FLAG_pretenuring_call_new) { |
| 1635 | // Make sure the function is the Array() function |
| 1636 | __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, ecx); |
| 1637 | __ cmp(edi, ecx); |
| 1638 | __ j(not_equal, ¬_array_function); |
| 1639 | |
| 1640 | // The target function is the Array constructor, |
| 1641 | // Create an AllocationSite if we don't already have it, store it in the |
| 1642 | // slot. |
| 1643 | { |
| 1644 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1645 | |
| 1646 | // Arguments register must be smi-tagged to call out. |
| 1647 | __ SmiTag(eax); |
| 1648 | __ push(eax); |
| 1649 | __ push(edi); |
| 1650 | __ push(edx); |
| 1651 | __ push(ebx); |
| 1652 | |
| 1653 | CreateAllocationSiteStub create_stub(isolate); |
| 1654 | __ CallStub(&create_stub); |
| 1655 | |
| 1656 | __ pop(ebx); |
| 1657 | __ pop(edx); |
| 1658 | __ pop(edi); |
| 1659 | __ pop(eax); |
| 1660 | __ SmiUntag(eax); |
| 1661 | } |
| 1662 | __ jmp(&done); |
| 1663 | |
| 1664 | __ bind(¬_array_function); |
| 1665 | } |
| 1666 | |
| 1667 | __ mov(FieldOperand(ebx, edx, times_half_pointer_size, |
| 1668 | FixedArray::kHeaderSize), |
| 1669 | edi); |
| 1670 | // We won't need edx or ebx anymore, just save edi |
| 1671 | __ push(edi); |
| 1672 | __ push(ebx); |
| 1673 | __ push(edx); |
| 1674 | __ RecordWriteArray(ebx, edi, edx, kDontSaveFPRegs, EMIT_REMEMBERED_SET, |
| 1675 | OMIT_SMI_CHECK); |
| 1676 | __ pop(edx); |
| 1677 | __ pop(ebx); |
| 1678 | __ pop(edi); |
| 1679 | |
| 1680 | __ bind(&done); |
| 1681 | } |
| 1682 | |
| 1683 | |
| 1684 | static void EmitContinueIfStrictOrNative(MacroAssembler* masm, Label* cont) { |
| 1685 | // Do not transform the receiver for strict mode functions. |
| 1686 | __ mov(ecx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 1687 | __ test_b(FieldOperand(ecx, SharedFunctionInfo::kStrictModeByteOffset), |
| 1688 | 1 << SharedFunctionInfo::kStrictModeBitWithinByte); |
| 1689 | __ j(not_equal, cont); |
| 1690 | |
| 1691 | // Do not transform the receiver for natives (shared already in ecx). |
| 1692 | __ test_b(FieldOperand(ecx, SharedFunctionInfo::kNativeByteOffset), |
| 1693 | 1 << SharedFunctionInfo::kNativeBitWithinByte); |
| 1694 | __ j(not_equal, cont); |
| 1695 | } |
| 1696 | |
| 1697 | |
| 1698 | static void EmitSlowCase(Isolate* isolate, |
| 1699 | MacroAssembler* masm, |
| 1700 | int argc, |
| 1701 | Label* non_function) { |
| 1702 | // Check for function proxy. |
| 1703 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 1704 | __ j(not_equal, non_function); |
| 1705 | __ pop(ecx); |
| 1706 | __ push(edi); // put proxy as additional argument under return address |
| 1707 | __ push(ecx); |
| 1708 | __ Move(eax, Immediate(argc + 1)); |
| 1709 | __ Move(ebx, Immediate(0)); |
| 1710 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY); |
| 1711 | { |
| 1712 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
| 1713 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 1714 | } |
| 1715 | |
| 1716 | // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 1717 | // of the original receiver from the call site). |
| 1718 | __ bind(non_function); |
| 1719 | __ mov(Operand(esp, (argc + 1) * kPointerSize), edi); |
| 1720 | __ Move(eax, Immediate(argc)); |
| 1721 | __ Move(ebx, Immediate(0)); |
| 1722 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); |
| 1723 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
| 1724 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 1725 | } |
| 1726 | |
| 1727 | |
| 1728 | static void EmitWrapCase(MacroAssembler* masm, int argc, Label* cont) { |
| 1729 | // Wrap the receiver and patch it back onto the stack. |
| 1730 | { FrameScope frame_scope(masm, StackFrame::INTERNAL); |
| 1731 | __ push(edi); |
| 1732 | __ push(eax); |
| 1733 | __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); |
| 1734 | __ pop(edi); |
| 1735 | } |
| 1736 | __ mov(Operand(esp, (argc + 1) * kPointerSize), eax); |
| 1737 | __ jmp(cont); |
| 1738 | } |
| 1739 | |
| 1740 | |
| 1741 | static void CallFunctionNoFeedback(MacroAssembler* masm, |
| 1742 | int argc, bool needs_checks, |
| 1743 | bool call_as_method) { |
| 1744 | // edi : the function to call |
| 1745 | Label slow, non_function, wrap, cont; |
| 1746 | |
| 1747 | if (needs_checks) { |
| 1748 | // Check that the function really is a JavaScript function. |
| 1749 | __ JumpIfSmi(edi, &non_function); |
| 1750 | |
| 1751 | // Goto slow case if we do not have a function. |
| 1752 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 1753 | __ j(not_equal, &slow); |
| 1754 | } |
| 1755 | |
| 1756 | // Fast-case: Just invoke the function. |
| 1757 | ParameterCount actual(argc); |
| 1758 | |
| 1759 | if (call_as_method) { |
| 1760 | if (needs_checks) { |
| 1761 | EmitContinueIfStrictOrNative(masm, &cont); |
| 1762 | } |
| 1763 | |
| 1764 | // Load the receiver from the stack. |
| 1765 | __ mov(eax, Operand(esp, (argc + 1) * kPointerSize)); |
| 1766 | |
| 1767 | if (needs_checks) { |
| 1768 | __ JumpIfSmi(eax, &wrap); |
| 1769 | |
| 1770 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 1771 | __ j(below, &wrap); |
| 1772 | } else { |
| 1773 | __ jmp(&wrap); |
| 1774 | } |
| 1775 | |
| 1776 | __ bind(&cont); |
| 1777 | } |
| 1778 | |
| 1779 | __ InvokeFunction(edi, actual, JUMP_FUNCTION, NullCallWrapper()); |
| 1780 | |
| 1781 | if (needs_checks) { |
| 1782 | // Slow-case: Non-function called. |
| 1783 | __ bind(&slow); |
| 1784 | // (non_function is bound in EmitSlowCase) |
| 1785 | EmitSlowCase(masm->isolate(), masm, argc, &non_function); |
| 1786 | } |
| 1787 | |
| 1788 | if (call_as_method) { |
| 1789 | __ bind(&wrap); |
| 1790 | EmitWrapCase(masm, argc, &cont); |
| 1791 | } |
| 1792 | } |
| 1793 | |
| 1794 | |
| 1795 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
| 1796 | CallFunctionNoFeedback(masm, argc(), NeedsChecks(), CallAsMethod()); |
| 1797 | } |
| 1798 | |
| 1799 | |
| 1800 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 1801 | // eax : number of arguments |
| 1802 | // ebx : feedback vector |
| 1803 | // edx : (only if ebx is not the megamorphic symbol) slot in feedback |
| 1804 | // vector (Smi) |
| 1805 | // edi : constructor function |
| 1806 | Label slow, non_function_call; |
| 1807 | |
| 1808 | // Check that function is not a smi. |
| 1809 | __ JumpIfSmi(edi, &non_function_call); |
| 1810 | // Check that function is a JSFunction. |
| 1811 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 1812 | __ j(not_equal, &slow); |
| 1813 | |
| 1814 | if (RecordCallTarget()) { |
| 1815 | GenerateRecordCallTarget(masm); |
| 1816 | |
| 1817 | if (FLAG_pretenuring_call_new) { |
| 1818 | // Put the AllocationSite from the feedback vector into ebx. |
| 1819 | // By adding kPointerSize we encode that we know the AllocationSite |
| 1820 | // entry is at the feedback vector slot given by edx + 1. |
| 1821 | __ mov(ebx, FieldOperand(ebx, edx, times_half_pointer_size, |
| 1822 | FixedArray::kHeaderSize + kPointerSize)); |
| 1823 | } else { |
| 1824 | Label feedback_register_initialized; |
| 1825 | // Put the AllocationSite from the feedback vector into ebx, or undefined. |
| 1826 | __ mov(ebx, FieldOperand(ebx, edx, times_half_pointer_size, |
| 1827 | FixedArray::kHeaderSize)); |
| 1828 | Handle<Map> allocation_site_map = |
| 1829 | isolate()->factory()->allocation_site_map(); |
| 1830 | __ cmp(FieldOperand(ebx, 0), Immediate(allocation_site_map)); |
| 1831 | __ j(equal, &feedback_register_initialized); |
| 1832 | __ mov(ebx, isolate()->factory()->undefined_value()); |
| 1833 | __ bind(&feedback_register_initialized); |
| 1834 | } |
| 1835 | |
| 1836 | __ AssertUndefinedOrAllocationSite(ebx); |
| 1837 | } |
| 1838 | |
| 1839 | // Jump to the function-specific construct stub. |
| 1840 | Register jmp_reg = ecx; |
| 1841 | __ mov(jmp_reg, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 1842 | __ mov(jmp_reg, FieldOperand(jmp_reg, |
| 1843 | SharedFunctionInfo::kConstructStubOffset)); |
| 1844 | __ lea(jmp_reg, FieldOperand(jmp_reg, Code::kHeaderSize)); |
| 1845 | __ jmp(jmp_reg); |
| 1846 | |
| 1847 | // edi: called object |
| 1848 | // eax: number of arguments |
| 1849 | // ecx: object map |
| 1850 | Label do_call; |
| 1851 | __ bind(&slow); |
| 1852 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 1853 | __ j(not_equal, &non_function_call); |
| 1854 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR); |
| 1855 | __ jmp(&do_call); |
| 1856 | |
| 1857 | __ bind(&non_function_call); |
| 1858 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
| 1859 | __ bind(&do_call); |
| 1860 | // Set expected number of arguments to zero (not changing eax). |
| 1861 | __ Move(ebx, Immediate(0)); |
| 1862 | Handle<Code> arguments_adaptor = |
| 1863 | isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
| 1864 | __ jmp(arguments_adaptor, RelocInfo::CODE_TARGET); |
| 1865 | } |
| 1866 | |
| 1867 | |
| 1868 | static void EmitLoadTypeFeedbackVector(MacroAssembler* masm, Register vector) { |
| 1869 | __ mov(vector, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1870 | __ mov(vector, FieldOperand(vector, JSFunction::kSharedFunctionInfoOffset)); |
| 1871 | __ mov(vector, FieldOperand(vector, |
| 1872 | SharedFunctionInfo::kFeedbackVectorOffset)); |
| 1873 | } |
| 1874 | |
| 1875 | |
| 1876 | void CallIC_ArrayStub::Generate(MacroAssembler* masm) { |
| 1877 | // edi - function |
| 1878 | // edx - slot id |
| 1879 | Label miss; |
| 1880 | int argc = arg_count(); |
| 1881 | ParameterCount actual(argc); |
| 1882 | |
| 1883 | EmitLoadTypeFeedbackVector(masm, ebx); |
| 1884 | |
| 1885 | __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, ecx); |
| 1886 | __ cmp(edi, ecx); |
| 1887 | __ j(not_equal, &miss); |
| 1888 | |
| 1889 | __ mov(eax, arg_count()); |
| 1890 | __ mov(ecx, FieldOperand(ebx, edx, times_half_pointer_size, |
| 1891 | FixedArray::kHeaderSize)); |
| 1892 | |
| 1893 | // Verify that ecx contains an AllocationSite |
| 1894 | Factory* factory = masm->isolate()->factory(); |
| 1895 | __ cmp(FieldOperand(ecx, HeapObject::kMapOffset), |
| 1896 | factory->allocation_site_map()); |
| 1897 | __ j(not_equal, &miss); |
| 1898 | |
| 1899 | __ mov(ebx, ecx); |
| 1900 | ArrayConstructorStub stub(masm->isolate(), arg_count()); |
| 1901 | __ TailCallStub(&stub); |
| 1902 | |
| 1903 | __ bind(&miss); |
| 1904 | GenerateMiss(masm); |
| 1905 | |
| 1906 | // The slow case, we need this no matter what to complete a call after a miss. |
| 1907 | CallFunctionNoFeedback(masm, |
| 1908 | arg_count(), |
| 1909 | true, |
| 1910 | CallAsMethod()); |
| 1911 | |
| 1912 | // Unreachable. |
| 1913 | __ int3(); |
| 1914 | } |
| 1915 | |
| 1916 | |
| 1917 | void CallICStub::Generate(MacroAssembler* masm) { |
| 1918 | // edi - function |
| 1919 | // edx - slot id |
| 1920 | Isolate* isolate = masm->isolate(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1921 | const int with_types_offset = |
| 1922 | FixedArray::OffsetOfElementAt(TypeFeedbackVector::kWithTypesIndex); |
| 1923 | const int generic_offset = |
| 1924 | FixedArray::OffsetOfElementAt(TypeFeedbackVector::kGenericCountIndex); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1925 | Label extra_checks_or_miss, slow_start; |
| 1926 | Label slow, non_function, wrap, cont; |
| 1927 | Label have_js_function; |
| 1928 | int argc = arg_count(); |
| 1929 | ParameterCount actual(argc); |
| 1930 | |
| 1931 | EmitLoadTypeFeedbackVector(masm, ebx); |
| 1932 | |
| 1933 | // The checks. First, does edi match the recorded monomorphic target? |
| 1934 | __ cmp(edi, FieldOperand(ebx, edx, times_half_pointer_size, |
| 1935 | FixedArray::kHeaderSize)); |
| 1936 | __ j(not_equal, &extra_checks_or_miss); |
| 1937 | |
| 1938 | __ bind(&have_js_function); |
| 1939 | if (CallAsMethod()) { |
| 1940 | EmitContinueIfStrictOrNative(masm, &cont); |
| 1941 | |
| 1942 | // Load the receiver from the stack. |
| 1943 | __ mov(eax, Operand(esp, (argc + 1) * kPointerSize)); |
| 1944 | |
| 1945 | __ JumpIfSmi(eax, &wrap); |
| 1946 | |
| 1947 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 1948 | __ j(below, &wrap); |
| 1949 | |
| 1950 | __ bind(&cont); |
| 1951 | } |
| 1952 | |
| 1953 | __ InvokeFunction(edi, actual, JUMP_FUNCTION, NullCallWrapper()); |
| 1954 | |
| 1955 | __ bind(&slow); |
| 1956 | EmitSlowCase(isolate, masm, argc, &non_function); |
| 1957 | |
| 1958 | if (CallAsMethod()) { |
| 1959 | __ bind(&wrap); |
| 1960 | EmitWrapCase(masm, argc, &cont); |
| 1961 | } |
| 1962 | |
| 1963 | __ bind(&extra_checks_or_miss); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1964 | Label uninitialized, miss; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1965 | |
| 1966 | __ mov(ecx, FieldOperand(ebx, edx, times_half_pointer_size, |
| 1967 | FixedArray::kHeaderSize)); |
| 1968 | __ cmp(ecx, Immediate(TypeFeedbackVector::MegamorphicSentinel(isolate))); |
| 1969 | __ j(equal, &slow_start); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1970 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1971 | // The following cases attempt to handle MISS cases without going to the |
| 1972 | // runtime. |
| 1973 | if (FLAG_trace_ic) { |
| 1974 | __ jmp(&miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1975 | } |
| 1976 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1977 | __ cmp(ecx, Immediate(TypeFeedbackVector::UninitializedSentinel(isolate))); |
| 1978 | __ j(equal, &uninitialized); |
| 1979 | |
| 1980 | // We are going megamorphic. If the feedback is a JSFunction, it is fine |
| 1981 | // to handle it here. More complex cases are dealt with in the runtime. |
| 1982 | __ AssertNotSmi(ecx); |
| 1983 | __ CmpObjectType(ecx, JS_FUNCTION_TYPE, ecx); |
| 1984 | __ j(not_equal, &miss); |
| 1985 | __ mov( |
| 1986 | FieldOperand(ebx, edx, times_half_pointer_size, FixedArray::kHeaderSize), |
| 1987 | Immediate(TypeFeedbackVector::MegamorphicSentinel(isolate))); |
| 1988 | // We have to update statistics for runtime profiling. |
| 1989 | __ sub(FieldOperand(ebx, with_types_offset), Immediate(Smi::FromInt(1))); |
| 1990 | __ add(FieldOperand(ebx, generic_offset), Immediate(Smi::FromInt(1))); |
| 1991 | __ jmp(&slow_start); |
| 1992 | |
| 1993 | __ bind(&uninitialized); |
| 1994 | |
| 1995 | // We are going monomorphic, provided we actually have a JSFunction. |
| 1996 | __ JumpIfSmi(edi, &miss); |
| 1997 | |
| 1998 | // Goto miss case if we do not have a function. |
| 1999 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 2000 | __ j(not_equal, &miss); |
| 2001 | |
| 2002 | // Make sure the function is not the Array() function, which requires special |
| 2003 | // behavior on MISS. |
| 2004 | __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, ecx); |
| 2005 | __ cmp(edi, ecx); |
| 2006 | __ j(equal, &miss); |
| 2007 | |
| 2008 | // Update stats. |
| 2009 | __ add(FieldOperand(ebx, with_types_offset), Immediate(Smi::FromInt(1))); |
| 2010 | |
| 2011 | // Store the function. |
| 2012 | __ mov( |
| 2013 | FieldOperand(ebx, edx, times_half_pointer_size, FixedArray::kHeaderSize), |
| 2014 | edi); |
| 2015 | |
| 2016 | // Update the write barrier. |
| 2017 | __ mov(eax, edi); |
| 2018 | __ RecordWriteArray(ebx, eax, edx, kDontSaveFPRegs, EMIT_REMEMBERED_SET, |
| 2019 | OMIT_SMI_CHECK); |
| 2020 | __ jmp(&have_js_function); |
| 2021 | |
| 2022 | // We are here because tracing is on or we encountered a MISS case we can't |
| 2023 | // handle here. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2024 | __ bind(&miss); |
| 2025 | GenerateMiss(masm); |
| 2026 | |
| 2027 | // the slow case |
| 2028 | __ bind(&slow_start); |
| 2029 | |
| 2030 | // Check that the function really is a JavaScript function. |
| 2031 | __ JumpIfSmi(edi, &non_function); |
| 2032 | |
| 2033 | // Goto slow case if we do not have a function. |
| 2034 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 2035 | __ j(not_equal, &slow); |
| 2036 | __ jmp(&have_js_function); |
| 2037 | |
| 2038 | // Unreachable |
| 2039 | __ int3(); |
| 2040 | } |
| 2041 | |
| 2042 | |
| 2043 | void CallICStub::GenerateMiss(MacroAssembler* masm) { |
| 2044 | // Get the receiver of the function from the stack; 1 ~ return address. |
| 2045 | __ mov(ecx, Operand(esp, (arg_count() + 1) * kPointerSize)); |
| 2046 | |
| 2047 | { |
| 2048 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2049 | |
| 2050 | // Push the receiver and the function and feedback info. |
| 2051 | __ push(ecx); |
| 2052 | __ push(edi); |
| 2053 | __ push(ebx); |
| 2054 | __ push(edx); |
| 2055 | |
| 2056 | // Call the entry. |
| 2057 | IC::UtilityId id = GetICState() == DEFAULT ? IC::kCallIC_Miss |
| 2058 | : IC::kCallIC_Customization_Miss; |
| 2059 | |
| 2060 | ExternalReference miss = ExternalReference(IC_Utility(id), |
| 2061 | masm->isolate()); |
| 2062 | __ CallExternalReference(miss, 4); |
| 2063 | |
| 2064 | // Move result to edi and exit the internal frame. |
| 2065 | __ mov(edi, eax); |
| 2066 | } |
| 2067 | } |
| 2068 | |
| 2069 | |
| 2070 | bool CEntryStub::NeedsImmovableCode() { |
| 2071 | return false; |
| 2072 | } |
| 2073 | |
| 2074 | |
| 2075 | void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 2076 | CEntryStub::GenerateAheadOfTime(isolate); |
| 2077 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); |
| 2078 | StubFailureTrampolineStub::GenerateAheadOfTime(isolate); |
| 2079 | // It is important that the store buffer overflow stubs are generated first. |
| 2080 | ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate); |
| 2081 | CreateAllocationSiteStub::GenerateAheadOfTime(isolate); |
| 2082 | BinaryOpICStub::GenerateAheadOfTime(isolate); |
| 2083 | BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate); |
| 2084 | } |
| 2085 | |
| 2086 | |
| 2087 | void CodeStub::GenerateFPStubs(Isolate* isolate) { |
| 2088 | CEntryStub save_doubles(isolate, 1, kSaveFPRegs); |
| 2089 | // Stubs might already be in the snapshot, detect that and don't regenerate, |
| 2090 | // which would lead to code stub initialization state being messed up. |
| 2091 | Code* save_doubles_code; |
| 2092 | if (!save_doubles.FindCodeInCache(&save_doubles_code)) { |
| 2093 | save_doubles_code = *(save_doubles.GetCode()); |
| 2094 | } |
| 2095 | isolate->set_fp_stubs_generated(true); |
| 2096 | } |
| 2097 | |
| 2098 | |
| 2099 | void CEntryStub::GenerateAheadOfTime(Isolate* isolate) { |
| 2100 | CEntryStub stub(isolate, 1, kDontSaveFPRegs); |
| 2101 | stub.GetCode(); |
| 2102 | } |
| 2103 | |
| 2104 | |
| 2105 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 2106 | // eax: number of arguments including receiver |
| 2107 | // ebx: pointer to C function (C callee-saved) |
| 2108 | // ebp: frame pointer (restored after C call) |
| 2109 | // esp: stack pointer (restored after C call) |
| 2110 | // esi: current context (C callee-saved) |
| 2111 | // edi: JS function of the caller (C callee-saved) |
| 2112 | |
| 2113 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 2114 | |
| 2115 | // Enter the exit frame that transitions from JavaScript to C++. |
| 2116 | __ EnterExitFrame(save_doubles()); |
| 2117 | |
| 2118 | // ebx: pointer to C function (C callee-saved) |
| 2119 | // ebp: frame pointer (restored after C call) |
| 2120 | // esp: stack pointer (restored after C call) |
| 2121 | // edi: number of arguments including receiver (C callee-saved) |
| 2122 | // esi: pointer to the first argument (C callee-saved) |
| 2123 | |
| 2124 | // Result returned in eax, or eax+edx if result size is 2. |
| 2125 | |
| 2126 | // Check stack alignment. |
| 2127 | if (FLAG_debug_code) { |
| 2128 | __ CheckStackAlignment(); |
| 2129 | } |
| 2130 | |
| 2131 | // Call C function. |
| 2132 | __ mov(Operand(esp, 0 * kPointerSize), edi); // argc. |
| 2133 | __ mov(Operand(esp, 1 * kPointerSize), esi); // argv. |
| 2134 | __ mov(Operand(esp, 2 * kPointerSize), |
| 2135 | Immediate(ExternalReference::isolate_address(isolate()))); |
| 2136 | __ call(ebx); |
| 2137 | // Result is in eax or edx:eax - do not destroy these registers! |
| 2138 | |
| 2139 | // Runtime functions should not return 'the hole'. Allowing it to escape may |
| 2140 | // lead to crashes in the IC code later. |
| 2141 | if (FLAG_debug_code) { |
| 2142 | Label okay; |
| 2143 | __ cmp(eax, isolate()->factory()->the_hole_value()); |
| 2144 | __ j(not_equal, &okay, Label::kNear); |
| 2145 | __ int3(); |
| 2146 | __ bind(&okay); |
| 2147 | } |
| 2148 | |
| 2149 | // Check result for exception sentinel. |
| 2150 | Label exception_returned; |
| 2151 | __ cmp(eax, isolate()->factory()->exception()); |
| 2152 | __ j(equal, &exception_returned); |
| 2153 | |
| 2154 | ExternalReference pending_exception_address( |
| 2155 | Isolate::kPendingExceptionAddress, isolate()); |
| 2156 | |
| 2157 | // Check that there is no pending exception, otherwise we |
| 2158 | // should have returned the exception sentinel. |
| 2159 | if (FLAG_debug_code) { |
| 2160 | __ push(edx); |
| 2161 | __ mov(edx, Immediate(isolate()->factory()->the_hole_value())); |
| 2162 | Label okay; |
| 2163 | __ cmp(edx, Operand::StaticVariable(pending_exception_address)); |
| 2164 | // Cannot use check here as it attempts to generate call into runtime. |
| 2165 | __ j(equal, &okay, Label::kNear); |
| 2166 | __ int3(); |
| 2167 | __ bind(&okay); |
| 2168 | __ pop(edx); |
| 2169 | } |
| 2170 | |
| 2171 | // Exit the JavaScript to C++ exit frame. |
| 2172 | __ LeaveExitFrame(save_doubles()); |
| 2173 | __ ret(0); |
| 2174 | |
| 2175 | // Handling of exception. |
| 2176 | __ bind(&exception_returned); |
| 2177 | |
| 2178 | // Retrieve the pending exception. |
| 2179 | __ mov(eax, Operand::StaticVariable(pending_exception_address)); |
| 2180 | |
| 2181 | // Clear the pending exception. |
| 2182 | __ mov(edx, Immediate(isolate()->factory()->the_hole_value())); |
| 2183 | __ mov(Operand::StaticVariable(pending_exception_address), edx); |
| 2184 | |
| 2185 | // Special handling of termination exceptions which are uncatchable |
| 2186 | // by javascript code. |
| 2187 | Label throw_termination_exception; |
| 2188 | __ cmp(eax, isolate()->factory()->termination_exception()); |
| 2189 | __ j(equal, &throw_termination_exception); |
| 2190 | |
| 2191 | // Handle normal exception. |
| 2192 | __ Throw(eax); |
| 2193 | |
| 2194 | __ bind(&throw_termination_exception); |
| 2195 | __ ThrowUncatchable(eax); |
| 2196 | } |
| 2197 | |
| 2198 | |
| 2199 | void JSEntryStub::Generate(MacroAssembler* masm) { |
| 2200 | Label invoke, handler_entry, exit; |
| 2201 | Label not_outermost_js, not_outermost_js_2; |
| 2202 | |
| 2203 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 2204 | |
| 2205 | // Set up frame. |
| 2206 | __ push(ebp); |
| 2207 | __ mov(ebp, esp); |
| 2208 | |
| 2209 | // Push marker in two places. |
| 2210 | int marker = type(); |
| 2211 | __ push(Immediate(Smi::FromInt(marker))); // context slot |
| 2212 | __ push(Immediate(Smi::FromInt(marker))); // function slot |
| 2213 | // Save callee-saved registers (C calling conventions). |
| 2214 | __ push(edi); |
| 2215 | __ push(esi); |
| 2216 | __ push(ebx); |
| 2217 | |
| 2218 | // Save copies of the top frame descriptor on the stack. |
| 2219 | ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, isolate()); |
| 2220 | __ push(Operand::StaticVariable(c_entry_fp)); |
| 2221 | |
| 2222 | // If this is the outermost JS call, set js_entry_sp value. |
| 2223 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate()); |
| 2224 | __ cmp(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
| 2225 | __ j(not_equal, ¬_outermost_js, Label::kNear); |
| 2226 | __ mov(Operand::StaticVariable(js_entry_sp), ebp); |
| 2227 | __ push(Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
| 2228 | __ jmp(&invoke, Label::kNear); |
| 2229 | __ bind(¬_outermost_js); |
| 2230 | __ push(Immediate(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
| 2231 | |
| 2232 | // Jump to a faked try block that does the invoke, with a faked catch |
| 2233 | // block that sets the pending exception. |
| 2234 | __ jmp(&invoke); |
| 2235 | __ bind(&handler_entry); |
| 2236 | handler_offset_ = handler_entry.pos(); |
| 2237 | // Caught exception: Store result (exception) in the pending exception |
| 2238 | // field in the JSEnv and return a failure sentinel. |
| 2239 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
| 2240 | isolate()); |
| 2241 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 2242 | __ mov(eax, Immediate(isolate()->factory()->exception())); |
| 2243 | __ jmp(&exit); |
| 2244 | |
| 2245 | // Invoke: Link this frame into the handler chain. There's only one |
| 2246 | // handler block in this code object, so its index is 0. |
| 2247 | __ bind(&invoke); |
| 2248 | __ PushTryHandler(StackHandler::JS_ENTRY, 0); |
| 2249 | |
| 2250 | // Clear any pending exceptions. |
| 2251 | __ mov(edx, Immediate(isolate()->factory()->the_hole_value())); |
| 2252 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 2253 | |
| 2254 | // Fake a receiver (NULL). |
| 2255 | __ push(Immediate(0)); // receiver |
| 2256 | |
| 2257 | // Invoke the function by calling through JS entry trampoline builtin and |
| 2258 | // pop the faked function when we return. Notice that we cannot store a |
| 2259 | // reference to the trampoline code directly in this stub, because the |
| 2260 | // builtin stubs may not have been generated yet. |
| 2261 | if (type() == StackFrame::ENTRY_CONSTRUCT) { |
| 2262 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
| 2263 | isolate()); |
| 2264 | __ mov(edx, Immediate(construct_entry)); |
| 2265 | } else { |
| 2266 | ExternalReference entry(Builtins::kJSEntryTrampoline, isolate()); |
| 2267 | __ mov(edx, Immediate(entry)); |
| 2268 | } |
| 2269 | __ mov(edx, Operand(edx, 0)); // deref address |
| 2270 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 2271 | __ call(edx); |
| 2272 | |
| 2273 | // Unlink this frame from the handler chain. |
| 2274 | __ PopTryHandler(); |
| 2275 | |
| 2276 | __ bind(&exit); |
| 2277 | // Check if the current stack frame is marked as the outermost JS frame. |
| 2278 | __ pop(ebx); |
| 2279 | __ cmp(ebx, Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
| 2280 | __ j(not_equal, ¬_outermost_js_2); |
| 2281 | __ mov(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
| 2282 | __ bind(¬_outermost_js_2); |
| 2283 | |
| 2284 | // Restore the top frame descriptor from the stack. |
| 2285 | __ pop(Operand::StaticVariable(ExternalReference( |
| 2286 | Isolate::kCEntryFPAddress, isolate()))); |
| 2287 | |
| 2288 | // Restore callee-saved registers (C calling conventions). |
| 2289 | __ pop(ebx); |
| 2290 | __ pop(esi); |
| 2291 | __ pop(edi); |
| 2292 | __ add(esp, Immediate(2 * kPointerSize)); // remove markers |
| 2293 | |
| 2294 | // Restore frame pointer and return. |
| 2295 | __ pop(ebp); |
| 2296 | __ ret(0); |
| 2297 | } |
| 2298 | |
| 2299 | |
| 2300 | // Generate stub code for instanceof. |
| 2301 | // This code can patch a call site inlined cache of the instance of check, |
| 2302 | // which looks like this. |
| 2303 | // |
| 2304 | // 81 ff XX XX XX XX cmp edi, <the hole, patched to a map> |
| 2305 | // 75 0a jne <some near label> |
| 2306 | // b8 XX XX XX XX mov eax, <the hole, patched to either true or false> |
| 2307 | // |
| 2308 | // If call site patching is requested the stack will have the delta from the |
| 2309 | // return address to the cmp instruction just below the return address. This |
| 2310 | // also means that call site patching can only take place with arguments in |
| 2311 | // registers. TOS looks like this when call site patching is requested |
| 2312 | // |
| 2313 | // esp[0] : return address |
| 2314 | // esp[4] : delta from return address to cmp instruction |
| 2315 | // |
| 2316 | void InstanceofStub::Generate(MacroAssembler* masm) { |
| 2317 | // Call site inlining and patching implies arguments in registers. |
| 2318 | DCHECK(HasArgsInRegisters() || !HasCallSiteInlineCheck()); |
| 2319 | |
| 2320 | // Fixed register usage throughout the stub. |
| 2321 | Register object = eax; // Object (lhs). |
| 2322 | Register map = ebx; // Map of the object. |
| 2323 | Register function = edx; // Function (rhs). |
| 2324 | Register prototype = edi; // Prototype of the function. |
| 2325 | Register scratch = ecx; |
| 2326 | |
| 2327 | // Constants describing the call site code to patch. |
| 2328 | static const int kDeltaToCmpImmediate = 2; |
| 2329 | static const int kDeltaToMov = 8; |
| 2330 | static const int kDeltaToMovImmediate = 9; |
| 2331 | static const int8_t kCmpEdiOperandByte1 = bit_cast<int8_t, uint8_t>(0x3b); |
| 2332 | static const int8_t kCmpEdiOperandByte2 = bit_cast<int8_t, uint8_t>(0x3d); |
| 2333 | static const int8_t kMovEaxImmediateByte = bit_cast<int8_t, uint8_t>(0xb8); |
| 2334 | |
| 2335 | DCHECK_EQ(object.code(), InstanceofStub::left().code()); |
| 2336 | DCHECK_EQ(function.code(), InstanceofStub::right().code()); |
| 2337 | |
| 2338 | // Get the object and function - they are always both needed. |
| 2339 | Label slow, not_js_object; |
| 2340 | if (!HasArgsInRegisters()) { |
| 2341 | __ mov(object, Operand(esp, 2 * kPointerSize)); |
| 2342 | __ mov(function, Operand(esp, 1 * kPointerSize)); |
| 2343 | } |
| 2344 | |
| 2345 | // Check that the left hand is a JS object. |
| 2346 | __ JumpIfSmi(object, ¬_js_object); |
| 2347 | __ IsObjectJSObjectType(object, map, scratch, ¬_js_object); |
| 2348 | |
| 2349 | // If there is a call site cache don't look in the global cache, but do the |
| 2350 | // real lookup and update the call site cache. |
| 2351 | if (!HasCallSiteInlineCheck() && !ReturnTrueFalseObject()) { |
| 2352 | // Look up the function and the map in the instanceof cache. |
| 2353 | Label miss; |
| 2354 | __ CompareRoot(function, scratch, Heap::kInstanceofCacheFunctionRootIndex); |
| 2355 | __ j(not_equal, &miss, Label::kNear); |
| 2356 | __ CompareRoot(map, scratch, Heap::kInstanceofCacheMapRootIndex); |
| 2357 | __ j(not_equal, &miss, Label::kNear); |
| 2358 | __ LoadRoot(eax, Heap::kInstanceofCacheAnswerRootIndex); |
| 2359 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 2360 | __ bind(&miss); |
| 2361 | } |
| 2362 | |
| 2363 | // Get the prototype of the function. |
| 2364 | __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true); |
| 2365 | |
| 2366 | // Check that the function prototype is a JS object. |
| 2367 | __ JumpIfSmi(prototype, &slow); |
| 2368 | __ IsObjectJSObjectType(prototype, scratch, scratch, &slow); |
| 2369 | |
| 2370 | // Update the global instanceof or call site inlined cache with the current |
| 2371 | // map and function. The cached answer will be set when it is known below. |
| 2372 | if (!HasCallSiteInlineCheck()) { |
| 2373 | __ StoreRoot(map, scratch, Heap::kInstanceofCacheMapRootIndex); |
| 2374 | __ StoreRoot(function, scratch, Heap::kInstanceofCacheFunctionRootIndex); |
| 2375 | } else { |
| 2376 | // The constants for the code patching are based on no push instructions |
| 2377 | // at the call site. |
| 2378 | DCHECK(HasArgsInRegisters()); |
| 2379 | // Get return address and delta to inlined map check. |
| 2380 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 2381 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 2382 | if (FLAG_debug_code) { |
| 2383 | __ cmpb(Operand(scratch, 0), kCmpEdiOperandByte1); |
| 2384 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheCmp1); |
| 2385 | __ cmpb(Operand(scratch, 1), kCmpEdiOperandByte2); |
| 2386 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheCmp2); |
| 2387 | } |
| 2388 | __ mov(scratch, Operand(scratch, kDeltaToCmpImmediate)); |
| 2389 | __ mov(Operand(scratch, 0), map); |
| 2390 | } |
| 2391 | |
| 2392 | // Loop through the prototype chain of the object looking for the function |
| 2393 | // prototype. |
| 2394 | __ mov(scratch, FieldOperand(map, Map::kPrototypeOffset)); |
| 2395 | Label loop, is_instance, is_not_instance; |
| 2396 | __ bind(&loop); |
| 2397 | __ cmp(scratch, prototype); |
| 2398 | __ j(equal, &is_instance, Label::kNear); |
| 2399 | Factory* factory = isolate()->factory(); |
| 2400 | __ cmp(scratch, Immediate(factory->null_value())); |
| 2401 | __ j(equal, &is_not_instance, Label::kNear); |
| 2402 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 2403 | __ mov(scratch, FieldOperand(scratch, Map::kPrototypeOffset)); |
| 2404 | __ jmp(&loop); |
| 2405 | |
| 2406 | __ bind(&is_instance); |
| 2407 | if (!HasCallSiteInlineCheck()) { |
| 2408 | __ mov(eax, Immediate(0)); |
| 2409 | __ StoreRoot(eax, scratch, Heap::kInstanceofCacheAnswerRootIndex); |
| 2410 | if (ReturnTrueFalseObject()) { |
| 2411 | __ mov(eax, factory->true_value()); |
| 2412 | } |
| 2413 | } else { |
| 2414 | // Get return address and delta to inlined map check. |
| 2415 | __ mov(eax, factory->true_value()); |
| 2416 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 2417 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 2418 | if (FLAG_debug_code) { |
| 2419 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 2420 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheMov); |
| 2421 | } |
| 2422 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 2423 | if (!ReturnTrueFalseObject()) { |
| 2424 | __ Move(eax, Immediate(0)); |
| 2425 | } |
| 2426 | } |
| 2427 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 2428 | |
| 2429 | __ bind(&is_not_instance); |
| 2430 | if (!HasCallSiteInlineCheck()) { |
| 2431 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 2432 | __ StoreRoot(eax, scratch, Heap::kInstanceofCacheAnswerRootIndex); |
| 2433 | if (ReturnTrueFalseObject()) { |
| 2434 | __ mov(eax, factory->false_value()); |
| 2435 | } |
| 2436 | } else { |
| 2437 | // Get return address and delta to inlined map check. |
| 2438 | __ mov(eax, factory->false_value()); |
| 2439 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 2440 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 2441 | if (FLAG_debug_code) { |
| 2442 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 2443 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheMov); |
| 2444 | } |
| 2445 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 2446 | if (!ReturnTrueFalseObject()) { |
| 2447 | __ Move(eax, Immediate(Smi::FromInt(1))); |
| 2448 | } |
| 2449 | } |
| 2450 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 2451 | |
| 2452 | Label object_not_null, object_not_null_or_smi; |
| 2453 | __ bind(¬_js_object); |
| 2454 | // Before null, smi and string value checks, check that the rhs is a function |
| 2455 | // as for a non-function rhs an exception needs to be thrown. |
| 2456 | __ JumpIfSmi(function, &slow, Label::kNear); |
| 2457 | __ CmpObjectType(function, JS_FUNCTION_TYPE, scratch); |
| 2458 | __ j(not_equal, &slow, Label::kNear); |
| 2459 | |
| 2460 | // Null is not instance of anything. |
| 2461 | __ cmp(object, factory->null_value()); |
| 2462 | __ j(not_equal, &object_not_null, Label::kNear); |
| 2463 | if (ReturnTrueFalseObject()) { |
| 2464 | __ mov(eax, factory->false_value()); |
| 2465 | } else { |
| 2466 | __ Move(eax, Immediate(Smi::FromInt(1))); |
| 2467 | } |
| 2468 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 2469 | |
| 2470 | __ bind(&object_not_null); |
| 2471 | // Smi values is not instance of anything. |
| 2472 | __ JumpIfNotSmi(object, &object_not_null_or_smi, Label::kNear); |
| 2473 | if (ReturnTrueFalseObject()) { |
| 2474 | __ mov(eax, factory->false_value()); |
| 2475 | } else { |
| 2476 | __ Move(eax, Immediate(Smi::FromInt(1))); |
| 2477 | } |
| 2478 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 2479 | |
| 2480 | __ bind(&object_not_null_or_smi); |
| 2481 | // String values is not instance of anything. |
| 2482 | Condition is_string = masm->IsObjectStringType(object, scratch, scratch); |
| 2483 | __ j(NegateCondition(is_string), &slow, Label::kNear); |
| 2484 | if (ReturnTrueFalseObject()) { |
| 2485 | __ mov(eax, factory->false_value()); |
| 2486 | } else { |
| 2487 | __ Move(eax, Immediate(Smi::FromInt(1))); |
| 2488 | } |
| 2489 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 2490 | |
| 2491 | // Slow-case: Go through the JavaScript implementation. |
| 2492 | __ bind(&slow); |
| 2493 | if (!ReturnTrueFalseObject()) { |
| 2494 | // Tail call the builtin which returns 0 or 1. |
| 2495 | if (HasArgsInRegisters()) { |
| 2496 | // Push arguments below return address. |
| 2497 | __ pop(scratch); |
| 2498 | __ push(object); |
| 2499 | __ push(function); |
| 2500 | __ push(scratch); |
| 2501 | } |
| 2502 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
| 2503 | } else { |
| 2504 | // Call the builtin and convert 0/1 to true/false. |
| 2505 | { |
| 2506 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2507 | __ push(object); |
| 2508 | __ push(function); |
| 2509 | __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION); |
| 2510 | } |
| 2511 | Label true_value, done; |
| 2512 | __ test(eax, eax); |
| 2513 | __ j(zero, &true_value, Label::kNear); |
| 2514 | __ mov(eax, factory->false_value()); |
| 2515 | __ jmp(&done, Label::kNear); |
| 2516 | __ bind(&true_value); |
| 2517 | __ mov(eax, factory->true_value()); |
| 2518 | __ bind(&done); |
| 2519 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 2520 | } |
| 2521 | } |
| 2522 | |
| 2523 | |
| 2524 | // ------------------------------------------------------------------------- |
| 2525 | // StringCharCodeAtGenerator |
| 2526 | |
| 2527 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
| 2528 | // If the receiver is a smi trigger the non-string case. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2529 | if (check_mode_ == RECEIVER_IS_UNKNOWN) { |
| 2530 | __ JumpIfSmi(object_, receiver_not_string_); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2531 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2532 | // Fetch the instance type of the receiver into result register. |
| 2533 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 2534 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 2535 | // If the receiver is not a string trigger the non-string case. |
| 2536 | __ test(result_, Immediate(kIsNotStringMask)); |
| 2537 | __ j(not_zero, receiver_not_string_); |
| 2538 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2539 | |
| 2540 | // If the index is non-smi trigger the non-smi case. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2541 | __ JumpIfNotSmi(index_, &index_not_smi_); |
| 2542 | __ bind(&got_smi_index_); |
| 2543 | |
| 2544 | // Check for index out of range. |
| 2545 | __ cmp(index_, FieldOperand(object_, String::kLengthOffset)); |
| 2546 | __ j(above_equal, index_out_of_range_); |
| 2547 | |
| 2548 | __ SmiUntag(index_); |
| 2549 | |
| 2550 | Factory* factory = masm->isolate()->factory(); |
| 2551 | StringCharLoadGenerator::Generate( |
| 2552 | masm, factory, object_, index_, result_, &call_runtime_); |
| 2553 | |
| 2554 | __ SmiTag(result_); |
| 2555 | __ bind(&exit_); |
| 2556 | } |
| 2557 | |
| 2558 | |
| 2559 | void StringCharCodeAtGenerator::GenerateSlow( |
| 2560 | MacroAssembler* masm, |
| 2561 | const RuntimeCallHelper& call_helper) { |
| 2562 | __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase); |
| 2563 | |
| 2564 | // Index is not a smi. |
| 2565 | __ bind(&index_not_smi_); |
| 2566 | // If index is a heap number, try converting it to an integer. |
| 2567 | __ CheckMap(index_, |
| 2568 | masm->isolate()->factory()->heap_number_map(), |
| 2569 | index_not_number_, |
| 2570 | DONT_DO_SMI_CHECK); |
| 2571 | call_helper.BeforeCall(masm); |
| 2572 | __ push(object_); |
| 2573 | __ push(index_); // Consumed by runtime conversion function. |
| 2574 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 2575 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 2576 | } else { |
| 2577 | DCHECK(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 2578 | // NumberToSmi discards numbers that are not exact integers. |
| 2579 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 2580 | } |
| 2581 | if (!index_.is(eax)) { |
| 2582 | // Save the conversion result before the pop instructions below |
| 2583 | // have a chance to overwrite it. |
| 2584 | __ mov(index_, eax); |
| 2585 | } |
| 2586 | __ pop(object_); |
| 2587 | // Reload the instance type. |
| 2588 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 2589 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 2590 | call_helper.AfterCall(masm); |
| 2591 | // If index is still not a smi, it must be out of range. |
| 2592 | STATIC_ASSERT(kSmiTag == 0); |
| 2593 | __ JumpIfNotSmi(index_, index_out_of_range_); |
| 2594 | // Otherwise, return to the fast path. |
| 2595 | __ jmp(&got_smi_index_); |
| 2596 | |
| 2597 | // Call runtime. We get here when the receiver is a string and the |
| 2598 | // index is a number, but the code of getting the actual character |
| 2599 | // is too complex (e.g., when the string needs to be flattened). |
| 2600 | __ bind(&call_runtime_); |
| 2601 | call_helper.BeforeCall(masm); |
| 2602 | __ push(object_); |
| 2603 | __ SmiTag(index_); |
| 2604 | __ push(index_); |
| 2605 | __ CallRuntime(Runtime::kStringCharCodeAtRT, 2); |
| 2606 | if (!result_.is(eax)) { |
| 2607 | __ mov(result_, eax); |
| 2608 | } |
| 2609 | call_helper.AfterCall(masm); |
| 2610 | __ jmp(&exit_); |
| 2611 | |
| 2612 | __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase); |
| 2613 | } |
| 2614 | |
| 2615 | |
| 2616 | // ------------------------------------------------------------------------- |
| 2617 | // StringCharFromCodeGenerator |
| 2618 | |
| 2619 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 2620 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 2621 | STATIC_ASSERT(kSmiTag == 0); |
| 2622 | STATIC_ASSERT(kSmiShiftSize == 0); |
| 2623 | DCHECK(base::bits::IsPowerOfTwo32(String::kMaxOneByteCharCode + 1)); |
| 2624 | __ test(code_, |
| 2625 | Immediate(kSmiTagMask | |
| 2626 | ((~String::kMaxOneByteCharCode) << kSmiTagSize))); |
| 2627 | __ j(not_zero, &slow_case_); |
| 2628 | |
| 2629 | Factory* factory = masm->isolate()->factory(); |
| 2630 | __ Move(result_, Immediate(factory->single_character_string_cache())); |
| 2631 | STATIC_ASSERT(kSmiTag == 0); |
| 2632 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2633 | STATIC_ASSERT(kSmiShiftSize == 0); |
| 2634 | // At this point code register contains smi tagged one byte char code. |
| 2635 | __ mov(result_, FieldOperand(result_, |
| 2636 | code_, times_half_pointer_size, |
| 2637 | FixedArray::kHeaderSize)); |
| 2638 | __ cmp(result_, factory->undefined_value()); |
| 2639 | __ j(equal, &slow_case_); |
| 2640 | __ bind(&exit_); |
| 2641 | } |
| 2642 | |
| 2643 | |
| 2644 | void StringCharFromCodeGenerator::GenerateSlow( |
| 2645 | MacroAssembler* masm, |
| 2646 | const RuntimeCallHelper& call_helper) { |
| 2647 | __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase); |
| 2648 | |
| 2649 | __ bind(&slow_case_); |
| 2650 | call_helper.BeforeCall(masm); |
| 2651 | __ push(code_); |
| 2652 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 2653 | if (!result_.is(eax)) { |
| 2654 | __ mov(result_, eax); |
| 2655 | } |
| 2656 | call_helper.AfterCall(masm); |
| 2657 | __ jmp(&exit_); |
| 2658 | |
| 2659 | __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase); |
| 2660 | } |
| 2661 | |
| 2662 | |
| 2663 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 2664 | Register dest, |
| 2665 | Register src, |
| 2666 | Register count, |
| 2667 | Register scratch, |
| 2668 | String::Encoding encoding) { |
| 2669 | DCHECK(!scratch.is(dest)); |
| 2670 | DCHECK(!scratch.is(src)); |
| 2671 | DCHECK(!scratch.is(count)); |
| 2672 | |
| 2673 | // Nothing to do for zero characters. |
| 2674 | Label done; |
| 2675 | __ test(count, count); |
| 2676 | __ j(zero, &done); |
| 2677 | |
| 2678 | // Make count the number of bytes to copy. |
| 2679 | if (encoding == String::TWO_BYTE_ENCODING) { |
| 2680 | __ shl(count, 1); |
| 2681 | } |
| 2682 | |
| 2683 | Label loop; |
| 2684 | __ bind(&loop); |
| 2685 | __ mov_b(scratch, Operand(src, 0)); |
| 2686 | __ mov_b(Operand(dest, 0), scratch); |
| 2687 | __ inc(src); |
| 2688 | __ inc(dest); |
| 2689 | __ dec(count); |
| 2690 | __ j(not_zero, &loop); |
| 2691 | |
| 2692 | __ bind(&done); |
| 2693 | } |
| 2694 | |
| 2695 | |
| 2696 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 2697 | Label runtime; |
| 2698 | |
| 2699 | // Stack frame on entry. |
| 2700 | // esp[0]: return address |
| 2701 | // esp[4]: to |
| 2702 | // esp[8]: from |
| 2703 | // esp[12]: string |
| 2704 | |
| 2705 | // Make sure first argument is a string. |
| 2706 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 2707 | STATIC_ASSERT(kSmiTag == 0); |
| 2708 | __ JumpIfSmi(eax, &runtime); |
| 2709 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 2710 | __ j(NegateCondition(is_string), &runtime); |
| 2711 | |
| 2712 | // eax: string |
| 2713 | // ebx: instance type |
| 2714 | |
| 2715 | // Calculate length of sub string using the smi values. |
| 2716 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); // To index. |
| 2717 | __ JumpIfNotSmi(ecx, &runtime); |
| 2718 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // From index. |
| 2719 | __ JumpIfNotSmi(edx, &runtime); |
| 2720 | __ sub(ecx, edx); |
| 2721 | __ cmp(ecx, FieldOperand(eax, String::kLengthOffset)); |
| 2722 | Label not_original_string; |
| 2723 | // Shorter than original string's length: an actual substring. |
| 2724 | __ j(below, ¬_original_string, Label::kNear); |
| 2725 | // Longer than original string's length or negative: unsafe arguments. |
| 2726 | __ j(above, &runtime); |
| 2727 | // Return original string. |
| 2728 | Counters* counters = isolate()->counters(); |
| 2729 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 2730 | __ ret(3 * kPointerSize); |
| 2731 | __ bind(¬_original_string); |
| 2732 | |
| 2733 | Label single_char; |
| 2734 | __ cmp(ecx, Immediate(Smi::FromInt(1))); |
| 2735 | __ j(equal, &single_char); |
| 2736 | |
| 2737 | // eax: string |
| 2738 | // ebx: instance type |
| 2739 | // ecx: sub string length (smi) |
| 2740 | // edx: from index (smi) |
| 2741 | // Deal with different string types: update the index if necessary |
| 2742 | // and put the underlying string into edi. |
| 2743 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 2744 | // If the string is not indirect, it can only be sequential or external. |
| 2745 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 2746 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 2747 | __ test(ebx, Immediate(kIsIndirectStringMask)); |
| 2748 | __ j(zero, &seq_or_external_string, Label::kNear); |
| 2749 | |
| 2750 | Factory* factory = isolate()->factory(); |
| 2751 | __ test(ebx, Immediate(kSlicedNotConsMask)); |
| 2752 | __ j(not_zero, &sliced_string, Label::kNear); |
| 2753 | // Cons string. Check whether it is flat, then fetch first part. |
| 2754 | // Flat cons strings have an empty second part. |
| 2755 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), |
| 2756 | factory->empty_string()); |
| 2757 | __ j(not_equal, &runtime); |
| 2758 | __ mov(edi, FieldOperand(eax, ConsString::kFirstOffset)); |
| 2759 | // Update instance type. |
| 2760 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 2761 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 2762 | __ jmp(&underlying_unpacked, Label::kNear); |
| 2763 | |
| 2764 | __ bind(&sliced_string); |
| 2765 | // Sliced string. Fetch parent and adjust start index by offset. |
| 2766 | __ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 2767 | __ mov(edi, FieldOperand(eax, SlicedString::kParentOffset)); |
| 2768 | // Update instance type. |
| 2769 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 2770 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 2771 | __ jmp(&underlying_unpacked, Label::kNear); |
| 2772 | |
| 2773 | __ bind(&seq_or_external_string); |
| 2774 | // Sequential or external string. Just move string to the expected register. |
| 2775 | __ mov(edi, eax); |
| 2776 | |
| 2777 | __ bind(&underlying_unpacked); |
| 2778 | |
| 2779 | if (FLAG_string_slices) { |
| 2780 | Label copy_routine; |
| 2781 | // edi: underlying subject string |
| 2782 | // ebx: instance type of underlying subject string |
| 2783 | // edx: adjusted start index (smi) |
| 2784 | // ecx: length (smi) |
| 2785 | __ cmp(ecx, Immediate(Smi::FromInt(SlicedString::kMinLength))); |
| 2786 | // Short slice. Copy instead of slicing. |
| 2787 | __ j(less, ©_routine); |
| 2788 | // Allocate new sliced string. At this point we do not reload the instance |
| 2789 | // type including the string encoding because we simply rely on the info |
| 2790 | // provided by the original string. It does not matter if the original |
| 2791 | // string's encoding is wrong because we always have to recheck encoding of |
| 2792 | // the newly created string's parent anyways due to externalized strings. |
| 2793 | Label two_byte_slice, set_slice_header; |
| 2794 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
| 2795 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 2796 | __ test(ebx, Immediate(kStringEncodingMask)); |
| 2797 | __ j(zero, &two_byte_slice, Label::kNear); |
| 2798 | __ AllocateOneByteSlicedString(eax, ebx, no_reg, &runtime); |
| 2799 | __ jmp(&set_slice_header, Label::kNear); |
| 2800 | __ bind(&two_byte_slice); |
| 2801 | __ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime); |
| 2802 | __ bind(&set_slice_header); |
| 2803 | __ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx); |
| 2804 | __ mov(FieldOperand(eax, SlicedString::kHashFieldOffset), |
| 2805 | Immediate(String::kEmptyHashField)); |
| 2806 | __ mov(FieldOperand(eax, SlicedString::kParentOffset), edi); |
| 2807 | __ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx); |
| 2808 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 2809 | __ ret(3 * kPointerSize); |
| 2810 | |
| 2811 | __ bind(©_routine); |
| 2812 | } |
| 2813 | |
| 2814 | // edi: underlying subject string |
| 2815 | // ebx: instance type of underlying subject string |
| 2816 | // edx: adjusted start index (smi) |
| 2817 | // ecx: length (smi) |
| 2818 | // The subject string can only be external or sequential string of either |
| 2819 | // encoding at this point. |
| 2820 | Label two_byte_sequential, runtime_drop_two, sequential_string; |
| 2821 | STATIC_ASSERT(kExternalStringTag != 0); |
| 2822 | STATIC_ASSERT(kSeqStringTag == 0); |
| 2823 | __ test_b(ebx, kExternalStringTag); |
| 2824 | __ j(zero, &sequential_string); |
| 2825 | |
| 2826 | // Handle external string. |
| 2827 | // Rule out short external strings. |
| 2828 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 2829 | __ test_b(ebx, kShortExternalStringMask); |
| 2830 | __ j(not_zero, &runtime); |
| 2831 | __ mov(edi, FieldOperand(edi, ExternalString::kResourceDataOffset)); |
| 2832 | // Move the pointer so that offset-wise, it looks like a sequential string. |
| 2833 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
| 2834 | __ sub(edi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 2835 | |
| 2836 | __ bind(&sequential_string); |
| 2837 | // Stash away (adjusted) index and (underlying) string. |
| 2838 | __ push(edx); |
| 2839 | __ push(edi); |
| 2840 | __ SmiUntag(ecx); |
| 2841 | STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
| 2842 | __ test_b(ebx, kStringEncodingMask); |
| 2843 | __ j(zero, &two_byte_sequential); |
| 2844 | |
| 2845 | // Sequential one byte string. Allocate the result. |
| 2846 | __ AllocateOneByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
| 2847 | |
| 2848 | // eax: result string |
| 2849 | // ecx: result string length |
| 2850 | // Locate first character of result. |
| 2851 | __ mov(edi, eax); |
| 2852 | __ add(edi, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
| 2853 | // Load string argument and locate character of sub string start. |
| 2854 | __ pop(edx); |
| 2855 | __ pop(ebx); |
| 2856 | __ SmiUntag(ebx); |
| 2857 | __ lea(edx, FieldOperand(edx, ebx, times_1, SeqOneByteString::kHeaderSize)); |
| 2858 | |
| 2859 | // eax: result string |
| 2860 | // ecx: result length |
| 2861 | // edi: first character of result |
| 2862 | // edx: character of sub string start |
| 2863 | StringHelper::GenerateCopyCharacters( |
| 2864 | masm, edi, edx, ecx, ebx, String::ONE_BYTE_ENCODING); |
| 2865 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 2866 | __ ret(3 * kPointerSize); |
| 2867 | |
| 2868 | __ bind(&two_byte_sequential); |
| 2869 | // Sequential two-byte string. Allocate the result. |
| 2870 | __ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
| 2871 | |
| 2872 | // eax: result string |
| 2873 | // ecx: result string length |
| 2874 | // Locate first character of result. |
| 2875 | __ mov(edi, eax); |
| 2876 | __ add(edi, |
| 2877 | Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 2878 | // Load string argument and locate character of sub string start. |
| 2879 | __ pop(edx); |
| 2880 | __ pop(ebx); |
| 2881 | // As from is a smi it is 2 times the value which matches the size of a two |
| 2882 | // byte character. |
| 2883 | STATIC_ASSERT(kSmiTag == 0); |
| 2884 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
| 2885 | __ lea(edx, FieldOperand(edx, ebx, times_1, SeqTwoByteString::kHeaderSize)); |
| 2886 | |
| 2887 | // eax: result string |
| 2888 | // ecx: result length |
| 2889 | // edi: first character of result |
| 2890 | // edx: character of sub string start |
| 2891 | StringHelper::GenerateCopyCharacters( |
| 2892 | masm, edi, edx, ecx, ebx, String::TWO_BYTE_ENCODING); |
| 2893 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 2894 | __ ret(3 * kPointerSize); |
| 2895 | |
| 2896 | // Drop pushed values on the stack before tail call. |
| 2897 | __ bind(&runtime_drop_two); |
| 2898 | __ Drop(2); |
| 2899 | |
| 2900 | // Just jump to runtime to create the sub string. |
| 2901 | __ bind(&runtime); |
| 2902 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
| 2903 | |
| 2904 | __ bind(&single_char); |
| 2905 | // eax: string |
| 2906 | // ebx: instance type |
| 2907 | // ecx: sub string length (smi) |
| 2908 | // edx: from index (smi) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2909 | StringCharAtGenerator generator(eax, edx, ecx, eax, &runtime, &runtime, |
| 2910 | &runtime, STRING_INDEX_IS_NUMBER, |
| 2911 | RECEIVER_IS_STRING); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2912 | generator.GenerateFast(masm); |
| 2913 | __ ret(3 * kPointerSize); |
| 2914 | generator.SkipSlow(masm, &runtime); |
| 2915 | } |
| 2916 | |
| 2917 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 2918 | void ToNumberStub::Generate(MacroAssembler* masm) { |
| 2919 | // The ToNumber stub takes one argument in eax. |
| 2920 | Label not_smi; |
| 2921 | __ JumpIfNotSmi(eax, ¬_smi, Label::kNear); |
| 2922 | __ Ret(); |
| 2923 | __ bind(¬_smi); |
| 2924 | |
| 2925 | Label not_heap_number; |
| 2926 | __ CompareMap(eax, masm->isolate()->factory()->heap_number_map()); |
| 2927 | __ j(not_equal, ¬_heap_number, Label::kNear); |
| 2928 | __ Ret(); |
| 2929 | __ bind(¬_heap_number); |
| 2930 | |
| 2931 | Label not_string, slow_string; |
| 2932 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, edi); |
| 2933 | // eax: object |
| 2934 | // edi: object map |
| 2935 | __ j(above_equal, ¬_string, Label::kNear); |
| 2936 | // Check if string has a cached array index. |
| 2937 | __ test(FieldOperand(eax, String::kHashFieldOffset), |
| 2938 | Immediate(String::kContainsCachedArrayIndexMask)); |
| 2939 | __ j(not_zero, &slow_string, Label::kNear); |
| 2940 | __ mov(eax, FieldOperand(eax, String::kHashFieldOffset)); |
| 2941 | __ IndexFromHash(eax, eax); |
| 2942 | __ Ret(); |
| 2943 | __ bind(&slow_string); |
| 2944 | __ pop(ecx); // Pop return address. |
| 2945 | __ push(eax); // Push argument. |
| 2946 | __ push(ecx); // Push return address. |
| 2947 | __ TailCallRuntime(Runtime::kStringToNumber, 1, 1); |
| 2948 | __ bind(¬_string); |
| 2949 | |
| 2950 | Label not_oddball; |
| 2951 | __ CmpInstanceType(edi, ODDBALL_TYPE); |
| 2952 | __ j(not_equal, ¬_oddball, Label::kNear); |
| 2953 | __ mov(eax, FieldOperand(eax, Oddball::kToNumberOffset)); |
| 2954 | __ Ret(); |
| 2955 | __ bind(¬_oddball); |
| 2956 | |
| 2957 | __ pop(ecx); // Pop return address. |
| 2958 | __ push(eax); // Push argument. |
| 2959 | __ push(ecx); // Push return address. |
| 2960 | __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION); |
| 2961 | } |
| 2962 | |
| 2963 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2964 | void StringHelper::GenerateFlatOneByteStringEquals(MacroAssembler* masm, |
| 2965 | Register left, |
| 2966 | Register right, |
| 2967 | Register scratch1, |
| 2968 | Register scratch2) { |
| 2969 | Register length = scratch1; |
| 2970 | |
| 2971 | // Compare lengths. |
| 2972 | Label strings_not_equal, check_zero_length; |
| 2973 | __ mov(length, FieldOperand(left, String::kLengthOffset)); |
| 2974 | __ cmp(length, FieldOperand(right, String::kLengthOffset)); |
| 2975 | __ j(equal, &check_zero_length, Label::kNear); |
| 2976 | __ bind(&strings_not_equal); |
| 2977 | __ Move(eax, Immediate(Smi::FromInt(NOT_EQUAL))); |
| 2978 | __ ret(0); |
| 2979 | |
| 2980 | // Check if the length is zero. |
| 2981 | Label compare_chars; |
| 2982 | __ bind(&check_zero_length); |
| 2983 | STATIC_ASSERT(kSmiTag == 0); |
| 2984 | __ test(length, length); |
| 2985 | __ j(not_zero, &compare_chars, Label::kNear); |
| 2986 | __ Move(eax, Immediate(Smi::FromInt(EQUAL))); |
| 2987 | __ ret(0); |
| 2988 | |
| 2989 | // Compare characters. |
| 2990 | __ bind(&compare_chars); |
| 2991 | GenerateOneByteCharsCompareLoop(masm, left, right, length, scratch2, |
| 2992 | &strings_not_equal, Label::kNear); |
| 2993 | |
| 2994 | // Characters are equal. |
| 2995 | __ Move(eax, Immediate(Smi::FromInt(EQUAL))); |
| 2996 | __ ret(0); |
| 2997 | } |
| 2998 | |
| 2999 | |
| 3000 | void StringHelper::GenerateCompareFlatOneByteStrings( |
| 3001 | MacroAssembler* masm, Register left, Register right, Register scratch1, |
| 3002 | Register scratch2, Register scratch3) { |
| 3003 | Counters* counters = masm->isolate()->counters(); |
| 3004 | __ IncrementCounter(counters->string_compare_native(), 1); |
| 3005 | |
| 3006 | // Find minimum length. |
| 3007 | Label left_shorter; |
| 3008 | __ mov(scratch1, FieldOperand(left, String::kLengthOffset)); |
| 3009 | __ mov(scratch3, scratch1); |
| 3010 | __ sub(scratch3, FieldOperand(right, String::kLengthOffset)); |
| 3011 | |
| 3012 | Register length_delta = scratch3; |
| 3013 | |
| 3014 | __ j(less_equal, &left_shorter, Label::kNear); |
| 3015 | // Right string is shorter. Change scratch1 to be length of right string. |
| 3016 | __ sub(scratch1, length_delta); |
| 3017 | __ bind(&left_shorter); |
| 3018 | |
| 3019 | Register min_length = scratch1; |
| 3020 | |
| 3021 | // If either length is zero, just compare lengths. |
| 3022 | Label compare_lengths; |
| 3023 | __ test(min_length, min_length); |
| 3024 | __ j(zero, &compare_lengths, Label::kNear); |
| 3025 | |
| 3026 | // Compare characters. |
| 3027 | Label result_not_equal; |
| 3028 | GenerateOneByteCharsCompareLoop(masm, left, right, min_length, scratch2, |
| 3029 | &result_not_equal, Label::kNear); |
| 3030 | |
| 3031 | // Compare lengths - strings up to min-length are equal. |
| 3032 | __ bind(&compare_lengths); |
| 3033 | __ test(length_delta, length_delta); |
| 3034 | Label length_not_equal; |
| 3035 | __ j(not_zero, &length_not_equal, Label::kNear); |
| 3036 | |
| 3037 | // Result is EQUAL. |
| 3038 | STATIC_ASSERT(EQUAL == 0); |
| 3039 | STATIC_ASSERT(kSmiTag == 0); |
| 3040 | __ Move(eax, Immediate(Smi::FromInt(EQUAL))); |
| 3041 | __ ret(0); |
| 3042 | |
| 3043 | Label result_greater; |
| 3044 | Label result_less; |
| 3045 | __ bind(&length_not_equal); |
| 3046 | __ j(greater, &result_greater, Label::kNear); |
| 3047 | __ jmp(&result_less, Label::kNear); |
| 3048 | __ bind(&result_not_equal); |
| 3049 | __ j(above, &result_greater, Label::kNear); |
| 3050 | __ bind(&result_less); |
| 3051 | |
| 3052 | // Result is LESS. |
| 3053 | __ Move(eax, Immediate(Smi::FromInt(LESS))); |
| 3054 | __ ret(0); |
| 3055 | |
| 3056 | // Result is GREATER. |
| 3057 | __ bind(&result_greater); |
| 3058 | __ Move(eax, Immediate(Smi::FromInt(GREATER))); |
| 3059 | __ ret(0); |
| 3060 | } |
| 3061 | |
| 3062 | |
| 3063 | void StringHelper::GenerateOneByteCharsCompareLoop( |
| 3064 | MacroAssembler* masm, Register left, Register right, Register length, |
| 3065 | Register scratch, Label* chars_not_equal, |
| 3066 | Label::Distance chars_not_equal_near) { |
| 3067 | // Change index to run from -length to -1 by adding length to string |
| 3068 | // start. This means that loop ends when index reaches zero, which |
| 3069 | // doesn't need an additional compare. |
| 3070 | __ SmiUntag(length); |
| 3071 | __ lea(left, |
| 3072 | FieldOperand(left, length, times_1, SeqOneByteString::kHeaderSize)); |
| 3073 | __ lea(right, |
| 3074 | FieldOperand(right, length, times_1, SeqOneByteString::kHeaderSize)); |
| 3075 | __ neg(length); |
| 3076 | Register index = length; // index = -length; |
| 3077 | |
| 3078 | // Compare loop. |
| 3079 | Label loop; |
| 3080 | __ bind(&loop); |
| 3081 | __ mov_b(scratch, Operand(left, index, times_1, 0)); |
| 3082 | __ cmpb(scratch, Operand(right, index, times_1, 0)); |
| 3083 | __ j(not_equal, chars_not_equal, chars_not_equal_near); |
| 3084 | __ inc(index); |
| 3085 | __ j(not_zero, &loop); |
| 3086 | } |
| 3087 | |
| 3088 | |
| 3089 | void StringCompareStub::Generate(MacroAssembler* masm) { |
| 3090 | Label runtime; |
| 3091 | |
| 3092 | // Stack frame on entry. |
| 3093 | // esp[0]: return address |
| 3094 | // esp[4]: right string |
| 3095 | // esp[8]: left string |
| 3096 | |
| 3097 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // left |
| 3098 | __ mov(eax, Operand(esp, 1 * kPointerSize)); // right |
| 3099 | |
| 3100 | Label not_same; |
| 3101 | __ cmp(edx, eax); |
| 3102 | __ j(not_equal, ¬_same, Label::kNear); |
| 3103 | STATIC_ASSERT(EQUAL == 0); |
| 3104 | STATIC_ASSERT(kSmiTag == 0); |
| 3105 | __ Move(eax, Immediate(Smi::FromInt(EQUAL))); |
| 3106 | __ IncrementCounter(isolate()->counters()->string_compare_native(), 1); |
| 3107 | __ ret(2 * kPointerSize); |
| 3108 | |
| 3109 | __ bind(¬_same); |
| 3110 | |
| 3111 | // Check that both objects are sequential one-byte strings. |
| 3112 | __ JumpIfNotBothSequentialOneByteStrings(edx, eax, ecx, ebx, &runtime); |
| 3113 | |
| 3114 | // Compare flat one-byte strings. |
| 3115 | // Drop arguments from the stack. |
| 3116 | __ pop(ecx); |
| 3117 | __ add(esp, Immediate(2 * kPointerSize)); |
| 3118 | __ push(ecx); |
| 3119 | StringHelper::GenerateCompareFlatOneByteStrings(masm, edx, eax, ecx, ebx, |
| 3120 | edi); |
| 3121 | |
| 3122 | // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 3123 | // tagged as a small integer. |
| 3124 | __ bind(&runtime); |
| 3125 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 3126 | } |
| 3127 | |
| 3128 | |
| 3129 | void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) { |
| 3130 | // ----------- S t a t e ------------- |
| 3131 | // -- edx : left |
| 3132 | // -- eax : right |
| 3133 | // -- esp[0] : return address |
| 3134 | // ----------------------------------- |
| 3135 | |
| 3136 | // Load ecx with the allocation site. We stick an undefined dummy value here |
| 3137 | // and replace it with the real allocation site later when we instantiate this |
| 3138 | // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate(). |
| 3139 | __ mov(ecx, handle(isolate()->heap()->undefined_value())); |
| 3140 | |
| 3141 | // Make sure that we actually patched the allocation site. |
| 3142 | if (FLAG_debug_code) { |
| 3143 | __ test(ecx, Immediate(kSmiTagMask)); |
| 3144 | __ Assert(not_equal, kExpectedAllocationSite); |
| 3145 | __ cmp(FieldOperand(ecx, HeapObject::kMapOffset), |
| 3146 | isolate()->factory()->allocation_site_map()); |
| 3147 | __ Assert(equal, kExpectedAllocationSite); |
| 3148 | } |
| 3149 | |
| 3150 | // Tail call into the stub that handles binary operations with allocation |
| 3151 | // sites. |
| 3152 | BinaryOpWithAllocationSiteStub stub(isolate(), state()); |
| 3153 | __ TailCallStub(&stub); |
| 3154 | } |
| 3155 | |
| 3156 | |
| 3157 | void CompareICStub::GenerateSmis(MacroAssembler* masm) { |
| 3158 | DCHECK(state() == CompareICState::SMI); |
| 3159 | Label miss; |
| 3160 | __ mov(ecx, edx); |
| 3161 | __ or_(ecx, eax); |
| 3162 | __ JumpIfNotSmi(ecx, &miss, Label::kNear); |
| 3163 | |
| 3164 | if (GetCondition() == equal) { |
| 3165 | // For equality we do not care about the sign of the result. |
| 3166 | __ sub(eax, edx); |
| 3167 | } else { |
| 3168 | Label done; |
| 3169 | __ sub(edx, eax); |
| 3170 | __ j(no_overflow, &done, Label::kNear); |
| 3171 | // Correct sign of result in case of overflow. |
| 3172 | __ not_(edx); |
| 3173 | __ bind(&done); |
| 3174 | __ mov(eax, edx); |
| 3175 | } |
| 3176 | __ ret(0); |
| 3177 | |
| 3178 | __ bind(&miss); |
| 3179 | GenerateMiss(masm); |
| 3180 | } |
| 3181 | |
| 3182 | |
| 3183 | void CompareICStub::GenerateNumbers(MacroAssembler* masm) { |
| 3184 | DCHECK(state() == CompareICState::NUMBER); |
| 3185 | |
| 3186 | Label generic_stub; |
| 3187 | Label unordered, maybe_undefined1, maybe_undefined2; |
| 3188 | Label miss; |
| 3189 | |
| 3190 | if (left() == CompareICState::SMI) { |
| 3191 | __ JumpIfNotSmi(edx, &miss); |
| 3192 | } |
| 3193 | if (right() == CompareICState::SMI) { |
| 3194 | __ JumpIfNotSmi(eax, &miss); |
| 3195 | } |
| 3196 | |
| 3197 | // Inlining the double comparison and falling back to the general compare |
| 3198 | // stub if NaN is involved or SSE2 or CMOV is unsupported. |
| 3199 | __ mov(ecx, edx); |
| 3200 | __ and_(ecx, eax); |
| 3201 | __ JumpIfSmi(ecx, &generic_stub, Label::kNear); |
| 3202 | |
| 3203 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 3204 | isolate()->factory()->heap_number_map()); |
| 3205 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
| 3206 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 3207 | isolate()->factory()->heap_number_map()); |
| 3208 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 3209 | |
| 3210 | __ bind(&unordered); |
| 3211 | __ bind(&generic_stub); |
| 3212 | CompareICStub stub(isolate(), op(), CompareICState::GENERIC, |
| 3213 | CompareICState::GENERIC, CompareICState::GENERIC); |
| 3214 | __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 3215 | |
| 3216 | __ bind(&maybe_undefined1); |
| 3217 | if (Token::IsOrderedRelationalCompareOp(op())) { |
| 3218 | __ cmp(eax, Immediate(isolate()->factory()->undefined_value())); |
| 3219 | __ j(not_equal, &miss); |
| 3220 | __ JumpIfSmi(edx, &unordered); |
| 3221 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx); |
| 3222 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 3223 | __ jmp(&unordered); |
| 3224 | } |
| 3225 | |
| 3226 | __ bind(&maybe_undefined2); |
| 3227 | if (Token::IsOrderedRelationalCompareOp(op())) { |
| 3228 | __ cmp(edx, Immediate(isolate()->factory()->undefined_value())); |
| 3229 | __ j(equal, &unordered); |
| 3230 | } |
| 3231 | |
| 3232 | __ bind(&miss); |
| 3233 | GenerateMiss(masm); |
| 3234 | } |
| 3235 | |
| 3236 | |
| 3237 | void CompareICStub::GenerateInternalizedStrings(MacroAssembler* masm) { |
| 3238 | DCHECK(state() == CompareICState::INTERNALIZED_STRING); |
| 3239 | DCHECK(GetCondition() == equal); |
| 3240 | |
| 3241 | // Registers containing left and right operands respectively. |
| 3242 | Register left = edx; |
| 3243 | Register right = eax; |
| 3244 | Register tmp1 = ecx; |
| 3245 | Register tmp2 = ebx; |
| 3246 | |
| 3247 | // Check that both operands are heap objects. |
| 3248 | Label miss; |
| 3249 | __ mov(tmp1, left); |
| 3250 | STATIC_ASSERT(kSmiTag == 0); |
| 3251 | __ and_(tmp1, right); |
| 3252 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
| 3253 | |
| 3254 | // Check that both operands are internalized strings. |
| 3255 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 3256 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 3257 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 3258 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 3259 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 3260 | __ or_(tmp1, tmp2); |
| 3261 | __ test(tmp1, Immediate(kIsNotStringMask | kIsNotInternalizedMask)); |
| 3262 | __ j(not_zero, &miss, Label::kNear); |
| 3263 | |
| 3264 | // Internalized strings are compared by identity. |
| 3265 | Label done; |
| 3266 | __ cmp(left, right); |
| 3267 | // Make sure eax is non-zero. At this point input operands are |
| 3268 | // guaranteed to be non-zero. |
| 3269 | DCHECK(right.is(eax)); |
| 3270 | __ j(not_equal, &done, Label::kNear); |
| 3271 | STATIC_ASSERT(EQUAL == 0); |
| 3272 | STATIC_ASSERT(kSmiTag == 0); |
| 3273 | __ Move(eax, Immediate(Smi::FromInt(EQUAL))); |
| 3274 | __ bind(&done); |
| 3275 | __ ret(0); |
| 3276 | |
| 3277 | __ bind(&miss); |
| 3278 | GenerateMiss(masm); |
| 3279 | } |
| 3280 | |
| 3281 | |
| 3282 | void CompareICStub::GenerateUniqueNames(MacroAssembler* masm) { |
| 3283 | DCHECK(state() == CompareICState::UNIQUE_NAME); |
| 3284 | DCHECK(GetCondition() == equal); |
| 3285 | |
| 3286 | // Registers containing left and right operands respectively. |
| 3287 | Register left = edx; |
| 3288 | Register right = eax; |
| 3289 | Register tmp1 = ecx; |
| 3290 | Register tmp2 = ebx; |
| 3291 | |
| 3292 | // Check that both operands are heap objects. |
| 3293 | Label miss; |
| 3294 | __ mov(tmp1, left); |
| 3295 | STATIC_ASSERT(kSmiTag == 0); |
| 3296 | __ and_(tmp1, right); |
| 3297 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
| 3298 | |
| 3299 | // Check that both operands are unique names. This leaves the instance |
| 3300 | // types loaded in tmp1 and tmp2. |
| 3301 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 3302 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 3303 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 3304 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 3305 | |
| 3306 | __ JumpIfNotUniqueNameInstanceType(tmp1, &miss, Label::kNear); |
| 3307 | __ JumpIfNotUniqueNameInstanceType(tmp2, &miss, Label::kNear); |
| 3308 | |
| 3309 | // Unique names are compared by identity. |
| 3310 | Label done; |
| 3311 | __ cmp(left, right); |
| 3312 | // Make sure eax is non-zero. At this point input operands are |
| 3313 | // guaranteed to be non-zero. |
| 3314 | DCHECK(right.is(eax)); |
| 3315 | __ j(not_equal, &done, Label::kNear); |
| 3316 | STATIC_ASSERT(EQUAL == 0); |
| 3317 | STATIC_ASSERT(kSmiTag == 0); |
| 3318 | __ Move(eax, Immediate(Smi::FromInt(EQUAL))); |
| 3319 | __ bind(&done); |
| 3320 | __ ret(0); |
| 3321 | |
| 3322 | __ bind(&miss); |
| 3323 | GenerateMiss(masm); |
| 3324 | } |
| 3325 | |
| 3326 | |
| 3327 | void CompareICStub::GenerateStrings(MacroAssembler* masm) { |
| 3328 | DCHECK(state() == CompareICState::STRING); |
| 3329 | Label miss; |
| 3330 | |
| 3331 | bool equality = Token::IsEqualityOp(op()); |
| 3332 | |
| 3333 | // Registers containing left and right operands respectively. |
| 3334 | Register left = edx; |
| 3335 | Register right = eax; |
| 3336 | Register tmp1 = ecx; |
| 3337 | Register tmp2 = ebx; |
| 3338 | Register tmp3 = edi; |
| 3339 | |
| 3340 | // Check that both operands are heap objects. |
| 3341 | __ mov(tmp1, left); |
| 3342 | STATIC_ASSERT(kSmiTag == 0); |
| 3343 | __ and_(tmp1, right); |
| 3344 | __ JumpIfSmi(tmp1, &miss); |
| 3345 | |
| 3346 | // Check that both operands are strings. This leaves the instance |
| 3347 | // types loaded in tmp1 and tmp2. |
| 3348 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 3349 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 3350 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 3351 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 3352 | __ mov(tmp3, tmp1); |
| 3353 | STATIC_ASSERT(kNotStringTag != 0); |
| 3354 | __ or_(tmp3, tmp2); |
| 3355 | __ test(tmp3, Immediate(kIsNotStringMask)); |
| 3356 | __ j(not_zero, &miss); |
| 3357 | |
| 3358 | // Fast check for identical strings. |
| 3359 | Label not_same; |
| 3360 | __ cmp(left, right); |
| 3361 | __ j(not_equal, ¬_same, Label::kNear); |
| 3362 | STATIC_ASSERT(EQUAL == 0); |
| 3363 | STATIC_ASSERT(kSmiTag == 0); |
| 3364 | __ Move(eax, Immediate(Smi::FromInt(EQUAL))); |
| 3365 | __ ret(0); |
| 3366 | |
| 3367 | // Handle not identical strings. |
| 3368 | __ bind(¬_same); |
| 3369 | |
| 3370 | // Check that both strings are internalized. If they are, we're done |
| 3371 | // because we already know they are not identical. But in the case of |
| 3372 | // non-equality compare, we still need to determine the order. We |
| 3373 | // also know they are both strings. |
| 3374 | if (equality) { |
| 3375 | Label do_compare; |
| 3376 | STATIC_ASSERT(kInternalizedTag == 0); |
| 3377 | __ or_(tmp1, tmp2); |
| 3378 | __ test(tmp1, Immediate(kIsNotInternalizedMask)); |
| 3379 | __ j(not_zero, &do_compare, Label::kNear); |
| 3380 | // Make sure eax is non-zero. At this point input operands are |
| 3381 | // guaranteed to be non-zero. |
| 3382 | DCHECK(right.is(eax)); |
| 3383 | __ ret(0); |
| 3384 | __ bind(&do_compare); |
| 3385 | } |
| 3386 | |
| 3387 | // Check that both strings are sequential one-byte. |
| 3388 | Label runtime; |
| 3389 | __ JumpIfNotBothSequentialOneByteStrings(left, right, tmp1, tmp2, &runtime); |
| 3390 | |
| 3391 | // Compare flat one byte strings. Returns when done. |
| 3392 | if (equality) { |
| 3393 | StringHelper::GenerateFlatOneByteStringEquals(masm, left, right, tmp1, |
| 3394 | tmp2); |
| 3395 | } else { |
| 3396 | StringHelper::GenerateCompareFlatOneByteStrings(masm, left, right, tmp1, |
| 3397 | tmp2, tmp3); |
| 3398 | } |
| 3399 | |
| 3400 | // Handle more complex cases in runtime. |
| 3401 | __ bind(&runtime); |
| 3402 | __ pop(tmp1); // Return address. |
| 3403 | __ push(left); |
| 3404 | __ push(right); |
| 3405 | __ push(tmp1); |
| 3406 | if (equality) { |
| 3407 | __ TailCallRuntime(Runtime::kStringEquals, 2, 1); |
| 3408 | } else { |
| 3409 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 3410 | } |
| 3411 | |
| 3412 | __ bind(&miss); |
| 3413 | GenerateMiss(masm); |
| 3414 | } |
| 3415 | |
| 3416 | |
| 3417 | void CompareICStub::GenerateObjects(MacroAssembler* masm) { |
| 3418 | DCHECK(state() == CompareICState::OBJECT); |
| 3419 | Label miss; |
| 3420 | __ mov(ecx, edx); |
| 3421 | __ and_(ecx, eax); |
| 3422 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
| 3423 | |
| 3424 | __ CmpObjectType(eax, JS_OBJECT_TYPE, ecx); |
| 3425 | __ j(not_equal, &miss, Label::kNear); |
| 3426 | __ CmpObjectType(edx, JS_OBJECT_TYPE, ecx); |
| 3427 | __ j(not_equal, &miss, Label::kNear); |
| 3428 | |
| 3429 | DCHECK(GetCondition() == equal); |
| 3430 | __ sub(eax, edx); |
| 3431 | __ ret(0); |
| 3432 | |
| 3433 | __ bind(&miss); |
| 3434 | GenerateMiss(masm); |
| 3435 | } |
| 3436 | |
| 3437 | |
| 3438 | void CompareICStub::GenerateKnownObjects(MacroAssembler* masm) { |
| 3439 | Label miss; |
| 3440 | __ mov(ecx, edx); |
| 3441 | __ and_(ecx, eax); |
| 3442 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
| 3443 | |
| 3444 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3445 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 3446 | __ cmp(ecx, known_map_); |
| 3447 | __ j(not_equal, &miss, Label::kNear); |
| 3448 | __ cmp(ebx, known_map_); |
| 3449 | __ j(not_equal, &miss, Label::kNear); |
| 3450 | |
| 3451 | __ sub(eax, edx); |
| 3452 | __ ret(0); |
| 3453 | |
| 3454 | __ bind(&miss); |
| 3455 | GenerateMiss(masm); |
| 3456 | } |
| 3457 | |
| 3458 | |
| 3459 | void CompareICStub::GenerateMiss(MacroAssembler* masm) { |
| 3460 | { |
| 3461 | // Call the runtime system in a fresh internal frame. |
| 3462 | ExternalReference miss = ExternalReference(IC_Utility(IC::kCompareIC_Miss), |
| 3463 | isolate()); |
| 3464 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 3465 | __ push(edx); // Preserve edx and eax. |
| 3466 | __ push(eax); |
| 3467 | __ push(edx); // And also use them as the arguments. |
| 3468 | __ push(eax); |
| 3469 | __ push(Immediate(Smi::FromInt(op()))); |
| 3470 | __ CallExternalReference(miss, 3); |
| 3471 | // Compute the entry point of the rewritten stub. |
| 3472 | __ lea(edi, FieldOperand(eax, Code::kHeaderSize)); |
| 3473 | __ pop(eax); |
| 3474 | __ pop(edx); |
| 3475 | } |
| 3476 | |
| 3477 | // Do a tail call to the rewritten stub. |
| 3478 | __ jmp(edi); |
| 3479 | } |
| 3480 | |
| 3481 | |
| 3482 | // Helper function used to check that the dictionary doesn't contain |
| 3483 | // the property. This function may return false negatives, so miss_label |
| 3484 | // must always call a backup property check that is complete. |
| 3485 | // This function is safe to call if the receiver has fast properties. |
| 3486 | // Name must be a unique name and receiver must be a heap object. |
| 3487 | void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 3488 | Label* miss, |
| 3489 | Label* done, |
| 3490 | Register properties, |
| 3491 | Handle<Name> name, |
| 3492 | Register r0) { |
| 3493 | DCHECK(name->IsUniqueName()); |
| 3494 | |
| 3495 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 3496 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 3497 | // undefined value), it guarantees the hash table doesn't contain the |
| 3498 | // property. It's true even if some slots represent deleted properties |
| 3499 | // (their names are the hole value). |
| 3500 | for (int i = 0; i < kInlinedProbes; i++) { |
| 3501 | // Compute the masked index: (hash + i + i * i) & mask. |
| 3502 | Register index = r0; |
| 3503 | // Capacity is smi 2^n. |
| 3504 | __ mov(index, FieldOperand(properties, kCapacityOffset)); |
| 3505 | __ dec(index); |
| 3506 | __ and_(index, |
| 3507 | Immediate(Smi::FromInt(name->Hash() + |
| 3508 | NameDictionary::GetProbeOffset(i)))); |
| 3509 | |
| 3510 | // Scale the index by multiplying by the entry size. |
| 3511 | DCHECK(NameDictionary::kEntrySize == 3); |
| 3512 | __ lea(index, Operand(index, index, times_2, 0)); // index *= 3. |
| 3513 | Register entity_name = r0; |
| 3514 | // Having undefined at this place means the name is not contained. |
| 3515 | DCHECK_EQ(kSmiTagSize, 1); |
| 3516 | __ mov(entity_name, Operand(properties, index, times_half_pointer_size, |
| 3517 | kElementsStartOffset - kHeapObjectTag)); |
| 3518 | __ cmp(entity_name, masm->isolate()->factory()->undefined_value()); |
| 3519 | __ j(equal, done); |
| 3520 | |
| 3521 | // Stop if found the property. |
| 3522 | __ cmp(entity_name, Handle<Name>(name)); |
| 3523 | __ j(equal, miss); |
| 3524 | |
| 3525 | Label good; |
| 3526 | // Check for the hole and skip. |
| 3527 | __ cmp(entity_name, masm->isolate()->factory()->the_hole_value()); |
| 3528 | __ j(equal, &good, Label::kNear); |
| 3529 | |
| 3530 | // Check if the entry name is not a unique name. |
| 3531 | __ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset)); |
| 3532 | __ JumpIfNotUniqueNameInstanceType( |
| 3533 | FieldOperand(entity_name, Map::kInstanceTypeOffset), miss); |
| 3534 | __ bind(&good); |
| 3535 | } |
| 3536 | |
| 3537 | NameDictionaryLookupStub stub(masm->isolate(), properties, r0, r0, |
| 3538 | NEGATIVE_LOOKUP); |
| 3539 | __ push(Immediate(Handle<Object>(name))); |
| 3540 | __ push(Immediate(name->Hash())); |
| 3541 | __ CallStub(&stub); |
| 3542 | __ test(r0, r0); |
| 3543 | __ j(not_zero, miss); |
| 3544 | __ jmp(done); |
| 3545 | } |
| 3546 | |
| 3547 | |
| 3548 | // Probe the name dictionary in the |elements| register. Jump to the |
| 3549 | // |done| label if a property with the given name is found leaving the |
| 3550 | // index into the dictionary in |r0|. Jump to the |miss| label |
| 3551 | // otherwise. |
| 3552 | void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 3553 | Label* miss, |
| 3554 | Label* done, |
| 3555 | Register elements, |
| 3556 | Register name, |
| 3557 | Register r0, |
| 3558 | Register r1) { |
| 3559 | DCHECK(!elements.is(r0)); |
| 3560 | DCHECK(!elements.is(r1)); |
| 3561 | DCHECK(!name.is(r0)); |
| 3562 | DCHECK(!name.is(r1)); |
| 3563 | |
| 3564 | __ AssertName(name); |
| 3565 | |
| 3566 | __ mov(r1, FieldOperand(elements, kCapacityOffset)); |
| 3567 | __ shr(r1, kSmiTagSize); // convert smi to int |
| 3568 | __ dec(r1); |
| 3569 | |
| 3570 | // Generate an unrolled loop that performs a few probes before |
| 3571 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 3572 | // cover ~93% of loads from dictionaries. |
| 3573 | for (int i = 0; i < kInlinedProbes; i++) { |
| 3574 | // Compute the masked index: (hash + i + i * i) & mask. |
| 3575 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 3576 | __ shr(r0, Name::kHashShift); |
| 3577 | if (i > 0) { |
| 3578 | __ add(r0, Immediate(NameDictionary::GetProbeOffset(i))); |
| 3579 | } |
| 3580 | __ and_(r0, r1); |
| 3581 | |
| 3582 | // Scale the index by multiplying by the entry size. |
| 3583 | DCHECK(NameDictionary::kEntrySize == 3); |
| 3584 | __ lea(r0, Operand(r0, r0, times_2, 0)); // r0 = r0 * 3 |
| 3585 | |
| 3586 | // Check if the key is identical to the name. |
| 3587 | __ cmp(name, Operand(elements, |
| 3588 | r0, |
| 3589 | times_4, |
| 3590 | kElementsStartOffset - kHeapObjectTag)); |
| 3591 | __ j(equal, done); |
| 3592 | } |
| 3593 | |
| 3594 | NameDictionaryLookupStub stub(masm->isolate(), elements, r1, r0, |
| 3595 | POSITIVE_LOOKUP); |
| 3596 | __ push(name); |
| 3597 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 3598 | __ shr(r0, Name::kHashShift); |
| 3599 | __ push(r0); |
| 3600 | __ CallStub(&stub); |
| 3601 | |
| 3602 | __ test(r1, r1); |
| 3603 | __ j(zero, miss); |
| 3604 | __ jmp(done); |
| 3605 | } |
| 3606 | |
| 3607 | |
| 3608 | void NameDictionaryLookupStub::Generate(MacroAssembler* masm) { |
| 3609 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 3610 | // we cannot call anything that could cause a GC from this stub. |
| 3611 | // Stack frame on entry: |
| 3612 | // esp[0 * kPointerSize]: return address. |
| 3613 | // esp[1 * kPointerSize]: key's hash. |
| 3614 | // esp[2 * kPointerSize]: key. |
| 3615 | // Registers: |
| 3616 | // dictionary_: NameDictionary to probe. |
| 3617 | // result_: used as scratch. |
| 3618 | // index_: will hold an index of entry if lookup is successful. |
| 3619 | // might alias with result_. |
| 3620 | // Returns: |
| 3621 | // result_ is zero if lookup failed, non zero otherwise. |
| 3622 | |
| 3623 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 3624 | |
| 3625 | Register scratch = result(); |
| 3626 | |
| 3627 | __ mov(scratch, FieldOperand(dictionary(), kCapacityOffset)); |
| 3628 | __ dec(scratch); |
| 3629 | __ SmiUntag(scratch); |
| 3630 | __ push(scratch); |
| 3631 | |
| 3632 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 3633 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 3634 | // undefined value), it guarantees the hash table doesn't contain the |
| 3635 | // property. It's true even if some slots represent deleted properties |
| 3636 | // (their names are the null value). |
| 3637 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 3638 | // Compute the masked index: (hash + i + i * i) & mask. |
| 3639 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 3640 | if (i > 0) { |
| 3641 | __ add(scratch, Immediate(NameDictionary::GetProbeOffset(i))); |
| 3642 | } |
| 3643 | __ and_(scratch, Operand(esp, 0)); |
| 3644 | |
| 3645 | // Scale the index by multiplying by the entry size. |
| 3646 | DCHECK(NameDictionary::kEntrySize == 3); |
| 3647 | __ lea(index(), Operand(scratch, scratch, times_2, 0)); // index *= 3. |
| 3648 | |
| 3649 | // Having undefined at this place means the name is not contained. |
| 3650 | DCHECK_EQ(kSmiTagSize, 1); |
| 3651 | __ mov(scratch, Operand(dictionary(), index(), times_pointer_size, |
| 3652 | kElementsStartOffset - kHeapObjectTag)); |
| 3653 | __ cmp(scratch, isolate()->factory()->undefined_value()); |
| 3654 | __ j(equal, ¬_in_dictionary); |
| 3655 | |
| 3656 | // Stop if found the property. |
| 3657 | __ cmp(scratch, Operand(esp, 3 * kPointerSize)); |
| 3658 | __ j(equal, &in_dictionary); |
| 3659 | |
| 3660 | if (i != kTotalProbes - 1 && mode() == NEGATIVE_LOOKUP) { |
| 3661 | // If we hit a key that is not a unique name during negative |
| 3662 | // lookup we have to bailout as this key might be equal to the |
| 3663 | // key we are looking for. |
| 3664 | |
| 3665 | // Check if the entry name is not a unique name. |
| 3666 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 3667 | __ JumpIfNotUniqueNameInstanceType( |
| 3668 | FieldOperand(scratch, Map::kInstanceTypeOffset), |
| 3669 | &maybe_in_dictionary); |
| 3670 | } |
| 3671 | } |
| 3672 | |
| 3673 | __ bind(&maybe_in_dictionary); |
| 3674 | // If we are doing negative lookup then probing failure should be |
| 3675 | // treated as a lookup success. For positive lookup probing failure |
| 3676 | // should be treated as lookup failure. |
| 3677 | if (mode() == POSITIVE_LOOKUP) { |
| 3678 | __ mov(result(), Immediate(0)); |
| 3679 | __ Drop(1); |
| 3680 | __ ret(2 * kPointerSize); |
| 3681 | } |
| 3682 | |
| 3683 | __ bind(&in_dictionary); |
| 3684 | __ mov(result(), Immediate(1)); |
| 3685 | __ Drop(1); |
| 3686 | __ ret(2 * kPointerSize); |
| 3687 | |
| 3688 | __ bind(¬_in_dictionary); |
| 3689 | __ mov(result(), Immediate(0)); |
| 3690 | __ Drop(1); |
| 3691 | __ ret(2 * kPointerSize); |
| 3692 | } |
| 3693 | |
| 3694 | |
| 3695 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime( |
| 3696 | Isolate* isolate) { |
| 3697 | StoreBufferOverflowStub stub(isolate, kDontSaveFPRegs); |
| 3698 | stub.GetCode(); |
| 3699 | StoreBufferOverflowStub stub2(isolate, kSaveFPRegs); |
| 3700 | stub2.GetCode(); |
| 3701 | } |
| 3702 | |
| 3703 | |
| 3704 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 3705 | // the value has just been written into the object, now this stub makes sure |
| 3706 | // we keep the GC informed. The word in the object where the value has been |
| 3707 | // written is in the address register. |
| 3708 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 3709 | Label skip_to_incremental_noncompacting; |
| 3710 | Label skip_to_incremental_compacting; |
| 3711 | |
| 3712 | // The first two instructions are generated with labels so as to get the |
| 3713 | // offset fixed up correctly by the bind(Label*) call. We patch it back and |
| 3714 | // forth between a compare instructions (a nop in this position) and the |
| 3715 | // real branch when we start and stop incremental heap marking. |
| 3716 | __ jmp(&skip_to_incremental_noncompacting, Label::kNear); |
| 3717 | __ jmp(&skip_to_incremental_compacting, Label::kFar); |
| 3718 | |
| 3719 | if (remembered_set_action() == EMIT_REMEMBERED_SET) { |
| 3720 | __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(), |
| 3721 | MacroAssembler::kReturnAtEnd); |
| 3722 | } else { |
| 3723 | __ ret(0); |
| 3724 | } |
| 3725 | |
| 3726 | __ bind(&skip_to_incremental_noncompacting); |
| 3727 | GenerateIncremental(masm, INCREMENTAL); |
| 3728 | |
| 3729 | __ bind(&skip_to_incremental_compacting); |
| 3730 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 3731 | |
| 3732 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 3733 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 3734 | masm->set_byte_at(0, kTwoByteNopInstruction); |
| 3735 | masm->set_byte_at(2, kFiveByteNopInstruction); |
| 3736 | } |
| 3737 | |
| 3738 | |
| 3739 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 3740 | regs_.Save(masm); |
| 3741 | |
| 3742 | if (remembered_set_action() == EMIT_REMEMBERED_SET) { |
| 3743 | Label dont_need_remembered_set; |
| 3744 | |
| 3745 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 3746 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 3747 | regs_.scratch0(), |
| 3748 | &dont_need_remembered_set); |
| 3749 | |
| 3750 | __ CheckPageFlag(regs_.object(), |
| 3751 | regs_.scratch0(), |
| 3752 | 1 << MemoryChunk::SCAN_ON_SCAVENGE, |
| 3753 | not_zero, |
| 3754 | &dont_need_remembered_set); |
| 3755 | |
| 3756 | // First notify the incremental marker if necessary, then update the |
| 3757 | // remembered set. |
| 3758 | CheckNeedsToInformIncrementalMarker( |
| 3759 | masm, |
| 3760 | kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, |
| 3761 | mode); |
| 3762 | InformIncrementalMarker(masm); |
| 3763 | regs_.Restore(masm); |
| 3764 | __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(), |
| 3765 | MacroAssembler::kReturnAtEnd); |
| 3766 | |
| 3767 | __ bind(&dont_need_remembered_set); |
| 3768 | } |
| 3769 | |
| 3770 | CheckNeedsToInformIncrementalMarker( |
| 3771 | masm, |
| 3772 | kReturnOnNoNeedToInformIncrementalMarker, |
| 3773 | mode); |
| 3774 | InformIncrementalMarker(masm); |
| 3775 | regs_.Restore(masm); |
| 3776 | __ ret(0); |
| 3777 | } |
| 3778 | |
| 3779 | |
| 3780 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) { |
| 3781 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode()); |
| 3782 | int argument_count = 3; |
| 3783 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 3784 | __ mov(Operand(esp, 0 * kPointerSize), regs_.object()); |
| 3785 | __ mov(Operand(esp, 1 * kPointerSize), regs_.address()); // Slot. |
| 3786 | __ mov(Operand(esp, 2 * kPointerSize), |
| 3787 | Immediate(ExternalReference::isolate_address(isolate()))); |
| 3788 | |
| 3789 | AllowExternalCallThatCantCauseGC scope(masm); |
| 3790 | __ CallCFunction( |
| 3791 | ExternalReference::incremental_marking_record_write_function(isolate()), |
| 3792 | argument_count); |
| 3793 | |
| 3794 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode()); |
| 3795 | } |
| 3796 | |
| 3797 | |
| 3798 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 3799 | MacroAssembler* masm, |
| 3800 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 3801 | Mode mode) { |
| 3802 | Label object_is_black, need_incremental, need_incremental_pop_object; |
| 3803 | |
| 3804 | __ mov(regs_.scratch0(), Immediate(~Page::kPageAlignmentMask)); |
| 3805 | __ and_(regs_.scratch0(), regs_.object()); |
| 3806 | __ mov(regs_.scratch1(), |
| 3807 | Operand(regs_.scratch0(), |
| 3808 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 3809 | __ sub(regs_.scratch1(), Immediate(1)); |
| 3810 | __ mov(Operand(regs_.scratch0(), |
| 3811 | MemoryChunk::kWriteBarrierCounterOffset), |
| 3812 | regs_.scratch1()); |
| 3813 | __ j(negative, &need_incremental); |
| 3814 | |
| 3815 | // Let's look at the color of the object: If it is not black we don't have |
| 3816 | // to inform the incremental marker. |
| 3817 | __ JumpIfBlack(regs_.object(), |
| 3818 | regs_.scratch0(), |
| 3819 | regs_.scratch1(), |
| 3820 | &object_is_black, |
| 3821 | Label::kNear); |
| 3822 | |
| 3823 | regs_.Restore(masm); |
| 3824 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 3825 | __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(), |
| 3826 | MacroAssembler::kReturnAtEnd); |
| 3827 | } else { |
| 3828 | __ ret(0); |
| 3829 | } |
| 3830 | |
| 3831 | __ bind(&object_is_black); |
| 3832 | |
| 3833 | // Get the value from the slot. |
| 3834 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 3835 | |
| 3836 | if (mode == INCREMENTAL_COMPACTION) { |
| 3837 | Label ensure_not_white; |
| 3838 | |
| 3839 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 3840 | regs_.scratch1(), // Scratch. |
| 3841 | MemoryChunk::kEvacuationCandidateMask, |
| 3842 | zero, |
| 3843 | &ensure_not_white, |
| 3844 | Label::kNear); |
| 3845 | |
| 3846 | __ CheckPageFlag(regs_.object(), |
| 3847 | regs_.scratch1(), // Scratch. |
| 3848 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 3849 | not_zero, |
| 3850 | &ensure_not_white, |
| 3851 | Label::kNear); |
| 3852 | |
| 3853 | __ jmp(&need_incremental); |
| 3854 | |
| 3855 | __ bind(&ensure_not_white); |
| 3856 | } |
| 3857 | |
| 3858 | // We need an extra register for this, so we push the object register |
| 3859 | // temporarily. |
| 3860 | __ push(regs_.object()); |
| 3861 | __ EnsureNotWhite(regs_.scratch0(), // The value. |
| 3862 | regs_.scratch1(), // Scratch. |
| 3863 | regs_.object(), // Scratch. |
| 3864 | &need_incremental_pop_object, |
| 3865 | Label::kNear); |
| 3866 | __ pop(regs_.object()); |
| 3867 | |
| 3868 | regs_.Restore(masm); |
| 3869 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 3870 | __ RememberedSetHelper(object(), address(), value(), save_fp_regs_mode(), |
| 3871 | MacroAssembler::kReturnAtEnd); |
| 3872 | } else { |
| 3873 | __ ret(0); |
| 3874 | } |
| 3875 | |
| 3876 | __ bind(&need_incremental_pop_object); |
| 3877 | __ pop(regs_.object()); |
| 3878 | |
| 3879 | __ bind(&need_incremental); |
| 3880 | |
| 3881 | // Fall through when we need to inform the incremental marker. |
| 3882 | } |
| 3883 | |
| 3884 | |
| 3885 | void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { |
| 3886 | // ----------- S t a t e ------------- |
| 3887 | // -- eax : element value to store |
| 3888 | // -- ecx : element index as smi |
| 3889 | // -- esp[0] : return address |
| 3890 | // -- esp[4] : array literal index in function |
| 3891 | // -- esp[8] : array literal |
| 3892 | // clobbers ebx, edx, edi |
| 3893 | // ----------------------------------- |
| 3894 | |
| 3895 | Label element_done; |
| 3896 | Label double_elements; |
| 3897 | Label smi_element; |
| 3898 | Label slow_elements; |
| 3899 | Label slow_elements_from_double; |
| 3900 | Label fast_elements; |
| 3901 | |
| 3902 | // Get array literal index, array literal and its map. |
| 3903 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 3904 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 3905 | __ mov(edi, FieldOperand(ebx, JSObject::kMapOffset)); |
| 3906 | |
| 3907 | __ CheckFastElements(edi, &double_elements); |
| 3908 | |
| 3909 | // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements |
| 3910 | __ JumpIfSmi(eax, &smi_element); |
| 3911 | __ CheckFastSmiElements(edi, &fast_elements, Label::kNear); |
| 3912 | |
| 3913 | // Store into the array literal requires a elements transition. Call into |
| 3914 | // the runtime. |
| 3915 | |
| 3916 | __ bind(&slow_elements); |
| 3917 | __ pop(edi); // Pop return address and remember to put back later for tail |
| 3918 | // call. |
| 3919 | __ push(ebx); |
| 3920 | __ push(ecx); |
| 3921 | __ push(eax); |
| 3922 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 3923 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 3924 | __ push(edx); |
| 3925 | __ push(edi); // Return return address so that tail call returns to right |
| 3926 | // place. |
| 3927 | __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1); |
| 3928 | |
| 3929 | __ bind(&slow_elements_from_double); |
| 3930 | __ pop(edx); |
| 3931 | __ jmp(&slow_elements); |
| 3932 | |
| 3933 | // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object. |
| 3934 | __ bind(&fast_elements); |
| 3935 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 3936 | __ lea(ecx, FieldOperand(ebx, ecx, times_half_pointer_size, |
| 3937 | FixedArrayBase::kHeaderSize)); |
| 3938 | __ mov(Operand(ecx, 0), eax); |
| 3939 | // Update the write barrier for the array store. |
| 3940 | __ RecordWrite(ebx, ecx, eax, kDontSaveFPRegs, EMIT_REMEMBERED_SET, |
| 3941 | OMIT_SMI_CHECK); |
| 3942 | __ ret(0); |
| 3943 | |
| 3944 | // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS, |
| 3945 | // and value is Smi. |
| 3946 | __ bind(&smi_element); |
| 3947 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 3948 | __ mov(FieldOperand(ebx, ecx, times_half_pointer_size, |
| 3949 | FixedArrayBase::kHeaderSize), eax); |
| 3950 | __ ret(0); |
| 3951 | |
| 3952 | // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS. |
| 3953 | __ bind(&double_elements); |
| 3954 | |
| 3955 | __ push(edx); |
| 3956 | __ mov(edx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 3957 | __ StoreNumberToDoubleElements(eax, |
| 3958 | edx, |
| 3959 | ecx, |
| 3960 | edi, |
| 3961 | &slow_elements_from_double, |
| 3962 | false); |
| 3963 | __ pop(edx); |
| 3964 | __ ret(0); |
| 3965 | } |
| 3966 | |
| 3967 | |
| 3968 | void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { |
| 3969 | CEntryStub ces(isolate(), 1, kSaveFPRegs); |
| 3970 | __ call(ces.GetCode(), RelocInfo::CODE_TARGET); |
| 3971 | int parameter_count_offset = |
| 3972 | StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset; |
| 3973 | __ mov(ebx, MemOperand(ebp, parameter_count_offset)); |
| 3974 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
| 3975 | __ pop(ecx); |
| 3976 | int additional_offset = |
| 3977 | function_mode() == JS_FUNCTION_STUB_MODE ? kPointerSize : 0; |
| 3978 | __ lea(esp, MemOperand(esp, ebx, times_pointer_size, additional_offset)); |
| 3979 | __ jmp(ecx); // Return to IC Miss stub, continuation still on stack. |
| 3980 | } |
| 3981 | |
| 3982 | |
| 3983 | void LoadICTrampolineStub::Generate(MacroAssembler* masm) { |
| 3984 | EmitLoadTypeFeedbackVector(masm, VectorLoadICDescriptor::VectorRegister()); |
| 3985 | VectorLoadStub stub(isolate(), state()); |
| 3986 | __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 3987 | } |
| 3988 | |
| 3989 | |
| 3990 | void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) { |
| 3991 | EmitLoadTypeFeedbackVector(masm, VectorLoadICDescriptor::VectorRegister()); |
| 3992 | VectorKeyedLoadStub stub(isolate()); |
| 3993 | __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 3994 | } |
| 3995 | |
| 3996 | |
| 3997 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
| 3998 | if (masm->isolate()->function_entry_hook() != NULL) { |
| 3999 | ProfileEntryHookStub stub(masm->isolate()); |
| 4000 | masm->CallStub(&stub); |
| 4001 | } |
| 4002 | } |
| 4003 | |
| 4004 | |
| 4005 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
| 4006 | // Save volatile registers. |
| 4007 | const int kNumSavedRegisters = 3; |
| 4008 | __ push(eax); |
| 4009 | __ push(ecx); |
| 4010 | __ push(edx); |
| 4011 | |
| 4012 | // Calculate and push the original stack pointer. |
| 4013 | __ lea(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize)); |
| 4014 | __ push(eax); |
| 4015 | |
| 4016 | // Retrieve our return address and use it to calculate the calling |
| 4017 | // function's address. |
| 4018 | __ mov(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize)); |
| 4019 | __ sub(eax, Immediate(Assembler::kCallInstructionLength)); |
| 4020 | __ push(eax); |
| 4021 | |
| 4022 | // Call the entry hook. |
| 4023 | DCHECK(isolate()->function_entry_hook() != NULL); |
| 4024 | __ call(FUNCTION_ADDR(isolate()->function_entry_hook()), |
| 4025 | RelocInfo::RUNTIME_ENTRY); |
| 4026 | __ add(esp, Immediate(2 * kPointerSize)); |
| 4027 | |
| 4028 | // Restore ecx. |
| 4029 | __ pop(edx); |
| 4030 | __ pop(ecx); |
| 4031 | __ pop(eax); |
| 4032 | |
| 4033 | __ ret(0); |
| 4034 | } |
| 4035 | |
| 4036 | |
| 4037 | template<class T> |
| 4038 | static void CreateArrayDispatch(MacroAssembler* masm, |
| 4039 | AllocationSiteOverrideMode mode) { |
| 4040 | if (mode == DISABLE_ALLOCATION_SITES) { |
| 4041 | T stub(masm->isolate(), |
| 4042 | GetInitialFastElementsKind(), |
| 4043 | mode); |
| 4044 | __ TailCallStub(&stub); |
| 4045 | } else if (mode == DONT_OVERRIDE) { |
| 4046 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 4047 | TERMINAL_FAST_ELEMENTS_KIND); |
| 4048 | for (int i = 0; i <= last_index; ++i) { |
| 4049 | Label next; |
| 4050 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 4051 | __ cmp(edx, kind); |
| 4052 | __ j(not_equal, &next); |
| 4053 | T stub(masm->isolate(), kind); |
| 4054 | __ TailCallStub(&stub); |
| 4055 | __ bind(&next); |
| 4056 | } |
| 4057 | |
| 4058 | // If we reached this point there is a problem. |
| 4059 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
| 4060 | } else { |
| 4061 | UNREACHABLE(); |
| 4062 | } |
| 4063 | } |
| 4064 | |
| 4065 | |
| 4066 | static void CreateArrayDispatchOneArgument(MacroAssembler* masm, |
| 4067 | AllocationSiteOverrideMode mode) { |
| 4068 | // ebx - allocation site (if mode != DISABLE_ALLOCATION_SITES) |
| 4069 | // edx - kind (if mode != DISABLE_ALLOCATION_SITES) |
| 4070 | // eax - number of arguments |
| 4071 | // edi - constructor? |
| 4072 | // esp[0] - return address |
| 4073 | // esp[4] - last argument |
| 4074 | Label normal_sequence; |
| 4075 | if (mode == DONT_OVERRIDE) { |
| 4076 | DCHECK(FAST_SMI_ELEMENTS == 0); |
| 4077 | DCHECK(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 4078 | DCHECK(FAST_ELEMENTS == 2); |
| 4079 | DCHECK(FAST_HOLEY_ELEMENTS == 3); |
| 4080 | DCHECK(FAST_DOUBLE_ELEMENTS == 4); |
| 4081 | DCHECK(FAST_HOLEY_DOUBLE_ELEMENTS == 5); |
| 4082 | |
| 4083 | // is the low bit set? If so, we are holey and that is good. |
| 4084 | __ test_b(edx, 1); |
| 4085 | __ j(not_zero, &normal_sequence); |
| 4086 | } |
| 4087 | |
| 4088 | // look at the first argument |
| 4089 | __ mov(ecx, Operand(esp, kPointerSize)); |
| 4090 | __ test(ecx, ecx); |
| 4091 | __ j(zero, &normal_sequence); |
| 4092 | |
| 4093 | if (mode == DISABLE_ALLOCATION_SITES) { |
| 4094 | ElementsKind initial = GetInitialFastElementsKind(); |
| 4095 | ElementsKind holey_initial = GetHoleyElementsKind(initial); |
| 4096 | |
| 4097 | ArraySingleArgumentConstructorStub stub_holey(masm->isolate(), |
| 4098 | holey_initial, |
| 4099 | DISABLE_ALLOCATION_SITES); |
| 4100 | __ TailCallStub(&stub_holey); |
| 4101 | |
| 4102 | __ bind(&normal_sequence); |
| 4103 | ArraySingleArgumentConstructorStub stub(masm->isolate(), |
| 4104 | initial, |
| 4105 | DISABLE_ALLOCATION_SITES); |
| 4106 | __ TailCallStub(&stub); |
| 4107 | } else if (mode == DONT_OVERRIDE) { |
| 4108 | // We are going to create a holey array, but our kind is non-holey. |
| 4109 | // Fix kind and retry. |
| 4110 | __ inc(edx); |
| 4111 | |
| 4112 | if (FLAG_debug_code) { |
| 4113 | Handle<Map> allocation_site_map = |
| 4114 | masm->isolate()->factory()->allocation_site_map(); |
| 4115 | __ cmp(FieldOperand(ebx, 0), Immediate(allocation_site_map)); |
| 4116 | __ Assert(equal, kExpectedAllocationSite); |
| 4117 | } |
| 4118 | |
| 4119 | // Save the resulting elements kind in type info. We can't just store r3 |
| 4120 | // in the AllocationSite::transition_info field because elements kind is |
| 4121 | // restricted to a portion of the field...upper bits need to be left alone. |
| 4122 | STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0); |
| 4123 | __ add(FieldOperand(ebx, AllocationSite::kTransitionInfoOffset), |
| 4124 | Immediate(Smi::FromInt(kFastElementsKindPackedToHoley))); |
| 4125 | |
| 4126 | __ bind(&normal_sequence); |
| 4127 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 4128 | TERMINAL_FAST_ELEMENTS_KIND); |
| 4129 | for (int i = 0; i <= last_index; ++i) { |
| 4130 | Label next; |
| 4131 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 4132 | __ cmp(edx, kind); |
| 4133 | __ j(not_equal, &next); |
| 4134 | ArraySingleArgumentConstructorStub stub(masm->isolate(), kind); |
| 4135 | __ TailCallStub(&stub); |
| 4136 | __ bind(&next); |
| 4137 | } |
| 4138 | |
| 4139 | // If we reached this point there is a problem. |
| 4140 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
| 4141 | } else { |
| 4142 | UNREACHABLE(); |
| 4143 | } |
| 4144 | } |
| 4145 | |
| 4146 | |
| 4147 | template<class T> |
| 4148 | static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) { |
| 4149 | int to_index = GetSequenceIndexFromFastElementsKind( |
| 4150 | TERMINAL_FAST_ELEMENTS_KIND); |
| 4151 | for (int i = 0; i <= to_index; ++i) { |
| 4152 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 4153 | T stub(isolate, kind); |
| 4154 | stub.GetCode(); |
| 4155 | if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) { |
| 4156 | T stub1(isolate, kind, DISABLE_ALLOCATION_SITES); |
| 4157 | stub1.GetCode(); |
| 4158 | } |
| 4159 | } |
| 4160 | } |
| 4161 | |
| 4162 | |
| 4163 | void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 4164 | ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>( |
| 4165 | isolate); |
| 4166 | ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>( |
| 4167 | isolate); |
| 4168 | ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>( |
| 4169 | isolate); |
| 4170 | } |
| 4171 | |
| 4172 | |
| 4173 | void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime( |
| 4174 | Isolate* isolate) { |
| 4175 | ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS }; |
| 4176 | for (int i = 0; i < 2; i++) { |
| 4177 | // For internal arrays we only need a few things |
| 4178 | InternalArrayNoArgumentConstructorStub stubh1(isolate, kinds[i]); |
| 4179 | stubh1.GetCode(); |
| 4180 | InternalArraySingleArgumentConstructorStub stubh2(isolate, kinds[i]); |
| 4181 | stubh2.GetCode(); |
| 4182 | InternalArrayNArgumentsConstructorStub stubh3(isolate, kinds[i]); |
| 4183 | stubh3.GetCode(); |
| 4184 | } |
| 4185 | } |
| 4186 | |
| 4187 | |
| 4188 | void ArrayConstructorStub::GenerateDispatchToArrayStub( |
| 4189 | MacroAssembler* masm, |
| 4190 | AllocationSiteOverrideMode mode) { |
| 4191 | if (argument_count() == ANY) { |
| 4192 | Label not_zero_case, not_one_case; |
| 4193 | __ test(eax, eax); |
| 4194 | __ j(not_zero, ¬_zero_case); |
| 4195 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode); |
| 4196 | |
| 4197 | __ bind(¬_zero_case); |
| 4198 | __ cmp(eax, 1); |
| 4199 | __ j(greater, ¬_one_case); |
| 4200 | CreateArrayDispatchOneArgument(masm, mode); |
| 4201 | |
| 4202 | __ bind(¬_one_case); |
| 4203 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode); |
| 4204 | } else if (argument_count() == NONE) { |
| 4205 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode); |
| 4206 | } else if (argument_count() == ONE) { |
| 4207 | CreateArrayDispatchOneArgument(masm, mode); |
| 4208 | } else if (argument_count() == MORE_THAN_ONE) { |
| 4209 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode); |
| 4210 | } else { |
| 4211 | UNREACHABLE(); |
| 4212 | } |
| 4213 | } |
| 4214 | |
| 4215 | |
| 4216 | void ArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 4217 | // ----------- S t a t e ------------- |
| 4218 | // -- eax : argc (only if argument_count() == ANY) |
| 4219 | // -- ebx : AllocationSite or undefined |
| 4220 | // -- edi : constructor |
| 4221 | // -- esp[0] : return address |
| 4222 | // -- esp[4] : last argument |
| 4223 | // ----------------------------------- |
| 4224 | if (FLAG_debug_code) { |
| 4225 | // The array construct code is only set for the global and natives |
| 4226 | // builtin Array functions which always have maps. |
| 4227 | |
| 4228 | // Initial map for the builtin Array function should be a map. |
| 4229 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 4230 | // Will both indicate a NULL and a Smi. |
| 4231 | __ test(ecx, Immediate(kSmiTagMask)); |
| 4232 | __ Assert(not_zero, kUnexpectedInitialMapForArrayFunction); |
| 4233 | __ CmpObjectType(ecx, MAP_TYPE, ecx); |
| 4234 | __ Assert(equal, kUnexpectedInitialMapForArrayFunction); |
| 4235 | |
| 4236 | // We should either have undefined in ebx or a valid AllocationSite |
| 4237 | __ AssertUndefinedOrAllocationSite(ebx); |
| 4238 | } |
| 4239 | |
| 4240 | Label no_info; |
| 4241 | // If the feedback vector is the undefined value call an array constructor |
| 4242 | // that doesn't use AllocationSites. |
| 4243 | __ cmp(ebx, isolate()->factory()->undefined_value()); |
| 4244 | __ j(equal, &no_info); |
| 4245 | |
| 4246 | // Only look at the lower 16 bits of the transition info. |
| 4247 | __ mov(edx, FieldOperand(ebx, AllocationSite::kTransitionInfoOffset)); |
| 4248 | __ SmiUntag(edx); |
| 4249 | STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0); |
| 4250 | __ and_(edx, Immediate(AllocationSite::ElementsKindBits::kMask)); |
| 4251 | GenerateDispatchToArrayStub(masm, DONT_OVERRIDE); |
| 4252 | |
| 4253 | __ bind(&no_info); |
| 4254 | GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES); |
| 4255 | } |
| 4256 | |
| 4257 | |
| 4258 | void InternalArrayConstructorStub::GenerateCase( |
| 4259 | MacroAssembler* masm, ElementsKind kind) { |
| 4260 | Label not_zero_case, not_one_case; |
| 4261 | Label normal_sequence; |
| 4262 | |
| 4263 | __ test(eax, eax); |
| 4264 | __ j(not_zero, ¬_zero_case); |
| 4265 | InternalArrayNoArgumentConstructorStub stub0(isolate(), kind); |
| 4266 | __ TailCallStub(&stub0); |
| 4267 | |
| 4268 | __ bind(¬_zero_case); |
| 4269 | __ cmp(eax, 1); |
| 4270 | __ j(greater, ¬_one_case); |
| 4271 | |
| 4272 | if (IsFastPackedElementsKind(kind)) { |
| 4273 | // We might need to create a holey array |
| 4274 | // look at the first argument |
| 4275 | __ mov(ecx, Operand(esp, kPointerSize)); |
| 4276 | __ test(ecx, ecx); |
| 4277 | __ j(zero, &normal_sequence); |
| 4278 | |
| 4279 | InternalArraySingleArgumentConstructorStub |
| 4280 | stub1_holey(isolate(), GetHoleyElementsKind(kind)); |
| 4281 | __ TailCallStub(&stub1_holey); |
| 4282 | } |
| 4283 | |
| 4284 | __ bind(&normal_sequence); |
| 4285 | InternalArraySingleArgumentConstructorStub stub1(isolate(), kind); |
| 4286 | __ TailCallStub(&stub1); |
| 4287 | |
| 4288 | __ bind(¬_one_case); |
| 4289 | InternalArrayNArgumentsConstructorStub stubN(isolate(), kind); |
| 4290 | __ TailCallStub(&stubN); |
| 4291 | } |
| 4292 | |
| 4293 | |
| 4294 | void InternalArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 4295 | // ----------- S t a t e ------------- |
| 4296 | // -- eax : argc |
| 4297 | // -- edi : constructor |
| 4298 | // -- esp[0] : return address |
| 4299 | // -- esp[4] : last argument |
| 4300 | // ----------------------------------- |
| 4301 | |
| 4302 | if (FLAG_debug_code) { |
| 4303 | // The array construct code is only set for the global and natives |
| 4304 | // builtin Array functions which always have maps. |
| 4305 | |
| 4306 | // Initial map for the builtin Array function should be a map. |
| 4307 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 4308 | // Will both indicate a NULL and a Smi. |
| 4309 | __ test(ecx, Immediate(kSmiTagMask)); |
| 4310 | __ Assert(not_zero, kUnexpectedInitialMapForArrayFunction); |
| 4311 | __ CmpObjectType(ecx, MAP_TYPE, ecx); |
| 4312 | __ Assert(equal, kUnexpectedInitialMapForArrayFunction); |
| 4313 | } |
| 4314 | |
| 4315 | // Figure out the right elements kind |
| 4316 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 4317 | |
| 4318 | // Load the map's "bit field 2" into |result|. We only need the first byte, |
| 4319 | // but the following masking takes care of that anyway. |
| 4320 | __ mov(ecx, FieldOperand(ecx, Map::kBitField2Offset)); |
| 4321 | // Retrieve elements_kind from bit field 2. |
| 4322 | __ DecodeField<Map::ElementsKindBits>(ecx); |
| 4323 | |
| 4324 | if (FLAG_debug_code) { |
| 4325 | Label done; |
| 4326 | __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
| 4327 | __ j(equal, &done); |
| 4328 | __ cmp(ecx, Immediate(FAST_HOLEY_ELEMENTS)); |
| 4329 | __ Assert(equal, |
| 4330 | kInvalidElementsKindForInternalArrayOrInternalPackedArray); |
| 4331 | __ bind(&done); |
| 4332 | } |
| 4333 | |
| 4334 | Label fast_elements_case; |
| 4335 | __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
| 4336 | __ j(equal, &fast_elements_case); |
| 4337 | GenerateCase(masm, FAST_HOLEY_ELEMENTS); |
| 4338 | |
| 4339 | __ bind(&fast_elements_case); |
| 4340 | GenerateCase(masm, FAST_ELEMENTS); |
| 4341 | } |
| 4342 | |
| 4343 | |
| 4344 | void CallApiFunctionStub::Generate(MacroAssembler* masm) { |
| 4345 | // ----------- S t a t e ------------- |
| 4346 | // -- eax : callee |
| 4347 | // -- ebx : call_data |
| 4348 | // -- ecx : holder |
| 4349 | // -- edx : api_function_address |
| 4350 | // -- esi : context |
| 4351 | // -- |
| 4352 | // -- esp[0] : return address |
| 4353 | // -- esp[4] : last argument |
| 4354 | // -- ... |
| 4355 | // -- esp[argc * 4] : first argument |
| 4356 | // -- esp[(argc + 1) * 4] : receiver |
| 4357 | // ----------------------------------- |
| 4358 | |
| 4359 | Register callee = eax; |
| 4360 | Register call_data = ebx; |
| 4361 | Register holder = ecx; |
| 4362 | Register api_function_address = edx; |
| 4363 | Register return_address = edi; |
| 4364 | Register context = esi; |
| 4365 | |
| 4366 | int argc = this->argc(); |
| 4367 | bool is_store = this->is_store(); |
| 4368 | bool call_data_undefined = this->call_data_undefined(); |
| 4369 | |
| 4370 | typedef FunctionCallbackArguments FCA; |
| 4371 | |
| 4372 | STATIC_ASSERT(FCA::kContextSaveIndex == 6); |
| 4373 | STATIC_ASSERT(FCA::kCalleeIndex == 5); |
| 4374 | STATIC_ASSERT(FCA::kDataIndex == 4); |
| 4375 | STATIC_ASSERT(FCA::kReturnValueOffset == 3); |
| 4376 | STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2); |
| 4377 | STATIC_ASSERT(FCA::kIsolateIndex == 1); |
| 4378 | STATIC_ASSERT(FCA::kHolderIndex == 0); |
| 4379 | STATIC_ASSERT(FCA::kArgsLength == 7); |
| 4380 | |
| 4381 | __ pop(return_address); |
| 4382 | |
| 4383 | // context save |
| 4384 | __ push(context); |
| 4385 | // load context from callee |
| 4386 | __ mov(context, FieldOperand(callee, JSFunction::kContextOffset)); |
| 4387 | |
| 4388 | // callee |
| 4389 | __ push(callee); |
| 4390 | |
| 4391 | // call data |
| 4392 | __ push(call_data); |
| 4393 | |
| 4394 | Register scratch = call_data; |
| 4395 | if (!call_data_undefined) { |
| 4396 | // return value |
| 4397 | __ push(Immediate(isolate()->factory()->undefined_value())); |
| 4398 | // return value default |
| 4399 | __ push(Immediate(isolate()->factory()->undefined_value())); |
| 4400 | } else { |
| 4401 | // return value |
| 4402 | __ push(scratch); |
| 4403 | // return value default |
| 4404 | __ push(scratch); |
| 4405 | } |
| 4406 | // isolate |
| 4407 | __ push(Immediate(reinterpret_cast<int>(isolate()))); |
| 4408 | // holder |
| 4409 | __ push(holder); |
| 4410 | |
| 4411 | __ mov(scratch, esp); |
| 4412 | |
| 4413 | // return address |
| 4414 | __ push(return_address); |
| 4415 | |
| 4416 | // API function gets reference to the v8::Arguments. If CPU profiler |
| 4417 | // is enabled wrapper function will be called and we need to pass |
| 4418 | // address of the callback as additional parameter, always allocate |
| 4419 | // space for it. |
| 4420 | const int kApiArgc = 1 + 1; |
| 4421 | |
| 4422 | // Allocate the v8::Arguments structure in the arguments' space since |
| 4423 | // it's not controlled by GC. |
| 4424 | const int kApiStackSpace = 4; |
| 4425 | |
| 4426 | __ PrepareCallApiFunction(kApiArgc + kApiStackSpace); |
| 4427 | |
| 4428 | // FunctionCallbackInfo::implicit_args_. |
| 4429 | __ mov(ApiParameterOperand(2), scratch); |
| 4430 | __ add(scratch, Immediate((argc + FCA::kArgsLength - 1) * kPointerSize)); |
| 4431 | // FunctionCallbackInfo::values_. |
| 4432 | __ mov(ApiParameterOperand(3), scratch); |
| 4433 | // FunctionCallbackInfo::length_. |
| 4434 | __ Move(ApiParameterOperand(4), Immediate(argc)); |
| 4435 | // FunctionCallbackInfo::is_construct_call_. |
| 4436 | __ Move(ApiParameterOperand(5), Immediate(0)); |
| 4437 | |
| 4438 | // v8::InvocationCallback's argument. |
| 4439 | __ lea(scratch, ApiParameterOperand(2)); |
| 4440 | __ mov(ApiParameterOperand(0), scratch); |
| 4441 | |
| 4442 | ExternalReference thunk_ref = |
| 4443 | ExternalReference::invoke_function_callback(isolate()); |
| 4444 | |
| 4445 | Operand context_restore_operand(ebp, |
| 4446 | (2 + FCA::kContextSaveIndex) * kPointerSize); |
| 4447 | // Stores return the first js argument |
| 4448 | int return_value_offset = 0; |
| 4449 | if (is_store) { |
| 4450 | return_value_offset = 2 + FCA::kArgsLength; |
| 4451 | } else { |
| 4452 | return_value_offset = 2 + FCA::kReturnValueOffset; |
| 4453 | } |
| 4454 | Operand return_value_operand(ebp, return_value_offset * kPointerSize); |
| 4455 | __ CallApiFunctionAndReturn(api_function_address, |
| 4456 | thunk_ref, |
| 4457 | ApiParameterOperand(1), |
| 4458 | argc + FCA::kArgsLength + 1, |
| 4459 | return_value_operand, |
| 4460 | &context_restore_operand); |
| 4461 | } |
| 4462 | |
| 4463 | |
| 4464 | void CallApiGetterStub::Generate(MacroAssembler* masm) { |
| 4465 | // ----------- S t a t e ------------- |
| 4466 | // -- esp[0] : return address |
| 4467 | // -- esp[4] : name |
| 4468 | // -- esp[8 - kArgsLength*4] : PropertyCallbackArguments object |
| 4469 | // -- ... |
| 4470 | // -- edx : api_function_address |
| 4471 | // ----------------------------------- |
| 4472 | DCHECK(edx.is(ApiGetterDescriptor::function_address())); |
| 4473 | |
| 4474 | // array for v8::Arguments::values_, handler for name and pointer |
| 4475 | // to the values (it considered as smi in GC). |
| 4476 | const int kStackSpace = PropertyCallbackArguments::kArgsLength + 2; |
| 4477 | // Allocate space for opional callback address parameter in case |
| 4478 | // CPU profiler is active. |
| 4479 | const int kApiArgc = 2 + 1; |
| 4480 | |
| 4481 | Register api_function_address = edx; |
| 4482 | Register scratch = ebx; |
| 4483 | |
| 4484 | // load address of name |
| 4485 | __ lea(scratch, Operand(esp, 1 * kPointerSize)); |
| 4486 | |
| 4487 | __ PrepareCallApiFunction(kApiArgc); |
| 4488 | __ mov(ApiParameterOperand(0), scratch); // name. |
| 4489 | __ add(scratch, Immediate(kPointerSize)); |
| 4490 | __ mov(ApiParameterOperand(1), scratch); // arguments pointer. |
| 4491 | |
| 4492 | ExternalReference thunk_ref = |
| 4493 | ExternalReference::invoke_accessor_getter_callback(isolate()); |
| 4494 | |
| 4495 | __ CallApiFunctionAndReturn(api_function_address, |
| 4496 | thunk_ref, |
| 4497 | ApiParameterOperand(2), |
| 4498 | kStackSpace, |
| 4499 | Operand(ebp, 7 * kPointerSize), |
| 4500 | NULL); |
| 4501 | } |
| 4502 | |
| 4503 | |
| 4504 | #undef __ |
| 4505 | |
| 4506 | } } // namespace v8::internal |
| 4507 | |
| 4508 | #endif // V8_TARGET_ARCH_X87 |