Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 CallRuntimePassFunction(masm, Runtime::kTryInstallOptimizedCode); | 118 CallRuntimePassFunction(masm, Runtime::kTryInstallOptimizedCode); | 
| 119 GenerateTailCallToReturnedCode(masm); | 119 GenerateTailCallToReturnedCode(masm); | 
| 120 | 120 | 
| 121 __ bind(&ok); | 121 __ bind(&ok); | 
| 122 GenerateTailCallToSharedCode(masm); | 122 GenerateTailCallToSharedCode(masm); | 
| 123 } | 123 } | 
| 124 | 124 | 
| 125 | 125 | 
| 126 static void Generate_JSConstructStubHelper(MacroAssembler* masm, | 126 static void Generate_JSConstructStubHelper(MacroAssembler* masm, | 
| 127 bool is_api_function, | 127 bool is_api_function, | 
| 128 bool count_constructions) { | 128 bool count_constructions, | 
| 129 bool create_memento) { | |
| 129 // ----------- S t a t e ------------- | 130 // ----------- S t a t e ------------- | 
| 130 // -- eax: number of arguments | 131 // -- eax: number of arguments | 
| 131 // -- edi: constructor function | 132 // -- edi: constructor function | 
| 133 // -- ebx: allocation site or undefined | |
| 132 // ----------------------------------- | 134 // ----------------------------------- | 
| 133 | 135 | 
| 134 // Should never count constructions for api objects. | 136 // Should never count constructions for api objects. | 
| 135 ASSERT(!is_api_function || !count_constructions); | 137 ASSERT(!is_api_function || !count_constructions); | 
| 136 | 138 | 
| 139 // Should never create mementos for api functions. (true?) | |
| 
 
Hannes Payer (out of office)
2014/02/11 15:51:23
probably
 
mvstanton
2014/02/17 15:53:08
Done.
 
 | |
| 140 ASSERT(!is_api_function || !create_memento); | |
| 141 | |
| 137 // Enter a construct frame. | 142 // Enter a construct frame. | 
| 138 { | 143 { | 
| 139 FrameScope scope(masm, StackFrame::CONSTRUCT); | 144 FrameScope scope(masm, StackFrame::CONSTRUCT); | 
| 140 | 145 | 
| 146 if (create_memento) { | |
| 147 __ AssertUndefinedOrAllocationSite(ebx); | |
| 148 __ push(ebx); | |
| 149 } | |
| 150 | |
| 141 // Store a smi-tagged arguments count on the stack. | 151 // Store a smi-tagged arguments count on the stack. | 
| 142 __ SmiTag(eax); | 152 __ SmiTag(eax); | 
| 143 __ push(eax); | 153 __ push(eax); | 
| 144 | 154 | 
| 145 // Push the function to invoke on the stack. | 155 // Push the function to invoke on the stack. | 
| 146 __ push(edi); | 156 __ push(edi); | 
| 147 | 157 | 
| 148 // Try to allocate the object without transitioning into C code. If any of | 158 // Try to allocate the object without transitioning into C code. If any of | 
| 149 // the preconditions is not met, the code bails out to the runtime call. | 159 // the preconditions is not met, the code bails out to the runtime call. | 
| 150 Label rt_call, allocated; | 160 Label rt_call, allocated; | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 __ pop(eax); | 205 __ pop(eax); | 
| 196 | 206 | 
| 197 __ bind(&allocate); | 207 __ bind(&allocate); | 
| 198 } | 208 } | 
| 199 | 209 | 
| 200 // Now allocate the JSObject on the heap. | 210 // Now allocate the JSObject on the heap. | 
| 201 // edi: constructor | 211 // edi: constructor | 
| 202 // eax: initial map | 212 // eax: initial map | 
| 203 __ movzx_b(edi, FieldOperand(eax, Map::kInstanceSizeOffset)); | 213 __ movzx_b(edi, FieldOperand(eax, Map::kInstanceSizeOffset)); | 
| 204 __ shl(edi, kPointerSizeLog2); | 214 __ shl(edi, kPointerSizeLog2); | 
| 215 if (create_memento) { | |
| 216 __ add(edi, Immediate(AllocationMemento::kSize)); | |
| 217 } | |
| 205 __ Allocate(edi, ebx, edi, no_reg, &rt_call, NO_ALLOCATION_FLAGS); | 218 __ Allocate(edi, ebx, edi, no_reg, &rt_call, NO_ALLOCATION_FLAGS); | 
| 219 Factory* factory = masm->isolate()->factory(); | |
| 220 if (create_memento) { | |
| 221 __ sub(edi, Immediate(AllocationMemento::kSize)); | |
| 222 Handle<Map> allocation_memento_map = factory->allocation_memento_map(); | |
| 223 __ mov(Operand(edi, AllocationMemento::kMapOffset), | |
| 224 allocation_memento_map); | |
| 225 // Get the cell or undefined. | |
| 226 Label do_store; | |
| 227 __ mov(ecx, Operand(esp, kPointerSize*2)); | |
| 228 __ cmp(ecx, masm->isolate()->factory()->undefined_value()); | |
| 229 __ j(equal, &do_store); | |
| 230 // ecx is an AllocationSite. We are creating a memento from it, so we | |
| 231 // need to increment the memento create count. | |
| 232 __ add(Operand(ecx, AllocationSite::kPretenureCreateCountOffset), | |
| 233 Immediate(Smi::FromInt(1))); | |
| 234 __ bind(&do_store); | |
| 
 
Hannes Payer (out of office)
2014/02/11 15:51:23
We could also undo the Memento allocation. WDYT?
 
mvstanton
2014/02/17 15:53:08
Good point, I'll go ahead and fix it to only incre
 
 | |
| 235 __ mov(Operand(edi, AllocationMemento::kAllocationSiteOffset), | |
| 236 ecx); | |
| 237 } | |
| 206 // Allocated the JSObject, now initialize the fields. | 238 // Allocated the JSObject, now initialize the fields. | 
| 207 // eax: initial map | 239 // eax: initial map | 
| 208 // ebx: JSObject | 240 // ebx: JSObject | 
| 209 // edi: start of next object | 241 // edi: start of next object (or memento if create_memento) | 
| 210 __ mov(Operand(ebx, JSObject::kMapOffset), eax); | 242 __ mov(Operand(ebx, JSObject::kMapOffset), eax); | 
| 211 Factory* factory = masm->isolate()->factory(); | |
| 212 __ mov(ecx, factory->empty_fixed_array()); | 243 __ mov(ecx, factory->empty_fixed_array()); | 
| 213 __ mov(Operand(ebx, JSObject::kPropertiesOffset), ecx); | 244 __ mov(Operand(ebx, JSObject::kPropertiesOffset), ecx); | 
| 214 __ mov(Operand(ebx, JSObject::kElementsOffset), ecx); | 245 __ mov(Operand(ebx, JSObject::kElementsOffset), ecx); | 
| 215 // Set extra fields in the newly allocated object. | 246 // Set extra fields in the newly allocated object. | 
| 216 // eax: initial map | 247 // eax: initial map | 
| 217 // ebx: JSObject | 248 // ebx: JSObject | 
| 218 // edi: start of next object | 249 // edi: start of next object (or memento if create_memento) | 
| 219 __ lea(ecx, Operand(ebx, JSObject::kHeaderSize)); | 250 __ lea(ecx, Operand(ebx, JSObject::kHeaderSize)); | 
| 220 __ mov(edx, factory->undefined_value()); | 251 __ mov(edx, factory->undefined_value()); | 
| 221 if (count_constructions) { | 252 if (count_constructions) { | 
| 222 __ movzx_b(esi, | 253 __ movzx_b(esi, | 
| 223 FieldOperand(eax, Map::kPreAllocatedPropertyFieldsOffset)); | 254 FieldOperand(eax, Map::kPreAllocatedPropertyFieldsOffset)); | 
| 224 __ lea(esi, | 255 __ lea(esi, | 
| 225 Operand(ebx, esi, times_pointer_size, JSObject::kHeaderSize)); | 256 Operand(ebx, esi, times_pointer_size, JSObject::kHeaderSize)); | 
| 226 // esi: offset of first field after pre-allocated fields | 257 // esi: offset of first field after pre-allocated fields | 
| 227 if (FLAG_debug_code) { | 258 if (FLAG_debug_code) { | 
| 228 __ cmp(esi, edi); | 259 __ cmp(esi, edi); | 
| 229 __ Assert(less_equal, | 260 __ Assert(less_equal, | 
| 230 kUnexpectedNumberOfPreAllocatedPropertyFields); | 261 kUnexpectedNumberOfPreAllocatedPropertyFields); | 
| 231 } | 262 } | 
| 232 __ InitializeFieldsWithFiller(ecx, esi, edx); | 263 __ InitializeFieldsWithFiller(ecx, esi, edx); | 
| 233 __ mov(edx, factory->one_pointer_filler_map()); | 264 __ mov(edx, factory->one_pointer_filler_map()); | 
| 234 } | 265 } | 
| 235 __ InitializeFieldsWithFiller(ecx, edi, edx); | 266 __ InitializeFieldsWithFiller(ecx, edi, edx); | 
| 267 if (create_memento) { | |
| 268 __ add(edi, Immediate(AllocationMemento::kSize)); | |
| 269 } | |
| 236 | 270 | 
| 237 // Add the object tag to make the JSObject real, so that we can continue | 271 // Add the object tag to make the JSObject real, so that we can continue | 
| 238 // and jump into the continuation code at any time from now on. Any | 272 // and jump into the continuation code at any time from now on. Any | 
| 239 // failures need to undo the allocation, so that the heap is in a | 273 // failures need to undo the allocation, so that the heap is in a | 
| 240 // consistent state and verifiable. | 274 // consistent state and verifiable. | 
| 241 // eax: initial map | 275 // eax: initial map | 
| 242 // ebx: JSObject | 276 // ebx: JSObject | 
| 243 // edi: start of next object | 277 // edi: start of next object | 
| 244 __ or_(ebx, Immediate(kHeapObjectTag)); | 278 __ or_(ebx, Immediate(kHeapObjectTag)); | 
| 245 | 279 | 
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 // Undo the setting of the new top so that the heap is verifiable. For | 350 // Undo the setting of the new top so that the heap is verifiable. For | 
| 317 // example, the map's unused properties potentially do not match the | 351 // example, the map's unused properties potentially do not match the | 
| 318 // allocated objects unused properties. | 352 // allocated objects unused properties. | 
| 319 // ebx: JSObject (previous new top) | 353 // ebx: JSObject (previous new top) | 
| 320 __ bind(&undo_allocation); | 354 __ bind(&undo_allocation); | 
| 321 __ UndoAllocationInNewSpace(ebx); | 355 __ UndoAllocationInNewSpace(ebx); | 
| 322 } | 356 } | 
| 323 | 357 | 
| 324 // Allocate the new receiver object using the runtime call. | 358 // Allocate the new receiver object using the runtime call. | 
| 325 __ bind(&rt_call); | 359 __ bind(&rt_call); | 
| 360 int offset = 0; | |
| 361 if (create_memento) { | |
| 362 // Get the cell or allocation site. | |
| 363 __ mov(edi, Operand(esp, kPointerSize*2)); | |
| 364 __ push(edi); | |
| 365 offset = kPointerSize; | |
| 366 } | |
| 367 | |
| 326 // Must restore edi (constructor) before calling runtime. | 368 // Must restore edi (constructor) before calling runtime. | 
| 327 __ mov(edi, Operand(esp, 0)); | 369 __ mov(edi, Operand(esp, offset)); | 
| 328 // edi: function (constructor) | 370 // edi: function (constructor) | 
| 329 __ push(edi); | 371 __ push(edi); | 
| 330 __ CallRuntime(Runtime::kNewObject, 1); | 372 if (create_memento) { | 
| 373 __ CallRuntime(Runtime::kNewObjectWithAllocationSite, 2); | |
| 374 } else { | |
| 375 __ CallRuntime(Runtime::kNewObject, 1); | |
| 376 } | |
| 331 __ mov(ebx, eax); // store result in ebx | 377 __ mov(ebx, eax); // store result in ebx | 
| 332 | 378 | 
| 333 // New object allocated. | 379 // New object allocated. | 
| 334 // ebx: newly allocated object | 380 // ebx: newly allocated object | 
| 335 __ bind(&allocated); | 381 __ bind(&allocated); | 
| 336 // Retrieve the function from the stack. | 382 // Retrieve the function from the stack. | 
| 337 __ pop(edi); | 383 __ pop(edi); | 
| 338 | 384 | 
| 339 // Retrieve smi-tagged arguments count from the stack. | 385 // Retrieve smi-tagged arguments count from the stack. | 
| 340 __ mov(eax, Operand(esp, 0)); | 386 __ mov(eax, Operand(esp, 0)); | 
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 408 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0); | 454 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0); | 
| 409 __ pop(ecx); | 455 __ pop(ecx); | 
| 410 __ lea(esp, Operand(esp, ebx, times_2, 1 * kPointerSize)); // 1 ~ receiver | 456 __ lea(esp, Operand(esp, ebx, times_2, 1 * kPointerSize)); // 1 ~ receiver | 
| 411 __ push(ecx); | 457 __ push(ecx); | 
| 412 __ IncrementCounter(masm->isolate()->counters()->constructed_objects(), 1); | 458 __ IncrementCounter(masm->isolate()->counters()->constructed_objects(), 1); | 
| 413 __ ret(0); | 459 __ ret(0); | 
| 414 } | 460 } | 
| 415 | 461 | 
| 416 | 462 | 
| 417 void Builtins::Generate_JSConstructStubCountdown(MacroAssembler* masm) { | 463 void Builtins::Generate_JSConstructStubCountdown(MacroAssembler* masm) { | 
| 418 Generate_JSConstructStubHelper(masm, false, true); | 464 Generate_JSConstructStubHelper(masm, false, true, true); | 
| 419 } | 465 } | 
| 420 | 466 | 
| 421 | 467 | 
| 422 void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { | 468 void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { | 
| 423 Generate_JSConstructStubHelper(masm, false, false); | 469 Generate_JSConstructStubHelper(masm, false, false, true); | 
| 424 } | 470 } | 
| 425 | 471 | 
| 426 | 472 | 
| 427 void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) { | 473 void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) { | 
| 428 Generate_JSConstructStubHelper(masm, true, false); | 474 Generate_JSConstructStubHelper(masm, true, false, false); | 
| 429 } | 475 } | 
| 430 | 476 | 
| 431 | 477 | 
| 432 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm, | 478 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm, | 
| 433 bool is_construct) { | 479 bool is_construct) { | 
| 434 ProfileEntryHookStub::MaybeCallEntryHook(masm); | 480 ProfileEntryHookStub::MaybeCallEntryHook(masm); | 
| 435 | 481 | 
| 436 // Clear the context before we push it when entering the internal frame. | 482 // Clear the context before we push it when entering the internal frame. | 
| 437 __ Set(esi, Immediate(0)); | 483 __ Set(esi, Immediate(0)); | 
| 438 | 484 | 
| (...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1365 | 1411 | 
| 1366 __ bind(&ok); | 1412 __ bind(&ok); | 
| 1367 __ ret(0); | 1413 __ ret(0); | 
| 1368 } | 1414 } | 
| 1369 | 1415 | 
| 1370 #undef __ | 1416 #undef __ | 
| 1371 } | 1417 } | 
| 1372 } // namespace v8::internal | 1418 } // namespace v8::internal | 
| 1373 | 1419 | 
| 1374 #endif // V8_TARGET_ARCH_IA32 | 1420 #endif // V8_TARGET_ARCH_IA32 | 
| OLD | NEW |