Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: src/ia32/builtins-ia32.cc

Issue 7084032: Add asserts and state tracking to ensure that we do not call (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/frames.h ('k') | src/ia32/code-stubs-ia32.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 } 107 }
108 108
109 109
110 static void Generate_JSConstructStubHelper(MacroAssembler* masm, 110 static void Generate_JSConstructStubHelper(MacroAssembler* masm,
111 bool is_api_function, 111 bool is_api_function,
112 bool count_constructions) { 112 bool count_constructions) {
113 // Should never count constructions for api objects. 113 // Should never count constructions for api objects.
114 ASSERT(!is_api_function || !count_constructions); 114 ASSERT(!is_api_function || !count_constructions);
115 115
116 // Enter a construct frame. 116 // Enter a construct frame.
117 __ EnterConstructFrame(); 117 {
118 FrameScope scope(masm, StackFrame::CONSTRUCT);
118 119
119 // Store a smi-tagged arguments count on the stack. 120 // Store a smi-tagged arguments count on the stack.
120 __ SmiTag(eax); 121 __ SmiTag(eax);
121 __ push(eax); 122 __ push(eax);
122 123
123 // Push the function to invoke on the stack. 124 // Push the function to invoke on the stack.
124 __ push(edi); 125 __ push(edi);
125 126
126 // Try to allocate the object without transitioning into C code. If any of the 127 // Try to allocate the object without transitioning into C code. If any of
127 // preconditions is not met, the code bails out to the runtime call. 128 // the preconditions is not met, the code bails out to the runtime call.
128 Label rt_call, allocated; 129 Label rt_call, allocated;
129 if (FLAG_inline_new) { 130 if (FLAG_inline_new) {
130 Label undo_allocation; 131 Label undo_allocation;
131 #ifdef ENABLE_DEBUGGER_SUPPORT 132 #ifdef ENABLE_DEBUGGER_SUPPORT
132 ExternalReference debug_step_in_fp = 133 ExternalReference debug_step_in_fp =
133 ExternalReference::debug_step_in_fp_address(masm->isolate()); 134 ExternalReference::debug_step_in_fp_address(masm->isolate());
134 __ cmp(Operand::StaticVariable(debug_step_in_fp), Immediate(0)); 135 __ cmp(Operand::StaticVariable(debug_step_in_fp), Immediate(0));
135 __ j(not_equal, &rt_call); 136 __ j(not_equal, &rt_call);
136 #endif 137 #endif
137 138
138 // Verified that the constructor is a JSFunction. 139 // Verified that the constructor is a JSFunction.
139 // Load the initial map and verify that it is in fact a map. 140 // Load the initial map and verify that it is in fact a map.
140 // edi: constructor 141 // edi: constructor
141 __ mov(eax, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); 142 __ mov(eax, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset));
142 // Will both indicate a NULL and a Smi 143 // Will both indicate a NULL and a Smi
143 __ test(eax, Immediate(kSmiTagMask)); 144 __ test(eax, Immediate(kSmiTagMask));
144 __ j(zero, &rt_call); 145 __ j(zero, &rt_call);
145 // edi: constructor 146 // edi: constructor
146 // eax: initial map (if proven valid below) 147 // eax: initial map (if proven valid below)
147 __ CmpObjectType(eax, MAP_TYPE, ebx); 148 __ CmpObjectType(eax, MAP_TYPE, ebx);
148 __ j(not_equal, &rt_call); 149 __ j(not_equal, &rt_call);
149 150
150 // Check that the constructor is not constructing a JSFunction (see comments 151 // Check that the constructor is not constructing a JSFunction (see
151 // in Runtime_NewObject in runtime.cc). In which case the initial map's 152 // comments in Runtime_NewObject in runtime.cc). In which case the initial
152 // instance type would be JS_FUNCTION_TYPE. 153 // map's instance type would be JS_FUNCTION_TYPE.
153 // edi: constructor 154 // edi: constructor
154 // eax: initial map 155 // eax: initial map
155 __ CmpInstanceType(eax, JS_FUNCTION_TYPE); 156 __ CmpInstanceType(eax, JS_FUNCTION_TYPE);
156 __ j(equal, &rt_call); 157 __ j(equal, &rt_call);
157 158
158 if (count_constructions) { 159 if (count_constructions) {
159 Label allocate; 160 Label allocate;
160 // Decrease generous allocation count. 161 // Decrease generous allocation count.
161 __ mov(ecx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); 162 __ mov(ecx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
162 __ dec_b(FieldOperand(ecx, SharedFunctionInfo::kConstructionCountOffset)); 163 __ dec_b(FieldOperand(ecx,
164 SharedFunctionInfo::kConstructionCountOffset));
163 __ j(not_zero, &allocate); 165 __ j(not_zero, &allocate);
164 166
165 __ push(eax); 167 __ push(eax);
166 __ push(edi); 168 __ push(edi);
167 169
168 __ push(edi); // constructor 170 __ push(edi); // constructor
169 // The call will replace the stub, so the countdown is only done once. 171 // The call will replace the stub, so the countdown is only done once.
170 __ CallRuntime(Runtime::kFinalizeInstanceSize, 1); 172 __ CallRuntime(Runtime::kFinalizeInstanceSize, 1);
171 173
172 __ pop(edi); 174 __ pop(edi);
173 __ pop(eax); 175 __ pop(eax);
174 176
175 __ bind(&allocate); 177 __ bind(&allocate);
176 } 178 }
177 179
178 // Now allocate the JSObject on the heap. 180 // Now allocate the JSObject on the heap.
179 // edi: constructor 181 // edi: constructor
180 // eax: initial map 182 // eax: initial map
181 __ movzx_b(edi, FieldOperand(eax, Map::kInstanceSizeOffset)); 183 __ movzx_b(edi, FieldOperand(eax, Map::kInstanceSizeOffset));
182 __ shl(edi, kPointerSizeLog2); 184 __ shl(edi, kPointerSizeLog2);
183 __ AllocateInNewSpace(edi, ebx, edi, no_reg, &rt_call, NO_ALLOCATION_FLAGS); 185 __ AllocateInNewSpace(edi,
186 ebx,
187 edi,
188 no_reg,
189 &rt_call,
190 NO_ALLOCATION_FLAGS);
184 // Allocated the JSObject, now initialize the fields. 191 // Allocated the JSObject, now initialize the fields.
185 // eax: initial map 192 // eax: initial map
186 // ebx: JSObject 193 // ebx: JSObject
187 // edi: start of next object 194 // edi: start of next object
188 __ mov(Operand(ebx, JSObject::kMapOffset), eax); 195 __ mov(Operand(ebx, JSObject::kMapOffset), eax);
189 Factory* factory = masm->isolate()->factory(); 196 Factory* factory = masm->isolate()->factory();
190 __ mov(ecx, factory->empty_fixed_array()); 197 __ mov(ecx, factory->empty_fixed_array());
191 __ mov(Operand(ebx, JSObject::kPropertiesOffset), ecx); 198 __ mov(Operand(ebx, JSObject::kPropertiesOffset), ecx);
192 __ mov(Operand(ebx, JSObject::kElementsOffset), ecx); 199 __ mov(Operand(ebx, JSObject::kElementsOffset), ecx);
193 // Set extra fields in the newly allocated object. 200 // Set extra fields in the newly allocated object.
(...skipping 10 matching lines...) Expand all
204 __ lea(ecx, Operand(ebx, JSObject::kHeaderSize)); 211 __ lea(ecx, Operand(ebx, JSObject::kHeaderSize));
205 __ jmp(&entry); 212 __ jmp(&entry);
206 __ bind(&loop); 213 __ bind(&loop);
207 __ mov(Operand(ecx, 0), edx); 214 __ mov(Operand(ecx, 0), edx);
208 __ add(Operand(ecx), Immediate(kPointerSize)); 215 __ add(Operand(ecx), Immediate(kPointerSize));
209 __ bind(&entry); 216 __ bind(&entry);
210 __ cmp(ecx, Operand(edi)); 217 __ cmp(ecx, Operand(edi));
211 __ j(less, &loop); 218 __ j(less, &loop);
212 } 219 }
213 220
214 // Add the object tag to make the JSObject real, so that we can continue and 221 // Add the object tag to make the JSObject real, so that we can continue
215 // jump into the continuation code at any time from now on. Any failures 222 // and jump into the continuation code at any time from now on. Any
216 // need to undo the allocation, so that the heap is in a consistent state 223 // failures need to undo the allocation, so that the heap is in a
217 // and verifiable. 224 // consistent state and verifiable.
218 // eax: initial map 225 // eax: initial map
219 // ebx: JSObject 226 // ebx: JSObject
220 // edi: start of next object 227 // edi: start of next object
221 __ or_(Operand(ebx), Immediate(kHeapObjectTag)); 228 __ or_(Operand(ebx), Immediate(kHeapObjectTag));
222 229
223 // Check if a non-empty properties array is needed. 230 // Check if a non-empty properties array is needed.
224 // Allocate and initialize a FixedArray if it is. 231 // Allocate and initialize a FixedArray if it is.
225 // eax: initial map 232 // eax: initial map
226 // ebx: JSObject 233 // ebx: JSObject
227 // edi: start of next object 234 // edi: start of next object
228 // Calculate the total number of properties described by the map. 235 // Calculate the total number of properties described by the map.
229 __ movzx_b(edx, FieldOperand(eax, Map::kUnusedPropertyFieldsOffset)); 236 __ movzx_b(edx, FieldOperand(eax, Map::kUnusedPropertyFieldsOffset));
230 __ movzx_b(ecx, FieldOperand(eax, Map::kPreAllocatedPropertyFieldsOffset)); 237 __ movzx_b(ecx,
238 FieldOperand(eax, Map::kPreAllocatedPropertyFieldsOffset));
231 __ add(edx, Operand(ecx)); 239 __ add(edx, Operand(ecx));
232 // Calculate unused properties past the end of the in-object properties. 240 // Calculate unused properties past the end of the in-object properties.
233 __ movzx_b(ecx, FieldOperand(eax, Map::kInObjectPropertiesOffset)); 241 __ movzx_b(ecx, FieldOperand(eax, Map::kInObjectPropertiesOffset));
234 __ sub(edx, Operand(ecx)); 242 __ sub(edx, Operand(ecx));
235 // Done if no extra properties are to be allocated. 243 // Done if no extra properties are to be allocated.
236 __ j(zero, &allocated); 244 __ j(zero, &allocated);
237 __ Assert(positive, "Property allocation count failed."); 245 __ Assert(positive, "Property allocation count failed.");
238 246
239 // Scale the number of elements by pointer size and add the header for 247 // Scale the number of elements by pointer size and add the header for
240 // FixedArrays to the start of the next object calculation from above. 248 // FixedArrays to the start of the next object calculation from above.
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 __ j(above_equal, &exit); 374 __ j(above_equal, &exit);
367 375
368 // Throw away the result of the constructor invocation and use the 376 // Throw away the result of the constructor invocation and use the
369 // on-stack receiver as the result. 377 // on-stack receiver as the result.
370 __ bind(&use_receiver); 378 __ bind(&use_receiver);
371 __ mov(eax, Operand(esp, 0)); 379 __ mov(eax, Operand(esp, 0));
372 380
373 // Restore the arguments count and leave the construct frame. 381 // Restore the arguments count and leave the construct frame.
374 __ bind(&exit); 382 __ bind(&exit);
375 __ mov(ebx, Operand(esp, kPointerSize)); // get arguments count 383 __ mov(ebx, Operand(esp, kPointerSize)); // get arguments count
376 __ LeaveConstructFrame(); 384
385 // Leave construct frame.
386 }
377 387
378 // Remove caller arguments from the stack and return. 388 // Remove caller arguments from the stack and return.
379 ASSERT(kSmiTagSize == 1 && kSmiTag == 0); 389 ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
380 __ pop(ecx); 390 __ pop(ecx);
381 __ lea(esp, Operand(esp, ebx, times_2, 1 * kPointerSize)); // 1 ~ receiver 391 __ lea(esp, Operand(esp, ebx, times_2, 1 * kPointerSize)); // 1 ~ receiver
382 __ push(ecx); 392 __ push(ecx);
383 __ IncrementCounter(masm->isolate()->counters()->constructed_objects(), 1); 393 __ IncrementCounter(masm->isolate()->counters()->constructed_objects(), 1);
384 __ ret(0); 394 __ ret(0);
385 } 395 }
386 396
387 397
388 void Builtins::Generate_JSConstructStubCountdown(MacroAssembler* masm) { 398 void Builtins::Generate_JSConstructStubCountdown(MacroAssembler* masm) {
389 Generate_JSConstructStubHelper(masm, false, true); 399 Generate_JSConstructStubHelper(masm, false, true);
390 } 400 }
391 401
392 402
393 void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { 403 void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) {
394 Generate_JSConstructStubHelper(masm, false, false); 404 Generate_JSConstructStubHelper(masm, false, false);
395 } 405 }
396 406
397 407
398 void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) { 408 void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) {
399 Generate_JSConstructStubHelper(masm, true, false); 409 Generate_JSConstructStubHelper(masm, true, false);
400 } 410 }
401 411
402 412
403 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm, 413 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm,
404 bool is_construct) { 414 bool is_construct) {
405 // Clear the context before we push it when entering the JS frame. 415 // Clear the context before we push it when entering the internal frame.
406 __ Set(esi, Immediate(0)); 416 __ Set(esi, Immediate(0));
407 417
408 // Enter an internal frame. 418 {
409 __ EnterInternalFrame(); 419 FrameScope scope(masm, StackFrame::INTERNAL);
410 420
411 // Load the previous frame pointer (ebx) to access C arguments 421 // Load the previous frame pointer (ebx) to access C arguments
412 __ mov(ebx, Operand(ebp, 0)); 422 __ mov(ebx, Operand(ebp, 0));
413 423
414 // Get the function from the frame and setup the context. 424 // Get the function from the frame and setup the context.
415 __ mov(ecx, Operand(ebx, EntryFrameConstants::kFunctionArgOffset)); 425 __ mov(ecx, Operand(ebx, EntryFrameConstants::kFunctionArgOffset));
416 __ mov(esi, FieldOperand(ecx, JSFunction::kContextOffset)); 426 __ mov(esi, FieldOperand(ecx, JSFunction::kContextOffset));
417 427
418 // Push the function and the receiver onto the stack. 428 // Push the function and the receiver onto the stack.
419 __ push(ecx); 429 __ push(ecx);
420 __ push(Operand(ebx, EntryFrameConstants::kReceiverArgOffset)); 430 __ push(Operand(ebx, EntryFrameConstants::kReceiverArgOffset));
421 431
422 // Load the number of arguments and setup pointer to the arguments. 432 // Load the number of arguments and setup pointer to the arguments.
423 __ mov(eax, Operand(ebx, EntryFrameConstants::kArgcOffset)); 433 __ mov(eax, Operand(ebx, EntryFrameConstants::kArgcOffset));
424 __ mov(ebx, Operand(ebx, EntryFrameConstants::kArgvOffset)); 434 __ mov(ebx, Operand(ebx, EntryFrameConstants::kArgvOffset));
425 435
426 // Copy arguments to the stack in a loop. 436 // Copy arguments to the stack in a loop.
427 Label loop, entry; 437 Label loop, entry;
428 __ Set(ecx, Immediate(0)); 438 __ Set(ecx, Immediate(0));
429 __ jmp(&entry); 439 __ jmp(&entry);
430 __ bind(&loop); 440 __ bind(&loop);
431 __ mov(edx, Operand(ebx, ecx, times_4, 0)); // push parameter from argv 441 __ mov(edx, Operand(ebx, ecx, times_4, 0)); // push parameter from argv
432 __ push(Operand(edx, 0)); // dereference handle 442 __ push(Operand(edx, 0)); // dereference handle
433 __ inc(Operand(ecx)); 443 __ inc(Operand(ecx));
434 __ bind(&entry); 444 __ bind(&entry);
435 __ cmp(ecx, Operand(eax)); 445 __ cmp(ecx, Operand(eax));
436 __ j(not_equal, &loop); 446 __ j(not_equal, &loop);
437 447
438 // Get the function from the stack and call it. 448 // Get the function from the stack and call it.
439 __ mov(edi, Operand(esp, eax, times_4, +1 * kPointerSize)); // +1 ~ receiver 449 // kPointerSize for the receiver.
450 __ mov(edi, Operand(esp, eax, times_4, kPointerSize));
440 451
441 // Invoke the code. 452 // Invoke the code.
442 if (is_construct) { 453 if (is_construct) {
443 __ call(masm->isolate()->builtins()->JSConstructCall(), 454 __ call(masm->isolate()->builtins()->JSConstructCall(),
444 RelocInfo::CODE_TARGET); 455 RelocInfo::CODE_TARGET);
445 } else { 456 } else {
446 ParameterCount actual(eax); 457 ParameterCount actual(eax);
447 __ InvokeFunction(edi, actual, CALL_FUNCTION, 458 __ InvokeFunction(edi, actual, CALL_FUNCTION,
448 NullCallWrapper(), CALL_AS_METHOD); 459 NullCallWrapper(), CALL_AS_METHOD);
449 } 460 }
450 461
451 // Exit the JS frame. Notice that this also removes the empty 462 // Exit the internal frame. Notice that this also removes the empty.
452 // context and the function left on the stack by the code 463 // context and the function left on the stack by the code
453 // invocation. 464 // invocation.
454 __ LeaveInternalFrame(); 465 }
455 __ ret(1 * kPointerSize); // remove receiver 466 __ ret(kPointerSize); // Remove receiver.
456 } 467 }
457 468
458 469
459 void Builtins::Generate_JSEntryTrampoline(MacroAssembler* masm) { 470 void Builtins::Generate_JSEntryTrampoline(MacroAssembler* masm) {
460 Generate_JSEntryTrampolineHelper(masm, false); 471 Generate_JSEntryTrampolineHelper(masm, false);
461 } 472 }
462 473
463 474
464 void Builtins::Generate_JSConstructEntryTrampoline(MacroAssembler* masm) { 475 void Builtins::Generate_JSConstructEntryTrampoline(MacroAssembler* masm) {
465 Generate_JSEntryTrampolineHelper(masm, true); 476 Generate_JSEntryTrampolineHelper(masm, true);
466 } 477 }
467 478
468 479
469 void Builtins::Generate_LazyCompile(MacroAssembler* masm) { 480 void Builtins::Generate_LazyCompile(MacroAssembler* masm) {
470 // Enter an internal frame. 481 {
471 __ EnterInternalFrame(); 482 FrameScope scope(masm, StackFrame::INTERNAL);
472 483
473 // Push a copy of the function. 484 // Push a copy of the function.
474 __ push(edi); 485 __ push(edi);
475 // Push call kind information. 486 // Push call kind information.
476 __ push(ecx); 487 __ push(ecx);
477 488
478 __ push(edi); // Function is also the parameter to the runtime call. 489 __ push(edi); // Function is also the parameter to the runtime call.
479 __ CallRuntime(Runtime::kLazyCompile, 1); 490 __ CallRuntime(Runtime::kLazyCompile, 1);
480 491
481 // Restore call kind information. 492 // Restore call kind information.
482 __ pop(ecx); 493 __ pop(ecx);
483 // Restore receiver. 494 // Restore receiver.
484 __ pop(edi); 495 __ pop(edi);
485 496
486 // Tear down temporary frame. 497 // Tear down internal frame.
487 __ LeaveInternalFrame(); 498 }
488 499
489 // Do a tail-call of the compiled function. 500 // Do a tail-call of the compiled function.
490 __ lea(eax, FieldOperand(eax, Code::kHeaderSize)); 501 __ lea(eax, FieldOperand(eax, Code::kHeaderSize));
491 __ jmp(Operand(eax)); 502 __ jmp(Operand(eax));
492 } 503 }
493 504
494 505
495 void Builtins::Generate_LazyRecompile(MacroAssembler* masm) { 506 void Builtins::Generate_LazyRecompile(MacroAssembler* masm) {
496 // Enter an internal frame. 507 {
497 __ EnterInternalFrame(); 508 FrameScope scope(masm, StackFrame::INTERNAL);
498 509
499 // Push a copy of the function onto the stack. 510 // Push a copy of the function onto the stack.
500 __ push(edi); 511 __ push(edi);
501 // Push call kind information. 512 // Push call kind information.
502 __ push(ecx); 513 __ push(ecx);
503 514
504 __ push(edi); // Function is also the parameter to the runtime call. 515 __ push(edi); // Function is also the parameter to the runtime call.
505 __ CallRuntime(Runtime::kLazyRecompile, 1); 516 __ CallRuntime(Runtime::kLazyRecompile, 1);
506 517
507 // Restore call kind information. 518 // Restore call kind information.
508 __ pop(ecx); 519 __ pop(ecx);
509 // Restore receiver. 520 // Restore receiver.
510 __ pop(edi); 521 __ pop(edi);
511 522
512 // Tear down temporary frame. 523 // Tear down internal frame.
513 __ LeaveInternalFrame(); 524 }
514 525
515 // Do a tail-call of the compiled function. 526 // Do a tail-call of the compiled function.
516 __ lea(eax, FieldOperand(eax, Code::kHeaderSize)); 527 __ lea(eax, FieldOperand(eax, Code::kHeaderSize));
517 __ jmp(Operand(eax)); 528 __ jmp(Operand(eax));
518 } 529 }
519 530
520 531
521 static void Generate_NotifyDeoptimizedHelper(MacroAssembler* masm, 532 static void Generate_NotifyDeoptimizedHelper(MacroAssembler* masm,
522 Deoptimizer::BailoutType type) { 533 Deoptimizer::BailoutType type) {
523 // Enter an internal frame. 534 {
524 __ EnterInternalFrame(); 535 FrameScope scope(masm, StackFrame::INTERNAL);
525 536
526 // Pass the function and deoptimization type to the runtime system. 537 // Pass the function and deoptimization type to the runtime system.
527 __ push(Immediate(Smi::FromInt(static_cast<int>(type)))); 538 __ push(Immediate(Smi::FromInt(static_cast<int>(type))));
528 __ CallRuntime(Runtime::kNotifyDeoptimized, 1); 539 __ CallRuntime(Runtime::kNotifyDeoptimized, 1);
529 540
530 // Tear down temporary frame. 541 // Tear down internal frame.
531 __ LeaveInternalFrame(); 542 }
532 543
533 // Get the full codegen state from the stack and untag it. 544 // Get the full codegen state from the stack and untag it.
534 __ mov(ecx, Operand(esp, 1 * kPointerSize)); 545 __ mov(ecx, Operand(esp, 1 * kPointerSize));
535 __ SmiUntag(ecx); 546 __ SmiUntag(ecx);
536 547
537 // Switch on the state. 548 // Switch on the state.
538 Label not_no_registers, not_tos_eax; 549 Label not_no_registers, not_tos_eax;
539 __ cmp(ecx, FullCodeGenerator::NO_REGISTERS); 550 __ cmp(ecx, FullCodeGenerator::NO_REGISTERS);
540 __ j(not_equal, &not_no_registers, Label::kNear); 551 __ j(not_equal, &not_no_registers, Label::kNear);
541 __ ret(1 * kPointerSize); // Remove state. 552 __ ret(1 * kPointerSize); // Remove state.
(...skipping 20 matching lines...) Expand all
562 573
563 574
564 void Builtins::Generate_NotifyOSR(MacroAssembler* masm) { 575 void Builtins::Generate_NotifyOSR(MacroAssembler* masm) {
565 // TODO(kasperl): Do we need to save/restore the XMM registers too? 576 // TODO(kasperl): Do we need to save/restore the XMM registers too?
566 577
567 // For now, we are relying on the fact that Runtime::NotifyOSR 578 // For now, we are relying on the fact that Runtime::NotifyOSR
568 // doesn't do any garbage collection which allows us to save/restore 579 // doesn't do any garbage collection which allows us to save/restore
569 // the registers without worrying about which of them contain 580 // the registers without worrying about which of them contain
570 // pointers. This seems a bit fragile. 581 // pointers. This seems a bit fragile.
571 __ pushad(); 582 __ pushad();
572 __ EnterInternalFrame(); 583 {
573 __ CallRuntime(Runtime::kNotifyOSR, 0); 584 FrameScope scope(masm, StackFrame::INTERNAL);
574 __ LeaveInternalFrame(); 585 __ CallRuntime(Runtime::kNotifyOSR, 0);
586 }
575 __ popad(); 587 __ popad();
576 __ ret(0); 588 __ ret(0);
577 } 589 }
578 590
579 591
580 void Builtins::Generate_FunctionCall(MacroAssembler* masm) { 592 void Builtins::Generate_FunctionCall(MacroAssembler* masm) {
581 Factory* factory = masm->isolate()->factory(); 593 Factory* factory = masm->isolate()->factory();
582 594
583 // 1. Make sure we have at least one argument. 595 // 1. Make sure we have at least one argument.
584 { Label done; 596 { Label done;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 __ cmp(ebx, factory->null_value()); 641 __ cmp(ebx, factory->null_value());
630 __ j(equal, &use_global_receiver); 642 __ j(equal, &use_global_receiver);
631 __ cmp(ebx, factory->undefined_value()); 643 __ cmp(ebx, factory->undefined_value());
632 __ j(equal, &use_global_receiver); 644 __ j(equal, &use_global_receiver);
633 STATIC_ASSERT(LAST_JS_OBJECT_TYPE + 1 == LAST_TYPE); 645 STATIC_ASSERT(LAST_JS_OBJECT_TYPE + 1 == LAST_TYPE);
634 STATIC_ASSERT(LAST_TYPE == JS_FUNCTION_TYPE); 646 STATIC_ASSERT(LAST_TYPE == JS_FUNCTION_TYPE);
635 __ CmpObjectType(ebx, FIRST_JS_OBJECT_TYPE, ecx); 647 __ CmpObjectType(ebx, FIRST_JS_OBJECT_TYPE, ecx);
636 __ j(above_equal, &shift_arguments); 648 __ j(above_equal, &shift_arguments);
637 649
638 __ bind(&convert_to_object); 650 __ bind(&convert_to_object);
639 __ EnterInternalFrame(); // In order to preserve argument count. 651
652 { // In order to preserve argument count.
653 FrameScope scope(masm, StackFrame::INTERNAL);
640 __ SmiTag(eax); 654 __ SmiTag(eax);
641 __ push(eax); 655 __ push(eax);
642 656
643 __ push(ebx); 657 __ push(ebx);
644 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); 658 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
645 __ mov(ebx, eax); 659 __ mov(ebx, eax);
646 660
647 __ pop(eax); 661 __ pop(eax);
648 __ SmiUntag(eax); 662 __ SmiUntag(eax);
649 __ LeaveInternalFrame(); 663 }
664
650 // Restore the function to edi. 665 // Restore the function to edi.
651 __ mov(edi, Operand(esp, eax, times_4, 1 * kPointerSize)); 666 __ mov(edi, Operand(esp, eax, times_4, 1 * kPointerSize));
652 __ jmp(&patch_receiver); 667 __ jmp(&patch_receiver);
653 668
654 // Use the global receiver object from the called function as the 669 // Use the global receiver object from the called function as the
655 // receiver. 670 // receiver.
656 __ bind(&use_global_receiver); 671 __ bind(&use_global_receiver);
657 const int kGlobalIndex = 672 const int kGlobalIndex =
658 Context::kHeaderSize + Context::GLOBAL_INDEX * kPointerSize; 673 Context::kHeaderSize + Context::GLOBAL_INDEX * kPointerSize;
659 __ mov(ebx, FieldOperand(esi, kGlobalIndex)); 674 __ mov(ebx, FieldOperand(esi, kGlobalIndex));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 __ j(not_equal, 731 __ j(not_equal,
717 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline()); 732 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline());
718 733
719 ParameterCount expected(0); 734 ParameterCount expected(0);
720 __ InvokeCode(Operand(edx), expected, expected, JUMP_FUNCTION, 735 __ InvokeCode(Operand(edx), expected, expected, JUMP_FUNCTION,
721 NullCallWrapper(), CALL_AS_METHOD); 736 NullCallWrapper(), CALL_AS_METHOD);
722 } 737 }
723 738
724 739
725 void Builtins::Generate_FunctionApply(MacroAssembler* masm) { 740 void Builtins::Generate_FunctionApply(MacroAssembler* masm) {
726 __ EnterInternalFrame(); 741 {
742 FrameScope scope(masm, StackFrame::INTERNAL);
727 743
728 __ push(Operand(ebp, 4 * kPointerSize)); // push this 744 __ push(Operand(ebp, 4 * kPointerSize)); // push this
729 __ push(Operand(ebp, 2 * kPointerSize)); // push arguments 745 __ push(Operand(ebp, 2 * kPointerSize)); // push arguments
730 __ InvokeBuiltin(Builtins::APPLY_PREPARE, CALL_FUNCTION); 746 __ InvokeBuiltin(Builtins::APPLY_PREPARE, CALL_FUNCTION);
731 747
732 // Check the stack for overflow. We are not trying need to catch 748 // Check the stack for overflow. We are not trying need to catch
733 // interruptions (e.g. debug break and preemption) here, so the "real stack 749 // interruptions (e.g. debug break and preemption) here, so the "real stack
734 // limit" is checked. 750 // limit" is checked.
735 Label okay; 751 Label okay;
736 ExternalReference real_stack_limit = 752 ExternalReference real_stack_limit =
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 __ cmp(eax, Operand(ebp, kLimitOffset)); 860 __ cmp(eax, Operand(ebp, kLimitOffset));
845 __ j(not_equal, &loop); 861 __ j(not_equal, &loop);
846 862
847 // Invoke the function. 863 // Invoke the function.
848 ParameterCount actual(eax); 864 ParameterCount actual(eax);
849 __ SmiUntag(eax); 865 __ SmiUntag(eax);
850 __ mov(edi, Operand(ebp, 4 * kPointerSize)); 866 __ mov(edi, Operand(ebp, 4 * kPointerSize));
851 __ InvokeFunction(edi, actual, CALL_FUNCTION, 867 __ InvokeFunction(edi, actual, CALL_FUNCTION,
852 NullCallWrapper(), CALL_AS_METHOD); 868 NullCallWrapper(), CALL_AS_METHOD);
853 869
854 __ LeaveInternalFrame(); 870 // Leave the internal frame.
871 }
855 __ ret(3 * kPointerSize); // remove this, receiver, and arguments 872 __ ret(3 * kPointerSize); // remove this, receiver, and arguments
856 } 873 }
857 874
858 875
859 // Number of empty elements to allocate for an empty array. 876 // Number of empty elements to allocate for an empty array.
860 static const int kPreallocatedArrayElements = 4; 877 static const int kPreallocatedArrayElements = 4;
861 878
862 879
863 // Allocate an empty JSArray. The allocated array is put into the result 880 // Allocate an empty JSArray. The allocated array is put into the result
864 // register. If the parameter initial_capacity is larger than zero an elements 881 // register. If the parameter initial_capacity is larger than zero an elements
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
1396 __ j(zero, &convert_argument); 1413 __ j(zero, &convert_argument);
1397 Condition is_string = masm->IsObjectStringType(eax, ebx, ecx); 1414 Condition is_string = masm->IsObjectStringType(eax, ebx, ecx);
1398 __ j(NegateCondition(is_string), &convert_argument); 1415 __ j(NegateCondition(is_string), &convert_argument);
1399 __ mov(ebx, eax); 1416 __ mov(ebx, eax);
1400 __ IncrementCounter(counters->string_ctor_string_value(), 1); 1417 __ IncrementCounter(counters->string_ctor_string_value(), 1);
1401 __ jmp(&argument_is_string); 1418 __ jmp(&argument_is_string);
1402 1419
1403 // Invoke the conversion builtin and put the result into ebx. 1420 // Invoke the conversion builtin and put the result into ebx.
1404 __ bind(&convert_argument); 1421 __ bind(&convert_argument);
1405 __ IncrementCounter(counters->string_ctor_conversions(), 1); 1422 __ IncrementCounter(counters->string_ctor_conversions(), 1);
1406 __ EnterInternalFrame(); 1423 {
1424 FrameScope scope(masm, StackFrame::INTERNAL);
1407 __ push(edi); // Preserve the function. 1425 __ push(edi); // Preserve the function.
1408 __ push(eax); 1426 __ push(eax);
1409 __ InvokeBuiltin(Builtins::TO_STRING, CALL_FUNCTION); 1427 __ InvokeBuiltin(Builtins::TO_STRING, CALL_FUNCTION);
1410 __ pop(edi); 1428 __ pop(edi);
1411 __ LeaveInternalFrame(); 1429 }
1412 __ mov(ebx, eax); 1430 __ mov(ebx, eax);
1413 __ jmp(&argument_is_string); 1431 __ jmp(&argument_is_string);
1414 1432
1415 // Load the empty string into ebx, remove the receiver from the 1433 // Load the empty string into ebx, remove the receiver from the
1416 // stack, and jump back to the case where the argument is a string. 1434 // stack, and jump back to the case where the argument is a string.
1417 __ bind(&no_arguments); 1435 __ bind(&no_arguments);
1418 __ Set(ebx, Immediate(factory->empty_string())); 1436 __ Set(ebx, Immediate(factory->empty_string()));
1419 __ pop(ecx); 1437 __ pop(ecx);
1420 __ lea(esp, Operand(esp, kPointerSize)); 1438 __ lea(esp, Operand(esp, kPointerSize));
1421 __ push(ecx); 1439 __ push(ecx);
1422 __ jmp(&argument_is_string); 1440 __ jmp(&argument_is_string);
1423 1441
1424 // At this point the argument is already a string. Call runtime to 1442 // At this point the argument is already a string. Call runtime to
1425 // create a string wrapper. 1443 // create a string wrapper.
1426 __ bind(&gc_required); 1444 __ bind(&gc_required);
1427 __ IncrementCounter(counters->string_ctor_gc_required(), 1); 1445 __ IncrementCounter(counters->string_ctor_gc_required(), 1);
1428 __ EnterInternalFrame(); 1446 {
1447 FrameScope scope(masm, StackFrame::INTERNAL);
1429 __ push(ebx); 1448 __ push(ebx);
1430 __ CallRuntime(Runtime::kNewStringWrapper, 1); 1449 __ CallRuntime(Runtime::kNewStringWrapper, 1);
1431 __ LeaveInternalFrame(); 1450 }
1432 __ ret(0); 1451 __ ret(0);
1433 } 1452 }
1434 1453
1435 1454
1436 static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) { 1455 static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) {
1437 __ push(ebp); 1456 __ push(ebp);
1438 __ mov(ebp, Operand(esp)); 1457 __ mov(ebp, Operand(esp));
1439 1458
1440 // Store the arguments adaptor context sentinel. 1459 // Store the arguments adaptor context sentinel.
1441 __ push(Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); 1460 __ push(Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1546 // ------------------------------------------- 1565 // -------------------------------------------
1547 // Dont adapt arguments. 1566 // Dont adapt arguments.
1548 // ------------------------------------------- 1567 // -------------------------------------------
1549 __ bind(&dont_adapt_arguments); 1568 __ bind(&dont_adapt_arguments);
1550 __ jmp(Operand(edx)); 1569 __ jmp(Operand(edx));
1551 } 1570 }
1552 1571
1553 1572
1554 void Builtins::Generate_OnStackReplacement(MacroAssembler* masm) { 1573 void Builtins::Generate_OnStackReplacement(MacroAssembler* masm) {
1555 CpuFeatures::TryForceFeatureScope scope(SSE2); 1574 CpuFeatures::TryForceFeatureScope scope(SSE2);
1556 if (!CpuFeatures::IsSupported(SSE2)) { 1575 if (!CpuFeatures::IsSupported(SSE2) && FLAG_debug_code) {
1557 __ Abort("Unreachable code: Cannot optimize without SSE2 support."); 1576 __ Abort("Unreachable code: Cannot optimize without SSE2 support.");
1558 return; 1577 return;
1559 } 1578 }
1560 1579
1561 // Get the loop depth of the stack guard check. This is recorded in 1580 // Get the loop depth of the stack guard check. This is recorded in
1562 // a test(eax, depth) instruction right after the call. 1581 // a test(eax, depth) instruction right after the call.
1563 Label stack_check; 1582 Label stack_check;
1564 __ mov(ebx, Operand(esp, 0)); // return address 1583 __ mov(ebx, Operand(esp, 0)); // return address
1565 if (FLAG_debug_code) { 1584 if (FLAG_debug_code) {
1566 __ cmpb(Operand(ebx, 0), Assembler::kTestAlByte); 1585 __ cmpb(Operand(ebx, 0), Assembler::kTestAlByte);
1567 __ Assert(equal, "test eax instruction not found after loop stack check"); 1586 __ Assert(equal, "test eax instruction not found after loop stack check");
1568 } 1587 }
1569 __ movzx_b(ebx, Operand(ebx, 1)); // depth 1588 __ movzx_b(ebx, Operand(ebx, 1)); // depth
1570 1589
1571 // Get the loop nesting level at which we allow OSR from the 1590 // Get the loop nesting level at which we allow OSR from the
1572 // unoptimized code and check if we want to do OSR yet. If not we 1591 // unoptimized code and check if we want to do OSR yet. If not we
1573 // should perform a stack guard check so we can get interrupts while 1592 // should perform a stack guard check so we can get interrupts while
1574 // waiting for on-stack replacement. 1593 // waiting for on-stack replacement.
1575 __ mov(eax, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); 1594 __ mov(eax, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
1576 __ mov(ecx, FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset)); 1595 __ mov(ecx, FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset));
1577 __ mov(ecx, FieldOperand(ecx, SharedFunctionInfo::kCodeOffset)); 1596 __ mov(ecx, FieldOperand(ecx, SharedFunctionInfo::kCodeOffset));
1578 __ cmpb(ebx, FieldOperand(ecx, Code::kAllowOSRAtLoopNestingLevelOffset)); 1597 __ cmpb(ebx, FieldOperand(ecx, Code::kAllowOSRAtLoopNestingLevelOffset));
1579 __ j(greater, &stack_check); 1598 __ j(greater, &stack_check);
1580 1599
1581 // Pass the function to optimize as the argument to the on-stack 1600 // Pass the function to optimize as the argument to the on-stack
1582 // replacement runtime function. 1601 // replacement runtime function.
1583 __ EnterInternalFrame(); 1602 {
1603 FrameScope scope(masm, StackFrame::INTERNAL);
1584 __ push(eax); 1604 __ push(eax);
1585 __ CallRuntime(Runtime::kCompileForOnStackReplacement, 1); 1605 __ CallRuntime(Runtime::kCompileForOnStackReplacement, 1);
1586 __ LeaveInternalFrame(); 1606 }
1587 1607
1588 // If the result was -1 it means that we couldn't optimize the 1608 // If the result was -1 it means that we couldn't optimize the
1589 // function. Just return and continue in the unoptimized version. 1609 // function. Just return and continue in the unoptimized version.
1590 Label skip; 1610 Label skip;
1591 __ cmp(Operand(eax), Immediate(Smi::FromInt(-1))); 1611 __ cmp(Operand(eax), Immediate(Smi::FromInt(-1)));
1592 __ j(not_equal, &skip, Label::kNear); 1612 __ j(not_equal, &skip, Label::kNear);
1593 __ ret(0); 1613 __ ret(0);
1594 1614
1595 // If we decide not to perform on-stack replacement we perform a 1615 // If we decide not to perform on-stack replacement we perform a
1596 // stack guard check to enable interrupts. 1616 // stack guard check to enable interrupts.
1597 __ bind(&stack_check); 1617 __ bind(&stack_check);
1598 Label ok; 1618 Label ok;
1599 ExternalReference stack_limit = 1619 ExternalReference stack_limit =
1600 ExternalReference::address_of_stack_limit(masm->isolate()); 1620 ExternalReference::address_of_stack_limit(masm->isolate());
1601 __ cmp(esp, Operand::StaticVariable(stack_limit)); 1621 __ cmp(esp, Operand::StaticVariable(stack_limit));
1602 __ j(above_equal, &ok, Label::kNear); 1622 __ j(above_equal, &ok, Label::kNear);
1603 StackCheckStub stub; 1623 StackCheckStub stub;
1604 __ TailCallStub(&stub); 1624 __ TailCallStub(&stub);
1605 __ Abort("Unreachable code: returned from tail call."); 1625 if (FLAG_debug_code) {
1626 __ Abort("Unreachable code: returned from tail call.");
1627 }
1606 __ bind(&ok); 1628 __ bind(&ok);
1607 __ ret(0); 1629 __ ret(0);
1608 1630
1609 __ bind(&skip); 1631 __ bind(&skip);
1610 // Untag the AST id and push it on the stack. 1632 // Untag the AST id and push it on the stack.
1611 __ SmiUntag(eax); 1633 __ SmiUntag(eax);
1612 __ push(eax); 1634 __ push(eax);
1613 1635
1614 // Generate the code for doing the frame-to-frame translation using 1636 // Generate the code for doing the frame-to-frame translation using
1615 // the deoptimizer infrastructure. 1637 // the deoptimizer infrastructure.
1616 Deoptimizer::EntryGenerator generator(masm, Deoptimizer::OSR); 1638 Deoptimizer::EntryGenerator generator(masm, Deoptimizer::OSR);
1617 generator.Generate(); 1639 generator.Generate();
1618 } 1640 }
1619 1641
1620 1642
1621 #undef __ 1643 #undef __
1622 } 1644 }
1623 } // namespace v8::internal 1645 } // namespace v8::internal
1624 1646
1625 #endif // V8_TARGET_ARCH_IA32 1647 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/frames.h ('k') | src/ia32/code-stubs-ia32.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698