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