From 0d1b90f8aa3c11e88028e2b53e32b84a9b44f99c Mon Sep 17 00:00:00 2001 From: "dslomov@chromium.org" Date: Fri, 28 Mar 2014 08:59:46 +0000 Subject: [PATCH] Fix deopts causing uninitialized fixed typed arrays. The deopt will not happen in production code, since we check that lengths of fixed typed arrays are smis before calling TypedArrayInitialze, but that makes deopt bot happy. R=svenpanne@chromium.org Review URL: https://codereview.chromium.org/212643016 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20324 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/hydrogen.cc | 15 ++++++++++----- src/runtime.cc | 3 ++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/hydrogen.cc b/src/hydrogen.cc index a7ef0cb..77e7778 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -8510,6 +8510,10 @@ HValue* HOptimizedGraphBuilder::BuildAllocateExternalElements( HValue* buffer, HValue* byte_offset, HValue* length) { Handle external_array_map( isolate()->heap()->MapForExternalArrayType(array_type)); + + // The HForceRepresentation is to prevent possible deopt on int-smi + // conversion after allocation but before the new object fields are set. + length = AddUncasted(length, Representation::Smi()); HValue* elements = Add( Add(ExternalArray::kAlignedSize), @@ -8518,6 +8522,8 @@ HValue* HOptimizedGraphBuilder::BuildAllocateExternalElements( external_array_map->instance_type()); AddStoreMapConstant(elements, external_array_map); + Add(elements, + HObjectAccess::ForFixedArrayLength(), length); HValue* backing_store = Add( buffer, static_cast(NULL), @@ -8535,13 +8541,10 @@ HValue* HOptimizedGraphBuilder::BuildAllocateExternalElements( typed_array_start = external_pointer; } - Add(elements, HObjectAccess::ForExternalArrayExternalPointer(), typed_array_start); - Add(elements, - HObjectAccess::ForFixedArrayLength(), length); return elements; } @@ -8565,6 +8568,9 @@ HValue* HOptimizedGraphBuilder::BuildAllocateFixedTypedArray( total_size->ClearFlag(HValue::kCanOverflow); } + // The HForceRepresentation is to prevent possible deopt on int-smi + // conversion after allocation but before the new object fields are set. + length = AddUncasted(length, Representation::Smi()); Handle fixed_typed_array_map( isolate()->heap()->MapForFixedTypedArray(array_type)); HValue* elements = @@ -8576,6 +8582,7 @@ HValue* HOptimizedGraphBuilder::BuildAllocateFixedTypedArray( Add(elements, HObjectAccess::ForFixedArrayLength(), length); + HValue* filler = Add(static_cast(0)); { @@ -8588,8 +8595,6 @@ HValue* HOptimizedGraphBuilder::BuildAllocateFixedTypedArray( builder.EndBody(); } - Add( - elements, HObjectAccess::ForFixedArrayLength(), length); return elements; } diff --git a/src/runtime.cc b/src/runtime.cc index 5142fd3..3195d20 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -1236,7 +1236,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArraySetFastCases) { RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayMaxSizeInHeap) { - ASSERT_OBJECT_SIZE(FLAG_typed_array_max_size_in_heap); + ASSERT_OBJECT_SIZE( + FLAG_typed_array_max_size_in_heap + FixedTypedArrayBase::kDataOffset); return Smi::FromInt(FLAG_typed_array_max_size_in_heap); } -- 2.7.4