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]

RFC: BC-ABI version IDs, take 2


Here's another version ID patch. The basic changes are:

- From the 32-bit version ID, we use 20 bits for a numerical version number. For the C++ ABI, this is calculated from the major and minor GCC version numbers. For the BC ABI, this number could be arbritary, but I think there is some value in using a number which relates to the first GCC version that ABI is compatible with. It avoids the need to maintain a table somewhere mapping version IDs to specific GCJ releases, and if we were to print some error message if a class with an incompatible version ID is loaded, then a useful error message can be derived from the version ID.

- 2 digits in the version number are reserved for a "minor ABI version". This could be used in the event that an addition/change to the ABI is made during a GCC release cycle.

- The remaining 12 bits are reserved for flags that could represent various ABI features, or just additional ABI-specific options. Currently 2 flags are defined:

FLAG_BINARYCOMPAT_ABI
FLAG_BOOTSTRAP_LOADER

This scheme should give us a more flexible and scalable ID number going forward. Comments?

Bryce

2005-05-20  Bryce McKinlay  <mckinlay@redhat.com>

	* decl.c (GCJ_BINARYCOMPAT_ADDITION, 
	GCJ_BOOTSTRAP_LOADER_ADDITION): Removed.
	(FLAG_BINARYCOMPAT_ABI, FLAG_BOOTSTRAP_LOADER,
	MINOR_BINARYCOMPAT_ABI_VERSION): New.
	(GCJ_CURRENT_BC_ABI_VERSION): Use new method to calculate version ID.
	(parse_version): Calculate version ID using new method. Use bit-flags
	for flag_indirect_dispatch and flag_bootstrap_classes.

2005-05-20  Bryce McKinlay  <mckinlay@redhat.com>

	* include/jvm.h (FLAG_BINARYCOMPAT_ABI, FLAG_BOOTSTRAP_LOADER): New.
	(GCJ_BINARYCOMPAT_ADDITION, GCJ_BOOTSTRAP_LOADER_ADDITION): Removed.
	(OLD_GCJ_40_BC_ABI_VERSION): Renamed. Old-style version ID for BC-ABI
	classes.
	(GCJ_40_BC_ABI_VERSION, GCJ_41_BC_ABI_VERSION): New. Calculate version
	IDs using new method.
	(_Jv_CheckABIVersion): Check for both old and new style version IDs.
	(_Jv_ClassForBootstrapLoader): Use FLAG_BOOTSTRAP_LOADER. 


Index: gcc/java/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/decl.c,v
retrieving revision 1.220
diff -u -r1.220 decl.c
--- gcc/java/decl.c	12 May 2005 01:26:50 -0000	1.220
+++ gcc/java/decl.c	20 May 2005 22:59:36 -0000
@@ -61,19 +61,31 @@
 static tree check_local_unnamed_variable (tree, tree, tree);
 static void parse_version (void);
 
-/* Used when computing the ABI version.  */
-#define GCJ_BINARYCOMPAT_ADDITION 5
 
-/* Used when defining a class that should be loaded by the bootstrap
-   loader.  */
-#define GCJ_BOOTSTRAP_LOADER_ADDITION 1
-
-/* The version of the BC ABI that we generate.  At the moment we are
-   compatible with what shipped in GCC 4.0.  This must be kept in sync
-   with parse_version(), libgcj, and reality (if the BC format
-   changes, this must change.  */
+/* The following ABI flags are used in the high-order bits of the version
+   ID field. The version ID number itself should never be larger than 
+   0xfffff, so it should be safe to use top 12 bits for these flags. */
+
+#define FLAG_BINARYCOMPAT_ABI (1<<31)  /* Class is built with the BC-ABI. */
+
+#define FLAG_BOOTSTRAP_LOADER (1<<30)  /* Used when defining a class that 
+					  should be loaded by the bootstrap
+					  loader.  */
+
+/* If an ABI change is made within a GCC release series, rendering current
+   binaries incompatible with the old runtimes, this number can be set to
+   enforce the compatibility rules. */
+#define MINOR_BINARYCOMPAT_ABI_VERSION 0
+
+/* The runtime may recognize a variety of BC ABIs (objects generated by 
+   different version of gcj), but will probably always require strict 
+   matching for the ordinary (C++) ABI.  */
+
+/* The version ID of the BC ABI that we generate.  This must be kept in
+   sync with parse_version(), libgcj, and reality (if the BC format changes, 
+   this must change).  */
 #define GCJ_CURRENT_BC_ABI_VERSION \
-  (4 * 10000 + 0 * 10 + GCJ_BINARYCOMPAT_ADDITION)
+  (4 * 100000 + 1 * 1000 + MINOR_BINARYCOMPAT_ABI_VERSION)
 
 /* The ABI version number.  */
 tree gcj_abi_version;
@@ -614,18 +626,20 @@
       ++p;
     }
 
-  /* Implicit in this computation is the idea that we won't break the
-     old-style binary ABI in a sub-minor release (e.g., from 4.0.0 to
-     4.0.1).  */
-  abi_version = 10000 * major + 10 * minor;
-  /* It is helpful to distinguish BC ABI from ordinary ABI at this
-     level, since at some point we will recognize a variety of BC ABIs
-     (objects generated by different version of gcj), but will
-     probably always require strict matching for ordinary ABI.  */
   if (flag_indirect_dispatch)
-    abi_version = GCJ_CURRENT_BC_ABI_VERSION;
+    {
+      abi_version = GCJ_CURRENT_BC_ABI_VERSION;
+      abi_version |= FLAG_BINARYCOMPAT_ABI;
+    }
+  else /* C++ ABI */
+    {
+      /* Implicit in this computation is the idea that we won't break the
+	 old-style binary ABI in a sub-minor release (e.g., from 4.0.0 to
+	 4.0.1).  */
+      abi_version = 100000 * major + 1000 * minor;
+    }
   if (flag_bootstrap_classes)
-    abi_version += GCJ_BOOTSTRAP_LOADER_ADDITION;
+    abi_version |= FLAG_BOOTSTRAP_LOADER;
 
   gcj_abi_version = build_int_cstu (ptr_type_node, abi_version);
 }
Index: libjava/include/jvm.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/jvm.h,v
retrieving revision 1.86
diff -u -r1.86 jvm.h
--- libjava/include/jvm.h	13 May 2005 01:02:32 -0000	1.86
+++ libjava/include/jvm.h	20 May 2005 22:59:36 -0000
@@ -564,31 +564,54 @@
 
 extern void _Jv_RegisterBootstrapPackages ();
 
+#define FLAG_BINARYCOMPAT_ABI (1<<31)  /* Class is built with the BC-ABI. */
+
+#define FLAG_BOOTSTRAP_LOADER (1<<30)  /* Used when defining a class that 
+					  should be loaded by the bootstrap
+					  loader.  */
+
+// These are used to find ABI versions we recognize.
+#define GCJ_VERSION (__GNUC__ * 100000 + __GNUC_MINOR__ * 1000)
+
+// This is the old-style BC version ID used by GCJ 4.0.
+#define OLD_GCJ_40_BC_ABI_VERSION (4 * 10000 + 0 * 10 + 5)
+
+// New style version IDs used by GCJ 4.0.1 and later.
+#define GCJ_40_BC_ABI_VERSION (4 * 100000 + 0 * 1000)
+#define GCJ_41_BC_ABI_VERSION (4 * 100000 + 1 * 1000)
 
-// This is used to find ABI versions we recognize.
-#define GCJ_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 10)
-#define GCJ_BINARYCOMPAT_ADDITION 5
-#define GCJ_BOOTSTRAP_LOADER_ADDITION 1
-
-// At present we know we are compatible with the BC ABI as used in GCC
-// 4.0.
-#define GCJ_40_BC_ABI_VERSION (4 * 10000 + 0 * 10 + GCJ_BINARYCOMPAT_ADDITION)
 
 inline bool
 _Jv_CheckABIVersion (unsigned long value)
 {
-  // Recognize our defined C++ ABIs.
-  return (value == GCJ_VERSION
-	  || value == (GCJ_VERSION + GCJ_BOOTSTRAP_LOADER_ADDITION)
-	  || value == GCJ_40_BC_ABI_VERSION
-	  || value == (GCJ_40_BC_ABI_VERSION + GCJ_BOOTSTRAP_LOADER_ADDITION));
+  // We are compatible with GCJ 4.0 BC-ABI classes. This release used a
+  // different format for the version ID string.
+   if (value == OLD_GCJ_40_BC_ABI_VERSION)
+     return true;
+     
+  // The 20 low-end bits are used for the version number.
+  unsigned long version = value & 0xfffff;
+
+  if (value & FLAG_BINARYCOMPAT_ABI)
+    {
+      int abi_rev = version % 100;
+      int abi_ver = version - abi_rev;
+      if (abi_ver == GCJ_40_BC_ABI_VERSION && abi_rev <= 0)
+        return true;
+      if (abi_ver == GCJ_41_BC_ABI_VERSION && abi_rev <= 0)
+        return true;
+    }
+  else
+    // C++ ABI
+    return version == GCJ_VERSION;
+  
+  return false;
 }
 
 inline bool
 _Jv_ClassForBootstrapLoader (unsigned long value)
 {
-  return (value == (GCJ_VERSION + GCJ_BOOTSTRAP_LOADER_ADDITION)
-	  || value == (GCJ_40_BC_ABI_VERSION + GCJ_BOOTSTRAP_LOADER_ADDITION));
+  return (value & FLAG_BOOTSTRAP_LOADER);
 }
 
 // It makes the source cleaner if we simply always define this

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