summaryrefslogtreecommitdiffstats
path: root/libjava/prims.cc
diff options
context:
space:
mode:
authorbryce <bryce@138bc75d-0d04-0410-961f-82ee72b054a4>2004-04-16 16:27:19 +0000
committerbryce <bryce@138bc75d-0d04-0410-961f-82ee72b054a4>2004-04-16 16:27:19 +0000
commitd8fff3ca9b99a853557ccd9e5d78510d4a39e22d (patch)
treef8e6ed92c4715a9964e9461e0650bbca33471270 /libjava/prims.cc
parent33ea6cc075fce69981316855b3ebe9e666489df9 (diff)
downloadppe42-gcc-d8fff3ca9b99a853557ccd9e5d78510d4a39e22d.tar.gz
ppe42-gcc-d8fff3ca9b99a853557ccd9e5d78510d4a39e22d.zip
libjava:
2004-04-15 Bryce McKinlay <mckinlay@redhat.com> * prims.cc (_Jv_AllocObject): Remove `size' argument. (_Jv_AllocObjectNoFinalizer): Likewise. (_Jv_AllocObjectNoInitNoFinalizer): Likewise. (_Jv_AllocPtrFreeObject): Likewise. (_Jv_AllocString): Moved from natString.cc. Call collector interface directly even in the JVMPI case. * gcj/cni.h (JvAllocObject): Remove `size' argument from _Jv_AllocObject calls. * gcj/javaprims.h: Update prototypes. * gnu/gcj/natCore.cc (_Jv_create_core): Use `new', not _Jv_AllocObject. * java/lang/Class.h: Update _Jv_AllocObject friend prototype. * java/lang/natString.cc (_Jv_AllocString): Move to prims.cc. gcc/cp: 2004-04-15 Bryce McKinlay <mckinlay@redhat.com> * init.c (build_new_1): Don't use type size argument for Java _Jv_AllocObject call. gcc/java: 2004-04-15 Bryce McKinlay <mckinlay@redhat.com> * expr.c (expand_java_NEW): Don't use size argument for _Jv_AllocObject calls. * parse.y (patch_invoke): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@80754 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/prims.cc')
-rw-r--r--libjava/prims.cc66
1 files changed, 57 insertions, 9 deletions
diff --git a/libjava/prims.cc b/libjava/prims.cc
index 06791d388f3..29f2b2090e8 100644
--- a/libjava/prims.cc
+++ b/libjava/prims.cc
@@ -389,16 +389,15 @@ jvmpi_notify_alloc(jclass klass, jint size, jobject obj)
# define jvmpi_notify_alloc(klass,size,obj) /* do nothing */
#endif
-// Allocate a new object of class KLASS. SIZE is the size of the object
-// to allocate. You might think this is redundant, but it isn't; some
-// classes, such as String, aren't of fixed size.
+// Allocate a new object of class KLASS.
// First a version that assumes that we have no finalizer, and that
// the class is already initialized.
// If we know that JVMPI is disabled, this can be replaced by a direct call
// to the allocator for the appropriate GC.
jobject
-_Jv_AllocObjectNoInitNoFinalizer (jclass klass, jint size)
+_Jv_AllocObjectNoInitNoFinalizer (jclass klass)
{
+ jint size = klass->size ();
jobject obj = (jobject) _Jv_AllocObj (size, klass);
jvmpi_notify_alloc (klass, size, obj);
return obj;
@@ -406,9 +405,10 @@ _Jv_AllocObjectNoInitNoFinalizer (jclass klass, jint size)
// And now a version that initializes if necessary.
jobject
-_Jv_AllocObjectNoFinalizer (jclass klass, jint size)
+_Jv_AllocObjectNoFinalizer (jclass klass)
{
_Jv_InitClass (klass);
+ jint size = klass->size ();
jobject obj = (jobject) _Jv_AllocObj (size, klass);
jvmpi_notify_alloc (klass, size, obj);
return obj;
@@ -416,10 +416,10 @@ _Jv_AllocObjectNoFinalizer (jclass klass, jint size)
// And now the general version that registers a finalizer if necessary.
jobject
-_Jv_AllocObject (jclass klass, jint size)
+_Jv_AllocObject (jclass klass)
{
- jobject obj = _Jv_AllocObjectNoFinalizer (klass, size);
-
+ jobject obj = _Jv_AllocObjectNoFinalizer (klass);
+
// We assume that the compiler only generates calls to this routine
// if there really is an interesting finalizer.
// Unfortunately, we still have to the dynamic test, since there may
@@ -432,14 +432,62 @@ _Jv_AllocObject (jclass klass, jint size)
return obj;
}
+// Allocate a String, including variable length storage.
+jstring
+_Jv_AllocString(jsize len)
+{
+ using namespace java::lang;
+
+ jsize sz = sizeof(java::lang::String) + len * sizeof(jchar);
+
+ // We assert that for strings allocated this way, the data field
+ // will always point to the object itself. Thus there is no reason
+ // for the garbage collector to scan any of it.
+ // Furthermore, we're about to overwrite the string data, so
+ // initialization of the object is not an issue.
+
+ // String needs no initialization, and there is no finalizer, so
+ // we can go directly to the collector's allocator interface.
+ jstring obj = (jstring) _Jv_AllocPtrFreeObj(sz, &String::class$);
+
+ obj->data = obj;
+ obj->boffset = sizeof(java::lang::String);
+ obj->count = len;
+ obj->cachedHashCode = 0;
+
+#ifdef ENABLE_JVMPI
+ // Service JVMPI request.
+
+ if (__builtin_expect (_Jv_JVMPI_Notify_OBJECT_ALLOC != 0, false))
+ {
+ JVMPI_Event event;
+
+ event.event_type = JVMPI_EVENT_OBJECT_ALLOC;
+ event.env_id = NULL;
+ event.u.obj_alloc.arena_id = 0;
+ event.u.obj_alloc.class_id = (jobjectID) &String::class$;
+ event.u.obj_alloc.is_array = 0;
+ event.u.obj_alloc.size = sz;
+ event.u.obj_alloc.obj_id = (jobjectID) obj;
+
+ _Jv_DisableGC ();
+ (*_Jv_JVMPI_Notify_OBJECT_ALLOC) (&event);
+ _Jv_EnableGC ();
+ }
+#endif
+
+ return obj;
+}
+
// A version of the above that assumes the object contains no pointers,
// and requires no finalization. This can't happen if we need pointers
// to locks.
#ifdef JV_HASH_SYNCHRONIZATION
jobject
-_Jv_AllocPtrFreeObject (jclass klass, jint size)
+_Jv_AllocPtrFreeObject (jclass klass)
{
_Jv_InitClass (klass);
+ jint size = klass->size ();
jobject obj = (jobject) _Jv_AllocPtrFreeObj (size, klass);
OpenPOWER on IntegriCloud