| 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 305 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   316   // Need to collect. Call into runtime system. |   316   // Need to collect. Call into runtime system. | 
|   317   __ bind(&gc); |   317   __ bind(&gc); | 
|   318   __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); |   318   __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); | 
|   319 } |   319 } | 
|   320  |   320  | 
|   321  |   321  | 
|   322 static void GenerateFastCloneShallowArrayCommon( |   322 static void GenerateFastCloneShallowArrayCommon( | 
|   323     MacroAssembler* masm, |   323     MacroAssembler* masm, | 
|   324     int length, |   324     int length, | 
|   325     FastCloneShallowArrayStub::Mode mode, |   325     FastCloneShallowArrayStub::Mode mode, | 
 |   326     AllocationSiteInfoMode allocation_site_info_mode, | 
|   326     Label* fail) { |   327     Label* fail) { | 
|   327   // Registers on entry: |   328   // Registers on entry: | 
|   328   // |   329   // | 
|   329   // ecx: boilerplate literal array. |   330   // ecx: boilerplate literal array. | 
|   330   ASSERT(mode != FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS); |   331   ASSERT(mode != FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS); | 
|   331  |   332  | 
|   332   // All sizes here are multiples of kPointerSize. |   333   // All sizes here are multiples of kPointerSize. | 
|   333   int elements_size = 0; |   334   int elements_size = 0; | 
|   334   if (length > 0) { |   335   if (length > 0) { | 
|   335     elements_size = mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS |   336     elements_size = mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS | 
|   336         ? FixedDoubleArray::SizeFor(length) |   337         ? FixedDoubleArray::SizeFor(length) | 
|   337         : FixedArray::SizeFor(length); |   338         : FixedArray::SizeFor(length); | 
|   338   } |   339   } | 
|   339   int size = JSArray::kSize + elements_size; |   340   int size = JSArray::kSize; | 
 |   341   int allocation_info_start = size; | 
 |   342   if (allocation_site_info_mode == TRACK_ALLOCATION_SITE_INFO) { | 
 |   343     size += AllocationSiteInfo::kSize; | 
 |   344   } | 
 |   345   size += elements_size; | 
|   340  |   346  | 
|   341   // Allocate both the JS array and the elements array in one big |   347   // Allocate both the JS array and the elements array in one big | 
|   342   // allocation. This avoids multiple limit checks. |   348   // allocation. This avoids multiple limit checks. | 
|   343   AllocationFlags flags = TAG_OBJECT; |   349   AllocationFlags flags = TAG_OBJECT; | 
|   344   if (mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS) { |   350   if (mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS) { | 
|   345     flags = static_cast<AllocationFlags>(DOUBLE_ALIGNMENT | flags); |   351     flags = static_cast<AllocationFlags>(DOUBLE_ALIGNMENT | flags); | 
|   346   } |   352   } | 
|   347   __ AllocateInNewSpace(size, eax, ebx, edx, fail, flags); |   353   __ AllocateInNewSpace(size, eax, ebx, edx, fail, flags); | 
|   348  |   354  | 
 |   355   if (allocation_site_info_mode == TRACK_ALLOCATION_SITE_INFO) { | 
 |   356     __ mov(FieldOperand(eax, allocation_info_start), | 
 |   357            Immediate(Handle<Map>(masm->isolate()->heap()-> | 
 |   358                                  allocation_site_info_map()))); | 
 |   359     __ mov(FieldOperand(eax, allocation_info_start + kPointerSize), ecx); | 
 |   360   } | 
 |   361  | 
|   349   // Copy the JS array part. |   362   // Copy the JS array part. | 
|   350   for (int i = 0; i < JSArray::kSize; i += kPointerSize) { |   363   for (int i = 0; i < JSArray::kSize; i += kPointerSize) { | 
|   351     if ((i != JSArray::kElementsOffset) || (length == 0)) { |   364     if ((i != JSArray::kElementsOffset) || (length == 0)) { | 
|   352       __ mov(ebx, FieldOperand(ecx, i)); |   365       __ mov(ebx, FieldOperand(ecx, i)); | 
|   353       __ mov(FieldOperand(eax, i), ebx); |   366       __ mov(FieldOperand(eax, i), ebx); | 
|   354     } |   367     } | 
|   355   } |   368   } | 
|   356  |   369  | 
|   357   if (length > 0) { |   370   if (length > 0) { | 
|   358     // Get hold of the elements array of the boilerplate and setup the |   371     // Get hold of the elements array of the boilerplate and setup the | 
|   359     // elements pointer in the resulting object. |   372     // elements pointer in the resulting object. | 
|   360     __ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset)); |   373     __ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset)); | 
|   361     __ lea(edx, Operand(eax, JSArray::kSize)); |   374     if (allocation_site_info_mode == TRACK_ALLOCATION_SITE_INFO) { | 
 |   375       __ lea(edx, Operand(eax, JSArray::kSize + AllocationSiteInfo::kSize)); | 
 |   376     } else { | 
 |   377       __ lea(edx, Operand(eax, JSArray::kSize)); | 
 |   378     } | 
|   362     __ mov(FieldOperand(eax, JSArray::kElementsOffset), edx); |   379     __ mov(FieldOperand(eax, JSArray::kElementsOffset), edx); | 
|   363  |   380  | 
|   364     // Copy the elements array. |   381     // Copy the elements array. | 
|   365     if (mode == FastCloneShallowArrayStub::CLONE_ELEMENTS) { |   382     if (mode == FastCloneShallowArrayStub::CLONE_ELEMENTS) { | 
|   366       for (int i = 0; i < elements_size; i += kPointerSize) { |   383       for (int i = 0; i < elements_size; i += kPointerSize) { | 
|   367         __ mov(ebx, FieldOperand(ecx, i)); |   384         __ mov(ebx, FieldOperand(ecx, i)); | 
|   368         __ mov(FieldOperand(edx, i), ebx); |   385         __ mov(FieldOperand(edx, i), ebx); | 
|   369       } |   386       } | 
|   370     } else { |   387     } else { | 
|   371       ASSERT(mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS); |   388       ASSERT(mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS); | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
|   401   STATIC_ASSERT(kSmiTag == 0); |   418   STATIC_ASSERT(kSmiTag == 0); | 
|   402   __ mov(ecx, FieldOperand(ecx, eax, times_half_pointer_size, |   419   __ mov(ecx, FieldOperand(ecx, eax, times_half_pointer_size, | 
|   403                            FixedArray::kHeaderSize)); |   420                            FixedArray::kHeaderSize)); | 
|   404   Factory* factory = masm->isolate()->factory(); |   421   Factory* factory = masm->isolate()->factory(); | 
|   405   __ cmp(ecx, factory->undefined_value()); |   422   __ cmp(ecx, factory->undefined_value()); | 
|   406   Label slow_case; |   423   Label slow_case; | 
|   407   __ j(equal, &slow_case); |   424   __ j(equal, &slow_case); | 
|   408  |   425  | 
|   409   FastCloneShallowArrayStub::Mode mode = mode_; |   426   FastCloneShallowArrayStub::Mode mode = mode_; | 
|   410   // ecx is boilerplate object. |   427   // ecx is boilerplate object. | 
 |   428   AllocationSiteInfoMode allocation_site_info_mode = | 
 |   429       DONT_TRACK_ALLOCATION_SITE_INFO; | 
 |   430   if (mode == CLONE_ANY_ELEMENTS_WITH_ALLOCATION_SITE_INFO) { | 
 |   431     mode = CLONE_ANY_ELEMENTS; | 
 |   432     allocation_site_info_mode = TRACK_ALLOCATION_SITE_INFO; | 
 |   433   } | 
 |   434  | 
|   411   if (mode == CLONE_ANY_ELEMENTS) { |   435   if (mode == CLONE_ANY_ELEMENTS) { | 
|   412     Label double_elements, check_fast_elements; |   436     Label double_elements, check_fast_elements; | 
|   413     __ mov(ebx, FieldOperand(ecx, JSArray::kElementsOffset)); |   437     __ mov(ebx, FieldOperand(ecx, JSArray::kElementsOffset)); | 
|   414     __ CheckMap(ebx, factory->fixed_cow_array_map(), |   438     __ CheckMap(ebx, factory->fixed_cow_array_map(), | 
|   415                 &check_fast_elements, DONT_DO_SMI_CHECK); |   439                 &check_fast_elements, DONT_DO_SMI_CHECK); | 
|   416     GenerateFastCloneShallowArrayCommon(masm, 0, |   440     GenerateFastCloneShallowArrayCommon(masm, 0, | 
|   417                                         COPY_ON_WRITE_ELEMENTS, &slow_case); |   441                                         COPY_ON_WRITE_ELEMENTS, | 
 |   442                                         allocation_site_info_mode, | 
 |   443                                         &slow_case); | 
|   418     __ ret(3 * kPointerSize); |   444     __ ret(3 * kPointerSize); | 
|   419  |   445  | 
|   420     __ bind(&check_fast_elements); |   446     __ bind(&check_fast_elements); | 
|   421     __ CheckMap(ebx, factory->fixed_array_map(), |   447     __ CheckMap(ebx, factory->fixed_array_map(), | 
|   422                 &double_elements, DONT_DO_SMI_CHECK); |   448                 &double_elements, DONT_DO_SMI_CHECK); | 
|   423     GenerateFastCloneShallowArrayCommon(masm, length_, |   449     GenerateFastCloneShallowArrayCommon(masm, length_, | 
|   424                                         CLONE_ELEMENTS, &slow_case); |   450                                         CLONE_ELEMENTS, | 
 |   451                                         allocation_site_info_mode, | 
 |   452                                         &slow_case); | 
|   425     __ ret(3 * kPointerSize); |   453     __ ret(3 * kPointerSize); | 
|   426  |   454  | 
|   427     __ bind(&double_elements); |   455     __ bind(&double_elements); | 
|   428     mode = CLONE_DOUBLE_ELEMENTS; |   456     mode = CLONE_DOUBLE_ELEMENTS; | 
|   429     // Fall through to generate the code to handle double elements. |   457     // Fall through to generate the code to handle double elements. | 
|   430   } |   458   } | 
|   431  |   459  | 
|   432   if (FLAG_debug_code) { |   460   if (FLAG_debug_code) { | 
|   433     const char* message; |   461     const char* message; | 
|   434     Handle<Map> expected_map; |   462     Handle<Map> expected_map; | 
|   435     if (mode == CLONE_ELEMENTS) { |   463     if (mode == CLONE_ELEMENTS) { | 
|   436       message = "Expected (writable) fixed array"; |   464       message = "Expected (writable) fixed array"; | 
|   437       expected_map = factory->fixed_array_map(); |   465       expected_map = factory->fixed_array_map(); | 
|   438     } else if (mode == CLONE_DOUBLE_ELEMENTS) { |   466     } else if (mode == CLONE_DOUBLE_ELEMENTS) { | 
|   439       message = "Expected (writable) fixed double array"; |   467       message = "Expected (writable) fixed double array"; | 
|   440       expected_map = factory->fixed_double_array_map(); |   468       expected_map = factory->fixed_double_array_map(); | 
|   441     } else { |   469     } else { | 
|   442       ASSERT(mode == COPY_ON_WRITE_ELEMENTS); |   470       ASSERT(mode == COPY_ON_WRITE_ELEMENTS); | 
|   443       message = "Expected copy-on-write fixed array"; |   471       message = "Expected copy-on-write fixed array"; | 
|   444       expected_map = factory->fixed_cow_array_map(); |   472       expected_map = factory->fixed_cow_array_map(); | 
|   445     } |   473     } | 
|   446     __ push(ecx); |   474     __ push(ecx); | 
|   447     __ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset)); |   475     __ mov(ecx, FieldOperand(ecx, JSArray::kElementsOffset)); | 
|   448     __ cmp(FieldOperand(ecx, HeapObject::kMapOffset), expected_map); |   476     __ cmp(FieldOperand(ecx, HeapObject::kMapOffset), expected_map); | 
|   449     __ Assert(equal, message); |   477     __ Assert(equal, message); | 
|   450     __ pop(ecx); |   478     __ pop(ecx); | 
|   451   } |   479   } | 
|   452  |   480  | 
|   453   GenerateFastCloneShallowArrayCommon(masm, length_, mode, &slow_case); |   481   GenerateFastCloneShallowArrayCommon(masm, length_, mode, | 
 |   482                                       allocation_site_info_mode, &slow_case); | 
|   454   // Return and remove the on-stack parameters. |   483   // Return and remove the on-stack parameters. | 
|   455   __ ret(3 * kPointerSize); |   484   __ ret(3 * kPointerSize); | 
|   456  |   485  | 
|   457   __ bind(&slow_case); |   486   __ bind(&slow_case); | 
|   458   __ TailCallRuntime(Runtime::kCreateArrayLiteralShallow, 3, 1); |   487   __ TailCallRuntime(Runtime::kCreateArrayLiteralShallow, 3, 1); | 
|   459 } |   488 } | 
|   460  |   489  | 
|   461  |   490  | 
|   462 void FastCloneShallowObjectStub::Generate(MacroAssembler* masm) { |   491 void FastCloneShallowObjectStub::Generate(MacroAssembler* masm) { | 
|   463   // Stack layout on entry: |   492   // Stack layout on entry: | 
| (...skipping 7012 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  7476   // Restore ecx. |  7505   // Restore ecx. | 
|  7477   __ pop(ecx); |  7506   __ pop(ecx); | 
|  7478   __ ret(0); |  7507   __ ret(0); | 
|  7479 } |  7508 } | 
|  7480  |  7509  | 
|  7481 #undef __ |  7510 #undef __ | 
|  7482  |  7511  | 
|  7483 } }  // namespace v8::internal |  7512 } }  // namespace v8::internal | 
|  7484  |  7513  | 
|  7485 #endif  // V8_TARGET_ARCH_IA32 |  7514 #endif  // V8_TARGET_ARCH_IA32 | 
| OLD | NEW |