| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #if V8_TARGET_ARCH_X87 | 7 #if V8_TARGET_ARCH_X87 |
| 8 | 8 |
| 9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
| 10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 | 175 |
| 176 // Original constructor and function are different. | 176 // Original constructor and function are different. |
| 177 Generate_Runtime_NewObject(masm, create_memento, edx, &count_incremented, | 177 Generate_Runtime_NewObject(masm, create_memento, edx, &count_incremented, |
| 178 &allocated); | 178 &allocated); |
| 179 __ bind(&normal_new); | 179 __ bind(&normal_new); |
| 180 | 180 |
| 181 // Try to allocate the object without transitioning into C code. If any of | 181 // Try to allocate the object without transitioning into C code. If any of |
| 182 // the preconditions is not met, the code bails out to the runtime call. | 182 // the preconditions is not met, the code bails out to the runtime call. |
| 183 Label rt_call; | 183 Label rt_call; |
| 184 if (FLAG_inline_new) { | 184 if (FLAG_inline_new) { |
| 185 Label undo_allocation; | |
| 186 ExternalReference debug_step_in_fp = | 185 ExternalReference debug_step_in_fp = |
| 187 ExternalReference::debug_step_in_fp_address(masm->isolate()); | 186 ExternalReference::debug_step_in_fp_address(masm->isolate()); |
| 188 __ cmp(Operand::StaticVariable(debug_step_in_fp), Immediate(0)); | 187 __ cmp(Operand::StaticVariable(debug_step_in_fp), Immediate(0)); |
| 189 __ j(not_equal, &rt_call); | 188 __ j(not_equal, &rt_call); |
| 190 | 189 |
| 191 // Verified that the constructor is a JSFunction. | 190 // Verified that the constructor is a JSFunction. |
| 192 // Load the initial map and verify that it is in fact a map. | 191 // Load the initial map and verify that it is in fact a map. |
| 193 // edi: constructor | 192 // edi: constructor |
| 194 __ mov(eax, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); | 193 __ mov(eax, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 195 // Will both indicate a NULL and a Smi | 194 // Will both indicate a NULL and a Smi |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 __ mov(edx, factory->undefined_value()); | 264 __ mov(edx, factory->undefined_value()); |
| 266 __ lea(ecx, Operand(ebx, JSObject::kHeaderSize)); | 265 __ lea(ecx, Operand(ebx, JSObject::kHeaderSize)); |
| 267 if (!is_api_function) { | 266 if (!is_api_function) { |
| 268 Label no_inobject_slack_tracking; | 267 Label no_inobject_slack_tracking; |
| 269 | 268 |
| 270 // Check if slack tracking is enabled. | 269 // Check if slack tracking is enabled. |
| 271 __ cmp(esi, Map::kSlackTrackingCounterEnd); | 270 __ cmp(esi, Map::kSlackTrackingCounterEnd); |
| 272 __ j(less, &no_inobject_slack_tracking); | 271 __ j(less, &no_inobject_slack_tracking); |
| 273 | 272 |
| 274 // Allocate object with a slack. | 273 // Allocate object with a slack. |
| 275 __ movzx_b(esi, | 274 __ movzx_b(esi, FieldOperand(eax, Map::kInObjectPropertiesOffset)); |
| 276 FieldOperand(eax, Map::kPreAllocatedPropertyFieldsOffset)); | 275 __ movzx_b(eax, FieldOperand(eax, Map::kUnusedPropertyFieldsOffset)); |
| 276 __ sub(esi, eax); |
| 277 __ lea(esi, | 277 __ lea(esi, |
| 278 Operand(ebx, esi, times_pointer_size, JSObject::kHeaderSize)); | 278 Operand(ebx, esi, times_pointer_size, JSObject::kHeaderSize)); |
| 279 // esi: offset of first field after pre-allocated fields | 279 // esi: offset of first field after pre-allocated fields |
| 280 if (FLAG_debug_code) { | 280 if (FLAG_debug_code) { |
| 281 __ cmp(esi, edi); | 281 __ cmp(esi, edi); |
| 282 __ Assert(less_equal, | 282 __ Assert(less_equal, |
| 283 kUnexpectedNumberOfPreAllocatedPropertyFields); | 283 kUnexpectedNumberOfPreAllocatedPropertyFields); |
| 284 } | 284 } |
| 285 __ InitializeFieldsWithFiller(ecx, esi, edx); | 285 __ InitializeFieldsWithFiller(ecx, esi, edx); |
| 286 __ mov(edx, factory->one_pointer_filler_map()); | 286 __ mov(edx, factory->one_pointer_filler_map()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 299 factory->allocation_memento_map()); | 299 factory->allocation_memento_map()); |
| 300 // Get the cell or undefined. | 300 // Get the cell or undefined. |
| 301 __ mov(edx, Operand(esp, kPointerSize*2)); | 301 __ mov(edx, Operand(esp, kPointerSize*2)); |
| 302 __ mov(Operand(esi, AllocationMemento::kAllocationSiteOffset), | 302 __ mov(Operand(esi, AllocationMemento::kAllocationSiteOffset), |
| 303 edx); | 303 edx); |
| 304 } else { | 304 } else { |
| 305 __ InitializeFieldsWithFiller(ecx, edi, edx); | 305 __ InitializeFieldsWithFiller(ecx, edi, edx); |
| 306 } | 306 } |
| 307 | 307 |
| 308 // Add the object tag to make the JSObject real, so that we can continue | 308 // Add the object tag to make the JSObject real, so that we can continue |
| 309 // and jump into the continuation code at any time from now on. Any | 309 // and jump into the continuation code at any time from now on. |
| 310 // failures need to undo the allocation, so that the heap is in a | 310 // ebx: JSObject (untagged) |
| 311 // consistent state and verifiable. | |
| 312 // eax: initial map | |
| 313 // ebx: JSObject | |
| 314 // edi: start of next object | |
| 315 __ or_(ebx, Immediate(kHeapObjectTag)); | 311 __ or_(ebx, Immediate(kHeapObjectTag)); |
| 316 | 312 |
| 317 // Check if a non-empty properties array is needed. | |
| 318 // Allocate and initialize a FixedArray if it is. | |
| 319 // eax: initial map | |
| 320 // ebx: JSObject | |
| 321 // edi: start of next object | |
| 322 // Calculate the total number of properties described by the map. | |
| 323 __ movzx_b(edx, FieldOperand(eax, Map::kUnusedPropertyFieldsOffset)); | |
| 324 __ movzx_b(ecx, | |
| 325 FieldOperand(eax, Map::kPreAllocatedPropertyFieldsOffset)); | |
| 326 __ add(edx, ecx); | |
| 327 // Calculate unused properties past the end of the in-object properties. | |
| 328 __ movzx_b(ecx, FieldOperand(eax, Map::kInObjectPropertiesOffset)); | |
| 329 __ sub(edx, ecx); | |
| 330 // Done if no extra properties are to be allocated. | |
| 331 __ j(zero, &allocated); | |
| 332 __ Assert(positive, kPropertyAllocationCountFailed); | |
| 333 | |
| 334 // Scale the number of elements by pointer size and add the header for | |
| 335 // FixedArrays to the start of the next object calculation from above. | |
| 336 // ebx: JSObject | |
| 337 // edi: start of next object (will be start of FixedArray) | |
| 338 // edx: number of elements in properties array | |
| 339 __ Allocate(FixedArray::kHeaderSize, | |
| 340 times_pointer_size, | |
| 341 edx, | |
| 342 REGISTER_VALUE_IS_INT32, | |
| 343 edi, | |
| 344 ecx, | |
| 345 no_reg, | |
| 346 &undo_allocation, | |
| 347 RESULT_CONTAINS_TOP); | |
| 348 | |
| 349 // Initialize the FixedArray. | |
| 350 // ebx: JSObject | |
| 351 // edi: FixedArray | |
| 352 // edx: number of elements | |
| 353 // ecx: start of next object | |
| 354 __ mov(eax, factory->fixed_array_map()); | |
| 355 __ mov(Operand(edi, FixedArray::kMapOffset), eax); // setup the map | |
| 356 __ SmiTag(edx); | |
| 357 __ mov(Operand(edi, FixedArray::kLengthOffset), edx); // and length | |
| 358 | |
| 359 // Initialize the fields to undefined. | |
| 360 // ebx: JSObject | |
| 361 // edi: FixedArray | |
| 362 // ecx: start of next object | |
| 363 __ mov(edx, factory->undefined_value()); | |
| 364 __ lea(eax, Operand(edi, FixedArray::kHeaderSize)); | |
| 365 __ InitializeFieldsWithFiller(eax, ecx, edx); | |
| 366 | |
| 367 // Store the initialized FixedArray into the properties field of | |
| 368 // the JSObject | |
| 369 // ebx: JSObject | |
| 370 // edi: FixedArray | |
| 371 __ or_(edi, Immediate(kHeapObjectTag)); // add the heap tag | |
| 372 __ mov(FieldOperand(ebx, JSObject::kPropertiesOffset), edi); | |
| 373 | |
| 374 | |
| 375 // Continue with JSObject being successfully allocated | 313 // Continue with JSObject being successfully allocated |
| 376 // ebx: JSObject | 314 // ebx: JSObject (tagged) |
| 377 __ jmp(&allocated); | 315 __ jmp(&allocated); |
| 378 | |
| 379 // Undo the setting of the new top so that the heap is verifiable. For | |
| 380 // example, the map's unused properties potentially do not match the | |
| 381 // allocated objects unused properties. | |
| 382 // ebx: JSObject (previous new top) | |
| 383 __ bind(&undo_allocation); | |
| 384 __ UndoAllocationInNewSpace(ebx); | |
| 385 } | 316 } |
| 386 | 317 |
| 387 // Allocate the new receiver object using the runtime call. | 318 // Allocate the new receiver object using the runtime call. |
| 388 __ bind(&rt_call); | 319 __ bind(&rt_call); |
| 389 Generate_Runtime_NewObject(masm, create_memento, edi, &count_incremented, | 320 Generate_Runtime_NewObject(masm, create_memento, edi, &count_incremented, |
| 390 &allocated); | 321 &allocated); |
| 391 // New object allocated. | 322 // New object allocated. |
| 392 // ebx: newly allocated object | 323 // ebx: newly allocated object |
| 393 __ bind(&allocated); | 324 __ bind(&allocated); |
| 394 | 325 |
| (...skipping 1333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1728 | 1659 |
| 1729 __ bind(&ok); | 1660 __ bind(&ok); |
| 1730 __ ret(0); | 1661 __ ret(0); |
| 1731 } | 1662 } |
| 1732 | 1663 |
| 1733 #undef __ | 1664 #undef __ |
| 1734 } // namespace internal | 1665 } // namespace internal |
| 1735 } // namespace v8 | 1666 } // namespace v8 |
| 1736 | 1667 |
| 1737 #endif // V8_TARGET_ARCH_X87 | 1668 #endif // V8_TARGET_ARCH_X87 |
| OLD | NEW |