Commit ad86a903 by Tom Tromey Committed by Tom Tromey

prims.cc (_Jv_NewObjectArray): Use palcement new to create array.

	* prims.cc (_Jv_NewObjectArray): Use palcement new to create
	array.
	(_Jv_NewPrimArray): Likewise.
	Include <new>.
	* gcj/array.h (__JArray): `length' field now const.  Added
	constructor.
	(class JArray): Added constructor.

From-SVN: r37718
parent 81d87b4e
2000-11-24 Tom Tromey <tromey@cygnus.com>
* prims.cc (_Jv_NewObjectArray): Use palcement new to create
array.
(_Jv_NewPrimArray): Likewise.
Include <new>.
* gcj/array.h (__JArray): `length' field now const. Added
constructor.
(class JArray): Added constructor.
2000-11-23 Mark Wielaard <mark@klomp.org> 2000-11-23 Mark Wielaard <mark@klomp.org>
* name-finder.cc (lookup): Check for a NULL _Jv_argv before attempting * name-finder.cc (lookup): Check for a NULL _Jv_argv before attempting
......
// array.h - Header file for CNI arrays. -*- c++ -*- // array.h - Header file for CNI arrays. -*- c++ -*-
/* Copyright (C) 1998, 1999 Free Software Foundation /* Copyright (C) 1998, 1999, 2000 Free Software Foundation
This file is part of libgcj. This file is part of libgcj.
...@@ -17,11 +17,21 @@ extern "Java" { ...@@ -17,11 +17,21 @@ extern "Java" {
class __JArray : public java::lang::Object class __JArray : public java::lang::Object
{ {
protected:
// FIXME: this is a hack to work around a bug in the g++ Java
// support. If we add a constructor with a jsize argument to
// JArray<T>, then g++ complains.
__JArray () : length (0)
{
}
public: public:
// FIXME: we'd like this to be `const' but that causes problems with const jsize length;
// the C++ compiler.
jsize length;
friend jsize JvGetArrayLength (__JArray*); friend jsize JvGetArrayLength (__JArray*);
// This probably shouldn't be public.
__JArray (jsize l) : length (l)
{
}
}; };
template<class T> template<class T>
......
...@@ -67,6 +67,9 @@ details. */ ...@@ -67,6 +67,9 @@ details. */
#include <ltdl.h> #include <ltdl.h>
#endif #endif
// We use placement new.
#include <new>
// We allocate a single OutOfMemoryError exception which we keep // We allocate a single OutOfMemoryError exception which we keep
// around for use if we run out of memory. // around for use if we run out of memory.
static java::lang::OutOfMemoryError *no_memory; static java::lang::OutOfMemoryError *no_memory;
...@@ -411,8 +414,9 @@ _Jv_NewObjectArray (jsize count, jclass elementClass, jobject init) ...@@ -411,8 +414,9 @@ _Jv_NewObjectArray (jsize count, jclass elementClass, jobject init)
obj = (jobjectArray) _Jv_AllocArray (size, klass); obj = (jobjectArray) _Jv_AllocArray (size, klass);
if (__builtin_expect (! obj, false)) if (__builtin_expect (! obj, false))
JvThrow (no_memory); JvThrow (no_memory);
obj->length = count; // Use placement new to initialize length field.
jobject* ptr = elements(obj); new (obj) __JArray (count);
jobject *ptr = elements(obj);
// We know the allocator returns zeroed memory. So don't bother // We know the allocator returns zeroed memory. So don't bother
// zeroing it again. // zeroing it again.
if (init) if (init)
...@@ -446,7 +450,8 @@ _Jv_NewPrimArray (jclass eltype, jint count) ...@@ -446,7 +450,8 @@ _Jv_NewPrimArray (jclass eltype, jint count)
__JArray *arr = (__JArray*) _Jv_AllocObj (size + elsize * count, klass); __JArray *arr = (__JArray*) _Jv_AllocObj (size + elsize * count, klass);
if (__builtin_expect (! arr, false)) if (__builtin_expect (! arr, false))
JvThrow (no_memory); 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. // Note that we assume we are given zeroed memory by the allocator.
return arr; return arr;
......
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