diff options
Diffstat (limited to 'libjava/prims.cc')
-rw-r--r-- | libjava/prims.cc | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/libjava/prims.cc b/libjava/prims.cc index 8ca05da3905..22fa4b64070 100644 --- a/libjava/prims.cc +++ b/libjava/prims.cc @@ -67,6 +67,9 @@ details. */ #include <ltdl.h> #endif +// We use placement new. +#include <new> + // We allocate a single OutOfMemoryError exception which we keep // around for use if we run out of memory. static java::lang::OutOfMemoryError *no_memory; @@ -411,8 +414,9 @@ _Jv_NewObjectArray (jsize count, jclass elementClass, jobject init) obj = (jobjectArray) _Jv_AllocArray (size, klass); if (__builtin_expect (! obj, false)) JvThrow (no_memory); - obj->length = count; - jobject* ptr = elements(obj); + // Use placement new to initialize length field. + new (obj) __JArray (count); + jobject *ptr = elements(obj); // We know the allocator returns zeroed memory. So don't bother // zeroing it again. if (init) @@ -446,7 +450,8 @@ _Jv_NewPrimArray (jclass eltype, jint count) __JArray *arr = (__JArray*) _Jv_AllocObj (size + elsize * count, klass); if (__builtin_expect (! arr, false)) JvThrow (no_memory); - arr->length = count; + // Use placement new to initialize length field. + new (arr) __JArray (count); // Note that we assume we are given zeroed memory by the allocator. return arr; |