This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[gcjx] Patch: FYI: (ugly) build fix + constant pool fixes
- From: Tom Tromey <tromey at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: 07 Mar 2005 18:18:56 -0700
- Subject: [gcjx] Patch: FYI: (ugly) build fix + constant pool fixes
- Reply-to: tromey at redhat dot com
I'm checking this in on the gcjx branch.
This patch fixes build_ref_from_constant_pool so that it works
instead of calling abort().
Also, output.h declares a function called output_constant_pool, but we
have a class named that in gcjx. The real fix will be to put all of
gcjx into its own namespace. Meanwhile we hack around the problem.
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* tree.hh (tree_generator::build_ref_from_constant_pool):
Updated.
* tree.cc (build_ref_from_constant_pool): Added 'type' argument.
(build_jni_stub): Updated.
(handle_string_literal): Updated.
* builtins.cc (HACK_WANT_OUTPUT_H): Define.
* glue.hh: Use HACK_WANT_OUTPUT_H.
* abi.cc (build_class_reference): Find constant pool.
* tree.cc (build_ref_from_constant_pool): Wrote.
* builtins.cc (get_constant_pool_decl): New method.
* builtins.hh (tree_builtins::cpool_map): New field.
(tree_builtins::get_constant_pool_decl): Declare.
* classobj.cc (create_constants): Handle "data" specially.
Correctly compute constructor contents. Ignore zero'th entry.
Index: abi.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/abi.cc,v
retrieving revision 1.1.2.9
diff -u -r1.1.2.9 abi.cc
--- abi.cc 8 Mar 2005 01:16:32 -0000 1.1.2.9
+++ abi.cc 8 Mar 2005 01:20:48 -0000
@@ -255,13 +255,13 @@
}
tree
-bc_abi::build_class_reference (tree_builtins *, aot_class *current,
+bc_abi::build_class_reference (tree_builtins *builtins,
+ aot_class *current,
const std::string &classname)
{
// FIXME: handle primitive classes
int index = current->add_class (classname);
- // FIXME: find the constant pool
- tree cpool = NULL_TREE;
+ tree cpool = builtins->get_constant_pool_decl (current->get ());
return build4 (ARRAY_REF, type_class_ptr,
cpool, build_int_cst (type_jint, index),
NULL_TREE, NULL_TREE);
@@ -274,8 +274,7 @@
{
// FIXME: handle primitive classes
int index = current->add (assert_cast<model_class *> (klass));
- // FIXME: find the constant pool
- tree cpool = NULL_TREE;
+ tree cpool = builtins->get_constant_pool_decl (current->get ());
return build4 (ARRAY_REF, type_class_ptr,
cpool, build_int_cst (type_jint, index),
NULL_TREE, NULL_TREE);
Index: builtins.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/builtins.cc,v
retrieving revision 1.1.2.14
diff -u -r1.1.2.14 builtins.cc
--- builtins.cc 8 Mar 2005 01:16:32 -0000 1.1.2.14
+++ builtins.cc 8 Mar 2005 01:20:48 -0000
@@ -19,6 +19,9 @@
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
+// FIXME: see glue.hh for why this is lame.
+#define HACK_WANT_OUTPUT_H
+
// This include must come first.
#include "java/glue.hh"
#include "aot/mangle.hh"
@@ -493,6 +496,23 @@
return vtable_map[klass];
}
+tree
+tree_builtins::get_constant_pool_decl (model_class *klass)
+{
+ if (cpool_map.find (klass) == cpool_map.end ())
+ {
+ tree type = build_array_type (ptr_type_node,
+ build_index_type (integer_zero_node));
+ tree decl = build_decl (VAR_DECL, get_symbol (), type);
+ TREE_STATIC (decl) = 1;
+ DECL_ARTIFICIAL (decl) = 1;
+ DECL_IGNORED_P (decl) = 1;
+
+ cpool_map[klass] = decl;
+ }
+ return cpool_map[klass];
+}
+
// FIXME: this whole method should probably migrate into the ABI or
// into classobj.cc. There's no need, I think, for it to be a generic
// part of the builtins.
Index: builtins.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/builtins.hh,v
retrieving revision 1.1.2.9
diff -u -r1.1.2.9 builtins.hh
--- builtins.hh 8 Mar 2005 00:34:36 -0000 1.1.2.9
+++ builtins.hh 8 Mar 2005 01:20:48 -0000
@@ -36,6 +36,9 @@
// This maps classes to their vtable decls
std::map<model_class *, tree> vtable_map;
+ // This maps classes to their constant pool decls.
+ std::map<model_class *, tree> cpool_map;
+
// This maps a method to its corresponding gcc tree.
std::map<model_method *, tree> methodmap;
@@ -122,6 +125,9 @@
/// Return the decl for a given class' vtable.
tree get_vtable_decl (model_class *);
+
+ /// Return the decl for a given class' constant pool.
+ tree get_constant_pool_decl (model_class *);
};
#endif // GCC_TREE_BUILTINS_HH
Index: classobj.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/classobj.cc,v
retrieving revision 1.1.2.16
diff -u -r1.1.2.16 classobj.cc
--- classobj.cc 8 Mar 2005 01:04:21 -0000 1.1.2.16
+++ classobj.cc 8 Mar 2005 01:20:48 -0000
@@ -358,35 +358,58 @@
if (pool.empty ())
return null_pointer_node;
+ // The zero'th entry is unusable, as libgcj does not attempt to link
+ // it.
+ int size = pool.size () + 1;
+
record_creator inst (type_constants);
- inst.set_field ("size", build_int_cst (type_juint, pool.size ()));
+ inst.set_field ("size", build_int_cst (type_juint, size));
tree type_tags
= build_array_type (type_jbyte,
- build_index_type (build_int_cst (type_jint,
- pool.size ())));
+ build_index_type (build_int_cst (type_jint, size)));
tree type_data
= build_array_type (ptr_type_node,
- build_index_type (build_int_cst (type_jint,
- pool.size ())));
+ build_index_type (build_int_cst (type_jint, size)));
tree tags_list = NULL_TREE;
tree data_list = NULL_TREE;
+
+ {
+ // NULL the zero'th entry.
+ tags_list = tree_cons (integer_zero_node, build_int_cst (type_jbyte, 0),
+ tags_list);
+ data_list = tree_cons (integer_zero_node, null_pointer_node, data_list);
+ }
+
+ int index = 1;
for (std::vector<aot_class::pool_entry>::const_iterator i = pool.begin ();
i != pool.end ();
- ++i)
+ ++i, ++index)
{
- tags_list = tree_cons (NULL_TREE, build_int_cst (type_jbyte, (*i).tag),
+ tree index_tree = build_int_cst (type_jint, index);
+ tags_list = tree_cons (index_tree, build_int_cst (type_jbyte, (*i).tag),
tags_list);
- data_list = tree_cons (NULL_TREE, builtins->map_utf8const ((*i).value),
+ data_list = tree_cons (index_tree, builtins->map_utf8const ((*i).value),
data_list);
}
tags_list = nreverse (tags_list);
data_list = nreverse (data_list);
- inst.set_field ("tags", make_decl (type_tags, tags_list));
- inst.set_field ("data", make_decl (type_data, data_list));
+ inst.set_field ("tags",
+ make_decl (type_tags, build_constructor (type_tags,
+ tags_list)));
+
+ // We handle "data" differently since the underlying decl for this
+ // is used by other parts of the compiler when generating code.
+ tree data_decl = builtins->get_constant_pool_decl (klass->get ());
+ TREE_TYPE (data_decl) = type_data;
+ DECL_INITIAL (data_decl) = build_constructor (type_data, data_list);
+ rest_of_decl_compilation (data_decl, 1, 0);
+
+ inst.set_field ("data", build1 (ADDR_EXPR, build_pointer_type (type_data),
+ data_decl));
return inst.finish_record ();
}
Index: glue.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/glue.hh,v
retrieving revision 1.1.2.8
diff -u -r1.1.2.8 glue.hh
--- glue.hh 8 Mar 2005 00:22:45 -0000 1.1.2.8
+++ glue.hh 8 Mar 2005 01:20:48 -0000
@@ -60,7 +60,14 @@
#include "langhooks-def.h"
#include "options.h"
#include "toplev.h"
- //#include "output.h"
+ // FIXME: This is just plain ugly. GCC defines output_constant_pool
+ // as a function, but it is also a class in gcjx. So we only
+ // include this conditionally. The real fix is to wrap everything
+ // in gcjx in a namespace, and rename our local "gcjx" namespace to
+ // something else, probably "gcj".
+#ifdef HACK_WANT_OUTPUT_H
+#include "output.h"
+#endif
#include "except.h"
#include "flags.h"
#include "tree-inline.h"
Index: tree.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/tree.cc,v
retrieving revision 1.1.2.11
diff -u -r1.1.2.11 tree.cc
--- tree.cc 8 Mar 2005 00:22:45 -0000 1.1.2.11
+++ tree.cc 8 Mar 2005 01:20:49 -0000
@@ -230,13 +230,12 @@
// exception if this function is not found at runtime.
tem = build_tree_list (NULL_TREE, build_int_cst (NULL_TREE, args_size));
tree method_sig
- = build_ref_from_constant_pool (class_wrapper->add_utf (method->get_descriptor ()));
- // FIXME: set TREE_TYPE on method_sig.
- // FIXME: this should probably be done by build_ref_from_constant_pool?
- TREE_CONSTANT (method_sig) = 1;
+ = build_ref_from_constant_pool (type_utf8const_ptr,
+ class_wrapper->add_utf (method->get_descriptor ()));
tree lookup_arg = tree_cons (NULL_TREE, method_sig, tem);
- tem = build_ref_from_constant_pool (class_wrapper->add_utf (method->get_name ()));
+ tem = build_ref_from_constant_pool (type_utf8const_ptr,
+ class_wrapper->add_utf (method->get_name ()));
lookup_arg
= tree_cons (NULL_TREE, klass,
tree_cons (NULL_TREE, tem, lookup_arg));
@@ -1582,11 +1581,9 @@
tree_generator::handle_string_literal (const std::string &val)
{
int location = class_wrapper->add (val);
- tree node = build_ref_from_constant_pool (location);
- TREE_TYPE (node)
+ tree type
= gcc_builtins->map_type (global->get_compiler ()->java_lang_String ());
- TREE_CONSTANT (node) = 1;
- return node;
+ return build_ref_from_constant_pool (type, location);
}
void
@@ -1899,9 +1896,14 @@
}
tree
-tree_generator::build_ref_from_constant_pool (int)
+tree_generator::build_ref_from_constant_pool (tree type, int index)
{
- abort (); // FIXME
+ tree cpool = gcc_builtins->get_constant_pool_decl (class_wrapper->get ());
+ tree result = build4 (ARRAY_REF, ptr_type_node,
+ cpool, build_int_cst (type_jint, index),
+ NULL_TREE, NULL_TREE);
+ TREE_CONSTANT (result) = 1;
+ return build1 (NOP_EXPR, type, result);
}
// This comes directly from gcj.
Index: tree.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/tree.hh,v
retrieving revision 1.1.2.4
diff -u -r1.1.2.4 tree.hh
--- tree.hh 8 Mar 2005 00:22:46 -0000 1.1.2.4
+++ tree.hh 8 Mar 2005 01:20:49 -0000
@@ -122,7 +122,7 @@
tree build_long (jlong);
tree handle_float (jfloat);
tree handle_double (jdouble);
- tree build_ref_from_constant_pool (int);
+ tree build_ref_from_constant_pool (tree, int);
tree build_new_array (model_type *, tree);
tree build_new_object_array (model_type *, tree);
model_type *find_model_class (const std::string &);