Patch: gcj, jcf-dump, and strictfp

Tom Tromey tromey@redhat.com
Sun Feb 17 17:38:00 GMT 2002


Inspired by the conversation the other day, I've written a patch that
adds better support for strictfp to gcj.

With this patch we now correctly generate .class files that have
strictfp set, and jcf-dump also prints that information.  This also
adds a couple error messages where `strictfp' is invalid.

It does not disable any optimizations when strictfp is in force.
This is something we ought to do.

I rebuilt libgcj with this with no problems.  I also ran Jacks with no
regressions.  I expected a Jacks improvement but investigation shows
it doesn't check for the errors I've added.

I also tried `gcj -C' and `jcf-dump -c' before and after this change
on a .class file with strictfp (for jcf-dump I compared against the
`javac' output to make sure the right thing was happening).

Ok to commit?

Tom

PS I find it weird that class.c:get_access_flags_from_decl() and
jcf-write.c:get_access_flags() duplicate so much code.  Surely one or
the other could be removed.


Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* java-tree.h (TYPE_STRICTFP): New macro.
	(struct lang_type) [strictfp]: New field.
	(CLASS_STRICTFP): New macro.
	(METHOD_STRICTFP): New macro.
	(struct lang_decl) [strictfp]: New field.
	* parse.y (method_header): Disallow strictfp constructor or
	abstract method.
	(STRICT_TK): Move before MODIFIER_TK.
	* parse.h (CLASS_MODIFIERS): Added ACC_STRICT.
	(METHOD_MODIFIERS): Likewise.
	(INTERFACE_MODIFIERS): Likewise.
	* jcf-write.c (get_access_flags): Likewise.
	* class.c (set_class_decl_access_flags): Recognize ACC_STRICT.
	(add_method_1): Likewise.
	(get_access_flags_from_decl): Likewise.
	* jcf-dump.c (print_access_flags): Print in standard order.  Also,
	recognize strictfp flag.
	* jcf.h (ACC_STRICT): New define.

Index: class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/class.c,v
retrieving revision 1.127
diff -u -r1.127 class.c
--- class.c 2002/02/11 22:53:09 1.127
+++ class.c 2002/02/18 00:04:09
@@ -425,6 +425,7 @@
   if (access_flags & ACC_STATIC)    CLASS_STATIC (class_decl) = 1;
   if (access_flags & ACC_PRIVATE)   CLASS_PRIVATE (class_decl) = 1;
   if (access_flags & ACC_PROTECTED) CLASS_PROTECTED (class_decl) = 1;
+  if (access_flags & ACC_STRICT)    CLASS_STRICTFP (class_decl) = 1;
 }
 
 /* Return length of inheritance chain of CLAS, where java.lang.Object is 0,
@@ -719,6 +720,7 @@
   if (access_flags & ACC_SYNCHRONIZED) METHOD_SYNCHRONIZED (fndecl) = 1;
   if (access_flags & ACC_ABSTRACT) METHOD_ABSTRACT (fndecl) = 1;
   if (access_flags & ACC_TRANSIENT) METHOD_TRANSIENT (fndecl) = 1;
+  if (access_flags & ACC_STRICT) METHOD_STRICTFP (fndecl) = 1;
   return fndecl;
 }
 
@@ -1223,6 +1225,8 @@
 	access_flags |= ACC_PRIVATE;
       if (CLASS_PROTECTED (decl))
 	access_flags |= ACC_PROTECTED;
+      if (CLASS_STRICTFP (decl))
+	access_flags |= ACC_STRICT;
       return access_flags;
     }
   if (TREE_CODE (decl) == FUNCTION_DECL)
@@ -1245,6 +1249,8 @@
 	access_flags |= ACC_ABSTRACT;
       if (METHOD_TRANSIENT (decl))
 	access_flags |= ACC_TRANSIENT;
+      if (METHOD_STRICTFP (decl))
+	access_flags |= ACC_STRICT;
       return access_flags;
     }
   abort ();
Index: java-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/java-tree.h,v
retrieving revision 1.134
diff -u -r1.134 java-tree.h
--- java-tree.h 2002/01/22 20:23:45 1.134
+++ java-tree.h 2002/02/18 00:04:11
@@ -942,6 +942,7 @@
   unsigned int init_final : 1;	/* Nonzero all finals are initialized */
   unsigned int fixed_ctor : 1;
   unsigned int init_calls_this : 1;
+  unsigned int strictfp : 1;
 };
 
 /* init_test_table hash table entry structure.  */
@@ -990,6 +991,7 @@
 #define TYPE_IMPORT_DEMAND_LIST(T) (TYPE_LANG_SPECIFIC(T)->import_demand_list)
 #define TYPE_PRIVATE_INNER_CLASS(T) (TYPE_LANG_SPECIFIC(T)->pic)
 #define TYPE_PROTECTED_INNER_CLASS(T) (TYPE_LANG_SPECIFIC(T)->poic)
+#define TYPE_STRICTFP(T) (TYPE_LANG_SPECIFIC(T)->strictfp)
 
 struct lang_type
 {
@@ -1009,6 +1011,7 @@
   tree import_demand_list;	/* Imported types, in the CU of this class */
   unsigned pic:1;		/* Private Inner Class. */
   unsigned poic:1;		/* Protected Inner Class. */
+  unsigned strictfp:1;		/* `strictfp' class.  */
 };
 
 #ifdef JAVA_USE_HANDLES
@@ -1249,6 +1252,7 @@
 #define METHOD_NATIVE(DECL) (DECL_LANG_SPECIFIC(DECL)->native)
 #define METHOD_ABSTRACT(DECL) DECL_LANG_FLAG_5 (DECL)
 #define METHOD_TRANSIENT(DECL) DECL_LANG_FLAG_6 (DECL)
+#define METHOD_STRICTFP(DECL) (DECL_LANG_SPECIFIC (DECL)->strictfp)
 
 #define JAVA_FILE_P(NODE) TREE_LANG_FLAG_2 (NODE)
 #define CLASS_FILE_P(NODE) TREE_LANG_FLAG_3 (NODE)
@@ -1291,6 +1295,7 @@
 #define CLASS_STATIC(DECL) DECL_LANG_FLAG_7 (DECL)
 #define CLASS_PRIVATE(DECL) (TYPE_PRIVATE_INNER_CLASS (TREE_TYPE (DECL)))
 #define CLASS_PROTECTED(DECL) (TYPE_PROTECTED_INNER_CLASS (TREE_TYPE (DECL)))
+#define CLASS_STRICTFP(DECL) (TYPE_STRICTFP (TREE_TYPE (DECL)))
 
 /* @deprecated marker flag on methods, fields and classes */
 
Index: jcf-dump.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/jcf-dump.c,v
retrieving revision 1.40
diff -u -r1.40 jcf-dump.c
--- jcf-dump.c 2002/01/31 19:36:25 1.40
+++ jcf-dump.c 2002/02/18 00:04:12
@@ -363,8 +363,12 @@
   if (flags & ACC_PUBLIC) fprintf (stream, " public");
   if (flags & ACC_PRIVATE) fprintf (stream, " private");
   if (flags & ACC_PROTECTED) fprintf (stream, " protected");
+  if (flags & ACC_ABSTRACT) fprintf (stream, " abstract");
   if (flags & ACC_STATIC) fprintf (stream, " static");
   if (flags & ACC_FINAL) fprintf (stream, " final");
+  if (flags & ACC_TRANSIENT) fprintf (stream, " transient");
+  if (flags & ACC_VOLATILE) fprintf (stream, " volatile");
+  if (flags & ACC_NATIVE) fprintf (stream, " native");
   if (flags & ACC_SYNCHRONIZED)
     {
       if (context == 'c')
@@ -372,11 +376,8 @@
       else
 	fprintf (stream, " synchronized");
     }
-  if (flags & ACC_VOLATILE) fprintf (stream, " volatile");
-  if (flags & ACC_TRANSIENT) fprintf (stream, " transient");
-  if (flags & ACC_NATIVE) fprintf (stream, " native");
   if (flags & ACC_INTERFACE) fprintf (stream, " interface");
-  if (flags & ACC_ABSTRACT) fprintf (stream, " abstract");
+  if (flags & ACC_STRICT) fprintf (stream, " strictfp");
 }
 
 
Index: jcf-write.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/jcf-write.c,v
retrieving revision 1.98
diff -u -r1.98 jcf-write.c
--- jcf-write.c 2001/12/21 05:28:27 1.98
+++ jcf-write.c 2002/02/18 00:04:14
@@ -1,5 +1,5 @@
 /* Write out a Java(TM) class file.
-   Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
 
 This file is part of GNU CC.
 
@@ -685,6 +685,8 @@
       if (ANONYMOUS_CLASS_P (TREE_TYPE (decl))
 	  || LOCAL_CLASS_P (TREE_TYPE (decl)))
 	flags |= ACC_PRIVATE;
+      if (CLASS_STRICTFP (decl))
+	flags |= ACC_STRICT;
     }
   else
     abort ();
@@ -699,6 +701,8 @@
 	flags |= ACC_SYNCHRONIZED;
       if (METHOD_ABSTRACT (decl))
 	flags |= ACC_ABSTRACT;
+      if (METHOD_STRICTFP (decl))
+	flags |= ACC_STRICT;
     }
   if (isfield)
     {
Index: jcf.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/jcf.h,v
retrieving revision 1.26
diff -u -r1.26 jcf.h
--- jcf.h 2001/12/03 23:09:42 1.26
+++ jcf.h 2002/02/18 00:04:14
@@ -1,6 +1,6 @@
 /* Utility macros to read Java(TM) .class files and byte codes.
 
-   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -207,6 +207,7 @@
 #define ACC_NATIVE 0x0100
 #define ACC_INTERFACE 0x0200
 #define ACC_ABSTRACT 0x0400
+#define ACC_STRICT 0x0800
 
 #define ACC_VISIBILITY (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED)
 
Index: parse.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.h,v
retrieving revision 1.81
diff -u -r1.81 parse.h
--- parse.h 2001/12/16 16:23:49 1.81
+++ parse.h 2002/02/18 00:04:15
@@ -1,5 +1,5 @@
 /* Language parser definitions for the GNU compiler for the Java(TM) language.
-   Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
    Contributed by Alexandre Petit-Bianco (apbianco@cygnus.com)
 
 This file is part of GNU CC.
@@ -73,12 +73,13 @@
 #define YYNOT_TWICE if (ctxp->prevent_ese != lineno)
 
 /* Accepted modifiers */
-#define CLASS_MODIFIERS ACC_PUBLIC|ACC_ABSTRACT|ACC_FINAL
+#define CLASS_MODIFIERS ACC_PUBLIC|ACC_ABSTRACT|ACC_FINAL|ACC_STRICT
 #define FIELD_MODIFIERS ACC_PUBLIC|ACC_PROTECTED|ACC_PRIVATE|ACC_FINAL| \
                         ACC_STATIC|ACC_TRANSIENT|ACC_VOLATILE
 #define METHOD_MODIFIERS ACC_PUBLIC|ACC_PROTECTED|ACC_PRIVATE|ACC_ABSTRACT| \
-			 ACC_STATIC|ACC_FINAL|ACC_SYNCHRONIZED|ACC_NATIVE
-#define INTERFACE_MODIFIERS ACC_PUBLIC|ACC_ABSTRACT
+			 ACC_STATIC|ACC_FINAL|ACC_SYNCHRONIZED|ACC_NATIVE| \
+			 ACC_STRICT
+#define INTERFACE_MODIFIERS ACC_PUBLIC|ACC_ABSTRACT|ACC_STRICT
 #define INTERFACE_INNER_MODIFIERS ACC_PUBLIC|ACC_PROTECTED|ACC_ABSTRACT|ACC_STATIC
 #define INTERFACE_METHOD_MODIFIERS ACC_PUBLIC|ACC_ABSTRACT
 #define INTERFACE_FIELD_MODIFIERS ACC_PUBLIC|ACC_STATIC|ACC_FINAL
Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.350
diff -u -r1.350 parse.y
--- parse.y 2002/02/04 02:38:16 1.350
+++ parse.y 2002/02/18 00:04:27
@@ -482,8 +482,8 @@
 %token   PUBLIC_TK       PRIVATE_TK         PROTECTED_TK
 %token   STATIC_TK       FINAL_TK           SYNCHRONIZED_TK
 %token   VOLATILE_TK     TRANSIENT_TK       NATIVE_TK
-%token   PAD_TK          ABSTRACT_TK        MODIFIER_TK
-%token   STRICT_TK
+%token   PAD_TK          ABSTRACT_TK        STRICT_TK
+%token   MODIFIER_TK
 
 /* Keep those two in order, too */
 %token   DECR_TK INCR_TK
@@ -4543,7 +4543,8 @@
       ABSTRACT_CHECK (flags, ACC_STATIC, id, "Static");
       ABSTRACT_CHECK (flags, ACC_FINAL, id, "Final");
       ABSTRACT_CHECK (flags, ACC_NATIVE, id, "Native");
-      ABSTRACT_CHECK (flags, ACC_SYNCHRONIZED,id, "Synchronized");
+      ABSTRACT_CHECK (flags, ACC_SYNCHRONIZED, id, "Synchronized");
+      ABSTRACT_CHECK (flags, ACC_STRICT, id, "Strictfp");
       if (!CLASS_ABSTRACT (TYPE_NAME (this_class))
 	  && !CLASS_INTERFACE (TYPE_NAME (this_class)))
 	parse_error_context 
@@ -4569,6 +4570,7 @@
 	  JCONSTRUCTOR_CHECK (flags, ACC_FINAL, id, "final");
 	  JCONSTRUCTOR_CHECK (flags, ACC_NATIVE, id, "native");
 	  JCONSTRUCTOR_CHECK (flags, ACC_SYNCHRONIZED, id, "synchronized");
+	  JCONSTRUCTOR_CHECK (flags, ACC_STRICT, id, "strictfp");
 	}
       /* If we found error here, we don't consider it's OK to tread
 	 the method definition as a constructor, for the rest of this



More information about the Java-patches mailing list