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]

Re: [ecj] More sun.misc.Unsafe stuff


We need to check to make sure we have compare-and-swap instructions;
otherwise gcc generates calls to compare_and_swap_N() routines that
don't exist.  In that case, libgcj contains the necessary fallback
routines.

Andrew.


2006-10-06  Andrew Haley  <aph@redhat.com>

        * builtins.c (compareAndSwapInt_builtin): Check that we really do
        have a compare_and_swap builtin.
        (compareAndSwapLong_builtin): Likewise.
        (compareAndSwapObject_builtin): Likewise.

Index: builtins.c
===================================================================
--- builtins.c	(revision 117434)
+++ builtins.c	(working copy)
@@ -36,7 +36,10 @@
 #include "java-tree.h"
 #include <stdarg.h>
 #include "convert.h"
-
+#include "rtl.h"
+#include "insn-codes.h"
+#include "expr.h"
+#include "optabs.h"
 
 static tree max_builtin (tree, tree);
 static tree min_builtin (tree, tree);
@@ -299,56 +302,75 @@
 compareAndSwapInt_builtin (tree method_return_type ATTRIBUTE_UNUSED,
 			   tree method_arguments)
 {
-  tree newarglist, addr, stmt;
-  UNMARSHAL5 (method_arguments);
+  enum machine_mode mode = TYPE_MODE (int_type_node);
+  if (sync_compare_and_swap_cc[mode] != CODE_FOR_nothing 
+      || sync_compare_and_swap[mode] != CODE_FOR_nothing)
+    {
+      tree newarglist, addr, stmt;
+      UNMARSHAL5 (method_arguments);
 
-  addr = build_addr_sum (int_type_node, obj_arg, offset_arg);
+      addr = build_addr_sum (int_type_node, obj_arg, offset_arg);
 
-  newarglist 
-    = build_arglist_for_builtin (addr, expected_arg, value_arg, NULL_TREE);
-  stmt = (build_function_call_expr
-	  (built_in_decls[BUILT_IN_BOOL_COMPARE_AND_SWAP_4],
-	   newarglist));
+      newarglist 
+	= build_arglist_for_builtin (addr, expected_arg, value_arg, NULL_TREE);
+      stmt = (build_function_call_expr
+	      (built_in_decls[BUILT_IN_BOOL_COMPARE_AND_SWAP_4],
+	       newarglist));
 
-  return build_check_this (stmt, this_arg);
+      return build_check_this (stmt, this_arg);
+    }
+  return NULL_TREE;
 }
 
 static tree
 compareAndSwapLong_builtin (tree method_return_type ATTRIBUTE_UNUSED,
 			    tree method_arguments)
 {
-  tree newarglist, addr, stmt;
-  UNMARSHAL5 (method_arguments);
+  enum machine_mode mode = TYPE_MODE (long_type_node);
+  if (sync_compare_and_swap_cc[mode] != CODE_FOR_nothing 
+      || sync_compare_and_swap[mode] != CODE_FOR_nothing)
+    {
+      tree newarglist, addr, stmt;
+      UNMARSHAL5 (method_arguments);
 
-  addr = build_addr_sum (long_type_node, obj_arg, offset_arg);
+      addr = build_addr_sum (long_type_node, obj_arg, offset_arg);
 
-  newarglist 
-    = build_arglist_for_builtin (addr, expected_arg, value_arg, NULL_TREE);
-  stmt = (build_function_call_expr
-	  (built_in_decls[BUILT_IN_BOOL_COMPARE_AND_SWAP_8],
-	   newarglist));
+      newarglist 
+	= build_arglist_for_builtin (addr, expected_arg, value_arg, NULL_TREE);
+      stmt = (build_function_call_expr
+	      (built_in_decls[BUILT_IN_BOOL_COMPARE_AND_SWAP_8],
+	       newarglist));
 
-  return build_check_this (stmt, this_arg);
+      return build_check_this (stmt, this_arg);
+    }
+  return NULL_TREE;
 }
-
 static tree
 compareAndSwapObject_builtin (tree method_return_type ATTRIBUTE_UNUSED, 
 			      tree method_arguments)
 {
-  tree newarglist, addr, stmt;
-  UNMARSHAL5 (method_arguments);
-
-  addr = build_addr_sum (value_type, obj_arg, offset_arg);
-
-  newarglist 
-    = build_arglist_for_builtin (addr, expected_arg, value_arg, NULL_TREE);
-  stmt = (build_function_call_expr
-	  (built_in_decls[POINTER_SIZE == 32 
-			  ? BUILT_IN_BOOL_COMPARE_AND_SWAP_4 
-			  : BUILT_IN_BOOL_COMPARE_AND_SWAP_8],
-	   newarglist));
-
-  return build_check_this (stmt, this_arg);
+  enum machine_mode mode = TYPE_MODE (ptr_type_node);
+  if (sync_compare_and_swap_cc[mode] != CODE_FOR_nothing 
+      || sync_compare_and_swap[mode] != CODE_FOR_nothing)
+  {
+    tree newarglist, addr, stmt;
+    UNMARSHAL5 (method_arguments);
+
+    int builtin = (POINTER_SIZE == 32 
+		   ? BUILT_IN_BOOL_COMPARE_AND_SWAP_4 
+		   : BUILT_IN_BOOL_COMPARE_AND_SWAP_8);
+
+    addr = build_addr_sum (value_type, obj_arg, offset_arg);
+
+    newarglist 
+      = build_arglist_for_builtin (addr, expected_arg, value_arg, NULL_TREE);
+    stmt = (build_function_call_expr
+	    (built_in_decls[builtin],
+	     newarglist));
+
+    return build_check_this (stmt, this_arg);
+  }
+  return NULL_TREE;
 }
 
 static tree
@@ -366,7 +388,7 @@
   newarglist = NULL_TREE;
   stmt = (build_function_call_expr
 	  (built_in_decls[BUILT_IN_SYNCHRONIZE],
-			  newarglist));
+	   newarglist));
   modify_stmt = fold_build2 (MODIFY_EXPR, value_type,
 			     build_java_indirect_ref (value_type, addr,
 						      flag_check_references),
@@ -392,7 +414,7 @@
   newarglist = NULL_TREE;
   stmt = (build_function_call_expr
 	  (built_in_decls[BUILT_IN_SYNCHRONIZE],
-			  newarglist));
+	   newarglist));
   
   tmp = build_decl (VAR_DECL, NULL, method_return_type);
   DECL_IGNORED_P (tmp) = 1;
@@ -525,7 +547,6 @@
 		  boolean_ftype_boolean_boolean,
 		  "__builtin_expect",
 		  BUILTIN_CONST | BUILTIN_NOTHROW);
-
   define_builtin (BUILT_IN_BOOL_COMPARE_AND_SWAP_4, 
 		  "__sync_bool_compare_and_swap_4",
 		  build_function_type_list (boolean_type_node,
@@ -533,7 +554,6 @@
 					    build_pointer_type (int_type_node),
 					    int_type_node, NULL_TREE), 
 		  "__sync_bool_compare_and_swap_4", 0);
-		  
   define_builtin (BUILT_IN_BOOL_COMPARE_AND_SWAP_8, 
 		  "__sync_bool_compare_and_swap_8",
 		  build_function_type_list (boolean_type_node,
@@ -541,11 +561,10 @@
 					    build_pointer_type (long_type_node),
 					    int_type_node, NULL_TREE), 
 		  "__sync_bool_compare_and_swap_8", 0);
-		  
   define_builtin (BUILT_IN_SYNCHRONIZE, "__sync_synchronize",
 		  build_function_type (void_type_node, void_list_node),
 		  "__sync_synchronize", BUILTIN_NOTHROW);
-
+  
   build_common_builtin_nodes ();
 }
 


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