This is the mail archive of the java-patches@gcc.gnu.org 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]
Other format: [Raw text]

Java: fixes for -fno-assume-compiled


Below are separate frontend and runtime patches.

The -fno-assume-compiled switch can eliminate the need for most external
data symbol references normally emitted by gcj, making it easy to build
Java executables mixed with native code and interpreted bytecode.
However it hasn't worked in a long time (if it ever did).

With these patches I can build and execute simple non-PIC Java
applications with -fno-assume-compiled.  It does not yet work with -fPIC
on i686-linux, but that doesn't affect use of -fassume-compiled, which is
the default behavior for gcj.

Regression tested on i686-pc-linux-gnu.  OK for mainline (after BiB merges
are through)?

Jeff

2002-12-14  Jeff Sturm  <jsturm@one-point.com>

	* class.c (build_static_field_ref): Check FIELD_FINAL.
	* constants.c (alloc_class_constant): Use TYPE_CPOOL_DATA_REF
	instead of current_constant_pool_data_ref.
	* except.c (prepare_eh_table_type ): Use DECL_NAME of class type,
	not build_internal_class_name.
	* parse.y (patch_incomplete_class_ref): Always emit `class$' method.
	Use it when class ref isn't certain to be compiled.

Index: class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/class.c,v
retrieving revision 1.139
diff -u -p -r1.139 class.c
--- class.c	3 Dec 2002 13:50:03 -0000	1.139
+++ class.c	14 Dec 2002 17:40:16 -0000
@@ -1074,7 +1074,9 @@ build_static_field_ref (fdecl)
 {
   tree fclass = DECL_CONTEXT (fdecl);
   int is_compiled = is_compiled_class (fclass);
-  if (is_compiled)
+
+  /* Allow static final fields to fold to a constant.  */
+  if (is_compiled || FIELD_FINAL (fdecl))
     {
       if (!DECL_RTL_SET_P (fdecl))
 	{
Index: constants.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/constants.c,v
retrieving revision 1.22
diff -u -p -r1.22 constants.c
--- constants.c	18 Nov 2002 15:46:32 -0000	1.22
+++ constants.c	14 Dec 2002 17:40:17 -0000
@@ -386,10 +386,12 @@ alloc_class_constant (clas)
 static tree
 build_constant_data_ref ()
 {
+  tree cpool_data_ref = NULL_TREE;
+
   if (TYPE_CPOOL_DATA_REF (current_class))
-    current_constant_pool_data_ref = TYPE_CPOOL_DATA_REF (current_class);
+    cpool_data_ref = TYPE_CPOOL_DATA_REF (current_class);

-  else if (current_constant_pool_data_ref == NULL_TREE)
+  if (cpool_data_ref == NULL_TREE)
     {
       tree decl;
       tree decl_name = mangled_classname ("_CD_", current_class);
@@ -398,10 +400,10 @@ build_constant_data_ref ()
 					   one_elt_array_domain_type));
       TREE_STATIC (decl) = 1;
       make_decl_rtl (decl, NULL);
-      TYPE_CPOOL_DATA_REF (current_class) = current_constant_pool_data_ref
+      TYPE_CPOOL_DATA_REF (current_class) = cpool_data_ref
 	= build1 (ADDR_EXPR, ptr_type_node, decl);
     }
-  return current_constant_pool_data_ref;
+  return cpool_data_ref;
 }

 /* Get the pointer value at the INDEX'th element of the constant pool. */
Index: except.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/except.c,v
retrieving revision 1.30
diff -u -p -r1.30 except.c
--- except.c	18 Nov 2002 15:46:32 -0000	1.30
+++ except.c	14 Dec 2002 17:40:17 -0000
@@ -334,7 +334,7 @@ prepare_eh_table_type (type)
   else
     exp = fold (build
 		(PLUS_EXPR, ptr_type_node,
-		 build_utf8_ref (build_internal_class_name (type)),
+		 build_utf8_ref (DECL_NAME (TYPE_NAME (type))),
 		 size_one_node));
   return exp;
 }
Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.405
diff -u -p -r1.405 parse.y
--- parse.y	6 Dec 2002 20:10:33 -0000	1.405
+++ parse.y	14 Dec 2002 17:40:26 -0000
@@ -14065,7 +14065,16 @@ patch_incomplete_class_ref (node)
   if (!(ref_type = resolve_type_during_patch (type)))
     return error_mark_node;

-  if (!flag_emit_class_files || JPRIMITIVE_TYPE_P (ref_type)
+  /* Generate the synthetic static method `class$'.  (Previously we
+     deferred this, causing different method tables to be emitted
+     for native code and bytecode.)  */
+  if (!TYPE_DOT_CLASS (current_class))
+      build_dot_class_method (current_class);
+
+  /* If we're not emitting class files and we know ref_type is a
+     compiled class, build a direct reference.  */
+  if ((! flag_emit_class_files && is_compiled_class (ref_type))
+      || JPRIMITIVE_TYPE_P (ref_type)
       || TREE_CODE (ref_type) == VOID_TYPE)
     {
       tree dot = build_class_ref (ref_type);
@@ -14076,10 +14085,7 @@ patch_incomplete_class_ref (node)
     }

   /* If we're emitting class files and we have to deal with non
-     primitive types, we invoke (and consider generating) the
-     synthetic static method `class$'. */
-  if (!TYPE_DOT_CLASS (current_class))
-      build_dot_class_method (current_class);
+     primitive types, we invoke the synthetic static method `class$'.  */
   ref_type = build_dot_class_method_invocation (ref_type);
   return java_complete_tree (ref_type);
 }

2002-12-14  Jeff Sturm  <jsturm@one-point.com>

	* exception.cc (PERSONALITY_FUNCTION): Clear least-significant-bit
	of catch_type.
	* java/lang/natClass.cc (initializeClass): Link vtable, otable,
	idt tables after initializing superclass.
	* java/lang/natClassLoader.cc (_Jv_PrepareCompiledClass): Resolve
	superclass, interfaces if they are constant pool indicies.  Don't
	link vtable, otable yet.

Index: exception.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/exception.cc,v
retrieving revision 1.21
diff -u -p -r1.21 exception.cc
--- exception.cc	6 Apr 2002 04:19:10 -0000	1.21
+++ exception.cc	14 Dec 2002 17:40:43 -0000
@@ -338,7 +338,7 @@ PERSONALITY_FUNCTION (int version,
 	      // The catch_type is either a (java::lang::Class*) or
 	      // is one more than a (Utf8Const*).
 	      if ((size_t)catch_type & 1)
-		catch_type = _Jv_FindClass ((Utf8Const*)catch_type - 1, NULL);
+		catch_type = _Jv_FindClass ((Utf8Const*)((size_t)catch_type ^ 1), NULL);

 	      if (_Jv_IsInstanceOf (xh->value, catch_type))
 		{
Index: java/lang/natClass.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natClass.cc,v
retrieving revision 1.57
diff -u -p -r1.57 natClass.cc
--- java/lang/natClass.cc	5 Dec 2002 07:43:45 -0000	1.57
+++ java/lang/natClass.cc	14 Dec 2002 17:40:47 -0000
@@ -748,9 +748,6 @@ java::lang::Class::initializeClass (void
 	}
     }

-  if (state <= JV_STATE_LINKED)
-    _Jv_PrepareConstantTimeTables (this);
-
   // Step 2.
   java::lang::Thread *self = java::lang::Thread::currentThread();
   // FIXME: `self' can be null at startup.  Hence this nasty trick.
@@ -794,6 +791,14 @@ java::lang::Class::initializeClass (void
 	  throw except;
 	}
     }
+
+  _Jv_PrepareConstantTimeTables (this);
+
+  if (vtable == NULL)
+    _Jv_MakeVTable(this);
+
+  if (otable != NULL && otable->state == 0)
+    _Jv_LinkOffsetTable(this);

   // Steps 8, 9, 10, 11.
   try
Index: java/lang/natClassLoader.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natClassLoader.cc,v
retrieving revision 1.55
diff -u -p -r1.55 natClassLoader.cc
--- java/lang/natClassLoader.cc	11 Dec 2002 19:18:59 -0000	1.55
+++ java/lang/natClassLoader.cc	14 Dec 2002 17:40:47 -0000
@@ -204,6 +204,9 @@ _Jv_PrepareCompiledClass (jclass klass)
   klass->state = JV_STATE_LINKED;

   _Jv_Constants *pool = &klass->constants;
+
+  // Resolve class constants first, since other constant pool
+  // entries may rely on these.
   for (int index = 1; index < pool->size; ++index)
     {
       if (pool->tags[index] == JV_CONSTANT_Class)
@@ -226,7 +229,22 @@ _Jv_PrepareCompiledClass (jclass klass)
 	  pool->data[index].clazz = found;
 	  pool->tags[index] |= JV_CONSTANT_ResolvedFlag;
 	}
-      else if (pool->tags[index] == JV_CONSTANT_String)
+    }
+
+  // If superclass looks like a constant pool entry,
+  // resolve it now.
+  if ((int) klass->superclass < pool->size)
+    klass->superclass = pool->data[(int) klass->superclass].clazz;
+
+  // Likewise for interfaces.
+  for (int i = 0; i < klass->interface_count; i++)
+    if ((int) klass->interfaces[i] < pool->size)
+      klass->interfaces[i] = pool->data[(int) klass->interfaces[i]].clazz;
+
+  // Resolve the remaining constant pool entries.
+  for (int index = 1; index < pool->size; ++index)
+    {
+      if (pool->tags[index] == JV_CONSTANT_String)
 	{
 	  jstring str;

@@ -261,12 +279,6 @@ _Jv_PrepareCompiledClass (jclass klass)
 #ifdef INTERPRETER
     }
 #endif /* INTERPRETER */
-
-  if (klass->vtable == NULL)
-    _Jv_MakeVTable(klass);
-
-  if (klass->otable != NULL && klass->otable->state == 0)
-    _Jv_LinkOffsetTable(klass);

   klass->notifyAll ();



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