Commit 48fd3dca authored by vitalyr@chromium.org's avatar vitalyr@chromium.org

Fix copy-on-write assert by setting the new array map early.

BUG=876

Review URL: http://codereview.chromium.org/3466013

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5513 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 622351fe
......@@ -59,6 +59,11 @@ Object* Heap::AllocateSymbol(Vector<const char> str,
}
Object* Heap::CopyFixedArray(FixedArray* src) {
return CopyFixedArrayWithMap(src, src->map());
}
Object* Heap::AllocateRaw(int size_in_bytes,
AllocationSpace space,
AllocationSpace retry_space) {
......
......@@ -3205,16 +3205,19 @@ Object* Heap::AllocateRawFixedArray(int length) {
}
Object* Heap::CopyFixedArray(FixedArray* src) {
Object* Heap::CopyFixedArrayWithMap(FixedArray* src, Map* map) {
int len = src->length();
Object* obj = AllocateRawFixedArray(len);
if (obj->IsFailure()) return obj;
if (Heap::InNewSpace(obj)) {
HeapObject* dst = HeapObject::cast(obj);
CopyBlock(dst->address(), src->address(), FixedArray::SizeFor(len));
dst->set_map(map);
CopyBlock(dst->address() + kPointerSize,
src->address() + kPointerSize,
FixedArray::SizeFor(len) - kPointerSize);
return obj;
}
HeapObject::cast(obj)->set_map(src->map());
HeapObject::cast(obj)->set_map(map);
FixedArray* result = FixedArray::cast(obj);
result->set_length(len);
......
......@@ -498,7 +498,12 @@ class Heap : public AllStatic {
// Make a copy of src and return it. Returns
// Failure::RetryAfterGC(requested_bytes, space) if the allocation failed.
MUST_USE_RESULT static Object* CopyFixedArray(FixedArray* src);
MUST_USE_RESULT static inline Object* CopyFixedArray(FixedArray* src);
// Make a copy of src, set the map, and return the copy. Returns
// Failure::RetryAfterGC(requested_bytes, space) if the allocation failed.
MUST_USE_RESULT static Object* CopyFixedArrayWithMap(FixedArray* src,
Map* map);
// Allocates a fixed array initialized with the hole values.
// Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
......
......@@ -3187,9 +3187,9 @@ Object* JSObject::EnsureWritableFastElements() {
ASSERT(HasFastElements());
FixedArray* elems = FixedArray::cast(elements());
if (elems->map() != Heap::fixed_cow_array_map()) return elems;
Object* writable_elems = Heap::CopyFixedArray(elems);
Object* writable_elems = Heap::CopyFixedArrayWithMap(elems,
Heap::fixed_array_map());
if (writable_elems->IsFailure()) return writable_elems;
FixedArray::cast(writable_elems)->set_map(Heap::fixed_array_map());
set_elements(FixedArray::cast(writable_elems));
Counters::cow_arrays_converted.Increment();
return writable_elems;
......
// Copyright 2010 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
function createLargeCOWArray() {
var s = "[0";
// The constant below depends on the max object size in new space.
for (var i = 0; i < (128 << 10); i++) {
s += ",0";
}
s += "]";
return eval(s);
}
var large_cow_array = createLargeCOWArray();
// Force copy. Because the array is large it will test the slow array
// cloning in large object space.
large_cow_array[17] = 42;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment