public inbox for java-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* jcf-reader: support for JSR 292 classfile extensions
@ 2012-04-11 10:22 Andrew Haley
  2012-04-11 12:43 ` Richard Guenther
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Haley @ 2012-04-11 10:22 UTC (permalink / raw)
  To: GCC Patches, GCJ-patches

This adds support for the new (Version 51.0) class file format.  It
doesn't actually generate code for invokedynamic bcause we don't have
any runtime support yet, but it's a start.  jcf-dump prints all of the
new attributes.

Andrew.


2012-04-11  Andrew Haley  <aph@redhat.com>

	* jcf.h (bootstrap_method): New.
	(BootstrapMethods): New.
	(JCF): Add BootstrapMethods.
	(enum cpool_tag): Add MethodHandle, MethodType, and InvokeDynamic.
	* jcf-reader.c (jcf_parse_bootstrap_methods): New.
	(jcf_parse_constant_pool): Handlers for MethodHandle, MethodType,
	and InvokeDynamic.
	(jcf_parse_bootstrap_methods): New.
	* javaop.def (invokedynamic): New opcode.
	* jcf-parse.c (get_constant): An unknown constant type should not
	be an internal error, but a fatal one.  Make it so.
	* jcf-dump.c (HANDLE_BOOTSTRAP_METHODS_ATTRIBUTE): New.
	(HANDLE_END_BOOTSTRAP_METHODS): New.
	(print_constant): Handlers for MethodHandle, MethodType, and
	InvokeDynamic.

Index: java/jcf-dump.c
===================================================================
--- java/jcf-dump.c	(revision 186103)
+++ java/jcf-dump.c	(working copy)
@@ -430,7 +430,24 @@
   print_element_value (out, jcf, 1);					\
 }

+#define HANDLE_BOOTSTRAP_METHODS_ATTRIBUTE()				\
+{									\
+  COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length);	\
+  fputc ('\n', out); jcf_parse_bootstrap_methods (jcf, attribute_length); \
+}

+#define HANDLE_END_BOOTSTRAP_METHODS(NUM_METHODS)			\
+  {									\
+    int i;								\
+    for (i = 0; i < NUM_METHODS; i++)					\
+      {									\
+	bootstrap_method *m = &jcf->bootstrap_methods.methods[i];	\
+	fprintf (out, "  %d: ", i);					\
+	print_constant (out, jcf, m->method_ref, 1);			\
+	fprintf (out, "\n");						\
+      }									\
+  }
+
 #define PROCESS_OTHER_ATTRIBUTE(JCF, INDEX, LENGTH) \
 { COMMON_HANDLE_ATTRIBUTE(JCF, INDEX, LENGTH); \
   fputc ('\n', out); JCF_SKIP (JCF, LENGTH); }
@@ -898,6 +915,53 @@
 	fputc ('\"', out);
       }
       break;
+    case CONSTANT_MethodHandle:
+      {
+	int kind = JPOOL_USHORT1 (jcf, index);
+	if (verbosity > 0)
+	  fprintf (out, "MethodHandle kind: %d=", kind);
+	switch(kind) {
+	case 1:
+	case 2:
+	case 3:
+	case 4:
+	  if (verbosity > 0)
+	    fprintf (out, "Fieldref: %ld=", JPOOL_USHORT2 (jcf, index));
+	  print_constant (out, jcf, JPOOL_USHORT2 (jcf, index), 0);
+	case 5:
+	case 6:
+	case 7:
+	case 8:
+	  if (verbosity > 0)
+	    fprintf (out, "Methodref: %ld=", JPOOL_USHORT2 (jcf, index));
+	  print_constant (out, jcf, JPOOL_USHORT2 (jcf, index), 0);
+	  break;
+	case 9:
+	  if (verbosity > 0)
+	    fprintf (out, "InterfaceMethodref: %ld=", JPOOL_USHORT2 (jcf, index));
+	  print_constant (out, jcf, JPOOL_USHORT2 (jcf, index), 0);
+	  break;
+	}
+	break;
+      }
+    case CONSTANT_MethodType:
+      if (verbosity > 0)
+	fprintf (out, "MethodType %ld: ", JPOOL_USHORT1 (jcf, index));
+      print_signature (out, jcf, JPOOL_USHORT1 (jcf, index), 0);
+      break;
+    case CONSTANT_InvokeDynamic:
+      {
+	uint16 name_and_type = JPOOL_USHORT2 (jcf, index);
+	if (verbosity > 0)
+	  fprintf (out, "InvokeDynamic: ");
+	fprintf (out, "bootstrap_method: %ld ", JPOOL_USHORT1 (jcf, index));
+	if (verbosity == 2)
+	  fprintf (out, " name_and_type: %d=<", name_and_type);
+	print_constant_terse (out, jcf, name_and_type, CONSTANT_NameAndType);
+	if (verbosity == 2)
+	  fputc ('>', out);
+	break;
+      }
     default:
       fprintf (out, "(Unknown constant type %d)", kind);
     }
Index: java/jcf-parse.c
===================================================================
--- java/jcf-parse.c	(revision 186103)
+++ java/jcf-parse.c	(working copy)
@@ -1113,8 +1113,8 @@
   jcf->cpool.data[index].t = value;
   return value;
  bad:
-  internal_error ("bad value constant type %d, index %d",
-		  JPOOL_TAG (jcf, index), index);
+  fatal_error ("bad value constant type %d, index %d",
+	       JPOOL_TAG (jcf, index), index);
 }

 tree
Index: java/javaop.def
===================================================================
--- java/javaop.def	(revision 186103)
+++ java/javaop.def	(working copy)
@@ -292,6 +292,7 @@
 JAVAOP (invokespecial, 183, INVOKE,  SPECIAL, 0)
 JAVAOP (invokestatic,  184, INVOKE,  STATIC, 0)
 JAVAOP (invokeinterface,185, INVOKE, INTERFACE, 1)
+JAVAOP (invokedynamic, 186, INVOKE,  DYNAMIC, 1)
 JAVAOP (new,           187, OBJECT,  PTR,    NEW)
 JAVAOP (newarray,      188, ARRAY,   NUM,    NEW)
 JAVAOP (anewarray,     189, ARRAY,   PTR,    NEW)
Index: java/jcf-reader.c
===================================================================
--- java/jcf-reader.c	(revision 186103)
+++ java/jcf-reader.c	(working copy)
@@ -36,6 +36,7 @@
 static int jcf_parse_one_method (JCF *, int);
 static int jcf_parse_methods (JCF *);
 static int jcf_parse_final_attributes (JCF *);
+static int jcf_parse_bootstrap_methods (JCF *, int );
 #ifdef NEED_PEEK_ATTRIBUTE
 static int peek_attribute (JCF *, int, const char *, int);
 #endif
@@ -293,7 +294,16 @@
     }
   else
 #endif
+  if (MATCH_ATTRIBUTE ("BootstrapMethods"))
     {
+#ifdef HANDLE_BOOTSTRAP_METHODS_ATTRIBUTE
+      HANDLE_BOOTSTRAP_METHODS_ATTRIBUTE();
+#else
+      JCF_SKIP (jcf, attribute_length);
+#endif
+    }
+   else
+    {
 #ifdef PROCESS_OTHER_ATTRIBUTE
       PROCESS_OTHER_ATTRIBUTE(jcf, attribute_name, attribute_length);
 #else
@@ -382,6 +392,17 @@
 	  JCF_SKIP (jcf, n);
 #endif
 	  break;
+	case CONSTANT_MethodHandle:
+	  jcf->cpool.data[i].w = JCF_readu (jcf);
+	  jcf->cpool.data[i].w |= JCF_readu2 (jcf) << 16;
+	  break;
+	case CONSTANT_MethodType:
+	  jcf->cpool.data[i].w = JCF_readu2 (jcf);
+	  break;
+	case CONSTANT_InvokeDynamic:
+	  jcf->cpool.data[i].w = JCF_readu2 (jcf);
+	  jcf->cpool.data[i].w |= JCF_readu2 (jcf) << 16;
+	  break;
 	default:
 	  return i;
 	}
@@ -521,3 +542,39 @@
   return 0;
 }

+/* Read and handle the "BootstrapMethods" attribute.
+
+   Return 0 if OK.
+*/
+static int
+jcf_parse_bootstrap_methods (JCF* jcf, int attribute_length ATTRIBUTE_UNUSED)
+{
+  int i;
+  uint16 num_methods = JCF_readu2 (jcf);
+  jcf->bootstrap_methods.count = num_methods;
+  jcf->bootstrap_methods.methods
+    = (bootstrap_method *) ggc_alloc_atomic (num_methods
+					      * sizeof (bootstrap_method));
+#ifdef HANDLE_START_BOOTSTRAP_METHODS
+  HANDLE_START_BOOTSTRAP_METHODS (jcf, num_methods);
+#endif
+
+  for (i = 0; i < num_methods; i++)
+    {
+      unsigned j;
+      bootstrap_method *m = &jcf->bootstrap_methods.methods[i];
+      m->method_ref = JCF_readu2 (jcf);
+      m->num_arguments = JCF_readu2 (jcf);
+      m->bootstrap_arguments
+	= (unsigned *) ggc_alloc_atomic (m->num_arguments
+					 * sizeof (unsigned));
+      for (j = 0; j < m->num_arguments; j++)
+	m->bootstrap_arguments[j] = JCF_readu2 (jcf);
+    }
+
+#ifdef HANDLE_END_BOOTSTRAP_METHODS
+  HANDLE_END_BOOTSTRAP_METHODS (num_methods);
+#endif
+
+  return 0;
+}
Index: java/jcf.h
===================================================================
--- java/jcf.h	(revision 186103)
+++ java/jcf.h	(working copy)
@@ -88,6 +88,17 @@
 			   desc ("cpool_entry_is_tree (%1.tags%a)")))	data;
 } CPool;

+typedef struct GTY(()) bootstrap_method {
+  unsigned method_ref;
+  unsigned num_arguments;
+  unsigned* GTY((length ("%h.num_arguments"))) bootstrap_arguments;
+} bootstrap_method;
+
+typedef struct GTY(()) BootstrapMethods {
+  unsigned count;
+  bootstrap_method* GTY((length ("%h.count"))) methods;
+} BootstrapMethods;
+
 struct ZipDirectory;

 /* JCF encapsulates the state of reading a Java Class File. */
@@ -109,6 +120,7 @@
   JCF_u2 this_class;
   JCF_u2 super_class;
   CPool cpool;
+  BootstrapMethods bootstrap_methods;
 } JCF;
 /*typedef JCF*  JCF_FILE;*/

@@ -245,6 +257,10 @@
   CONSTANT_NameAndType = 12,
   CONSTANT_Utf8 = 1,
   CONSTANT_Unicode = 2,
+  CONSTANT_MethodHandle = 15,
+  CONSTANT_MethodType = 16,
+  CONSTANT_InvokeDynamic = 18,
+
   CONSTANT_None = 0
 };

Index: java/jcf-io.c
===================================================================
--- java/jcf-io.c	(revision 186103)
+++ java/jcf-io.c	(working copy)
@@ -518,6 +518,26 @@
 	case CONSTANT_Utf8:
 	case CONSTANT_Unicode:
 	  break;
+	case CONSTANT_MethodHandle:
+	  n = JPOOL_USHORT1 (jcf, i);
+	  if (n < 1 || n > 9)
+	    return i;
+	  n = JPOOL_USHORT2 (jcf, i);
+	  if (n <= 0 || n >= JPOOL_SIZE(jcf))
+	    return i;
+	  break;
+	case CONSTANT_MethodType:
+	  n = JPOOL_USHORT1 (jcf, i);
+	  if (n <= 0 || n >= JPOOL_SIZE(jcf)
+	      || JPOOL_TAG (jcf, n) != CONSTANT_Utf8)
+	    return i;
+	  break;
+	case CONSTANT_InvokeDynamic:
+	  n = JPOOL_USHORT2 (jcf, i);
+	  if (n <= 0 || n >= JPOOL_SIZE(jcf)
+	      || JPOOL_TAG (jcf, n) != CONSTANT_NameAndType)
+	    return i;
+	  break;
 	default:
 	  return i;
 	}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: jcf-reader: support for JSR 292 classfile extensions
  2012-04-11 10:22 jcf-reader: support for JSR 292 classfile extensions Andrew Haley
@ 2012-04-11 12:43 ` Richard Guenther
  2012-04-11 13:21   ` Andrew Haley
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Guenther @ 2012-04-11 12:43 UTC (permalink / raw)
  To: Andrew Haley; +Cc: GCC Patches, GCJ-patches

On Wed, Apr 11, 2012 at 12:22 PM, Andrew Haley <aph@redhat.com> wrote:
> This adds support for the new (Version 51.0) class file format.  It
> doesn't actually generate code for invokedynamic bcause we don't have
> any runtime support yet, but it's a start.  jcf-dump prints all of the
> new attributes.

This breaks bootstrap for me:

In file included from
/space/rguenther/src/svn/trunk/gcc/java/jcf-parse.c:1009:0:
/space/rguenther/src/svn/trunk/gcc/java/jcf-reader.c:550:1: error:
'int jcf_parse_bootstrap_methods(JCF*, int)' defined but not used
[-Werror=unused-function]
 jcf_parse_bootstrap_methods (JCF* jcf, int attribute_length ATTRIBUTE_UNUSED)
 ^
cc1plus: all warnings being treated as errors
make[3]: *** [java/jcf-parse.o] Error 1
make[3]: *** Waiting for unfinished jobs....


> Andrew.
>
>
> 2012-04-11  Andrew Haley  <aph@redhat.com>
>
>        * jcf.h (bootstrap_method): New.
>        (BootstrapMethods): New.
>        (JCF): Add BootstrapMethods.
>        (enum cpool_tag): Add MethodHandle, MethodType, and InvokeDynamic.
>        * jcf-reader.c (jcf_parse_bootstrap_methods): New.
>        (jcf_parse_constant_pool): Handlers for MethodHandle, MethodType,
>        and InvokeDynamic.
>        (jcf_parse_bootstrap_methods): New.
>        * javaop.def (invokedynamic): New opcode.
>        * jcf-parse.c (get_constant): An unknown constant type should not
>        be an internal error, but a fatal one.  Make it so.
>        * jcf-dump.c (HANDLE_BOOTSTRAP_METHODS_ATTRIBUTE): New.
>        (HANDLE_END_BOOTSTRAP_METHODS): New.
>        (print_constant): Handlers for MethodHandle, MethodType, and
>        InvokeDynamic.
>
> Index: java/jcf-dump.c
> ===================================================================
> --- java/jcf-dump.c     (revision 186103)
> +++ java/jcf-dump.c     (working copy)
> @@ -430,7 +430,24 @@
>   print_element_value (out, jcf, 1);                                   \
>  }
>
> +#define HANDLE_BOOTSTRAP_METHODS_ATTRIBUTE()                           \
> +{                                                                      \
> +  COMMON_HANDLE_ATTRIBUTE(jcf, attribute_name, attribute_length);      \
> +  fputc ('\n', out); jcf_parse_bootstrap_methods (jcf, attribute_length); \
> +}
>
> +#define HANDLE_END_BOOTSTRAP_METHODS(NUM_METHODS)                      \
> +  {                                                                    \
> +    int i;                                                             \
> +    for (i = 0; i < NUM_METHODS; i++)                                  \
> +      {                                                                        \
> +       bootstrap_method *m = &jcf->bootstrap_methods.methods[i];       \
> +       fprintf (out, "  %d: ", i);                                     \
> +       print_constant (out, jcf, m->method_ref, 1);                    \
> +       fprintf (out, "\n");                                            \
> +      }                                                                        \
> +  }
> +
>  #define PROCESS_OTHER_ATTRIBUTE(JCF, INDEX, LENGTH) \
>  { COMMON_HANDLE_ATTRIBUTE(JCF, INDEX, LENGTH); \
>   fputc ('\n', out); JCF_SKIP (JCF, LENGTH); }
> @@ -898,6 +915,53 @@
>        fputc ('\"', out);
>       }
>       break;
> +    case CONSTANT_MethodHandle:
> +      {
> +       int kind = JPOOL_USHORT1 (jcf, index);
> +       if (verbosity > 0)
> +         fprintf (out, "MethodHandle kind: %d=", kind);
> +       switch(kind) {
> +       case 1:
> +       case 2:
> +       case 3:
> +       case 4:
> +         if (verbosity > 0)
> +           fprintf (out, "Fieldref: %ld=", JPOOL_USHORT2 (jcf, index));
> +         print_constant (out, jcf, JPOOL_USHORT2 (jcf, index), 0);
> +       case 5:
> +       case 6:
> +       case 7:
> +       case 8:
> +         if (verbosity > 0)
> +           fprintf (out, "Methodref: %ld=", JPOOL_USHORT2 (jcf, index));
> +         print_constant (out, jcf, JPOOL_USHORT2 (jcf, index), 0);
> +         break;
> +       case 9:
> +         if (verbosity > 0)
> +           fprintf (out, "InterfaceMethodref: %ld=", JPOOL_USHORT2 (jcf, index));
> +         print_constant (out, jcf, JPOOL_USHORT2 (jcf, index), 0);
> +         break;
> +       }
> +       break;
> +      }
> +    case CONSTANT_MethodType:
> +      if (verbosity > 0)
> +       fprintf (out, "MethodType %ld: ", JPOOL_USHORT1 (jcf, index));
> +      print_signature (out, jcf, JPOOL_USHORT1 (jcf, index), 0);
> +      break;
> +    case CONSTANT_InvokeDynamic:
> +      {
> +       uint16 name_and_type = JPOOL_USHORT2 (jcf, index);
> +       if (verbosity > 0)
> +         fprintf (out, "InvokeDynamic: ");
> +       fprintf (out, "bootstrap_method: %ld ", JPOOL_USHORT1 (jcf, index));
> +       if (verbosity == 2)
> +         fprintf (out, " name_and_type: %d=<", name_and_type);
> +       print_constant_terse (out, jcf, name_and_type, CONSTANT_NameAndType);
> +       if (verbosity == 2)
> +         fputc ('>', out);
> +       break;
> +      }
>     default:
>       fprintf (out, "(Unknown constant type %d)", kind);
>     }
> Index: java/jcf-parse.c
> ===================================================================
> --- java/jcf-parse.c    (revision 186103)
> +++ java/jcf-parse.c    (working copy)
> @@ -1113,8 +1113,8 @@
>   jcf->cpool.data[index].t = value;
>   return value;
>  bad:
> -  internal_error ("bad value constant type %d, index %d",
> -                 JPOOL_TAG (jcf, index), index);
> +  fatal_error ("bad value constant type %d, index %d",
> +              JPOOL_TAG (jcf, index), index);
>  }
>
>  tree
> Index: java/javaop.def
> ===================================================================
> --- java/javaop.def     (revision 186103)
> +++ java/javaop.def     (working copy)
> @@ -292,6 +292,7 @@
>  JAVAOP (invokespecial, 183, INVOKE,  SPECIAL, 0)
>  JAVAOP (invokestatic,  184, INVOKE,  STATIC, 0)
>  JAVAOP (invokeinterface,185, INVOKE, INTERFACE, 1)
> +JAVAOP (invokedynamic, 186, INVOKE,  DYNAMIC, 1)
>  JAVAOP (new,           187, OBJECT,  PTR,    NEW)
>  JAVAOP (newarray,      188, ARRAY,   NUM,    NEW)
>  JAVAOP (anewarray,     189, ARRAY,   PTR,    NEW)
> Index: java/jcf-reader.c
> ===================================================================
> --- java/jcf-reader.c   (revision 186103)
> +++ java/jcf-reader.c   (working copy)
> @@ -36,6 +36,7 @@
>  static int jcf_parse_one_method (JCF *, int);
>  static int jcf_parse_methods (JCF *);
>  static int jcf_parse_final_attributes (JCF *);
> +static int jcf_parse_bootstrap_methods (JCF *, int );
>  #ifdef NEED_PEEK_ATTRIBUTE
>  static int peek_attribute (JCF *, int, const char *, int);
>  #endif
> @@ -293,7 +294,16 @@
>     }
>   else
>  #endif
> +  if (MATCH_ATTRIBUTE ("BootstrapMethods"))
>     {
> +#ifdef HANDLE_BOOTSTRAP_METHODS_ATTRIBUTE
> +      HANDLE_BOOTSTRAP_METHODS_ATTRIBUTE();
> +#else
> +      JCF_SKIP (jcf, attribute_length);
> +#endif
> +    }
> +   else
> +    {
>  #ifdef PROCESS_OTHER_ATTRIBUTE
>       PROCESS_OTHER_ATTRIBUTE(jcf, attribute_name, attribute_length);
>  #else
> @@ -382,6 +392,17 @@
>          JCF_SKIP (jcf, n);
>  #endif
>          break;
> +       case CONSTANT_MethodHandle:
> +         jcf->cpool.data[i].w = JCF_readu (jcf);
> +         jcf->cpool.data[i].w |= JCF_readu2 (jcf) << 16;
> +         break;
> +       case CONSTANT_MethodType:
> +         jcf->cpool.data[i].w = JCF_readu2 (jcf);
> +         break;
> +       case CONSTANT_InvokeDynamic:
> +         jcf->cpool.data[i].w = JCF_readu2 (jcf);
> +         jcf->cpool.data[i].w |= JCF_readu2 (jcf) << 16;
> +         break;
>        default:
>          return i;
>        }
> @@ -521,3 +542,39 @@
>   return 0;
>  }
>
> +/* Read and handle the "BootstrapMethods" attribute.
> +
> +   Return 0 if OK.
> +*/
> +static int
> +jcf_parse_bootstrap_methods (JCF* jcf, int attribute_length ATTRIBUTE_UNUSED)
> +{
> +  int i;
> +  uint16 num_methods = JCF_readu2 (jcf);
> +  jcf->bootstrap_methods.count = num_methods;
> +  jcf->bootstrap_methods.methods
> +    = (bootstrap_method *) ggc_alloc_atomic (num_methods
> +                                             * sizeof (bootstrap_method));
> +#ifdef HANDLE_START_BOOTSTRAP_METHODS
> +  HANDLE_START_BOOTSTRAP_METHODS (jcf, num_methods);
> +#endif
> +
> +  for (i = 0; i < num_methods; i++)
> +    {
> +      unsigned j;
> +      bootstrap_method *m = &jcf->bootstrap_methods.methods[i];
> +      m->method_ref = JCF_readu2 (jcf);
> +      m->num_arguments = JCF_readu2 (jcf);
> +      m->bootstrap_arguments
> +       = (unsigned *) ggc_alloc_atomic (m->num_arguments
> +                                        * sizeof (unsigned));
> +      for (j = 0; j < m->num_arguments; j++)
> +       m->bootstrap_arguments[j] = JCF_readu2 (jcf);
> +    }
> +
> +#ifdef HANDLE_END_BOOTSTRAP_METHODS
> +  HANDLE_END_BOOTSTRAP_METHODS (num_methods);
> +#endif
> +
> +  return 0;
> +}
> Index: java/jcf.h
> ===================================================================
> --- java/jcf.h  (revision 186103)
> +++ java/jcf.h  (working copy)
> @@ -88,6 +88,17 @@
>                           desc ("cpool_entry_is_tree (%1.tags%a)")))   data;
>  } CPool;
>
> +typedef struct GTY(()) bootstrap_method {
> +  unsigned method_ref;
> +  unsigned num_arguments;
> +  unsigned* GTY((length ("%h.num_arguments"))) bootstrap_arguments;
> +} bootstrap_method;
> +
> +typedef struct GTY(()) BootstrapMethods {
> +  unsigned count;
> +  bootstrap_method* GTY((length ("%h.count"))) methods;
> +} BootstrapMethods;
> +
>  struct ZipDirectory;
>
>  /* JCF encapsulates the state of reading a Java Class File. */
> @@ -109,6 +120,7 @@
>   JCF_u2 this_class;
>   JCF_u2 super_class;
>   CPool cpool;
> +  BootstrapMethods bootstrap_methods;
>  } JCF;
>  /*typedef JCF*  JCF_FILE;*/
>
> @@ -245,6 +257,10 @@
>   CONSTANT_NameAndType = 12,
>   CONSTANT_Utf8 = 1,
>   CONSTANT_Unicode = 2,
> +  CONSTANT_MethodHandle = 15,
> +  CONSTANT_MethodType = 16,
> +  CONSTANT_InvokeDynamic = 18,
> +
>   CONSTANT_None = 0
>  };
>
> Index: java/jcf-io.c
> ===================================================================
> --- java/jcf-io.c       (revision 186103)
> +++ java/jcf-io.c       (working copy)
> @@ -518,6 +518,26 @@
>        case CONSTANT_Utf8:
>        case CONSTANT_Unicode:
>          break;
> +       case CONSTANT_MethodHandle:
> +         n = JPOOL_USHORT1 (jcf, i);
> +         if (n < 1 || n > 9)
> +           return i;
> +         n = JPOOL_USHORT2 (jcf, i);
> +         if (n <= 0 || n >= JPOOL_SIZE(jcf))
> +           return i;
> +         break;
> +       case CONSTANT_MethodType:
> +         n = JPOOL_USHORT1 (jcf, i);
> +         if (n <= 0 || n >= JPOOL_SIZE(jcf)
> +             || JPOOL_TAG (jcf, n) != CONSTANT_Utf8)
> +           return i;
> +         break;
> +       case CONSTANT_InvokeDynamic:
> +         n = JPOOL_USHORT2 (jcf, i);
> +         if (n <= 0 || n >= JPOOL_SIZE(jcf)
> +             || JPOOL_TAG (jcf, n) != CONSTANT_NameAndType)
> +           return i;
> +         break;
>        default:
>          return i;
>        }

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: jcf-reader: support for JSR 292 classfile extensions
  2012-04-11 12:43 ` Richard Guenther
@ 2012-04-11 13:21   ` Andrew Haley
  2012-04-11 15:57     ` Rainer Orth
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Haley @ 2012-04-11 13:21 UTC (permalink / raw)
  To: Richard Guenther; +Cc: GCC Patches, GCJ-patches

On 04/11/2012 01:43 PM, Richard Guenther wrote:
> This breaks bootstrap for me:
>
> In file included from
> /space/rguenther/src/svn/trunk/gcc/java/jcf-parse.c:1009:0:
> /space/rguenther/src/svn/trunk/gcc/java/jcf-reader.c:550:1: error:
> 'int jcf_parse_bootstrap_methods(JCF*, int)' defined but not used
> [-Werror=unused-function]
>  jcf_parse_bootstrap_methods (JCF* jcf, int attribute_length ATTRIBUTE_UNUSED)
>  ^
> cc1plus: all warnings being treated as errors
> make[3]: *** [java/jcf-parse.o] Error 1
> make[3]: *** Waiting for unfinished jobs....
>

Sorry.

Andrew.


2012-04-11  Andrew Haley  <aph@redhat.com>

	* jcf-reader.c (jcf_parse_bootstrap_methods): Add
	ATTRIBUTE_UNUSED.

Index: gcc/java/jcf-reader.c
===================================================================
--- gcc/java/jcf-reader.c	(revision 186307)
+++ gcc/java/jcf-reader.c	(working copy)
@@ -36,7 +36,7 @@
 static int jcf_parse_one_method (JCF *, int);
 static int jcf_parse_methods (JCF *);
 static int jcf_parse_final_attributes (JCF *);
-static int jcf_parse_bootstrap_methods (JCF *, int );
+static int jcf_parse_bootstrap_methods (JCF *, int) ATTRIBUTE_UNUSED;
 #ifdef NEED_PEEK_ATTRIBUTE
 static int peek_attribute (JCF *, int, const char *, int);
 #endif

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: jcf-reader: support for JSR 292 classfile extensions
  2012-04-11 13:21   ` Andrew Haley
@ 2012-04-11 15:57     ` Rainer Orth
  2012-04-11 16:09       ` Andrew Haley
  0 siblings, 1 reply; 5+ messages in thread
From: Rainer Orth @ 2012-04-11 15:57 UTC (permalink / raw)
  To: Andrew Haley; +Cc: Richard Guenther, GCC Patches, GCJ-patches

[-- Attachment #1: Type: text/plain, Size: 2673 bytes --]

Andrew Haley <aph@redhat.com> writes:

> On 04/11/2012 01:43 PM, Richard Guenther wrote:
>> This breaks bootstrap for me:
>>
>> In file included from
>> /space/rguenther/src/svn/trunk/gcc/java/jcf-parse.c:1009:0:
>> /space/rguenther/src/svn/trunk/gcc/java/jcf-reader.c:550:1: error:
>> 'int jcf_parse_bootstrap_methods(JCF*, int)' defined but not used
>> [-Werror=unused-function]
>>  jcf_parse_bootstrap_methods (JCF* jcf, int attribute_length ATTRIBUTE_UNUSED)
>>  ^
>> cc1plus: all warnings being treated as errors
>> make[3]: *** [java/jcf-parse.o] Error 1
>> make[3]: *** Waiting for unfinished jobs....
>>
>
> Sorry.

It also broke Java bootstrap on 32-bit targets:

/vol/gcc/src/hg/trunk/solaris/gcc/java/jcf-dump.c: In function 'void print_constant(std::FILE*, JCF*, int, int)':
/vol/gcc/src/hg/trunk/solaris/gcc/java/jcf-dump.c:929:64: error: format '%ld' expects argument of type 'long int', but argument 3 has type 'uint32 {aka unsigned int}' [-Werror=format]
      fprintf (out, "Fieldref: %ld=", JPOOL_USHORT2 (jcf, index));
                                                                ^
/vol/gcc/src/hg/trunk/solaris/gcc/java/jcf-dump.c:936:65: error: format '%ld' expects argument of type 'long int', but argument 3 has type 'uint32 {aka unsigned int}' [-Werror=format]
      fprintf (out, "Methodref: %ld=", JPOOL_USHORT2 (jcf, index));
                                                                 ^
/vol/gcc/src/hg/trunk/solaris/gcc/java/jcf-dump.c:941:74: error: format '%ld' expects argument of type 'long int', but argument 3 has type 'uint32 {aka unsigned int}' [-Werror=format]
      fprintf (out, "InterfaceMethodref: %ld=", JPOOL_USHORT2 (jcf, index));
                                                                          ^
/vol/gcc/src/hg/trunk/solaris/gcc/java/jcf-dump.c:949:62: error: format '%ld' expects argument of type 'long int', but argument 3 has type 'uint32 {aka unsigned int}' [-Werror=format]
  fprintf (out, "MethodType %ld: ", JPOOL_USHORT1 (jcf, index));
                                                              ^
/vol/gcc/src/hg/trunk/solaris/gcc/java/jcf-dump.c:957:68: error: format '%ld' expects argument of type 'long int', but argument 3 has type 'uint32 {aka unsigned int}' [-Werror=format]
  fprintf (out, "bootstrap_method: %ld ", JPOOL_USHORT1 (jcf, index));
                                                                    ^
The following patch got me into stage3 on i386-pc-solaris2.10 and
amd64-pc-solaris2.10.

Ok for mainline?

	Rainer


2012-04-11  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	* jcf-dump.c (print_constant): Cast JPOOL_USHORT2, JPOOL_USHORT1
	results to long to match formats.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: java-jcf-dump.patch --]
[-- Type: text/x-patch, Size: 1939 bytes --]

# HG changeset patch
# Parent 94918a528698bab552dc2f8be5c1666444afca67
Fix java bootstrap on 32-bit targets

diff --git a/gcc/java/jcf-dump.c b/gcc/java/jcf-dump.c
--- a/gcc/java/jcf-dump.c
+++ b/gcc/java/jcf-dump.c
@@ -926,19 +926,20 @@ print_constant (FILE *out, JCF *jcf, int
 	case 3:
 	case 4:
 	  if (verbosity > 0)
-	    fprintf (out, "Fieldref: %ld=", JPOOL_USHORT2 (jcf, index));
+	    fprintf (out, "Fieldref: %ld=", (long) JPOOL_USHORT2 (jcf, index));
 	  print_constant (out, jcf, JPOOL_USHORT2 (jcf, index), 0);
 	case 5:
 	case 6:
 	case 7:
 	case 8:
 	  if (verbosity > 0)
-	    fprintf (out, "Methodref: %ld=", JPOOL_USHORT2 (jcf, index));
+	    fprintf (out, "Methodref: %ld=", (long) JPOOL_USHORT2 (jcf, index));
 	  print_constant (out, jcf, JPOOL_USHORT2 (jcf, index), 0);
 	  break;
 	case 9:
 	  if (verbosity > 0)
-	    fprintf (out, "InterfaceMethodref: %ld=", JPOOL_USHORT2 (jcf, index));
+	    fprintf (out, "InterfaceMethodref: %ld=",
+		     (long) JPOOL_USHORT2 (jcf, index));
 	  print_constant (out, jcf, JPOOL_USHORT2 (jcf, index), 0);
 	  break;
 	}
@@ -946,7 +947,7 @@ print_constant (FILE *out, JCF *jcf, int
       }
     case CONSTANT_MethodType:
       if (verbosity > 0)
-	fprintf (out, "MethodType %ld: ", JPOOL_USHORT1 (jcf, index));
+	fprintf (out, "MethodType %ld: ", (long) JPOOL_USHORT1 (jcf, index));
       print_signature (out, jcf, JPOOL_USHORT1 (jcf, index), 0);
       break;
     case CONSTANT_InvokeDynamic:
@@ -954,7 +955,8 @@ print_constant (FILE *out, JCF *jcf, int
 	uint16 name_and_type = JPOOL_USHORT2 (jcf, index);
 	if (verbosity > 0)
 	  fprintf (out, "InvokeDynamic: ");
-	fprintf (out, "bootstrap_method: %ld ", JPOOL_USHORT1 (jcf, index));
+	fprintf (out, "bootstrap_method: %ld ",
+		 (long) JPOOL_USHORT1 (jcf, index));
 	if (verbosity == 2)
 	  fprintf (out, " name_and_type: %d=<", name_and_type);
 	print_constant_terse (out, jcf, name_and_type, CONSTANT_NameAndType);

[-- Attachment #3: Type: text/plain, Size: 144 bytes --]



-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: jcf-reader: support for JSR 292 classfile extensions
  2012-04-11 15:57     ` Rainer Orth
@ 2012-04-11 16:09       ` Andrew Haley
  0 siblings, 0 replies; 5+ messages in thread
From: Andrew Haley @ 2012-04-11 16:09 UTC (permalink / raw)
  To: java-patches

On 04/11/2012 04:57 PM, Rainer Orth wrote:
> Ok for mainline?
> 
> 	Rainer
> 
> 
> 2012-04-11  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
> 
> 	* jcf-dump.c (print_constant): Cast JPOOL_USHORT2, JPOOL_USHORT1
> 	results to long to match formats.

Sure.  Sorry for the noise.

I wonder what we're supposed to do about warnings that only trigger
on 32-bit systems.  Just wait for reports, or do we really have to
boostrap with both?

Andrew.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-04-11 16:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-11 10:22 jcf-reader: support for JSR 292 classfile extensions Andrew Haley
2012-04-11 12:43 ` Richard Guenther
2012-04-11 13:21   ` Andrew Haley
2012-04-11 15:57     ` Rainer Orth
2012-04-11 16:09       ` Andrew Haley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).