Author: [EMAIL PROTECTED]
Date: Sun Oct 19 23:35:28 2008
New Revision: 524

Modified:
    branches/bleeding_edge/src/heap.cc
    branches/bleeding_edge/src/heap.h
    branches/bleeding_edge/src/objects-inl.h
    branches/bleeding_edge/src/objects.cc
    branches/bleeding_edge/src/objects.h

Log:
- Optimized copying of FixedArray.

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

Modified: branches/bleeding_edge/src/heap.cc
==============================================================================
--- branches/bleeding_edge/src/heap.cc  (original)
+++ branches/bleeding_edge/src/heap.cc  Sun Oct 19 23:35:28 2008
@@ -2034,6 +2034,43 @@
  }


+Object* Heap::AllocateRawFixedArray(int length) {
+  // Allocate the raw data for a fixed array.
+  int size = FixedArray::SizeFor(length);
+  return (size > MaxHeapObjectSize())
+      ? lo_space_->AllocateRawFixedArray(size)
+      : new_space_.AllocateRaw(size);
+}
+
+
+Object* Heap::CopyFixedArray(FixedArray* src) {
+  int len = src->length();
+  Object* obj = Heap::AllocateRawFixedArray(len);
+  if (obj->IsFailure()) return obj;
+  HeapObject::cast(obj)->set_map(src->map());
+  FixedArray* result = FixedArray::cast(obj);
+  result->set_length(len);
+  FixedArray::WriteBarrierMode mode = result->GetWriteBarrierMode();
+  // Copy the content
+  for (int i = 0; i < len; i++) result->set(i, src->get(i), mode);
+  return result;
+}
+
+
+Object* Heap::AllocateFixedArray(int length) {
+  Object* result = AllocateRawFixedArray(length);
+  if (!result->IsFailure()) {
+    // Initialize header.
+    reinterpret_cast<Array*>(result)->set_map(fixed_array_map());
+    FixedArray* array = FixedArray::cast(result);
+    array->set_length(length);
+    // Initialize body.
+    for (int index = 0; index < length; index++)  
array->set_undefined(index);
+  }
+  return result;
+}
+
+
  Object* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) {
    ASSERT(empty_fixed_array()->IsFixedArray());
    if (length == 0) return empty_fixed_array();
@@ -2060,18 +2097,16 @@

  Object* Heap::AllocateFixedArrayWithHoles(int length) {
    if (length == 0) return empty_fixed_array();
-  int size = FixedArray::SizeFor(length);
-  Object* result = size > MaxHeapObjectSize()
-      ? lo_space_->AllocateRawFixedArray(size)
-      : AllocateRaw(size, NEW_SPACE);
-  if (result->IsFailure()) return result;
-
-  // Initialize the object.
-  reinterpret_cast<Array*>(result)->set_map(fixed_array_map());
-  FixedArray* array = FixedArray::cast(result);
-  array->set_length(length);
-  for (int index = 0; index < length; index++) array->set_the_hole(index);
-  return array;
+  Object* result = AllocateRawFixedArray(length);
+  if (!result->IsFailure()) {
+    // Initialize header.
+    reinterpret_cast<Array*>(result)->set_map(fixed_array_map());
+    FixedArray* array = FixedArray::cast(result);
+    array->set_length(length);
+    // Initialize body.
+    for (int index = 0; index < length; index++)  
array->set_the_hole(index);
+  }
+  return result;
  }



Modified: branches/bleeding_edge/src/heap.h
==============================================================================
--- branches/bleeding_edge/src/heap.h   (original)
+++ branches/bleeding_edge/src/heap.h   Sun Oct 19 23:35:28 2008
@@ -379,9 +379,13 @@
    // Returns Failure::RetryAfterGC(requested_bytes, space) if the  
allocation
    // failed.
    // Please note this does not perform a garbage collection.
-  static Object* AllocateFixedArray(int length,
-                                    PretenureFlag pretenure = NOT_TENURED);
-
+  static Object* AllocateFixedArray(int length, PretenureFlag pretenure);
+  // Allocate uninitialized, non-tenured fixed array with length elements.
+  static Object* AllocateFixedArray(int length);
+
+  // Make a copy of src and return it. Returns
+  // Failure::RetryAfterGC(requested_bytes, space) if the allocation  
failed.
+  static Object* CopyFixedArray(FixedArray* src);

    // Allocates a fixed array initialized with the hole values.
    // Returns Failure::RetryAfterGC(requested_bytes, space) if the  
allocation
@@ -814,6 +818,8 @@
    // (since both AllocateRaw and AllocateRawMap are inlined).
    static inline Object* AllocateRawMap(int size_in_bytes);

+  // Allocate unitialized fixed array (pretenure == NON_TENURE).
+  static Object* AllocateRawFixedArray(int length);

    // Initializes a JSObject based on its map.
    static void InitializeJSObjectFromMap(JSObject* obj,

Modified: branches/bleeding_edge/src/objects-inl.h
==============================================================================
--- branches/bleeding_edge/src/objects-inl.h    (original)
+++ branches/bleeding_edge/src/objects-inl.h    Sun Oct 19 23:35:28 2008
@@ -2295,6 +2295,12 @@
  }


+Object* FixedArray::Copy() {
+  if (length() == 0) return this;
+  return Heap::CopyFixedArray(this);
+}
+
+
  #undef CAST_ACCESSOR
  #undef INT_ACCESSORS
  #undef SMI_ACCESSORS

Modified: branches/bleeding_edge/src/objects.cc
==============================================================================
--- branches/bleeding_edge/src/objects.cc       (original)
+++ branches/bleeding_edge/src/objects.cc       Sun Oct 19 23:35:28 2008
@@ -889,13 +889,12 @@

  String* JSObject::class_name() {
    if (IsJSFunction()) return Heap::function_class_symbol();
-  // If the constructor is not present "Object" is returned.
-  String* result = Heap::Object_symbol();
    if (map()->constructor()->IsJSFunction()) {
      JSFunction* constructor = JSFunction::cast(map()->constructor());
      return String::cast(constructor->shared()->instance_class_name());
    }
-  return result;
+  // If the constructor is not present, return "Object".
+  return Heap::Object_symbol();
  }


@@ -2537,21 +2536,6 @@
    return result;
  }

-
-Object* FixedArray::Copy() {
-  int len = length();
-  if (len == 0) return this;
-  Object* obj = Heap::AllocateFixedArray(len);
-  if (obj->IsFailure()) return obj;
-  FixedArray* result = FixedArray::cast(obj);
-  WriteBarrierMode mode = result->GetWriteBarrierMode();
-  // Copy the content
-  for (int i = 0; i < len; i++) {
-    result->set(i, get(i), mode);
-  }
-  result->set_map(map());
-  return result;
-}

  Object* FixedArray::CopySize(int new_length) {
    if (new_length == 0) return Heap::empty_fixed_array();

Modified: branches/bleeding_edge/src/objects.h
==============================================================================
--- branches/bleeding_edge/src/objects.h        (original)
+++ branches/bleeding_edge/src/objects.h        Sun Oct 19 23:35:28 2008
@@ -1489,7 +1489,7 @@
    inline WriteBarrierMode GetWriteBarrierMode();

    // Copy operations.
-  Object* Copy();
+  inline Object* Copy();
    Object* CopySize(int new_length);

    // Add the elements of a JSArray to this FixedArray.

--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to