This is the mail archive of the java-patches@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch to use __attribute__((__malloc__))



Last week I introduced a new function attribute to gcc: __malloc__.
This tells the compiler that the function returns a pointer that
cannot alias anything.  The compiler is able to generate slightly
better code given this information.

A compiler that doesn't understand the malloc attribute will issue
a warning when it comes across one (but not an error).  Any strong
objections to this before I commit?

1999-12-05  Anthony Green  <green@cygnus.com>

	* include/jvm.h: Declare many functions with
	__attribute__((__malloc__)).
	* gcj/javaprims.h: Ditto.


Index: gcj/javaprims.h
===================================================================
RCS file: /cvs/java/libgcj/libjava/gcj/javaprims.h,v
retrieving revision 1.2
diff -u -r1.2 javaprims.h
--- javaprims.h	1999/11/19 19:13:42	1.2
+++ javaprims.h	1999/12/05 15:59:37
@@ -257,20 +257,22 @@
 typedef struct _Jv_Field *jfieldID;
 typedef struct _Jv_Method *jmethodID;
 
-extern "C" jobject _Jv_AllocObject (jclass, jint);
+extern "C" jobject _Jv_AllocObject (jclass, jint) __attribute__((__malloc__));
 extern "C" jboolean _Jv_IsInstanceOf(jobject, jclass);
-extern "C" jstring _Jv_AllocString(jsize);
-extern "C" jstring _Jv_NewString (const jchar*, jsize);
+extern "C" jstring _Jv_AllocString(jsize) __attribute__((__malloc__));
+extern "C" jstring _Jv_NewString (const jchar*, jsize)
+  __attribute__((__malloc__));
 extern "C" jchar* _Jv_GetStringChars (jstring str);
 extern "C" jint _Jv_MonitorEnter (jobject);
 extern "C" jint _Jv_MonitorExit (jobject);
-extern "C" jstring _Jv_NewStringLatin1(const char*, jsize);
+extern "C" jstring _Jv_NewStringLatin1(const char*, jsize)
+  __attribute__((__malloc__));
 extern "C" jsize _Jv_GetStringUTFLength (jstring);
 extern "C" jsize _Jv_GetStringUTFRegion (jstring, jsize, jsize, char *);
 
 extern "C" void _Jv_Throw (void *) __attribute__ ((__noreturn__));
 extern "C" void _Jv_Sjlj_Throw (void *) __attribute__ ((__noreturn__));
-extern "C" void* _Jv_Malloc (jsize);
+extern "C" void* _Jv_Malloc (jsize) __attribute__((__malloc__));
 extern "C" void _Jv_Free (void*);
 
 typedef unsigned short _Jv_ushort __attribute__((__mode__(__HI__)));
Index: include/jvm.h
===================================================================
RCS file: /cvs/java/libgcj/libjava/include/jvm.h,v
retrieving revision 1.7
diff -u -r1.7 jvm.h
--- jvm.h	1999/11/25 00:36:51	1.7
+++ jvm.h	1999/12/05 15:59:37
@@ -61,11 +61,11 @@
 typedef void _Jv_FinalizerFunc (jobject);
 
 /* Allocate space for a new Java object.  */
-void *_Jv_AllocObj (jsize size);
+void *_Jv_AllocObj (jsize size) __attribute__((__malloc__));
 /* Allocate space for an array of Java objects.  */
-void *_Jv_AllocArray (jsize size);
+void *_Jv_AllocArray (jsize size) __attribute__((__malloc__));
 /* Allocate space that is known to be pointer-free.  */
-void *_Jv_AllocBytes (jsize size);
+void *_Jv_AllocBytes (jsize size) __attribute__((__malloc__));
 /* Initialize the GC.  */
 void _Jv_InitGC (void);
 /* Register a finalizer.  */
@@ -102,7 +102,7 @@
 void _Jv_SetMaximumHeapSize (const char *arg);
 
 /* Allocate some unscanned bytes.  Throw exception if out of memory.  */
-void *_Jv_AllocBytesChecked (jsize size);
+void *_Jv_AllocBytesChecked (jsize size) __attribute__((__malloc__));
 
 extern "C" void JvRunMain (jclass klass, int argc, const char **argv);
 void _Jv_RunMain (const char* name, int argc, const char **argv);
@@ -145,8 +145,10 @@
 }
 
 extern "C" void _Jv_ThrowBadArrayIndex (jint bad_index);
-extern "C" jobject _Jv_NewArray (jint type, jint size);
-extern "C" jobject _Jv_NewMultiArray (jclass klass, jint dims, ...);
+extern "C" jobject _Jv_NewArray (jint type, jint size)
+  __attribute__((__malloc__));
+extern "C" jobject _Jv_NewMultiArray (jclass klass, jint dims, ...)
+  __attribute__((__malloc__));
 extern "C" void *_Jv_CheckCast (jclass klass, jobject obj);
 extern "C" void *_Jv_LookupInterfaceMethod (jclass klass, Utf8Const *name,
 					    Utf8Const *signature);
@@ -160,7 +162,8 @@
 extern jclass _Jv_FindClassFromSignature (char *,
 					  java::lang::ClassLoader *loader);
 
-extern jobject _Jv_NewMultiArray (jclass, jint ndims, jint* dims);
+extern jobject _Jv_NewMultiArray (jclass, jint ndims, jint* dims)
+  __attribute__((__malloc__));
 
 /* Checked divide subroutines. */
 extern "C"

-- 
Anthony Green                                               Cygnus Solutions
                                                       Sunnyvale, California

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]