This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[RFA/JVMTI] _Jv_Malloc cleanup
- From: Keith Seitz <keiths at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: Wed, 20 Sep 2006 16:58:30 -0700
- Subject: [RFA/JVMTI] _Jv_Malloc cleanup
Hi,
Earlier Tom mentioned something about the _Jv_Malloc mess in jvmti.cc.
This patch changes all the calls to _Jv_Malloc to use
_Jv_MallocUnchecked and returns JVMTI_ERROR_OUT_OF_MEMORY when the
malloc fails.
Okay?
Keith
ChangeLog
2006-09-20 Keith Seitz <keiths@redhat.com>
* jvmti.cc (_Jv_JVMTI_CreateRawMonitor): Use _Jv_MallocUnchked
and return JVMTI_ERROR_OUT_OF_MEMORY if necessary.
(_Jv_JVMTI_GetClassMethods): Likewise.
(_Jv_JVMTI_GetClassLoaderClasses): Likewise.
(_Jv_JVMTI_GetJNIFunctionTable): Likewise.
(_Jv_JVMTI_GetSystemProperty): Likewise.
Index: jvmti.cc
===================================================================
--- jvmti.cc (revision 117093)
+++ jvmti.cc (working copy)
@@ -156,7 +156,9 @@
REQUIRE_PHASE (env, JVMTI_PHASE_ONLOAD | JVMTI_PHASE_LIVE);
NULL_CHECK (name);
NULL_CHECK (result);
- *result = (jrawMonitorID) _Jv_Malloc (sizeof (_Jv_rawMonitorID));
+ *result = (jrawMonitorID) _Jv_MallocUnchecked (sizeof (_Jv_rawMonitorID));
+ if (*result == NULL)
+ return JVMTI_ERROR_OUT_OF_MEMORY;
_Jv_MutexInit (&(*result)->mutex);
_Jv_CondInit (&(*result)->condition);
return JVMTI_ERROR_NONE;
@@ -285,7 +287,11 @@
NULL_CHECK (methods_ptr);
*count_ptr = JvNumMethods(klass);
- *methods_ptr = (jmethodID *) _Jv_Malloc (*count_ptr * sizeof (jmethodID));
+ *methods_ptr
+ = (jmethodID *) _Jv_MallocUnchecked (*count_ptr * sizeof (jmethodID));
+ if (*methods_ptr == NULL)
+ return JVMTI_ERROR_OUT_OF_MEMORY;
+
jmethodID start = JvGetFirstMethod (klass);
for (jint i = 0; i < *count_ptr; ++i)
// FIXME: correct?
@@ -437,7 +443,11 @@
jobjectArray array = values->toArray();
*count_ptr = array->length;
jobject *elts = elements (array);
- jclass *result = (jclass *) _Jv_Malloc (*count_ptr * sizeof (jclass));
+ jclass *result
+ = (jclass *) _Jv_MallocUnchecked (*count_ptr * sizeof (jclass));
+ if (result == NULL)
+ return JVMTI_ERROR_OUT_OF_MEMORY;
+
// FIXME: JNI references...
memcpy (result, elts, *count_ptr * sizeof (jclass));
@@ -471,7 +481,9 @@
REQUIRE_PHASE (env, JVMTI_PHASE_START | JVMTI_PHASE_LIVE);
NULL_CHECK (function_table);
*function_table
- = (jniNativeInterface *) _Jv_Malloc (sizeof (jniNativeInterface));
+ = (jniNativeInterface *) _Jv_MallocUnchecked (sizeof (jniNativeInterface));
+ if (*function_table == NULL)
+ return JVMTI_ERROR_OUT_OF_MEMORY;
memcpy (*function_table, &_Jv_JNIFunctions, sizeof (jniNativeInterface));
return JVMTI_ERROR_NONE;
}
@@ -525,7 +537,9 @@
return JVMTI_ERROR_NOT_AVAILABLE;
int len = JvGetStringUTFLength (result_str);
- *result = (char *) _Jv_Malloc (len + 1);
+ *result = (char *) _Jv_MallocUnchecked (len + 1);
+ if (*result == NULL)
+ return JVMTI_ERROR_OUT_OF_MEMORY;
JvGetStringUTFRegion (result_str, 0, result_str->length(), *result);
(*result)[len] = '\0';