Reviewers: Jakob, danno, Paul Lind, kisg,

Message:
In case you don't like having the arch-specific define in the code, here are
some more solutions that could be implemented:

-set this size to 8 bytes on all architectures. It probably won't matter.
-use something similar to alignof (like in
http://codereview.chromium.org/9702114/), possibly combined with some bitwise
magic to get the necessary size.

Description:
MIPS: Increase external array allocation header size to 8 bytes.

This fixes alignment issues on MIPS HW, found for example in mjsunit
external-array.
The issue originates from r11144 (86563c3e21) which adds a 4-byte header to
these arrays.
This causes problems on MIPS, where certain pointers need to be 8-byte aligned.

BUG=
TEST=mjsunit/external-array


Please review this at http://codereview.chromium.org/9956049/

SVN Base: git://github.com/v8/v8.git@bleeding_edge

Affected files:
  M src/d8.cc


Index: src/d8.cc
diff --git a/src/d8.cc b/src/d8.cc
index 1e8b4c8a2011935672b7ac054b51a34ae932f8a4..705a19291fc76b82982842f99a38419c16bdff55 100644
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -318,6 +318,11 @@ static size_t convertToUint(Local<Value> value_in, TryCatch* try_catch) {
 const char kArrayBufferReferencePropName[] = "_is_array_buffer_";
 const char kArrayBufferMarkerPropName[] = "_array_buffer_ref_";

+#if V8_TARGET_ARCH_MIPS
+static const int kExternalArrayAllocationHeaderSize = 2;
+#else
+static const int kExternalArrayAllocationHeaderSize = 1;
+#endif

 Handle<Value> Shell::CreateExternalArray(const Arguments& args,
                                          ExternalArrayType type,
@@ -433,13 +438,14 @@ Handle<Value> Shell::CreateExternalArray(const Arguments& args, return ThrowException(String::New("Array exceeds maximum size (2G)"));
     }
     // Prepend the size of the allocated chunk to the data itself.
-    int total_size = length * element_size + sizeof(size_t);
+    int total_size = length * element_size +
+        kExternalArrayAllocationHeaderSize * sizeof(size_t);
     data = malloc(total_size);
     if (data == NULL) {
       return ThrowException(String::New("Memory allocation failed."));
     }
     *reinterpret_cast<size_t*>(data) = total_size;
-    data = reinterpret_cast<size_t*>(data) + 1;
+ data = reinterpret_cast<size_t*>(data) + kExternalArrayAllocationHeaderSize;
     memset(data, 0, length * element_size);
     V8::AdjustAmountOfExternalAllocatedMemory(total_size);
   }
@@ -463,7 +469,7 @@ void Shell::ExternalArrayWeakCallback(Persistent<Value> object, void* data) {
   Handle<Object> converted_object = object->ToObject();
   Local<Value> prop_value = converted_object->Get(prop_name);
   if (data != NULL && !prop_value->IsObject()) {
-    data = reinterpret_cast<size_t*>(data) - 1;
+ data = reinterpret_cast<size_t*>(data) - kExternalArrayAllocationHeaderSize;
     V8::AdjustAmountOfExternalAllocatedMemory(
         -static_cast<int>(*reinterpret_cast<size_t*>(data)));
     free(data);


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

Reply via email to