Patch: switch to __builtin_alloca

Anthony Green green@cygnus.com
Sat Feb 10 22:59:00 GMT 2001


I made a number of minor changes to libjava and the gcj build system
in order to improve cross-compilation, especially for embedded
targets.

The hope is that the runtime should just build, no matter what the
target.  Perhaps there will be no thread support, or even GC, but at
least something will work.  So, for instance, I just built an xscale
cross toolchain, and java programs run on the xscale simulator:

$ xscale-elf-gcj -o Hello --main=Hello Hello.java
$ xscale-elf-run Hello
Hello World!

Here's my first patch...

We don't really run configure tests for cross targets.  Rather than
mess about with alloca junk, let's just use __builtin_alloca.  This is
a GCC extension, but it is target independent - so it should be
available for all ports.  I struggled with alloca and newlib for a
while before a realized there was no point.


2001-02-10  Anthony Green  <green@redhat.com>

	* defineclass.cc: Don't include alloca.h.
	(prepare_pool_entry): Convert alloca to __builtin_alloca.
	* interpret.cc (run_normal): Ditto.
	(continue1): Ditto.
	* java/lang/natDouble.cc (parseDouble): Ditto.

Index: libjava/defineclass.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/defineclass.cc,v
retrieving revision 1.13
diff -u -r1.13 defineclass.cc
--- defineclass.cc	2000/10/20 23:25:57	1.13
+++ defineclass.cc	2001/02/11 06:48:28
@@ -25,9 +25,6 @@
 #ifdef INTERPRETER
 
 #include <stdlib.h>
-#if HAVE_ALLOCA_H
-#include <alloca.h>
-#endif
 #include <java-cpool.h>
 #include <gcj/cni.h>
 
@@ -678,7 +675,7 @@
 	// order to accomondate gcj's internal representation.
 
 	int len = get2u (this_data);
-	char *buffer = (char*) alloca (len);
+	char *buffer = (char*) __builtin_alloca (len);
 	char *s = ((char*) this_data)+2;
 
 	/* FIXME: avoid using a buffer here */
Index: libjava/interpret.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/interpret.cc,v
retrieving revision 1.22
diff -u -r1.22 interpret.cc
--- interpret.cc	2000/10/20 23:25:57	1.22
+++ interpret.cc	2001/02/11 06:48:31
@@ -36,9 +36,6 @@
 #ifdef INTERPRETER
 
 #include <stdlib.h>
-#if HAVE_ALLOCA_H
-#include <alloca.h>
-#endif
 
 static _Jv_Utf8Const *init_name = _Jv_makeUtf8Const ("<init>", 6);
 
@@ -336,8 +333,8 @@
   // "run" ro be inlined.  Otherwise gcc will ignore the inline directive.
   int storage_size = _this->max_stack+_this->max_locals;
   _Jv_InterpMethodInvocation* inv = (_Jv_InterpMethodInvocation*) 
-    alloca (sizeof (_Jv_InterpMethodInvocation)
-	    + storage_size * sizeof (_Jv_word));
+    __builtin_alloca (sizeof (_Jv_InterpMethodInvocation)
+		      + storage_size * sizeof (_Jv_word));
 
   jobject ex = _this->run (cif, ret, args, inv);
   if (ex != 0) _Jv_Throw (ex);
@@ -353,8 +350,8 @@
 
   int storage_size = _this->max_stack+_this->max_locals;
   _Jv_InterpMethodInvocation* inv = (_Jv_InterpMethodInvocation*) 
-    alloca (sizeof (_Jv_InterpMethodInvocation)
-	    + storage_size * sizeof (_Jv_word));
+    __builtin_alloca (sizeof (_Jv_InterpMethodInvocation)
+		      + storage_size * sizeof (_Jv_word));
 
   _Jv_MonitorEnter (rcv);
   jobject ex = _this->run (cif, ret, args, inv);
@@ -373,8 +370,8 @@
 
   int storage_size = _this->max_stack+_this->max_locals;
   _Jv_InterpMethodInvocation* inv = (_Jv_InterpMethodInvocation*) 
-    alloca (sizeof (_Jv_InterpMethodInvocation)
-	    + storage_size * sizeof (_Jv_word));
+    __builtin_alloca (sizeof (_Jv_InterpMethodInvocation)
+		      + storage_size * sizeof (_Jv_word));
 
   _Jv_MonitorEnter (sync);
   jobject ex = _this->run (cif, ret, args, inv);
@@ -2376,7 +2373,7 @@
 	jclass type    
 	  = (_Jv_ResolvePoolEntry (defining_class, kind_index)).clazz;
 	_Jv_InitClass (type);
-	jint *sizes    = (jint*) alloca (sizeof (jint)*dim);
+	jint *sizes    = (jint*) __builtin_alloca (sizeof (jint)*dim);
 
 	for (int i = dim - 1; i >= 0; i--)
 	  {
Index: libjava/java/lang/natDouble.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natDouble.cc,v
retrieving revision 1.11
diff -u -r1.11 natDouble.cc
--- natDouble.cc	2001/02/09 22:13:33	1.11
+++ natDouble.cc	2001/02/11 06:48:32
@@ -10,10 +10,6 @@
 
 #include <config.h>
 
-#if HAVE_ALLOCA_H
-#include <alloca.h>
-#endif
-
 #include <stdlib.h>
 
 #include <gcj/cni.h>
@@ -166,11 +162,7 @@
   int length = str->length();
   // Note that UTF can expand 3x.
 
-#ifdef HAVE_ALLOCA
-  char *data = (char *) alloca (3 * length + 1);
-#else
-#error --- need an alternate implementation here ---
-#endif
+  char *data = (char *) __builtin_alloca (3 * length + 1);
 
   data[_Jv_GetStringUTFRegion (str, 0, length, data)] = 0; 
 



More information about the Java-patches mailing list