| OLD | NEW | 
|---|
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/builtins/builtins-utils.h" | 5 #include "src/builtins/builtins-utils.h" | 
| 6 #include "src/builtins/builtins.h" | 6 #include "src/builtins/builtins.h" | 
| 7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" | 
| 8 #include "src/code-stub-assembler.h" | 8 #include "src/code-stub-assembler.h" | 
| 9 #include "src/regexp/jsregexp.h" | 9 #include "src/regexp/jsregexp.h" | 
| 10 #include "src/regexp/regexp-utils.h" | 10 #include "src/regexp/regexp-utils.h" | 
| (...skipping 1368 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1379 | 1379 | 
| 1380     Node* const length = var_length_.value(); | 1380     Node* const length = var_length_.value(); | 
| 1381     Node* const capacity = var_capacity_.value(); | 1381     Node* const capacity = var_capacity_.value(); | 
| 1382 | 1382 | 
| 1383     Label grow(a), store(a); | 1383     Label grow(a), store(a); | 
| 1384     a->Branch(a->IntPtrEqual(capacity, length), &grow, &store); | 1384     a->Branch(a->IntPtrEqual(capacity, length), &grow, &store); | 
| 1385 | 1385 | 
| 1386     a->Bind(&grow); | 1386     a->Bind(&grow); | 
| 1387     { | 1387     { | 
| 1388       Node* const new_capacity = NewCapacity(a, capacity); | 1388       Node* const new_capacity = NewCapacity(a, capacity); | 
| 1389       Node* const new_array = GrowFixedArray(capacity, new_capacity, mode); | 1389       Node* const new_array = ResizeFixedArray(length, new_capacity, mode); | 
| 1390 | 1390 | 
| 1391       var_capacity_.Bind(new_capacity); | 1391       var_capacity_.Bind(new_capacity); | 
| 1392       var_array_.Bind(new_array); | 1392       var_array_.Bind(new_array); | 
| 1393       a->Goto(&store); | 1393       a->Goto(&store); | 
| 1394     } | 1394     } | 
| 1395 | 1395 | 
| 1396     a->Bind(&store); | 1396     a->Bind(&store); | 
| 1397     { | 1397     { | 
| 1398       Node* const array = var_array_.value(); | 1398       Node* const array = var_array_.value(); | 
| 1399       a->StoreFixedArrayElement(array, length, value, barrier_mode, 0, mode); | 1399       a->StoreFixedArrayElement(array, length, value, barrier_mode, 0, mode); | 
| 1400 | 1400 | 
| 1401       Node* const new_length = a->IntPtrAdd(length, a->IntPtrConstant(1)); | 1401       Node* const new_length = a->IntPtrAdd(length, a->IntPtrConstant(1)); | 
| 1402       var_length_.Bind(new_length); | 1402       var_length_.Bind(new_length); | 
| 1403     } | 1403     } | 
| 1404   } | 1404   } | 
| 1405 | 1405 | 
| 1406   Node* ToJSArray(Node* const context) { | 1406   Node* ToJSArray(Node* const context) { | 
| 1407     CodeStubAssembler* a = assembler_; | 1407     CodeStubAssembler* a = assembler_; | 
| 1408 | 1408 | 
| 1409     const ElementsKind kind = FAST_ELEMENTS; | 1409     const ElementsKind kind = FAST_ELEMENTS; | 
|  | 1410     const ParameterMode mode = CodeStubAssembler::INTPTR_PARAMETERS; | 
| 1410 | 1411 | 
| 1411     Node* const native_context = a->LoadNativeContext(context); | 1412     Node* const native_context = a->LoadNativeContext(context); | 
| 1412     Node* const array_map = a->LoadJSArrayElementsMap(kind, native_context); | 1413     Node* const array_map = a->LoadJSArrayElementsMap(kind, native_context); | 
| 1413 | 1414 | 
|  | 1415     // Shrink to fit if necessary. | 
|  | 1416     { | 
|  | 1417       Label next(a); | 
|  | 1418 | 
|  | 1419       Node* const length = var_length_.value(); | 
|  | 1420       Node* const capacity = var_capacity_.value(); | 
|  | 1421 | 
|  | 1422       a->GotoIf(a->WordEqual(length, capacity), &next); | 
|  | 1423 | 
|  | 1424       Node* const array = ResizeFixedArray(length, length, mode); | 
|  | 1425       var_array_.Bind(array); | 
|  | 1426       var_capacity_.Bind(length); | 
|  | 1427       a->Goto(&next); | 
|  | 1428 | 
|  | 1429       a->Bind(&next); | 
|  | 1430     } | 
|  | 1431 | 
| 1414     Node* const result_length = a->SmiTag(length()); | 1432     Node* const result_length = a->SmiTag(length()); | 
| 1415     Node* const result = a->AllocateUninitializedJSArrayWithoutElements( | 1433     Node* const result = a->AllocateUninitializedJSArrayWithoutElements( | 
| 1416         kind, array_map, result_length, nullptr); | 1434         kind, array_map, result_length, nullptr); | 
| 1417 | 1435 | 
| 1418     // Note: We do not currently shrink the fixed array. | 1436     // Note: We do not currently shrink the fixed array. | 
| 1419 | 1437 | 
| 1420     a->StoreObjectField(result, JSObject::kElementsOffset, var_array_.value()); | 1438     a->StoreObjectField(result, JSObject::kElementsOffset, var_array_.value()); | 
| 1421 | 1439 | 
| 1422     return result; | 1440     return result; | 
| 1423   } | 1441   } | 
| (...skipping 23 matching lines...) Expand all  Loading... | 
| 1447     // Growth rate is analog to JSObject::NewElementsCapacity: | 1465     // Growth rate is analog to JSObject::NewElementsCapacity: | 
| 1448     // new_capacity = (current_capacity + (current_capacity >> 1)) + 16. | 1466     // new_capacity = (current_capacity + (current_capacity >> 1)) + 16. | 
| 1449 | 1467 | 
| 1450     Node* const new_capacity = a->IntPtrAdd( | 1468     Node* const new_capacity = a->IntPtrAdd( | 
| 1451         a->IntPtrAdd(current_capacity, a->WordShr(current_capacity, 1)), | 1469         a->IntPtrAdd(current_capacity, a->WordShr(current_capacity, 1)), | 
| 1452         a->IntPtrConstant(16)); | 1470         a->IntPtrConstant(16)); | 
| 1453 | 1471 | 
| 1454     return new_capacity; | 1472     return new_capacity; | 
| 1455   } | 1473   } | 
| 1456 | 1474 | 
| 1457   Node* GrowFixedArray(Node* const current_capacity, Node* const new_capacity, | 1475   // Creates a new array with {new_capacity} and copies the first | 
| 1458                        ParameterMode mode) { | 1476   // {element_count} elements from the current array. | 
|  | 1477   Node* ResizeFixedArray(Node* const element_count, Node* const new_capacity, | 
|  | 1478                          ParameterMode mode) { | 
| 1459     DCHECK(mode == CodeStubAssembler::INTPTR_PARAMETERS); | 1479     DCHECK(mode == CodeStubAssembler::INTPTR_PARAMETERS); | 
| 1460 | 1480 | 
| 1461     CodeStubAssembler* a = assembler_; | 1481     CodeStubAssembler* a = assembler_; | 
| 1462 | 1482 | 
| 1463     CSA_ASSERT(a, a->IntPtrGreaterThan(current_capacity, a->IntPtrConstant(0))); | 1483     CSA_ASSERT(a, a->IntPtrGreaterThan(element_count, a->IntPtrConstant(0))); | 
| 1464     CSA_ASSERT(a, a->IntPtrGreaterThan(new_capacity, current_capacity)); | 1484     CSA_ASSERT(a, a->IntPtrGreaterThan(new_capacity, a->IntPtrConstant(0))); | 
|  | 1485     CSA_ASSERT(a, a->IntPtrGreaterThanOrEqual(new_capacity, element_count)); | 
| 1465 | 1486 | 
| 1466     const ElementsKind kind = FAST_ELEMENTS; | 1487     const ElementsKind kind = FAST_ELEMENTS; | 
| 1467     const WriteBarrierMode barrier_mode = UPDATE_WRITE_BARRIER; | 1488     const WriteBarrierMode barrier_mode = UPDATE_WRITE_BARRIER; | 
| 1468     const CodeStubAssembler::AllocationFlags flags = | 1489     const CodeStubAssembler::AllocationFlags flags = | 
| 1469         CodeStubAssembler::kAllowLargeObjectAllocation; | 1490         CodeStubAssembler::kAllowLargeObjectAllocation; | 
| 1470 | 1491 | 
| 1471     Node* const from_array = var_array_.value(); | 1492     Node* const from_array = var_array_.value(); | 
| 1472     Node* const to_array = | 1493     Node* const to_array = | 
| 1473         a->AllocateFixedArray(kind, new_capacity, mode, flags); | 1494         a->AllocateFixedArray(kind, new_capacity, mode, flags); | 
| 1474     a->CopyFixedArrayElements(kind, from_array, kind, to_array, | 1495     a->CopyFixedArrayElements(kind, from_array, kind, to_array, element_count, | 
| 1475                               current_capacity, new_capacity, barrier_mode, | 1496                               new_capacity, barrier_mode, mode); | 
| 1476                               mode); |  | 
| 1477 | 1497 | 
| 1478     return to_array; | 1498     return to_array; | 
| 1479   } | 1499   } | 
| 1480 | 1500 | 
| 1481  private: | 1501  private: | 
| 1482   CodeStubAssembler* const assembler_; | 1502   CodeStubAssembler* const assembler_; | 
| 1483   Variable var_array_; | 1503   Variable var_array_; | 
| 1484   Variable var_length_; | 1504   Variable var_length_; | 
| 1485   Variable var_capacity_; | 1505   Variable var_capacity_; | 
| 1486 }; | 1506 }; | 
| (...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2524   Bind(&if_matched); | 2544   Bind(&if_matched); | 
| 2525   { | 2545   { | 
| 2526     Node* result = | 2546     Node* result = | 
| 2527         ConstructNewResultFromMatchInfo(context, match_indices, string); | 2547         ConstructNewResultFromMatchInfo(context, match_indices, string); | 
| 2528     Return(result); | 2548     Return(result); | 
| 2529   } | 2549   } | 
| 2530 } | 2550 } | 
| 2531 | 2551 | 
| 2532 }  // namespace internal | 2552 }  // namespace internal | 
| 2533 }  // namespace v8 | 2553 }  // namespace v8 | 
| OLD | NEW | 
|---|