OSDN Git Service

2004-12-17 Andrew Haley <aph@redhat.com>
[pf3gnuchains/gcc-fork.git] / gcc / java / expr.c
index 182d247..8c1ad70 100644 (file)
@@ -1,21 +1,21 @@
 /* Process expressions for the GNU compiler for the Java(TM) language.
-   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
+   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
    Free Software Foundation, Inc.
 
-This file is part of GNU CC.
+This file is part of GCC.
 
-GNU CC is free software; you can redistribute it and/or modify
+GCC is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2, or (at your option)
 any later version.
 
-GNU CC is distributed in the hope that it will be useful,
+GCC is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with GNU CC; see the file COPYING.  If not, write to
+along with GCC; see the file COPYING.  If not, write to
 the Free Software Foundation, 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  
 
@@ -27,6 +27,8 @@ The Free Software Foundation is independent of Sun Microsystems, Inc.  */
 
 #include "config.h"
 #include "system.h"
+#include "coretypes.h"
+#include "tm.h"
 #include "tree.h"
 #include "real.h"
 #include "rtl.h"
@@ -41,60 +43,59 @@ The Free Software Foundation is independent of Sun Microsystems, Inc.  */
 #include "toplev.h"
 #include "except.h"
 #include "ggc.h"
-
-static void flush_quick_stack PARAMS ((void));
-static void push_value PARAMS ((tree));
-static tree pop_value PARAMS ((tree));
-static void java_stack_swap PARAMS ((void));
-static void java_stack_dup PARAMS ((int, int));
-static void build_java_athrow PARAMS ((tree));
-static void build_java_jsr PARAMS ((tree, tree));
-static void build_java_ret PARAMS ((tree));
-static void expand_java_multianewarray PARAMS ((tree, int));
-static void expand_java_arraystore PARAMS ((tree));
-static void expand_java_arrayload PARAMS ((tree));
-static void expand_java_array_length PARAMS ((void));
-static tree build_java_monitor PARAMS ((tree, tree));
-static void expand_java_pushc PARAMS ((int, tree));
-static void expand_java_return PARAMS ((tree));
-static void expand_load_internal PARAMS ((int, tree, int));
-static void expand_java_NEW PARAMS ((tree));
-static void expand_java_INSTANCEOF PARAMS ((tree));
-static void expand_java_CHECKCAST PARAMS ((tree));
-static void expand_iinc PARAMS ((unsigned int, int, int));
-static void expand_java_binop PARAMS ((tree, enum tree_code));
-static void note_label PARAMS ((int, int));
-static void expand_compare PARAMS ((enum tree_code, tree, tree, int));
-static void expand_test PARAMS ((enum tree_code, tree, int));
-static void expand_cond PARAMS ((enum tree_code, tree, int));
-static void expand_java_goto PARAMS ((int));
+#include "tree-gimple.h"
+#include "target.h"
+
+static void flush_quick_stack (void);
+static void push_value (tree);
+static tree pop_value (tree);
+static void java_stack_swap (void);
+static void java_stack_dup (int, int);
+static void build_java_athrow (tree);
+static void build_java_jsr (int, int);
+static void build_java_ret (tree);
+static void expand_java_multianewarray (tree, int);
+static void expand_java_arraystore (tree);
+static void expand_java_arrayload (tree);
+static void expand_java_array_length (void);
+static tree build_java_monitor (tree, tree);
+static void expand_java_pushc (int, tree);
+static void expand_java_return (tree);
+static void expand_load_internal (int, tree, int);
+static void expand_java_NEW (tree);
+static void expand_java_INSTANCEOF (tree);
+static void expand_java_CHECKCAST (tree);
+static void expand_iinc (unsigned int, int, int);
+static void expand_java_binop (tree, enum tree_code);
+static void note_label (int, int);
+static void expand_compare (enum tree_code, tree, tree, int);
+static void expand_test (enum tree_code, tree, int);
+static void expand_cond (enum tree_code, tree, int);
+static void expand_java_goto (int);
+static tree expand_java_switch (tree, int);
+static void expand_java_add_case (tree, int, int);
 #if 0
-static void expand_java_call PARAMS ((int, int));
-static void expand_java_ret PARAMS ((tree)); 
+static void expand_java_call (int, int);
+static void expand_java_ret (tree); 
 #endif
-static tree pop_arguments PARAMS ((tree)); 
-static void expand_invoke PARAMS ((int, int, int)); 
-static void expand_java_field_op PARAMS ((int, int, int)); 
-static void java_push_constant_from_pool PARAMS ((struct JCF *, int)); 
-static void java_stack_pop PARAMS ((int)); 
-static tree build_java_throw_out_of_bounds_exception PARAMS ((tree)); 
-static tree build_java_check_indexed_type PARAMS ((tree, tree)); 
-static tree java_array_data_offset PARAMS ((tree)); 
-static tree case_identity PARAMS ((tree, tree)); 
-static unsigned char peek_opcode_at_pc PARAMS ((struct JCF *, int, int));
-static bool emit_init_test_initialization PARAMS ((struct hash_entry *,
-                                                  PTR ptr));
-
-static tree operand_type[59];
-extern struct obstack permanent_obstack;
-
-static tree methods_ident = NULL_TREE;
-static tree ncode_ident = NULL_TREE;
+static tree pop_arguments (tree); 
+static void expand_invoke (int, int, int); 
+static void expand_java_field_op (int, int, int); 
+static void java_push_constant_from_pool (struct JCF *, int); 
+static void java_stack_pop (int); 
+static tree build_java_throw_out_of_bounds_exception (tree); 
+static tree build_java_check_indexed_type (tree, tree); 
+static unsigned char peek_opcode_at_pc (struct JCF *, int, int);
+
+static GTY(()) tree operand_type[59];
+
+static GTY(()) tree methods_ident;
+static GTY(()) tree ncode_ident;
 tree dtable_ident = NULL_TREE;
 
-/* Set to non-zero value in order to emit class initilization code
+/* Set to nonzero value in order to emit class initialization code
    before static field references.  */
-int always_initialize_class_p;
+int always_initialize_class_p = 0;
 
 /* We store the stack state in two places:
    Within a basic block, we use the quick_stack, which is a
@@ -108,7 +109,7 @@ int always_initialize_class_p;
 
    If a variable is on the quick stack, it means the value of variable
    when the quick stack was last flushed.  Conceptually, flush_quick_stack
-   saves all the the quick_stack elements in parellel.  However, that is
+   saves all the quick_stack elements in parallel.  However, that is
    complicated, so it actually saves them (i.e. copies each stack value
    to is home virtual register) from low indexes.  This allows a quick_stack
    element at index i (counting from the bottom of stack the) to references
@@ -123,10 +124,10 @@ int always_initialize_class_p;
    So dup cannot just add an extra element to the quick_stack, but iadd can.
 */
 
-static tree quick_stack = NULL_TREE;
+static GTY(()) tree quick_stack;
 
-/* A free-list of unused permamnet TREE_LIST nodes. */
-static tree tree_list_free_list = NULL_TREE;
+/* A free-list of unused permanent TREE_LIST nodes.  */
+static GTY((deletable)) tree tree_list_free_list;
 
 /* The stack pointer of the Java virtual machine.
    This does include the size of the quick_stack. */
@@ -137,23 +138,17 @@ const unsigned char *linenumber_table;
 int linenumber_count;
 
 void
-init_expr_processing()
+init_expr_processing (void)
 {
   operand_type[21] = operand_type[54] = int_type_node;
   operand_type[22] = operand_type[55] = long_type_node;
   operand_type[23] = operand_type[56] = float_type_node;
   operand_type[24] = operand_type[57] = double_type_node;
   operand_type[25] = operand_type[58] = ptr_type_node;
-  ggc_add_tree_root (operand_type, 59);
-  ggc_add_tree_root (&methods_ident, 1);
-  ggc_add_tree_root (&ncode_ident, 1);
-  ggc_add_tree_root (&quick_stack, 1);
-  ggc_add_tree_root (&tree_list_free_list, 1);
 }
 
 tree
-truthvalue_conversion (expr)
-     tree expr;
+java_truthvalue_conversion (tree expr)
 {
   /* It is simpler and generates better code to have only TRUTH_*_EXPR
      or comparison expressions as truth values at this level.
@@ -162,12 +157,16 @@ truthvalue_conversion (expr)
 
   switch (TREE_CODE (expr))
     {
-    case EQ_EXPR:
-    case NE_EXPR: case LE_EXPR: case GE_EXPR: case LT_EXPR: case GT_EXPR:
+    case EQ_EXPR:   case NE_EXPR:   case UNEQ_EXPR: case LTGT_EXPR:
+    case LE_EXPR:   case GE_EXPR:   case LT_EXPR:   case GT_EXPR:
+    case UNLE_EXPR: case UNGE_EXPR: case UNLT_EXPR: case UNGT_EXPR:
+    case ORDERED_EXPR: case UNORDERED_EXPR:
     case TRUTH_ANDIF_EXPR:
     case TRUTH_ORIF_EXPR:
     case TRUTH_AND_EXPR:
     case TRUTH_OR_EXPR:
+    case TRUTH_XOR_EXPR:
+    case TRUTH_NOT_EXPR:
     case ERROR_MARK:
       return expr;
 
@@ -181,44 +180,29 @@ truthvalue_conversion (expr)
     case NEGATE_EXPR:
     case ABS_EXPR:
     case FLOAT_EXPR:
-    case FFS_EXPR:
-      /* These don't change whether an object is non-zero or zero.  */
-      return truthvalue_conversion (TREE_OPERAND (expr, 0));
+      /* These don't change whether an object is nonzero or zero.  */
+      return java_truthvalue_conversion (TREE_OPERAND (expr, 0));
 
     case COND_EXPR:
       /* Distribute the conversion into the arms of a COND_EXPR.  */
-      return fold (build (COND_EXPR, boolean_type_node, TREE_OPERAND (expr, 0),
-                          truthvalue_conversion (TREE_OPERAND (expr, 1)),
-                          truthvalue_conversion (TREE_OPERAND (expr, 2))));
+      return fold
+              (build3 (COND_EXPR, boolean_type_node, TREE_OPERAND (expr, 0),
+                       java_truthvalue_conversion (TREE_OPERAND (expr, 1)),
+                       java_truthvalue_conversion (TREE_OPERAND (expr, 2))));
 
     case NOP_EXPR:
       /* If this is widening the argument, we can ignore it.  */
       if (TYPE_PRECISION (TREE_TYPE (expr))
           >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
-        return truthvalue_conversion (TREE_OPERAND (expr, 0));
+        return java_truthvalue_conversion (TREE_OPERAND (expr, 0));
       /* fall through to default */
 
     default:
-      return fold (build (NE_EXPR, boolean_type_node, expr, boolean_false_node));
+      return fold (build2 (NE_EXPR, boolean_type_node,
+                          expr, boolean_false_node));
     }
 }
 
-#ifdef JAVA_USE_HANDLES
-/* Given a pointer to a handle, get a pointer to an object. */
-
-tree
-unhand_expr (expr)
-     tree expr;
-{
-  tree field, handle_type;
-  expr = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (expr)), expr);
-  handle_type = TREE_TYPE (expr);
-  field = TYPE_FIELDS (handle_type);
-  expr = build (COMPONENT_REF, TREE_TYPE (field), expr, field);
-  return expr;
-}
-#endif
-
 /* Save any stack slots that happen to be in the quick_stack into their
    home virtual register slots.
 
@@ -227,10 +211,10 @@ unhand_expr (expr)
    higher (or the same) index, but not lower. */
 
 static void
-flush_quick_stack ()
+flush_quick_stack (void)
 {
   int stack_index = stack_pointer;
-  register tree prev, cur, next;
+  tree prev, cur, next;
 
   /* First reverse the quick_stack, and count the number of slots it has. */
   for (cur = quick_stack, prev = NULL_TREE; cur != NULL_TREE; cur = next)
@@ -254,7 +238,7 @@ flush_quick_stack ()
 
       decl = find_stack_slot (stack_index, type);
       if (decl != node)
-         expand_assignment (decl, node, 0, 0);
+       java_add_stmt (build2 (MODIFY_EXPR, TREE_TYPE (node), decl, node));
       stack_index += 1 + TYPE_IS_WIDE (type);
     }
 }
@@ -263,14 +247,16 @@ flush_quick_stack ()
    Return true on success, 0 on overflow. */
 
 int
-push_type_0 (type)
-     tree type;
+push_type_0 (tree type)
 {
   int n_words;
   type = promote_type (type);
   n_words = 1 + TYPE_IS_WIDE (type);
   if (stack_pointer + n_words > DECL_MAX_STACK (current_function_decl))
     return 0;
+  /* Allocate decl for this variable now, so we get a temporary that
+     survives the whole method. */
+  find_stack_slot (stack_pointer, type);
   stack_type_map[stack_pointer++] = type;
   n_words--;
   while (--n_words >= 0)
@@ -279,16 +265,14 @@ push_type_0 (type)
 }
 
 void
-push_type (type)
-     tree type;
+push_type (tree type)
 {
   if (! push_type_0 (type))
     abort ();
 }
 
 static void
-push_value (value)
-     tree value;
+push_value (tree value)
 {
   tree type = TREE_TYPE (value);
   if (TYPE_PRECISION (type) < 32 && INTEGRAL_TYPE_P (type))
@@ -315,9 +299,7 @@ push_value (value)
    On an error, *MESSAGEP is set to a freshly malloc'd error message. */
 
 tree
-pop_type_0 (type, messagep)
-     tree type;
-     char **messagep;
+pop_type_0 (tree type, char **messagep)
 {
   int n_words;
   tree t;
@@ -341,26 +323,63 @@ pop_type_0 (type, messagep)
   t = stack_type_map[--stack_pointer];
   if (type == NULL_TREE || t == type)
     return t;
+  if (TREE_CODE (t) == TREE_LIST)
+    {      
+      do
+       {
+         tree tt = TREE_PURPOSE (t);
+         if (! can_widen_reference_to (tt, type))
+           {
+             t = tt;
+             goto fail;
+           }
+         t = TREE_CHAIN (t);
+       }
+      while (t);
+      return t;
+    }
   if (INTEGRAL_TYPE_P (type) && INTEGRAL_TYPE_P (t)
       && TYPE_PRECISION (type) <= 32 && TYPE_PRECISION (t) <= 32)
-      return t;
+    return t;
   if (TREE_CODE (type) == POINTER_TYPE && TREE_CODE (t) == POINTER_TYPE)
     {
-      if (type == ptr_type_node || type == object_ptr_type_node)
-       return t;
-      else if (t == ptr_type_node)  /* Special case for null reference. */
-       return type;
-      else if (can_widen_reference_to (t, type))
-       return t;
-      /* This is a kludge, but matches what Sun's verifier does.
-        It can be tricked, but is safe as long as type errors
-        (i.e. interface method calls) are caught at run-time. */
-      else if (CLASS_INTERFACE (TYPE_NAME (TREE_TYPE (type))))
-       return object_ptr_type_node;
+      if (flag_new_verifier)
+       {
+         /* Since the verifier has already run, we know that any
+            types we see will be compatible.  In BC mode, this fact
+            may be checked at runtime, but if that is so then we can
+            assume its truth here as well.  So, we always succeed
+            here, with the expected type.  */
+         return type;
+       }
+      else
+       {
+         if (type == ptr_type_node || type == object_ptr_type_node)
+           return t;
+         else if (t == ptr_type_node)  /* Special case for null reference. */
+           return type;
+         /* This is a kludge, but matches what Sun's verifier does.
+            It can be tricked, but is safe as long as type errors
+            (i.e. interface method calls) are caught at run-time. */
+         else if (CLASS_INTERFACE (TYPE_NAME (TREE_TYPE (type))))
+           return object_ptr_type_node;
+         else if (can_widen_reference_to (t, type))
+           return t;
+       }
+    }
+
+  if (! flag_verify_invocations && flag_indirect_dispatch
+      && t == object_ptr_type_node)
+    {
+      if (type != ptr_type_node)
+       warning ("need to insert runtime check for %s", 
+                xstrdup (lang_printable_name (type, 0)));
+      return type;
     }
 
   /* lang_printable_name uses a static buffer, so we must save the result
      from calling it the first time.  */
+ fail:
   {
     char *temp = xstrdup (lang_printable_name (type, 0));
     *messagep = concat ("expected type '", temp,
@@ -376,8 +395,7 @@ pop_type_0 (type, messagep)
    convertible to TYPE, otherwise call error. */
 
 tree
-pop_type (type)
-     tree type;
+pop_type (tree type)
 {
   char *message = NULL;
   type = pop_type_0 (type, &message);
@@ -389,12 +407,73 @@ pop_type (type)
   return type;
 }
 
-/* Return 1f if SOURCE_TYPE can be safely widened to TARGET_TYPE.
+\f
+/* Return true if two type assertions are equal.  */
+
+static int
+type_assertion_eq (const void * k1_p, const void * k2_p)
+{
+  type_assertion k1 = *(type_assertion *)k1_p;
+  type_assertion k2 = *(type_assertion *)k2_p;
+  return (k1.assertion_code == k2.assertion_code
+          && k1.op1 == k2.op1
+         && k1.op2 == k2.op2);
+}
+
+/* Hash a type assertion.  */
+
+static hashval_t
+type_assertion_hash (const void *p)
+{
+  const type_assertion *k_p = p;
+  hashval_t hash = iterative_hash (&k_p->assertion_code, sizeof
+                                  k_p->assertion_code, 0);
+  hash = iterative_hash (&k_p->op1, sizeof k_p->op1, hash);
+  return iterative_hash (&k_p->op2, sizeof k_p->op2, hash);
+}
+
+/* Add an entry to the type assertion table for the given class.  
+   CLASS is the class for which this assertion will be evaluated by the 
+   runtime during loading/initialization.
+   ASSERTION_CODE is the 'opcode' or type of this assertion: see java-tree.h.
+   OP1 and OP2 are the operands. The tree type of these arguments may be
+   specific to each assertion_code. */
+
+void
+add_type_assertion (tree class, int assertion_code, tree op1, tree op2)
+{
+  htab_t assertions_htab;
+  type_assertion as;
+  void **as_pp;
+
+  assertions_htab = TYPE_ASSERTIONS (class);
+  if (assertions_htab == NULL)
+    {
+      assertions_htab = htab_create_ggc (7, type_assertion_hash, 
+                                        type_assertion_eq, NULL);
+      TYPE_ASSERTIONS (current_class) = assertions_htab;
+    }
+
+  as.assertion_code = assertion_code;
+  as.op1 = op1;
+  as.op2 = op2;
+
+  as_pp = htab_find_slot (assertions_htab, &as, true);
+
+  /* Don't add the same assertion twice.  */
+  if (*as_pp)
+    return;
+
+  *as_pp = ggc_alloc (sizeof (type_assertion));
+  **(type_assertion **)as_pp = as;
+}
+
+\f
+/* Return 1 if SOURCE_TYPE can be safely widened to TARGET_TYPE.
    Handles array types and interfaces.  */
 
 int
-can_widen_reference_to (source_type, target_type)
-     tree source_type, target_type;
+can_widen_reference_to (tree source_type, tree target_type)
 {
   if (source_type == ptr_type_node || target_type == object_ptr_type_node)
     return 1;
@@ -407,15 +486,40 @@ can_widen_reference_to (source_type, target_type)
 
   if (source_type == target_type)
     return 1;
+
+  /* FIXME: This is very pessimistic, in that it checks everything,
+     even if we already know that the types are compatible.  If we're
+     to support full Java class loader semantics, we need this.
+     However, we could do something more optimal.  */
+  if (! flag_verify_invocations)
+    {
+      add_type_assertion (current_class, JV_ASSERT_TYPES_COMPATIBLE, 
+                         source_type, target_type);
+
+      if (!quiet_flag)
+       warning ("assert: %s is assign compatible with %s", 
+               xstrdup (lang_printable_name (target_type, 0)),
+               xstrdup (lang_printable_name (source_type, 0)));
+      /* Punt everything to runtime.  */
+      return 1;
+    }
+
+  if (TYPE_DUMMY (source_type) || TYPE_DUMMY (target_type))
+    {
+      return 1;
+    }
   else
     {
-      source_type = HANDLE_TO_CLASS_TYPE (source_type);
-      target_type = HANDLE_TO_CLASS_TYPE (target_type);
       if (TYPE_ARRAY_P (source_type) || TYPE_ARRAY_P (target_type))
        {
          HOST_WIDE_INT source_length, target_length;
          if (TYPE_ARRAY_P (source_type) != TYPE_ARRAY_P (target_type))
-           return 0;
+           {
+             /* An array implements Cloneable and Serializable.  */
+             tree name = DECL_NAME (TYPE_NAME (target_type));
+             return (name == java_lang_cloneable_identifier_node
+                     || name == java_io_serializable_identifier_node);
+           }
          target_length = java_array_type_length (target_type);
          if (target_length >= 0)
            {
@@ -437,7 +541,16 @@ can_widen_reference_to (source_type, target_type)
          int source_depth = class_depth (source_type);
          int target_depth = class_depth (target_type);
 
-         /* class_depth can return a negative depth if an error occurred */
+         if (TYPE_DUMMY (source_type) || TYPE_DUMMY (target_type))
+           {
+             if (! quiet_flag)
+               warning ("assert: %s is assign compatible with %s", 
+                        xstrdup (lang_printable_name (target_type, 0)),
+                        xstrdup (lang_printable_name (source_type, 0)));
+             return 1;
+           }
+
+         /* class_depth can return a negative depth if an error occurred */
          if (source_depth < 0 || target_depth < 0)
            return 0;
 
@@ -445,21 +558,23 @@ can_widen_reference_to (source_type, target_type)
            {
              /* target_type is OK if source_type or source_type ancestors
                 implement target_type. We handle multiple sub-interfaces  */
+             tree binfo, base_binfo;
+             int i;
 
-             tree basetype_vec = TYPE_BINFO_BASETYPES (source_type);
-             int n = TREE_VEC_LENGTH (basetype_vec), i;
-             for (i=0 ; i < n; i++)
-               if (can_widen_reference_to 
-                   (TREE_TYPE (TREE_VEC_ELT (basetype_vec, i)),
-                    target_type))
+             for (binfo = TYPE_BINFO (source_type), i = 0;
+                  BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
+               if (can_widen_reference_to
+                   (BINFO_TYPE (base_binfo), target_type))
                  return 1;
-             if (n == 0)
+             
+             if (!i)
                return 0;
            }
 
          for ( ; source_depth > target_depth;  source_depth--) 
            {
-             source_type = TYPE_BINFO_BASETYPE (source_type, 0); 
+             source_type
+               = BINFO_TYPE (BINFO_BASE_BINFO (TYPE_BINFO (source_type), 0));
            }
          return source_type == target_type;
        }
@@ -467,8 +582,7 @@ can_widen_reference_to (source_type, target_type)
 }
 
 static tree
-pop_value (type)
-     tree type;
+pop_value (tree type)
 {
   type = pop_type (type);
   if (quick_stack)
@@ -485,11 +599,10 @@ pop_value (type)
 }
 
 
-/* Pop and discrad the top COUNT stack slots. */
+/* Pop and discard the top COUNT stack slots. */
 
 static void
-java_stack_pop (count)
-     int count;
+java_stack_pop (int count)
 {
   while (count > 0)
     {
@@ -515,10 +628,10 @@ java_stack_pop (count)
 /* Implement the 'swap' operator (to swap two top stack slots). */
 
 static void
-java_stack_swap ()
+java_stack_swap (void)
 {
   tree type1, type2;
-  rtx temp;
+  tree temp;
   tree decl1, decl2;
 
   if (stack_pointer < 2
@@ -532,16 +645,21 @@ java_stack_swap ()
   flush_quick_stack ();
   decl1 = find_stack_slot (stack_pointer - 1, type1);
   decl2 = find_stack_slot (stack_pointer - 2, type2);
-  temp = copy_to_reg (DECL_RTL (decl1));
-  emit_move_insn (DECL_RTL (decl1), DECL_RTL (decl2));
-  emit_move_insn (DECL_RTL (decl2), temp);
+  temp = build_decl (VAR_DECL, NULL_TREE, type1);
+  java_add_local_var (temp);
+  java_add_stmt (build2 (MODIFY_EXPR, type1, temp, decl1));
+  java_add_stmt (build2 (MODIFY_EXPR, type2, 
+                        find_stack_slot (stack_pointer - 1, type2),
+                        decl2));
+  java_add_stmt (build2 (MODIFY_EXPR, type1, 
+                        find_stack_slot (stack_pointer - 2, type1),
+                        temp));
   stack_type_map[stack_pointer - 1] = type2;
   stack_type_map[stack_pointer - 2] = type1;
 }
 
 static void
-java_stack_dup (size, offset)
-     int size, offset;
+java_stack_dup (int size, int offset)
 {
   int low_index = stack_pointer - size - offset;
   int dst_index;
@@ -579,7 +697,9 @@ java_stack_dup (size, offset)
        {
          tree src_decl = find_stack_slot (src_index, type);
          tree dst_decl = find_stack_slot (dst_index, type);
-         emit_move_insn (DECL_RTL (dst_decl), DECL_RTL (src_decl));
+
+         java_add_stmt 
+           (build2 (MODIFY_EXPR, TREE_TYPE (dst_decl), dst_decl, src_decl));
          stack_type_map[dst_index] = type;
        }
     }
@@ -589,52 +709,47 @@ java_stack_dup (size, offset)
    value stack. */
 
 static void
-build_java_athrow (node)
-    tree node;
+build_java_athrow (tree node)
 {
   tree call;
 
-  call = build (CALL_EXPR,
-               void_type_node,
-               build_address_of (throw_node),
-               build_tree_list (NULL_TREE, node),
-               NULL_TREE);
+  call = build3 (CALL_EXPR,
+                void_type_node,
+                build_address_of (throw_node),
+                build_tree_list (NULL_TREE, node),
+                NULL_TREE);
   TREE_SIDE_EFFECTS (call) = 1;
-  expand_expr_stmt (call);
+  java_add_stmt (call);
   java_stack_pop (stack_pointer);
 }
 
 /* Implementation for jsr/ret */
 
 static void
-build_java_jsr (where, ret)
-    tree where;
-    tree ret;
+build_java_jsr (int target_pc, int return_pc)
 {
+  tree where =  lookup_label (target_pc);
+  tree ret = lookup_label (return_pc);
   tree ret_label = fold (build1 (ADDR_EXPR, return_address_type_node, ret));
   push_value (ret_label);
   flush_quick_stack ();
-  emit_jump (label_rtx (where));
-  expand_label (ret);
+  java_add_stmt (build1 (GOTO_EXPR, void_type_node, where));
+
+  /* Do not need to emit the label here.  We noted the existence of the
+     label as a jump target in note_instructions; we'll emit the label
+     for real at the beginning of the expand_byte_code loop.  */
 }
 
 static void
-build_java_ret (location)
-  tree location;
+build_java_ret (tree location)
 {
-  expand_computed_goto (location);
+  java_add_stmt (build1 (GOTO_EXPR, void_type_node, location));
 }
  
 /* Implementation of operations on array: new, load, store, length */
 
-/* Array core info access macros */
-
-#define JAVA_ARRAY_LENGTH_OFFSET(A) \
-  byte_position (TREE_CHAIN (TYPE_FIELDS (TREE_TYPE (TREE_TYPE (A)))))
-
 tree
-decode_newarray_type (atype)
-  int atype;
+decode_newarray_type (int atype)
 {
   switch (atype)
     {
@@ -653,8 +768,7 @@ decode_newarray_type (atype)
 /* Map primitive type to the code used by OPCODE_newarray. */
 
 int
-encode_newarray_type (type)
-     tree type;
+encode_newarray_type (tree type)
 {
   if (type == boolean_type_node)
     return 4;
@@ -680,12 +794,11 @@ encode_newarray_type (type)
    ArrayIndexOfBoundsException exception handler.  */
 
 static tree
-build_java_throw_out_of_bounds_exception (index)
-    tree index;
+build_java_throw_out_of_bounds_exception (tree index)
 {
-  tree node = build (CALL_EXPR, int_type_node,
-                    build_address_of (soft_badarrayindex_node), 
-                    build_tree_list (NULL_TREE, index), NULL_TREE);
+  tree node = build3 (CALL_EXPR, int_type_node,
+                     build_address_of (soft_badarrayindex_node), 
+                     build_tree_list (NULL_TREE, index), NULL_TREE);
   TREE_SIDE_EFFECTS (node) = 1;        /* Allows expansion within ANDIF */
   return (node);
 }
@@ -694,22 +807,40 @@ build_java_throw_out_of_bounds_exception (index)
    or value of the array NODE. May be used to implement some bytecodes.  */
 
 tree
-build_java_array_length_access (node)
-    tree node;
+build_java_array_length_access (tree node)
 {
   tree type = TREE_TYPE (node);
+  tree array_type = TREE_TYPE (type);
   HOST_WIDE_INT length;
 
+  /* JVM spec: If the arrayref is null, the arraylength instruction
+     throws a NullPointerException.  The only way we could get a node
+     of type ptr_type_node at this point is `aconst_null; arraylength'
+     or something equivalent.  */
+  if (!flag_new_verifier && type == ptr_type_node)
+    return build3 (CALL_EXPR, int_type_node, 
+                  build_address_of (soft_nullpointer_node),
+                  NULL_TREE, NULL_TREE);
+
   if (!is_array_type_p (type))
-    abort ();
+    {
+      /* With the new verifier, we will see an ordinary pointer type
+        here.  In this case, we just use an arbitrary array type.  */
+      array_type = build_java_array_type (object_ptr_type_node, -1);
+      type = promote_type (array_type);
+    }
 
   length = java_array_type_length (type);
   if (length >= 0)
-    return build_int_2 (length, 0);
-  return fold (build1 (INDIRECT_REF, int_type_node,
-                      fold (build (PLUS_EXPR, ptr_type_node,
-                                   java_check_reference (node, 1), 
-                                   JAVA_ARRAY_LENGTH_OFFSET(node)))));
+    return build_int_cst (NULL_TREE, length);
+
+  node = build3 (COMPONENT_REF, int_type_node,
+                build_java_indirect_ref (array_type, node,
+                                         flag_check_references),
+                lookup_field (&array_type, get_identifier ("length")),
+                NULL_TREE);
+  IS_ARRAY_LENGTH_ACCESS (node) = 1;
+  return node;
 }
 
 /* Optionally checks a reference against the NULL pointer.  ARG1: the
@@ -717,21 +848,18 @@ build_java_array_length_access (node)
    checks if we're not generating code.  */
 
 tree 
-java_check_reference (expr, check)
-     tree expr;
-     int check;
+java_check_reference (tree expr, int check)
 {
   if (!flag_syntax_only && check)
     {
-      tree cond;
       expr = save_expr (expr);
-      cond = build (COND_EXPR, void_type_node,
-                   build (EQ_EXPR, boolean_type_node, expr, null_pointer_node),
-                   build (CALL_EXPR, void_type_node, 
-                          build_address_of (soft_nullpointer_node),
-                          NULL_TREE, NULL_TREE),
-                   empty_stmt_node);
-      expr = build (COMPOUND_EXPR, TREE_TYPE (expr), cond, expr);
+      expr = build3 (COND_EXPR, TREE_TYPE (expr),
+                    build2 (EQ_EXPR, boolean_type_node,
+                            expr, null_pointer_node),
+                    build3 (CALL_EXPR, void_type_node, 
+                            build_address_of (soft_nullpointer_node),
+                            NULL_TREE, NULL_TREE),
+                    expr);
     }
 
   return expr;
@@ -740,25 +868,12 @@ java_check_reference (expr, check)
 /* Reference an object: just like an INDIRECT_REF, but with checking.  */
 
 tree
-build_java_indirect_ref (type, expr, check)
-     tree type;
-     tree expr;
-     int check;
-{
-  return build1 (INDIRECT_REF, type, java_check_reference (expr, check));
-}
-
-static tree
-java_array_data_offset (array)
-     tree array;
+build_java_indirect_ref (tree type, tree expr, int check)
 {
-  tree array_type = TREE_TYPE (TREE_TYPE (array));
-  tree data_fld = TREE_CHAIN (TREE_CHAIN (TYPE_FIELDS (array_type)));
-
-  if (data_fld == NULL_TREE)
-    return size_in_bytes (array_type);
-  else
-    return byte_position (data_fld);
+  tree t;
+  t = java_check_reference (expr, check);
+  t = convert (build_pointer_type (type), t);
+  return build1 (INDIRECT_REF, type, t);
 }
 
 /* Implement array indexing (either as l-value or r-value).
@@ -767,15 +882,19 @@ java_array_data_offset (array)
    At this point, ARRAY should have been verified as an array.  */
 
 tree
-build_java_arrayaccess (array, type, index)
-    tree array, type, index;
+build_java_arrayaccess (tree array, tree type, tree index)
 {
-  tree arith, node, throw = NULL_TREE;
+  tree node, throw = NULL_TREE;
+  tree data_field;
+  tree ref;
+  tree array_type = TREE_TYPE (TREE_TYPE (array));
 
-  arith = fold (build (PLUS_EXPR, int_type_node,
-                      java_array_data_offset (array),
-                      fold (build (MULT_EXPR, int_type_node,
-                                   index, size_in_bytes(type)))));
+  if (!is_array_type_p (TREE_TYPE (array)))
+    {
+      /* With the new verifier, we will see an ordinary pointer type
+        here.  In this case, we just use the correct array type.  */
+      array_type = build_java_array_type (type, -1);
+    }
 
   if (flag_bounds_check)
     {
@@ -785,54 +904,143 @@ build_java_arrayaccess (array, type, index)
        * Note this is equivalent to and more efficient than:
        * INDEX < 0 || INDEX >= LEN && throw ... */
       tree test;
-      tree len = build_java_array_length_access (array);
-      TREE_TYPE (len) = unsigned_int_type_node;
-      test = fold (build (GE_EXPR, boolean_type_node, 
-                              convert (unsigned_int_type_node, index),
-                              len));
+      tree len = convert (unsigned_int_type_node,
+                         build_java_array_length_access (array));
+      test = fold (build2 (GE_EXPR, boolean_type_node, 
+                          convert (unsigned_int_type_node, index),
+                          len));
       if (! integer_zerop (test))
        {
-         throw = build (TRUTH_ANDIF_EXPR, int_type_node, test,
-                        build_java_throw_out_of_bounds_exception (index));
+         throw = build2 (TRUTH_ANDIF_EXPR, int_type_node, test,
+                         build_java_throw_out_of_bounds_exception (index));
          /* allows expansion within COMPOUND */
          TREE_SIDE_EFFECTS( throw ) = 1;
        }
     }
+
+  /* If checking bounds, wrap the index expr with a COMPOUND_EXPR in order
+     to have the bounds check evaluated first. */
+  if (throw != NULL_TREE)
+    index = build2 (COMPOUND_EXPR, int_type_node, throw, index);
+  data_field = lookup_field (&array_type, get_identifier ("data"));
+
+  ref = build3 (COMPONENT_REF, TREE_TYPE (data_field),    
+               build_java_indirect_ref (array_type, array, 
+                                        flag_check_references),
+               data_field, NULL_TREE);
   
-  node = build1 (INDIRECT_REF, type, 
-                fold (build (PLUS_EXPR, ptr_type_node, 
-                             java_check_reference (array, flag_check_references), 
-                             (throw ? build (COMPOUND_EXPR, int_type_node, 
-                                             throw, arith )
-                                    : arith))));
-  
+  node = build4 (ARRAY_REF, type, ref, index, NULL_TREE, NULL_TREE);
   return node;
 }
 
+/* Generate code to throw an ArrayStoreException if OBJECT is not assignable
+   (at runtime) to an element of ARRAY.  A NOP_EXPR is returned if it can
+   determine that no check is required. */
+
+tree
+build_java_arraystore_check (tree array, tree object)
+{
+  tree check, element_type, source;
+  tree array_type_p = TREE_TYPE (array);
+  tree object_type = TYPE_NAME (TREE_TYPE (TREE_TYPE (object)));
+
+  if (! flag_verify_invocations)
+    {
+      /* With the new verifier, we don't track precise types.  FIXME:
+        performance regression here.  */
+      element_type = TYPE_NAME (object_type_node);
+    }
+  else
+    {
+      if (! is_array_type_p (array_type_p))
+       abort ();
+
+      /* Get the TYPE_DECL for ARRAY's element type. */
+      element_type
+       = TYPE_NAME (TREE_TYPE (TREE_TYPE (TREE_TYPE (array_type_p))));
+    }
+
+  if (TREE_CODE (element_type) != TYPE_DECL   
+      || TREE_CODE (object_type) != TYPE_DECL)
+    abort ();
+
+  if (!flag_store_check)
+    return build1 (NOP_EXPR, array_type_p, array);
+
+  /* No check is needed if the element type is final.  Also check that
+     element_type matches object_type, since in the bytecode
+     compilation case element_type may be the actual element type of
+     the array rather than its declared type.  However, if we're doing
+     indirect dispatch, we can't do the `final' optimization.  */
+  if (element_type == object_type
+      && ! flag_indirect_dispatch
+      && CLASS_FINAL (element_type))
+    return build1 (NOP_EXPR, array_type_p, array);
+  
+  /* OBJECT might be wrapped by a SAVE_EXPR. */
+  if (TREE_CODE (object) == SAVE_EXPR)
+    source = TREE_OPERAND (object, 0);
+  else
+    source = object;
+  
+  /* Avoid the check if OBJECT was just loaded from the same array. */
+  if (TREE_CODE (source) == ARRAY_REF)
+    {
+      tree target;
+      source = TREE_OPERAND (source, 0); /* COMPONENT_REF. */
+      source = TREE_OPERAND (source, 0); /* INDIRECT_REF. */
+      source = TREE_OPERAND (source, 0); /* Source array's DECL or SAVE_EXPR. */
+      if (TREE_CODE (source) == SAVE_EXPR)
+       source = TREE_OPERAND (source, 0);
+      
+      target = array;
+      if (TREE_CODE (target) == SAVE_EXPR)
+       target = TREE_OPERAND (target, 0);
+      
+      if (source == target)
+        return build1 (NOP_EXPR, array_type_p, array);
+    }
+
+  /* Build an invocation of _Jv_CheckArrayStore */
+  check = build3 (CALL_EXPR, void_type_node,
+                 build_address_of (soft_checkarraystore_node),
+                 tree_cons (NULL_TREE, array,
+                            build_tree_list (NULL_TREE, object)),
+                 NULL_TREE);
+  TREE_SIDE_EFFECTS (check) = 1;
+
+  return check;
+}
+
 /* Makes sure that INDEXED_TYPE is appropriate. If not, make it from
    ARRAY_NODE. This function is used to retrieve something less vague than
    a pointer type when indexing the first dimension of something like [[<t>.
    May return a corrected type, if necessary, otherwise INDEXED_TYPE is
-   return unchanged.
-   As a side effect, it also makes sure that ARRAY_NODE is an array.  */
+   return unchanged.  */
 
 static tree
-build_java_check_indexed_type (array_node, indexed_type)
-    tree array_node;
-    tree indexed_type;
+build_java_check_indexed_type (tree array_node, tree indexed_type)
 {
   tree elt_type;
 
+  /* We used to check to see if ARRAY_NODE really had array type.
+     However, with the new verifier, this is not necessary, as we know
+     that the object will be an array of the appropriate type.  */
+
+  if (flag_new_verifier)
+    return indexed_type;
+
   if (!is_array_type_p (TREE_TYPE (array_node)))
     abort ();
 
   elt_type = (TYPE_ARRAY_ELEMENT (TREE_TYPE (TREE_TYPE (array_node))));
 
-  if (indexed_type == ptr_type_node )
-      return promote_type (elt_type);
+  if (indexed_type == ptr_type_node)
+    return promote_type (elt_type);
 
   /* BYTE/BOOLEAN store and load are used for both type */
-  if (indexed_type == byte_type_node && elt_type == boolean_type_node )
+  if (indexed_type == byte_type_node && elt_type == boolean_type_node)
     return boolean_type_node;
 
   if (indexed_type != elt_type )
@@ -846,9 +1054,7 @@ build_java_check_indexed_type (array_node, indexed_type)
    of the array to create.  */
 
 tree
-build_newarray (atype_value, length)
-     int atype_value;
-     tree length;
+build_newarray (int atype_value, tree length)
 {
   tree type_arg;
 
@@ -862,46 +1068,42 @@ build_newarray (atype_value, length)
      and save the runtime some work. However, the bytecode generator
      expects to find the type_code int here. */
   if (flag_emit_class_files)
-    type_arg = build_int_2 (atype_value, 0);
+    type_arg = build_int_cst (NULL_TREE, atype_value);
   else
     type_arg = build_class_ref (prim_type);
 
-  return build (CALL_EXPR, promote_type (type),
-               build_address_of (soft_newarray_node),
-               tree_cons (NULL_TREE, 
-                          type_arg,
-                          build_tree_list (NULL_TREE, length)),
-               NULL_TREE);
+  return build3 (CALL_EXPR, promote_type (type),
+                build_address_of (soft_newarray_node),
+                tree_cons (NULL_TREE, 
+                           type_arg,
+                           build_tree_list (NULL_TREE, length)),
+                NULL_TREE);
 }
 
 /* Generates anewarray from a given CLASS_TYPE. Gets from the stack the size
    of the dimension. */
 
 tree
-build_anewarray (class_type, length)
-    tree class_type;
-    tree length;
+build_anewarray (tree class_type, tree length)
 {
   tree type
     = build_java_array_type (class_type,
                             host_integerp (length, 0)
                             ? tree_low_cst (length, 0) : -1);
 
-  return build (CALL_EXPR, promote_type (type),
-               build_address_of (soft_anewarray_node),
-               tree_cons (NULL_TREE, length,
-                          tree_cons (NULL_TREE, build_class_ref (class_type),
-                                     build_tree_list (NULL_TREE,
-                                                      null_pointer_node))),
-               NULL_TREE);
+  return build3 (CALL_EXPR, promote_type (type),
+                build_address_of (soft_anewarray_node),
+                tree_cons (NULL_TREE, length,
+                           tree_cons (NULL_TREE, build_class_ref (class_type),
+                                      build_tree_list (NULL_TREE,
+                                                       null_pointer_node))),
+                NULL_TREE);
 }
 
 /* Return a node the evaluates 'new TYPE[LENGTH]'. */
 
 tree
-build_new_array (type, length)
-     tree type;
-     tree length;
+build_new_array (tree type, tree length)
 {
   if (JPRIMITIVE_TYPE_P (type))
     return build_newarray (encode_newarray_type (type), length);
@@ -914,9 +1116,7 @@ build_new_array (type, length)
    dimensions. The argument list is NULL terminated.  */
 
 static void
-expand_java_multianewarray (class_type, ndim)
-    tree class_type;
-    int  ndim;
+expand_java_multianewarray (tree class_type, int ndim)
 {
   int i;
   tree args = build_tree_list( NULL_TREE, null_pointer_node );
@@ -924,34 +1124,52 @@ expand_java_multianewarray (class_type, ndim)
   for( i = 0; i < ndim; i++ )
     args = tree_cons (NULL_TREE, pop_value (int_type_node), args);
 
-  push_value (build (CALL_EXPR,
-                    promote_type (class_type),
-                    build_address_of (soft_multianewarray_node),
-                    tree_cons (NULL_TREE, build_class_ref (class_type),
-                               tree_cons (NULL_TREE, 
-                                          build_int_2 (ndim, 0), args )),
-                    NULL_TREE));
+  push_value (build3 (CALL_EXPR,
+                     promote_type (class_type),
+                     build_address_of (soft_multianewarray_node),
+                     tree_cons (NULL_TREE, build_class_ref (class_type),
+                                tree_cons (NULL_TREE, 
+                                           build_int_cst (NULL_TREE, ndim),
+                                           args)),
+                     NULL_TREE));
 }
 
 /*  ARRAY[INDEX] <- RHS. build_java_check_indexed_type makes sure that
     ARRAY is an array type. May expand some bound checking and NULL
     pointer checking. RHS_TYPE_NODE we are going to store. In the case
     of the CHAR/BYTE/BOOLEAN SHORT, the type popped of the stack is an
-    INT. In those cases, we make the convertion.
+    INT. In those cases, we make the conversion.
 
     if ARRAy is a reference type, the assignment is checked at run-time
     to make sure that the RHS can be assigned to the array element
     type. It is not necessary to generate this code if ARRAY is final.  */
 
 static void
-expand_java_arraystore (rhs_type_node)
-     tree rhs_type_node;
+expand_java_arraystore (tree rhs_type_node)
 {
   tree rhs_node    = pop_value ((INTEGRAL_TYPE_P (rhs_type_node) 
                                 && TYPE_PRECISION (rhs_type_node) <= 32) ? 
                                 int_type_node : rhs_type_node);
   tree index = pop_value (int_type_node);
-  tree array = pop_value (ptr_type_node);
+  tree array_type, array;
+
+  if (flag_new_verifier)
+    {
+      /* If we're processing an `aaload' we might as well just pick
+        `Object'.  */
+      if (TREE_CODE (rhs_type_node) == POINTER_TYPE)
+       {
+         array_type = build_java_array_type (object_ptr_type_node, -1);
+         rhs_type_node = object_ptr_type_node;
+       }
+      else
+       array_type = build_java_array_type (rhs_type_node, -1);
+    }
+  else
+    array_type = ptr_type_node;
+  array = pop_value (array_type);
+  if (flag_new_verifier)
+    array = build1 (NOP_EXPR, promote_type (array_type), array);
 
   rhs_type_node    = build_java_check_indexed_type (array, rhs_type_node);
 
@@ -962,19 +1180,12 @@ expand_java_arraystore (rhs_type_node)
 
   if (TREE_CODE (rhs_type_node) == POINTER_TYPE)
     {
-      tree check = build (CALL_EXPR, void_type_node,
-                         build_address_of (soft_checkarraystore_node),
-                         tree_cons (NULL_TREE, array,
-                                    build_tree_list (NULL_TREE, rhs_node)),
-                         NULL_TREE);
-      TREE_SIDE_EFFECTS (check) = 1;
-      expand_expr_stmt (check);
+      tree check = build_java_arraystore_check (array, rhs_node);
+      java_add_stmt (check);
     }
   
-  expand_assignment (build_java_arrayaccess (array,
-                                            rhs_type_node,
-                                            index),
-                    rhs_node, 0, 0);
+  array = build_java_arrayaccess (array, rhs_type_node, index);
+  java_add_stmt (build2 (MODIFY_EXPR, TREE_TYPE (array), array, rhs_node));  
 }
 
 /* Expand the evaluation of ARRAY[INDEX]. build_java_check_indexed_type makes 
@@ -985,21 +1196,49 @@ expand_java_arraystore (rhs_type_node)
 */
 
 static void
-expand_java_arrayload (lhs_type_node )
-    tree lhs_type_node;
+expand_java_arrayload (tree lhs_type_node)
 {
   tree load_node;
   tree index_node = pop_value (int_type_node);
-  tree array_node = pop_value (ptr_type_node);
+  tree array_type;
+  tree array_node;
+
+  if (flag_new_verifier)
+    {
+      /* If we're processing an `aaload' we might as well just pick
+        `Object'.  */
+      if (TREE_CODE (lhs_type_node) == POINTER_TYPE)
+       {
+         array_type = build_java_array_type (object_ptr_type_node, -1);
+         lhs_type_node = object_ptr_type_node;
+       }
+      else
+       array_type = build_java_array_type (lhs_type_node, -1);
+    }
+  else
+    array_type = ptr_type_node;
+  array_node = pop_value (array_type);
+  if (flag_new_verifier)
+    array_node = build1 (NOP_EXPR, promote_type (array_type), array_node);
 
   index_node = save_expr (index_node);
   array_node = save_expr (array_node);
-  lhs_type_node   = build_java_check_indexed_type (array_node, lhs_type_node);
-
-  load_node = build_java_arrayaccess (array_node,
-                                     lhs_type_node,
-                                     index_node);
 
+  if (TREE_TYPE (array_node) == ptr_type_node)
+    /* The only way we could get a node of type ptr_type_node at this
+       point is `aconst_null; arraylength' or something equivalent, so
+       unconditionally throw NullPointerException.  */
+    load_node = build3 (CALL_EXPR, lhs_type_node, 
+                       build_address_of (soft_nullpointer_node),
+                       NULL_TREE, NULL_TREE);
+  else
+    {
+      lhs_type_node = build_java_check_indexed_type (array_node,
+                                                    lhs_type_node);
+      load_node = build_java_arrayaccess (array_node,
+                                         lhs_type_node,
+                                         index_node);
+    }
   if (INTEGRAL_TYPE_P (lhs_type_node) && TYPE_PRECISION (lhs_type_node) <= 32)
     load_node = fold (build1 (NOP_EXPR, int_type_node, load_node));
   push_value (load_node);
@@ -1009,7 +1248,7 @@ expand_java_arrayload (lhs_type_node )
    a NULL check on the array object.  */
 
 static void
-expand_java_array_length ()
+expand_java_array_length (void)
 {
   tree array  = pop_value (ptr_type_node);
   tree length = build_java_array_length_access (array);
@@ -1021,40 +1260,29 @@ expand_java_array_length ()
    either soft_monitorenter_node or soft_monitorexit_node.  */
 
 static tree
-build_java_monitor (call, object)
-    tree call;
-    tree object;
+build_java_monitor (tree call, tree object)
 {
-  return (build (CALL_EXPR,
+  return build3 (CALL_EXPR,
                 void_type_node,
                 build_address_of (call),
                 build_tree_list (NULL_TREE, object),
-                NULL_TREE));
+                NULL_TREE);
 }
 
 /* Emit code for one of the PUSHC instructions. */
 
 static void
-expand_java_pushc (ival, type)
-     int ival;
-     tree type;
+expand_java_pushc (int ival, tree type)
 {
   tree value;
   if (type == ptr_type_node && ival == 0)
     value = null_pointer_node;
   else if (type == int_type_node || type == long_type_node)
-    {
-      value = build_int_2 (ival, ival < 0 ? -1 : 0);
-      TREE_TYPE (value) = type;
-    }
+    value = build_int_cst (type, ival);
   else if (type == float_type_node || type == double_type_node)
     {
       REAL_VALUE_TYPE x;
-#ifdef REAL_ARITHMETIC
       REAL_VALUE_FROM_INT (x, ival, 0, TYPE_MODE (type));
-#else
-      x = ival;
-#endif
       value = build_real (type, x);
     }
   else
@@ -1064,16 +1292,15 @@ expand_java_pushc (ival, type)
 }
 
 static void
-expand_java_return (type)
-     tree type;
+expand_java_return (tree type)
 {
   if (type == void_type_node)
-    expand_null_return ();
+    java_add_stmt (build1 (RETURN_EXPR, void_type_node, NULL));   
   else
     {
       tree retval = pop_value (type);
       tree res = DECL_RESULT (current_function_decl);
-      retval = build (MODIFY_EXPR, TREE_TYPE (res), res, retval);
+      retval = build2 (MODIFY_EXPR, TREE_TYPE (res), res, retval);
 
       /* Handle the situation where the native integer type is smaller
         than the JVM integer. It can happen for many cross compilers.
@@ -1085,15 +1312,12 @@ expand_java_return (type)
        retval = build1(NOP_EXPR, TREE_TYPE(res), retval);
       
       TREE_SIDE_EFFECTS (retval) = 1;
-      expand_return (retval);
+      java_add_stmt (build1 (RETURN_EXPR, TREE_TYPE (retval), retval));
     }
 }
 
 static void
-expand_load_internal (index, type, pc)
-     int index;
-     tree type;
-     int pc;
+expand_load_internal (int index, tree type, int pc)
 {
   tree copy;
   tree var = find_local_variable (index, type, pc);
@@ -1105,55 +1329,78 @@ expand_load_internal (index, type, pc)
      value into it.  Then we push this new local on the stack.
      Hopefully this all gets optimized out.  */
   copy = build_decl (VAR_DECL, NULL_TREE, type);
-  DECL_CONTEXT (copy) = current_function_decl;
-  layout_decl (copy, 0);
-  DECL_REGISTER (copy) = 1;
-  expand_decl (copy);
-  MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (copy);
-  DECL_INITIAL (copy) = var;
-  expand_decl_init (copy);
+  if (INTEGRAL_TYPE_P (type)
+      && TREE_TYPE (copy) != TREE_TYPE (var))
+    var = convert (type, var);
+  java_add_local_var (copy);
+  java_add_stmt (build2 (MODIFY_EXPR, TREE_TYPE (var), copy, var));
+  
   push_value (copy);
 }
 
 tree
-build_address_of (value)
-     tree value;
+build_address_of (tree value)
 {
   return build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (value)), value);
 }
 
+bool
+class_has_finalize_method (tree type)
+{
+  tree super = CLASSTYPE_SUPER (type);
+
+  if (super == NULL_TREE)
+    return false;      /* Every class with a real finalizer inherits   */
+                       /* from java.lang.Object.                       */
+  else
+    return HAS_FINALIZER_P (type) || class_has_finalize_method (super);
+}
+
+tree
+java_create_object (tree type)
+{
+  tree alloc_node = (class_has_finalize_method (type) 
+                    ? alloc_object_node
+                    : alloc_no_finalizer_node);
+  
+  return build (CALL_EXPR, promote_type (type),
+               build_address_of (alloc_node),
+               build_tree_list (NULL_TREE, build_class_ref (type)),
+               NULL_TREE);
+}
+
 static void
-expand_java_NEW (type)
-     tree type;
+expand_java_NEW (tree type)
 {
+  tree alloc_node;
+
+  alloc_node = (class_has_finalize_method (type) ? alloc_object_node
+                                                : alloc_no_finalizer_node);
   if (! CLASS_LOADED_P (type))
     load_class (type, 1);
   safe_layout_class (type);
-  push_value (build (CALL_EXPR, promote_type (type),
-                    build_address_of (alloc_object_node),
-                    tree_cons (NULL_TREE, build_class_ref (type),
-                               build_tree_list (NULL_TREE,
-                                                size_in_bytes (type))),
-                    NULL_TREE));
+  push_value (build3 (CALL_EXPR, promote_type (type),
+                     build_address_of (alloc_node),
+                     build_tree_list (NULL_TREE, build_class_ref (type)),
+                     NULL_TREE));
 }
 
 /* This returns an expression which will extract the class of an
    object.  */
 
 tree
-build_get_class (value)
-     tree value;
+build_get_class (tree value)
 {
   tree class_field = lookup_field (&dtable_type, get_identifier ("class"));
   tree vtable_field = lookup_field (&object_type_node,
                                    get_identifier ("vtable"));
-  return build (COMPONENT_REF, class_ptr_type,
-               build1 (INDIRECT_REF, dtable_type,
-                       build (COMPONENT_REF, dtable_ptr_type,
-                              build_java_indirect_ref (object_type_node, value,
-                                                       flag_check_references),
-                              vtable_field)),
-               class_field);
+  tree tmp = build3 (COMPONENT_REF, dtable_ptr_type,
+                    build_java_indirect_ref (object_type_node, value,
+                                             flag_check_references),
+                    vtable_field, NULL_TREE);
+  return build3 (COMPONENT_REF, class_ptr_type,
+                build1 (INDIRECT_REF, dtable_type, tmp),
+                class_field, NULL_TREE);
 }
 
 /* This builds the tree representation of the `instanceof' operator.
@@ -1161,8 +1408,7 @@ build_get_class (value)
    known.  */
 
 tree
-build_instanceof (value, type)
-     tree value, type;
+build_instanceof (tree value, tree type)
 {
   tree expr;
   tree itype = TREE_TYPE (TREE_TYPE (soft_instanceof_node));
@@ -1186,11 +1432,10 @@ build_instanceof (value, type)
       /* Anything except `null' is an instance of Object.  Likewise,
         if the object is known to be an instance of the class, then
         we only need to check for `null'.  */
-      expr = build (COND_EXPR, itype,
-                   value,
-                   boolean_true_node, boolean_false_node);
+      expr = build2 (NE_EXPR, itype, value, null_pointer_node);
     }
-  else if (! TYPE_ARRAY_P (type)
+  else if (flag_verify_invocations
+          && ! TYPE_ARRAY_P (type)
           && ! TYPE_ARRAY_P (valtype)
           && DECL_P (klass) && DECL_P (valclass)
           && ! CLASS_INTERFACE (valclass)
@@ -1206,29 +1451,29 @@ build_instanceof (value, type)
   else if (DECL_P (klass) && CLASS_FINAL (klass))
     {
       tree save = save_expr (value);
-      expr = build (COND_EXPR, itype,
-                   save,
-                   build (EQ_EXPR, itype,
-                          build_get_class (save),
-                          build_class_ref (type)),
-                   boolean_false_node);
+      expr = build3 (COND_EXPR, itype,
+                    build2 (NE_EXPR, boolean_type_node,
+                            save, null_pointer_node),
+                    build2 (EQ_EXPR, itype,
+                            build_get_class (save),
+                            build_class_ref (type)),
+                    boolean_false_node);
     }
   else
     {
-      expr = build (CALL_EXPR, itype,
-                   build_address_of (soft_instanceof_node),
-                   tree_cons (NULL_TREE, value,
-                              build_tree_list (NULL_TREE,
-                                               build_class_ref (type))),
-                   NULL_TREE);
+      expr = build3 (CALL_EXPR, itype,
+                    build_address_of (soft_instanceof_node),
+                    tree_cons (NULL_TREE, value,
+                               build_tree_list (NULL_TREE,
+                                                build_class_ref (type))),
+                    NULL_TREE);
     }
   TREE_SIDE_EFFECTS (expr) = TREE_SIDE_EFFECTS (value);
   return expr;
 }
 
 static void
-expand_java_INSTANCEOF (type)
-     tree type;
+expand_java_INSTANCEOF (tree type)
 {
   tree value = pop_value (object_ptr_type_node);
   value = build_instanceof (value, type);
@@ -1236,39 +1481,34 @@ expand_java_INSTANCEOF (type)
 }
 
 static void
-expand_java_CHECKCAST (type)
-     tree type;
+expand_java_CHECKCAST (tree type)
 {
   tree value = pop_value (ptr_type_node);
-  value = build (CALL_EXPR, promote_type (type),
-                build_address_of (soft_checkcast_node),
-                tree_cons (NULL_TREE, build_class_ref (type),
-                           build_tree_list (NULL_TREE, value)),
-                NULL_TREE);
+  value = build3 (CALL_EXPR, promote_type (type),
+                 build_address_of (soft_checkcast_node),
+                 tree_cons (NULL_TREE, build_class_ref (type),
+                            build_tree_list (NULL_TREE, value)),
+                 NULL_TREE);
   push_value (value);
 }
 
 static void
-expand_iinc (local_var_index, ival, pc)
-     unsigned int local_var_index;
-     int ival;
-     int pc;
+expand_iinc (unsigned int local_var_index, int ival, int pc)
 {
-    tree local_var, res;
-    tree constant_value;
+  tree local_var, res;
+  tree constant_value;
 
-    flush_quick_stack ();
-    local_var = find_local_variable (local_var_index, int_type_node, pc);
-    constant_value = build_int_2 (ival, ival < 0 ? -1 : 0);
-    res = fold (build (PLUS_EXPR, int_type_node, local_var, constant_value));
-    expand_assignment (local_var, res, 0, 0);
+  flush_quick_stack ();
+  local_var = find_local_variable (local_var_index, int_type_node, pc);
+  constant_value = build_int_cst (NULL_TREE, ival);
+  res = fold (build2 (PLUS_EXPR, int_type_node, local_var, constant_value));
+  java_add_stmt (build2 (MODIFY_EXPR, TREE_TYPE (local_var), local_var, res));
+  update_aliases (local_var, local_var_index, pc);
 }
 
-      
+
 tree
-build_java_soft_divmod (op, type, op1, op2)
-    enum tree_code op;
-    tree type, op1, op2;
+build_java_soft_divmod (enum tree_code op, tree type, tree op1, tree op2)
 {
   tree call = NULL;
   tree arg1 = convert (type, op1);
@@ -1306,63 +1546,62 @@ build_java_soft_divmod (op, type, op1, op2)
   if (! call)
     abort ();
                  
-  call = build (CALL_EXPR, type,
-               build_address_of (call),
-               tree_cons (NULL_TREE, arg1,
-                          build_tree_list (NULL_TREE, arg2)),
-               NULL_TREE);
+  call = build3 (CALL_EXPR, type,
+                build_address_of (call),
+                tree_cons (NULL_TREE, arg1,
+                           build_tree_list (NULL_TREE, arg2)),
+                NULL_TREE);
          
   return call;
 }
 
 tree
-build_java_binop (op, type, arg1, arg2)
-     enum tree_code op;
-     tree type, arg1, arg2;
+build_java_binop (enum tree_code op, tree type, tree arg1, tree arg2)
 {
   tree mask;
   switch (op)
     {
     case URSHIFT_EXPR:
       {
-       tree u_type = unsigned_type (type);
+       tree u_type = java_unsigned_type (type);
        arg1 = convert (u_type, arg1);
        arg1 = build_java_binop (RSHIFT_EXPR, u_type, arg1, arg2);
        return convert (type, arg1);
       }
     case LSHIFT_EXPR:
     case RSHIFT_EXPR:
-      mask = build_int_2 (TYPE_PRECISION (TREE_TYPE (arg1)) - 1, 0);
-      arg2 = fold (build (BIT_AND_EXPR, int_type_node, arg2, mask));
+      mask = build_int_cst (NULL_TREE,
+                           TYPE_PRECISION (TREE_TYPE (arg1)) - 1);
+      arg2 = fold (build2 (BIT_AND_EXPR, int_type_node, arg2, mask));
       break;
 
     case COMPARE_L_EXPR:  /* arg1 > arg2 ?  1 : arg1 == arg2 ? 0 : -1 */
     case COMPARE_G_EXPR:  /* arg1 < arg2 ? -1 : arg1 == arg2 ? 0 :  1 */
       arg1 = save_expr (arg1);  arg2 = save_expr (arg2);
       {
-       tree ifexp1 = fold ( build (op == COMPARE_L_EXPR ? GT_EXPR : LT_EXPR,
+       tree ifexp1 = fold (build2 (op == COMPARE_L_EXPR ? GT_EXPR : LT_EXPR,
                                    boolean_type_node, arg1, arg2));
-       tree ifexp2 = fold ( build (EQ_EXPR, boolean_type_node, arg1, arg2));
-       tree second_compare = fold (build (COND_EXPR, int_type_node,
-                                          ifexp2, integer_zero_node,
-                                          op == COMPARE_L_EXPR
-                                          ? integer_minus_one_node
-                                          : integer_one_node));
-       return fold (build (COND_EXPR, int_type_node, ifexp1,
-                           op == COMPARE_L_EXPR ? integer_one_node
-                           : integer_minus_one_node,
-                           second_compare));
+       tree ifexp2 = fold (build2 (EQ_EXPR, boolean_type_node, arg1, arg2));
+       tree second_compare = fold (build3 (COND_EXPR, int_type_node,
+                                           ifexp2, integer_zero_node,
+                                           op == COMPARE_L_EXPR
+                                           ? integer_minus_one_node
+                                           : integer_one_node));
+       return fold (build3 (COND_EXPR, int_type_node, ifexp1,
+                            op == COMPARE_L_EXPR ? integer_one_node
+                            : integer_minus_one_node,
+                            second_compare));
       }
     case COMPARE_EXPR:
       arg1 = save_expr (arg1);  arg2 = save_expr (arg2);
       {
-       tree ifexp1 = fold ( build (LT_EXPR, boolean_type_node, arg1, arg2));
-       tree ifexp2 = fold ( build (GT_EXPR, boolean_type_node, arg1, arg2));
-       tree second_compare = fold ( build (COND_EXPR, int_type_node,
+       tree ifexp1 = fold (build2 (LT_EXPR, boolean_type_node, arg1, arg2));
+       tree ifexp2 = fold (build2 (GT_EXPR, boolean_type_node, arg1, arg2));
+       tree second_compare = fold (build3 (COND_EXPR, int_type_node,
                                            ifexp2, integer_one_node,
                                            integer_zero_node));
-       return fold (build (COND_EXPR, int_type_node,
-                           ifexp1, integer_minus_one_node, second_compare));
+       return fold (build3 (COND_EXPR, int_type_node,
+                            ifexp1, integer_minus_one_node, second_compare));
       }      
     case TRUNC_DIV_EXPR:
     case TRUNC_MOD_EXPR:
@@ -1375,11 +1614,11 @@ build_java_binop (op, type, arg1, arg2)
              arg1 = convert (double_type_node, arg1);
              arg2 = convert (double_type_node, arg2);
            }
-         call = build (CALL_EXPR, double_type_node,
-                       build_address_of (soft_fmod_node),
-                       tree_cons (NULL_TREE, arg1,
-                                  build_tree_list (NULL_TREE, arg2)),
-                       NULL_TREE);
+         call = build3 (CALL_EXPR, double_type_node,
+                        build_address_of (soft_fmod_node),
+                        tree_cons (NULL_TREE, arg1,
+                                   build_tree_list (NULL_TREE, arg2)),
+                        NULL_TREE);
          if (type != double_type_node)
            call = convert (type, call);
          return call;
@@ -1393,12 +1632,11 @@ build_java_binop (op, type, arg1, arg2)
       break;
     default:  ;
     }
-  return fold (build (op, type, arg1, arg2));
+  return fold (build2 (op, type, arg1, arg2));
 }
 
 static void
-expand_java_binop (type, op)
-     tree type;  enum tree_code op;
+expand_java_binop (tree type, enum tree_code op)
 {
   tree larg, rarg;
   tree ltype = type;
@@ -1426,9 +1664,7 @@ expand_java_binop (type, op)
    class containing the field. */
 
 tree
-lookup_field (typep, name)
-     tree *typep;
-     tree name;
+lookup_field (tree *typep, tree name)
 {
   if (CLASS_P (*typep) && !CLASS_LOADED_P (*typep))
     {
@@ -1439,31 +1675,20 @@ lookup_field (typep, name)
     }
   do
     {
-      tree field, basetype_vec;
+      tree field, binfo, base_binfo;
       tree save_field;
-      int n, i;
+      int i;
 
       for (field = TYPE_FIELDS (*typep); field; field = TREE_CHAIN (field))
        if (DECL_NAME (field) == name)
          return field;
 
-      /* If *typep is an innerclass, lookup the field in its enclosing
-         contexts */
-      if (INNER_CLASS_TYPE_P (*typep))
-       {
-         tree outer_type = TREE_TYPE (DECL_CONTEXT (TYPE_NAME (*typep)));
-
-         if ((field = lookup_field (&outer_type, name)))
-           return field;
-       }
-
       /* Process implemented interfaces. */
-      basetype_vec = TYPE_BINFO_BASETYPES (*typep);
-      n = TREE_VEC_LENGTH (basetype_vec);
       save_field = NULL_TREE;
-      for (i = 0; i < n; i++)
+      for (binfo = TYPE_BINFO (*typep), i = 0;
+          BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
        {
-         tree t = BINFO_TYPE (TREE_VEC_ELT (basetype_vec, i));
+         tree t = BINFO_TYPE (base_binfo);
          if ((field = lookup_field (&t, name)))
            {
              if (save_field == field)
@@ -1474,7 +1699,7 @@ lookup_field (typep, name)
                {
                  tree i1 = DECL_CONTEXT (save_field);
                  tree i2 = DECL_CONTEXT (field);
-                 error ("reference `%s' is ambiguous: appears in interface `%s' and interface `%s'",
+                 error ("reference %qs is ambiguous: appears in interface %qs and interface %qs",
                         IDENTIFIER_POINTER (name),
                         IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (i1))),
                         IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (i2))));
@@ -1496,14 +1721,13 @@ lookup_field (typep, name)
    SELF_VALUE is NULL_TREE if looking for a static field. */
 
 tree
-build_field_ref (self_value, self_class, name)
-     tree self_value, self_class, name;
+build_field_ref (tree self_value, tree self_class, tree name)
 {
   tree base_class = self_class;
   tree field_decl = lookup_field (&base_class, name);
   if (field_decl == NULL_TREE)
     {
-      error ("field `%s' not found", IDENTIFIER_POINTER (name));
+      error ("field %qs not found", IDENTIFIER_POINTER (name));
       return error_mark_node;
     }
   if (self_value == NULL_TREE)
@@ -1512,22 +1736,47 @@ build_field_ref (self_value, self_class, name)
     }
   else
     {
-      tree base_handle_type = promote_type (base_class);
-      if (base_handle_type != TREE_TYPE (self_value))
-       self_value = fold (build1 (NOP_EXPR, base_handle_type, self_value));
-#ifdef JAVA_USE_HANDLES
-      self_value = unhand_expr (self_value);
-#endif
+      int check = (flag_check_references
+                  && ! (DECL_P (self_value)
+                        && DECL_NAME (self_value) == this_identifier_node));
+
+      tree base_type = promote_type (base_class);
+      if (base_type != TREE_TYPE (self_value))
+       self_value = fold (build1 (NOP_EXPR, base_type, self_value));
+      if (! flag_syntax_only
+         && (flag_indirect_dispatch
+             /* DECL_FIELD_OFFSET == 0 if we have no reference for
+                the field, perhaps because we couldn't find the class
+                in which the field is defined.  
+                FIXME: We should investigate this.  */
+             || DECL_FIELD_OFFSET (field_decl) == 0))
+       {
+         tree otable_index
+           = build_int_cst (NULL_TREE, get_symbol_table_index 
+                            (field_decl, &TYPE_OTABLE_METHODS (output_class)));
+         tree field_offset
+           = build4 (ARRAY_REF, integer_type_node,
+                     TYPE_OTABLE_DECL (output_class), otable_index,
+                     NULL_TREE, NULL_TREE);
+         tree address;
+
+         field_offset = fold (convert (sizetype, field_offset));
+         address 
+           = fold (build2 (PLUS_EXPR, 
+                           build_pointer_type (TREE_TYPE (field_decl)),
+                           self_value, field_offset));
+         return fold (build1 (INDIRECT_REF, TREE_TYPE (field_decl), address));
+       }
+
       self_value = build_java_indirect_ref (TREE_TYPE (TREE_TYPE (self_value)),
-                                           self_value, flag_check_references);
-      return fold (build (COMPONENT_REF, TREE_TYPE (field_decl),
-                         self_value, field_decl));
+                                           self_value, check);
+      return fold (build3 (COMPONENT_REF, TREE_TYPE (field_decl),
+                          self_value, field_decl, NULL_TREE));
     }
 }
 
 tree
-lookup_label (pc)
-     int pc;
+lookup_label (int pc)
 {
   tree name;
   char buf[32];
@@ -1540,7 +1789,6 @@ lookup_label (pc)
       /* The type of the address of a label is return_address_type_node. */
       tree decl = create_label_decl (name);
       LABEL_PC (decl) = pc;
-      label_rtx (decl);
       return pushdecl (decl);
     }
 }
@@ -1549,7 +1797,7 @@ lookup_label (pc)
    labels, and try-catch-finally blocks label or temporary variables.  */
 
 tree
-generate_name ()
+generate_name (void)
 {
   static int l_number = 0;
   char buff [32];
@@ -1559,8 +1807,7 @@ generate_name ()
 }
 
 tree
-create_label_decl (name)
-     tree name;
+create_label_decl (tree name)
 {
   tree decl;
   decl = build_decl (LABEL_DECL, name, 
@@ -1574,8 +1821,7 @@ create_label_decl (name)
 char *instruction_bits;
 
 static void
-note_label (current_pc, target_pc)
-     int current_pc ATTRIBUTE_UNUSED, target_pc;
+note_label (int current_pc ATTRIBUTE_UNUSED, int target_pc)
 {
   lookup_label (target_pc);
   instruction_bits [target_pc] |= BCODE_JUMP_TARGET;
@@ -1585,25 +1831,21 @@ note_label (current_pc, target_pc)
    where CONDITION is one of one the compare operators. */
 
 static void
-expand_compare (condition, value1, value2, target_pc)
-     enum tree_code condition;
-     tree value1, value2;
-     int target_pc;
+expand_compare (enum tree_code condition, tree value1, tree value2,
+               int target_pc)
 {
   tree target = lookup_label (target_pc);
-  tree cond = fold (build (condition, boolean_type_node, value1, value2));
-  expand_start_cond (truthvalue_conversion (cond), 0);
-  expand_goto (target);
-  expand_end_cond ();
+  tree cond = fold (build2 (condition, boolean_type_node, value1, value2));
+  java_add_stmt 
+    (build3 (COND_EXPR, void_type_node, java_truthvalue_conversion (cond),
+            build1 (GOTO_EXPR, void_type_node, target), 
+            build_java_empty_stmt ()));
 }
 
 /* Emit code for a TEST-type opcode. */
 
 static void
-expand_test (condition, type, target_pc)
-     enum tree_code condition;
-     tree type;
-     int target_pc;
+expand_test (enum tree_code condition, tree type, int target_pc)
 {
   tree value1, value2;
   flush_quick_stack ();
@@ -1615,10 +1857,7 @@ expand_test (condition, type, target_pc)
 /* Emit code for a COND-type opcode. */
 
 static void
-expand_cond (condition, type, target_pc)
-     enum tree_code condition;
-     tree type;
-     int target_pc;
+expand_cond (enum tree_code condition, tree type, int target_pc)
 {
   tree value1, value2;
   flush_quick_stack ();
@@ -1630,42 +1869,50 @@ expand_cond (condition, type, target_pc)
 }
 
 static void
-expand_java_goto (target_pc)
-     int target_pc;
+expand_java_goto (int target_pc)
 {
   tree target_label = lookup_label (target_pc);
   flush_quick_stack ();
-  expand_goto (target_label);
+  java_add_stmt (build1 (GOTO_EXPR, void_type_node, target_label));
 }
 
-#if 0
-static void
-expand_java_call (target_pc, return_address)
-     int target_pc, return_address;
+static tree
+expand_java_switch (tree selector, int default_pc)
 {
-  tree target_label = lookup_label (target_pc);
-  tree value = build_int_2 (return_address, return_address < 0 ? -1 : 0);
-  push_value (value);
+  tree switch_expr, x;
+
   flush_quick_stack ();
-  expand_goto (target_label);
+  switch_expr = build3 (SWITCH_EXPR, TREE_TYPE (selector), selector,
+                       NULL_TREE, NULL_TREE);
+  java_add_stmt (switch_expr);
+
+  x = build3 (CASE_LABEL_EXPR, void_type_node, NULL_TREE, NULL_TREE,
+             create_artificial_label ());
+  append_to_statement_list (x, &SWITCH_BODY (switch_expr));
+
+  x = build1 (GOTO_EXPR, void_type_node, lookup_label (default_pc));
+  append_to_statement_list (x, &SWITCH_BODY (switch_expr));
+
+  return switch_expr;
 }
 
 static void
-expand_java_ret (return_address)
-     tree return_address ATTRIBUTE_UNUSED;
+expand_java_add_case (tree switch_expr, int match, int target_pc)
 {
-  warning ("ret instruction not implemented");
-#if 0
-  tree target_label = lookup_label (target_pc);
-  flush_quick_stack ();
-  expand_goto (target_label);
-#endif
+  tree value, x;
+
+  value = build_int_cst (TREE_TYPE (switch_expr), match);
+  
+  x = build3 (CASE_LABEL_EXPR, void_type_node, value, NULL_TREE,
+             create_artificial_label ());
+  append_to_statement_list (x, &SWITCH_BODY (switch_expr));
+
+  x = build1 (GOTO_EXPR, void_type_node, lookup_label (target_pc));
+  append_to_statement_list (x, &SWITCH_BODY (switch_expr));
 }
-#endif
 
 static tree
-pop_arguments (arg_types)
-     tree arg_types;
+pop_arguments (tree arg_types)
 {
   if (arg_types == end_params_node)
     return NULL_TREE;
@@ -1674,78 +1921,128 @@ pop_arguments (arg_types)
       tree tail = pop_arguments (TREE_CHAIN (arg_types));
       tree type = TREE_VALUE (arg_types);
       tree arg = pop_value (type);
-      if (PROMOTE_PROTOTYPES
-         && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)
-         && INTEGRAL_TYPE_P (type))
+
+      /* With the new verifier we simply cast each argument to its
+        proper type.  This is needed since we lose type information
+        coming out of the verifier.  We also have to do this with the
+        old verifier when we pop an integer type that must be
+        promoted for the function call.  */
+      if (flag_new_verifier && TREE_CODE (type) == POINTER_TYPE)
+       arg = build1 (NOP_EXPR, type, arg);
+      else if (targetm.calls.promote_prototypes (type)
+              && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)
+              && INTEGRAL_TYPE_P (type))
        arg = convert (integer_type_node, arg);
       return tree_cons (NULL_TREE, arg, tail);
     }
   abort ();
 }
 
+/* Attach to PTR (a block) the declaration found in ENTRY. */
+
+int
+attach_init_test_initialization_flags (void **entry, void *ptr)
+{
+  tree block = (tree)ptr;
+  struct treetreehash_entry *ite = (struct treetreehash_entry *) *entry;
+
+  if (block != error_mark_node)
+    {
+      if (TREE_CODE (block) == BIND_EXPR)
+        {
+         tree body = BIND_EXPR_BODY (block);
+         TREE_CHAIN (ite->value) = BIND_EXPR_VARS (block);
+         BIND_EXPR_VARS (block) = ite->value;
+         body = build2 (COMPOUND_EXPR, void_type_node,
+                        build1 (DECL_EXPR, void_type_node, ite->value), body);
+         BIND_EXPR_BODY (block) = body;
+       }
+      else
+       {
+         tree body = BLOCK_SUBBLOCKS (block);
+         TREE_CHAIN (ite->value) = BLOCK_EXPR_DECLS (block);
+         BLOCK_EXPR_DECLS (block) = ite->value;
+         body = build2 (COMPOUND_EXPR, void_type_node,
+                        build1 (DECL_EXPR, void_type_node, ite->value), body);
+         BLOCK_SUBBLOCKS (block) = body;
+        }
+      
+    }
+  return true;
+}
+
 /* Build an expression to initialize the class CLAS.
    if EXPR is non-NULL, returns an expression to first call the initializer
    (if it is needed) and then calls EXPR. */
 
 tree
-build_class_init (clas, expr)
-     tree clas, expr;
+build_class_init (tree clas, tree expr)
 {
   tree init;
-  struct init_test_hash_entry *ite;
-  if (inherits_from_p (current_class, clas))
+
+  /* An optimization: if CLAS is a superclass of the class we're
+     compiling, we don't need to initialize it.  However, if CLAS is
+     an interface, it won't necessarily be initialized, even if we
+     implement it.  */
+  if ((! CLASS_INTERFACE (TYPE_NAME (clas))
+       && inherits_from_p (current_class, clas))
+      || current_class == clas)
     return expr;
 
   if (always_initialize_class_p)
     {
-      init = build (CALL_EXPR, void_type_node,
-                   build_address_of (soft_initclass_node),
-                   build_tree_list (NULL_TREE, build_class_ref (clas)),
-                   NULL_TREE);
+      init = build3 (CALL_EXPR, void_type_node,
+                    build_address_of (soft_initclass_node),
+                    build_tree_list (NULL_TREE, build_class_ref (clas)),
+                    NULL_TREE);
       TREE_SIDE_EFFECTS (init) = 1;
     }
   else
     {
-      ite = (struct init_test_hash_entry *)
-       hash_lookup (&DECL_FUNCTION_INIT_TEST_TABLE (current_function_decl),
-                    (const hash_table_key) clas,
-                    TRUE, NULL);
-      
-      if (ite->init_test_decl == 0)
+      tree *init_test_decl;
+      tree decl;
+      init_test_decl = java_treetreehash_new
+       (DECL_FUNCTION_INIT_TEST_TABLE (current_function_decl), clas);
+
+      if (*init_test_decl == NULL)
        {
          /* Build a declaration and mark it as a flag used to track
             static class initializations. */
-         ite->init_test_decl = build_decl (VAR_DECL, NULL_TREE,
-                                           boolean_type_node);
-         MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (ite->init_test_decl);
-         LOCAL_CLASS_INITIALIZATION_FLAG (ite->init_test_decl) = 1;
-         DECL_CONTEXT (ite->init_test_decl) = current_function_decl;
-
+         decl = build_decl (VAR_DECL, NULL_TREE,
+                            boolean_type_node);
+         MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (decl);
+         LOCAL_CLASS_INITIALIZATION_FLAG (decl) = 1;
+         DECL_CONTEXT (decl) = current_function_decl;
+         DECL_FUNCTION_INIT_TEST_CLASS (decl) = clas;
          /* Tell the check-init code to ignore this decl when not
              optimizing class initialization. */
          if (!STATIC_CLASS_INIT_OPT_P ())
-           DECL_BIT_INDEX(ite->init_test_decl) = -1;
+           DECL_BIT_INDEX (decl) = -1;
+         DECL_INITIAL (decl) = boolean_false_node;
+         /* Don't emit any symbolic debugging info for this decl.  */
+         DECL_IGNORED_P (decl) = 1;      
+         *init_test_decl = decl;
        }
 
-      init = build (CALL_EXPR, void_type_node,
-                   build_address_of (soft_initclass_node),
-                   build_tree_list (NULL_TREE, build_class_ref (clas)),
-                   NULL_TREE);
+      init = build3 (CALL_EXPR, void_type_node,
+                    build_address_of (soft_initclass_node),
+                    build_tree_list (NULL_TREE, build_class_ref (clas)),
+                    NULL_TREE);
       TREE_SIDE_EFFECTS (init) = 1;
-      init = build (COND_EXPR, void_type_node,
-                   build (EQ_EXPR, boolean_type_node, 
-                          ite->init_test_decl, boolean_false_node),
-                   init, integer_zero_node);
+      init = build3 (COND_EXPR, void_type_node,
+                    build2 (EQ_EXPR, boolean_type_node, 
+                            *init_test_decl, boolean_false_node),
+                    init, integer_zero_node);
       TREE_SIDE_EFFECTS (init) = 1;
-      init = build (COMPOUND_EXPR, TREE_TYPE (expr), init, 
-                   build (MODIFY_EXPR, boolean_type_node,
-                          ite->init_test_decl, boolean_true_node));
+      init = build2 (COMPOUND_EXPR, TREE_TYPE (expr), init, 
+                    build2 (MODIFY_EXPR, boolean_type_node,
+                            *init_test_decl, boolean_true_node));
       TREE_SIDE_EFFECTS (init) = 1;
     }
 
   if (expr != NULL_TREE)
     {
-      expr = build (COMPOUND_EXPR, TREE_TYPE (expr), init, expr);
+      expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), init, expr);
       TREE_SIDE_EFFECTS (expr) = 1;
       return expr;
     }
@@ -1753,38 +2050,63 @@ build_class_init (clas, expr)
 }
 
 tree
-build_known_method_ref (method, method_type, self_type, method_signature, arg_list)
-     tree method, method_type ATTRIBUTE_UNUSED, self_type,
-          method_signature ATTRIBUTE_UNUSED, arg_list ATTRIBUTE_UNUSED;
+build_known_method_ref (tree method, tree method_type ATTRIBUTE_UNUSED,
+                       tree self_type, tree method_signature ATTRIBUTE_UNUSED,
+                       tree arg_list ATTRIBUTE_UNUSED)
 {
   tree func;
   if (is_compiled_class (self_type))
     {
-      make_decl_rtl (method, NULL);
-      func = build1 (ADDR_EXPR, method_ptr_type_node, method);
+      /* With indirect dispatch we have to use indirect calls for all
+        publicly visible methods or gcc will use PLT indirections
+        to reach them.  We also have to use indirect dispatch for all
+        external methods.  */
+      if (! flag_indirect_dispatch 
+         || (! DECL_EXTERNAL (method) && ! TREE_PUBLIC (method)))
+       {
+         make_decl_rtl (method);
+         func = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (method)),
+                        method);
+       }
+      else
+       {
+         tree table_index
+           = build_int_cst (NULL_TREE, get_symbol_table_index 
+                            (method, &TYPE_ATABLE_METHODS (output_class)));
+         func 
+           = build4 (ARRAY_REF,  
+                     TREE_TYPE (TREE_TYPE (TYPE_ATABLE_DECL (output_class))),
+                     TYPE_ATABLE_DECL (output_class), table_index,
+                     NULL_TREE, NULL_TREE);
+       }
+      func = convert (method_ptr_type_node, func);
     }
   else
     {
       /* We don't know whether the method has been (statically) compiled.
         Compile this code to get a reference to the method's code:
-        
+
         SELF_TYPE->methods[METHOD_INDEX].ncode
-        
-        This is guaranteed to work (assuming SELF_TYPE has
-        been initialized), since if the method is not compiled yet,
-        its ncode points to a trampoline that forces compilation. */
-      
+
+      */
+
       int method_index = 0;
-      tree meth;
-      tree ref = build_class_ref (self_type);
+      tree meth, ref;
+
+      /* The method might actually be declared in some superclass, so
+        we have to use its class context, not the caller's notion of
+        where the method is.  */
+      self_type = DECL_CONTEXT (method);
+      ref = build_class_ref (self_type);
       ref = build1 (INDIRECT_REF, class_type_node, ref);
       if (ncode_ident == NULL_TREE)
        ncode_ident = get_identifier ("ncode");
       if (methods_ident == NULL_TREE)
        methods_ident = get_identifier ("methods");
-      ref = build (COMPONENT_REF, method_ptr_type_node, ref,
-                  lookup_field (&class_type_node, methods_ident));
-      for (meth = TYPE_METHODS (CLASS_TO_HANDLE_TYPE (self_type));
+      ref = build3 (COMPONENT_REF, method_ptr_type_node, ref,
+                   lookup_field (&class_type_node, methods_ident),
+                   NULL_TREE);
+      for (meth = TYPE_METHODS (self_type);
           ; meth = TREE_CHAIN (meth))
        {
          if (method == meth)
@@ -1795,20 +2117,18 @@ build_known_method_ref (method, method_type, self_type, method_signature, arg_li
          method_index++;
        }
       method_index *= int_size_in_bytes (method_type_node);
-      ref = fold (build (PLUS_EXPR, method_ptr_type_node,
-                        ref, build_int_2 (method_index, 0)));
+      ref = fold (build2 (PLUS_EXPR, method_ptr_type_node,
+                         ref, build_int_cst (NULL_TREE, method_index)));
       ref = build1 (INDIRECT_REF, method_type_node, ref);
-      func = build (COMPONENT_REF, nativecode_ptr_type_node,
-                   ref,
-                   lookup_field (&method_type_node, ncode_ident));
+      func = build3 (COMPONENT_REF, nativecode_ptr_type_node,
+                    ref, lookup_field (&method_type_node, ncode_ident),
+                    NULL_TREE);
     }
   return func;
 }
 
 tree
-invoke_build_dtable (is_invoke_interface, arg_list)
-     int is_invoke_interface;
-     tree arg_list;
+invoke_build_dtable (int is_invoke_interface, tree arg_list)
 {
   tree dtable, objectref;
 
@@ -1818,40 +2138,91 @@ invoke_build_dtable (is_invoke_interface, arg_list)
      argument is an array then get the dispatch table of the class
      Object rather than the one from the objectref.  */
   objectref = (is_invoke_interface 
-              && is_array_type_p (TREE_TYPE (TREE_VALUE (arg_list))) ?
-              object_type_node : TREE_VALUE (arg_list));
-  
+              && is_array_type_p (TREE_TYPE (TREE_VALUE (arg_list)))
+              ? build_class_ref (object_type_node) : TREE_VALUE (arg_list));
+
   if (dtable_ident == NULL_TREE)
     dtable_ident = get_identifier ("vtable");
   dtable = build_java_indirect_ref (object_type_node, objectref, 
                                    flag_check_references);
-  dtable = build (COMPONENT_REF, dtable_ptr_type, dtable,
-                 lookup_field (&object_type_node, dtable_ident));
+  dtable = build3 (COMPONENT_REF, dtable_ptr_type, dtable,
+                  lookup_field (&object_type_node, dtable_ident), NULL_TREE);
 
   return dtable;
 }
 
+/* Determine the index in SYMBOL_TABLE for a reference to the decl
+   T. If this decl has not been seen before, it will be added to the
+   [oa]table_methods. If it has, the existing table slot will be
+   reused.  */
+
+int
+get_symbol_table_index (tree t, tree *symbol_table)
+{
+  int i = 1;
+  tree method_list;
+
+  if (*symbol_table == NULL_TREE)
+    {
+      *symbol_table = build_tree_list (t, t);
+      return 1;
+    }
+  
+  method_list = *symbol_table;
+  
+  while (1)
+    {
+      tree value = TREE_VALUE (method_list);
+      if (value == t)
+       return i;
+      i++;
+      if (TREE_CHAIN (method_list) == NULL_TREE)
+        break;
+      else
+        method_list = TREE_CHAIN (method_list);
+    }
+
+  TREE_CHAIN (method_list) = build_tree_list (t, t);
+  return i;
+}
+
 tree 
-build_invokevirtual (dtable, method)
-     tree dtable, method;
+build_invokevirtual (tree dtable, tree method)
 {
   tree func;
   tree nativecode_ptr_ptr_type_node
     = build_pointer_type (nativecode_ptr_type_node);
-  tree method_index = convert (sizetype, DECL_VINDEX (method));
+  tree method_index;
+  tree otable_index;
 
-  /* Add one to skip "class" field of dtable, and one to skip unused
-     vtable entry (for C++ compatibility). */
-  method_index = size_binop (PLUS_EXPR, method_index, size_int (2));
-  method_index = size_binop (MULT_EXPR, method_index,
-                            TYPE_SIZE_UNIT (nativecode_ptr_ptr_type_node));
+  if (flag_indirect_dispatch)
+    {
+      if (CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (method))))
+       abort ();
 
-  if (TARGET_VTABLE_USES_DESCRIPTORS)
-    method_index = size_binop (MULT_EXPR, method_index,
-                              size_int (TARGET_VTABLE_USES_DESCRIPTORS));
+      otable_index 
+       = build_int_cst (NULL_TREE, get_symbol_table_index 
+                        (method, &TYPE_OTABLE_METHODS (output_class)));
+      method_index = build4 (ARRAY_REF, integer_type_node, 
+                            TYPE_OTABLE_DECL (output_class), 
+                            otable_index, NULL_TREE, NULL_TREE);
+    }
+  else
+    {
+      /* We fetch the DECL_VINDEX field directly here, rather than
+        using get_method_index().  DECL_VINDEX is the true offset
+        from the vtable base to a method, regrdless of any extra
+        words inserted at the start of the vtable.  */
+      method_index = DECL_VINDEX (method);
+      method_index = size_binop (MULT_EXPR, method_index,
+                                TYPE_SIZE_UNIT (nativecode_ptr_ptr_type_node));
+      if (TARGET_VTABLE_USES_DESCRIPTORS)
+       method_index = size_binop (MULT_EXPR, method_index,
+                                  size_int (TARGET_VTABLE_USES_DESCRIPTORS));
+    }
 
-  func = fold (build (PLUS_EXPR, nativecode_ptr_ptr_type_node, dtable,
-                     convert (nativecode_ptr_ptr_type_node, method_index)));
+  func = fold (build2 (PLUS_EXPR, nativecode_ptr_ptr_type_node, dtable,
+                      convert (nativecode_ptr_ptr_type_node, method_index)));
 
   if (TARGET_VTABLE_USES_DESCRIPTORS)
     func = build1 (NOP_EXPR, nativecode_ptr_type_node, func);
@@ -1861,70 +2232,81 @@ build_invokevirtual (dtable, method)
   return func;
 }
 
+static GTY(()) tree class_ident;
 tree
-build_invokeinterface (dtable, method)
-     tree dtable, method;
+build_invokeinterface (tree dtable, tree method)
 {
-  static tree class_ident = NULL_TREE;
   tree lookup_arg;
   tree interface;
   tree idx;
-  tree meth;
-  int i;
 
-  /* We expand invokeinterface here.  _Jv_LookupInterfaceMethod() will
-     ensure that the selected method exists, is public and not
-     abstract nor static.  */
+  /* We expand invokeinterface here.  */
            
   if (class_ident == NULL_TREE)
-    {
-      class_ident = get_identifier ("class");
-      ggc_add_tree_root (&class_ident, 1);
-    }
+    class_ident = get_identifier ("class");
 
-  dtable = build_java_indirect_ref (dtable_type, dtable, flag_check_references);
-  dtable = build (COMPONENT_REF, class_ptr_type, dtable,
-                 lookup_field (&dtable_type, class_ident));
+  dtable = build_java_indirect_ref (dtable_type, dtable,
+                                   flag_check_references);
+  dtable = build3 (COMPONENT_REF, class_ptr_type, dtable,
+                  lookup_field (&dtable_type, class_ident), NULL_TREE);
 
   interface = DECL_CONTEXT (method);
+  if (! CLASS_INTERFACE (TYPE_NAME (interface)))
+    abort ();
   layout_class_methods (interface);
   
-  i = 1;
-  for (meth = TYPE_METHODS (interface); ; meth = TREE_CHAIN (meth), i++)
+  if (flag_indirect_dispatch)
+    {
+      int itable_index 
+       = 2 * (get_symbol_table_index 
+              (method, &TYPE_ITABLE_METHODS (output_class)));
+      interface 
+       = build4 (ARRAY_REF, 
+                TREE_TYPE (TREE_TYPE (TYPE_ITABLE_DECL (output_class))),
+                TYPE_ITABLE_DECL (output_class), 
+                 build_int_cst (NULL_TREE, itable_index-1),
+                 NULL_TREE, NULL_TREE);
+      idx 
+       = build4 (ARRAY_REF, 
+                TREE_TYPE (TREE_TYPE (TYPE_ITABLE_DECL (output_class))),
+                TYPE_ITABLE_DECL (output_class), 
+                 build_int_cst (NULL_TREE, itable_index),
+                 NULL_TREE, NULL_TREE);
+      interface = convert (class_ptr_type, interface);
+      idx = convert (integer_type_node, idx);
+    }
+  else
     {
-      if (meth == method)
-        {
-         idx = build_int_2 (i, 0);
-         break;
-       }
-      if (meth == NULL_TREE)
-       abort ();
+      idx = build_int_cst (NULL_TREE, 
+                          get_interface_method_index (method, interface));
+      interface = build_class_ref (interface);
     }
-
-  lookup_arg = tree_cons (NULL_TREE, dtable,
-                          tree_cons (NULL_TREE, build_class_ref (interface),
-                                    build_tree_list (NULL_TREE, idx)));
                                                          
-  return build (CALL_EXPR, ptr_type_node, 
-               build_address_of (soft_lookupinterfacemethod_node),
-               lookup_arg, NULL_TREE);
+  lookup_arg = tree_cons (NULL_TREE, dtable,
+                         tree_cons (NULL_TREE, interface,
+                                    build_tree_list (NULL_TREE, idx)));
+
+  return build3 (CALL_EXPR, ptr_type_node, 
+                build_address_of (soft_lookupinterfacemethod_node),
+                lookup_arg, NULL_TREE);
 }
   
 /* Expand one of the invoke_* opcodes.
-   OCPODE is the specific opcode.
+   OPCODE is the specific opcode.
    METHOD_REF_INDEX is an index into the constant pool.
    NARGS is the number of arguments, or -1 if not specified. */
 
 static void
-expand_invoke (opcode, method_ref_index, nargs)
-     int opcode;
-     int method_ref_index;
-     int nargs ATTRIBUTE_UNUSED;
-{
-  tree method_signature = COMPONENT_REF_SIGNATURE(&current_jcf->cpool, method_ref_index);
-  tree method_name = COMPONENT_REF_NAME (&current_jcf->cpool, method_ref_index);
-  tree self_type = get_class_constant
-    (current_jcf, COMPONENT_REF_CLASS_INDEX(&current_jcf->cpool, method_ref_index));
+expand_invoke (int opcode, int method_ref_index, int nargs ATTRIBUTE_UNUSED)
+{
+  tree method_signature
+    = COMPONENT_REF_SIGNATURE(&current_jcf->cpool, method_ref_index);
+  tree method_name = COMPONENT_REF_NAME (&current_jcf->cpool,
+                                        method_ref_index);
+  tree self_type
+    = get_class_constant (current_jcf,
+                          COMPONENT_REF_CLASS_INDEX(&current_jcf->cpool,
+                          method_ref_index));
   const char *const self_name
     = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (self_type)));
   tree call, func, method, arg_list, method_type;
@@ -1940,43 +2322,85 @@ expand_invoke (opcode, method_ref_index, nargs)
   layout_class_methods (self_type);
 
   if (ID_INIT_P (method_name))
-    method = lookup_java_constructor (CLASS_TO_HANDLE_TYPE (self_type),
-                                     method_signature);
+    method = lookup_java_constructor (self_type, method_signature);
   else
-    method = lookup_java_method (CLASS_TO_HANDLE_TYPE (self_type),
-                                method_name, method_signature);
+    method = lookup_java_method (self_type, method_name, method_signature);
+
+  /* We've found a method in an interface, but this isn't an interface
+     call.  */
+  if (opcode != OPCODE_invokeinterface
+      && method
+      && (CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (method)))))
+    method = NULL_TREE;
+
+  /* We've found a non-interface method but we are making an
+     interface call.  This can happen if the interface overrides a
+     method in Object.  */
+  if (! flag_verify_invocations
+      && opcode == OPCODE_invokeinterface
+      && method
+      && ! CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (method))))
+    method = NULL_TREE;
+
   if (method == NULL_TREE)
     {
-      error ("Class '%s' has no method named '%s' matching signature '%s'",
-            self_name,
-            IDENTIFIER_POINTER (method_name),
-            IDENTIFIER_POINTER (method_signature));
-    }
-  /* Invoke static can't invoke static/abstract method */
-  else if (opcode == OPCODE_invokestatic)
-    {
-      if (!METHOD_STATIC (method))
+      if (flag_verify_invocations || ! flag_indirect_dispatch)
        {
-         error ("invokestatic on non static method");
-         method = NULL_TREE;
+         error ("class '%s' has no method named '%s' matching signature '%s'",
+                self_name,
+                IDENTIFIER_POINTER (method_name),
+                IDENTIFIER_POINTER (method_signature));
        }
-      else if (METHOD_ABSTRACT (method))
+      else
        {
-         error ("invokestatic on abstract method");
-         method = NULL_TREE;
+         int flags = ACC_PUBLIC;
+         if (opcode == OPCODE_invokestatic)
+           flags |= ACC_STATIC;
+         if (opcode == OPCODE_invokeinterface)
+           {
+             flags |= ACC_INTERFACE | ACC_ABSTRACT;
+             CLASS_INTERFACE (TYPE_NAME (self_type)) = 1;
+           }
+         method = add_method (self_type, flags, method_name,
+                              method_signature);
+         DECL_ARTIFICIAL (method) = 1;
+         METHOD_DUMMY (method) = 1;
+         layout_class_method (self_type, NULL,
+                              method, NULL);
        }
     }
-  else
+
+  /* Invoke static can't invoke static/abstract method */
+  if (method != NULL_TREE)
     {
-      if (METHOD_STATIC (method))
+      if (opcode == OPCODE_invokestatic)
        {
-         error ("invoke[non-static] on static method");
-         method = NULL_TREE;
+         if (!METHOD_STATIC (method))
+           {
+             error ("invokestatic on non static method");
+             method = NULL_TREE;
+           }
+         else if (METHOD_ABSTRACT (method))
+           {
+             error ("invokestatic on abstract method");
+             method = NULL_TREE;
+           }
+       }
+      else
+       {
+         if (METHOD_STATIC (method))
+           {
+             error ("invoke[non-static] on static method");
+             method = NULL_TREE;
+           }
        }
     }
 
   if (method == NULL_TREE)
     {
+      /* If we got here, we emitted an error message above.  So we
+        just pop the arguments, push a properly-typed zero, and
+        continue.  */
       method_type = get_type_from_signature (method_signature);
       pop_arguments (TYPE_ARG_TYPES (method_type));
       if (opcode != OPCODE_invokestatic) 
@@ -2005,12 +2429,13 @@ expand_invoke (opcode, method_ref_index, nargs)
         method's `this'.  In other cases we just rely on an
         optimization pass to eliminate redundant checks.  FIXME:
         Unfortunately there doesn't seem to be a way to determine
-        what the current method is right now.  */
+        what the current method is right now.
+        We do omit the check if we're calling <init>.  */
       /* We use a SAVE_EXPR here to make sure we only evaluate
         the new `self' expression once.  */
       tree save_arg = save_expr (TREE_VALUE (arg_list));
       TREE_VALUE (arg_list) = save_arg;
-      check = java_check_reference (save_arg, 1);
+      check = java_check_reference (save_arg, ! DECL_INIT_P (method));
       func = build_known_method_ref (method, method_type, self_type,
                                     method_signature, arg_list);
     }
@@ -2023,18 +2448,25 @@ expand_invoke (opcode, method_ref_index, nargs)
       else
        func = build_invokeinterface (dtable, method);
     }
-  func = build1 (NOP_EXPR, build_pointer_type (method_type), func);
-  call = build (CALL_EXPR, TREE_TYPE (method_type), func, arg_list, NULL_TREE);
+      
+  if (TREE_CODE (func) == ADDR_EXPR)
+    TREE_TYPE (func) = build_pointer_type (method_type);
+  else
+    func = build1 (NOP_EXPR, build_pointer_type (method_type), func);
+
+  call = build3 (CALL_EXPR, TREE_TYPE (method_type),
+                func, arg_list, NULL_TREE);
   TREE_SIDE_EFFECTS (call) = 1;
+  call = check_for_builtin (method, call);
 
   if (check != NULL_TREE)
     {
-      call = build (COMPOUND_EXPR, TREE_TYPE (call), check, call);
+      call = build2 (COMPOUND_EXPR, TREE_TYPE (call), check, call);
       TREE_SIDE_EFFECTS (call) = 1;
     }
 
   if (TREE_CODE (TREE_TYPE (method_type)) == VOID_TYPE)
-    expand_expr_stmt (call);
+    java_add_stmt (call);
   else
     {
       push_value (call);
@@ -2046,14 +2478,16 @@ expand_invoke (opcode, method_ref_index, nargs)
    a JNI function.  */
 
 tree
-build_jni_stub (method)
-     tree method;
+build_jni_stub (tree method)
 {
   tree jnifunc, call, args, body, lookup_arg, method_sig, arg_types;
   tree jni_func_type, tem;
   tree env_var, res_var = NULL_TREE, block;
   tree method_args, res_type;
   tree meth_var;
+  tree bind;
+
+  int args_size = 0;
 
   tree klass = DECL_CONTEXT (method);
   int from_class = ! CLASS_FROM_SOURCE_P (klass);
@@ -2081,8 +2515,11 @@ build_jni_stub (method)
   TREE_PUBLIC (meth_var) = 0;
   DECL_EXTERNAL (meth_var) = 0;
   DECL_CONTEXT (meth_var) = method;
-  make_decl_rtl (meth_var, NULL);
-  meth_var = pushdecl_top_level (meth_var);
+  DECL_ARTIFICIAL (meth_var) = 1;
+  DECL_INITIAL (meth_var) = null_pointer_node;
+  TREE_USED (meth_var) = 1;
+  chainon (env_var, meth_var);
+  build_result_decl (method);
 
   /* One strange way that the front ends are different is that they
      store arguments differently.  */
@@ -2099,11 +2536,11 @@ build_jni_stub (method)
     TREE_TYPE (block) = TREE_TYPE (TREE_TYPE (method));
 
   /* Compute the local `env' by calling _Jv_GetJNIEnvNewFrame.  */
-  body = build (MODIFY_EXPR, ptr_type_node, env_var,
-               build (CALL_EXPR, ptr_type_node,
-                      build_address_of (soft_getjnienvnewframe_node),
-                      build_tree_list (NULL_TREE, klass),
-                      NULL_TREE));
+  body = build2 (MODIFY_EXPR, ptr_type_node, env_var,
+                build3 (CALL_EXPR, ptr_type_node,
+                        build_address_of (soft_getjnienvnewframe_node),
+                        build_tree_list (NULL_TREE, klass),
+                        NULL_TREE));
   CAN_COMPLETE_NORMALLY (body) = 1;
 
   /* All the arguments to this method become arguments to the
@@ -2111,7 +2548,16 @@ build_jni_stub (method)
      special way, we would do that here.  */
   args = NULL_TREE;
   for (tem = method_args; tem != NULL_TREE; tem = TREE_CHAIN (tem))
-    args = tree_cons (NULL_TREE, tem, args);
+    {
+      int arg_bits = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (tem)));
+#ifdef PARM_BOUNDARY
+      arg_bits = (((arg_bits + PARM_BOUNDARY - 1) / PARM_BOUNDARY)
+                  * PARM_BOUNDARY);
+#endif
+      args_size += (arg_bits / BITS_PER_UNIT);
+
+      args = tree_cons (NULL_TREE, tem, args);
+    }
   args = nreverse (args);
   arg_types = TYPE_ARG_TYPES (TREE_TYPE (method));
 
@@ -2120,101 +2566,100 @@ build_jni_stub (method)
      available in the argument list.  */
   if (METHOD_STATIC (method))
     {
+      args_size += int_size_in_bytes (TREE_TYPE (klass));
       args = tree_cons (NULL_TREE, klass, args);
       arg_types = tree_cons (NULL_TREE, object_ptr_type_node, arg_types);
     }
 
   /* The JNIEnv structure is the first argument to the JNI function.  */
+  args_size += int_size_in_bytes (TREE_TYPE (env_var));
   args = tree_cons (NULL_TREE, env_var, args);
   arg_types = tree_cons (NULL_TREE, ptr_type_node, arg_types);
 
   /* We call _Jv_LookupJNIMethod to find the actual underlying
      function pointer.  _Jv_LookupJNIMethod will throw the appropriate
      exception if this function is not found at runtime.  */
+  tem = build_tree_list (NULL_TREE, build_int_cst (NULL_TREE, args_size));
   method_sig = build_java_signature (TREE_TYPE (method));
-  lookup_arg =
-    build_tree_list (NULL_TREE,
-                    build_utf8_ref (unmangle_classname
-                                    (IDENTIFIER_POINTER (method_sig),
-                                     IDENTIFIER_LENGTH (method_sig))));
+  lookup_arg = tree_cons (NULL_TREE,
+                          build_utf8_ref (unmangle_classname
+                                          (IDENTIFIER_POINTER (method_sig),
+                                           IDENTIFIER_LENGTH (method_sig))), 
+                          tem);
   tem = DECL_NAME (method);
   lookup_arg
     = tree_cons (NULL_TREE, klass,
                 tree_cons (NULL_TREE, build_utf8_ref (tem), lookup_arg));
+  
+  tem = build_function_type (TREE_TYPE (TREE_TYPE (method)), arg_types);
+
+#ifdef MODIFY_JNI_METHOD_CALL
+  tem = MODIFY_JNI_METHOD_CALL (tem);
+#endif
 
-  jni_func_type
-    = build_pointer_type (build_function_type (TREE_TYPE (TREE_TYPE (method)),
-                                              arg_types));
+  jni_func_type = build_pointer_type (tem);
 
-  jnifunc = build (COND_EXPR, ptr_type_node,
-                  meth_var, meth_var,
-                  build (MODIFY_EXPR, ptr_type_node,
-                         meth_var,
-                         build (CALL_EXPR, ptr_type_node,
-                                build_address_of (soft_lookupjnimethod_node),
-                                lookup_arg, NULL_TREE)));
+  jnifunc = build3 (COND_EXPR, ptr_type_node,
+                   meth_var, meth_var,
+                   build2 (MODIFY_EXPR, ptr_type_node, meth_var,
+                           build3 (CALL_EXPR, ptr_type_node,
+                                   build_address_of
+                                     (soft_lookupjnimethod_node),
+                                   lookup_arg, NULL_TREE)));
 
   /* Now we make the actual JNI call via the resulting function
      pointer.    */
-  call = build (CALL_EXPR, TREE_TYPE (TREE_TYPE (method)),
-               build1 (NOP_EXPR, jni_func_type, jnifunc),
-               args, NULL_TREE);
+  call = build3 (CALL_EXPR, TREE_TYPE (TREE_TYPE (method)),
+                build1 (NOP_EXPR, jni_func_type, jnifunc),
+                args, NULL_TREE);
 
   /* If the JNI call returned a result, capture it here.  If we had to
      unwrap JNI object results, we would do that here.  */
   if (res_var != NULL_TREE)
-    call = build (MODIFY_EXPR, TREE_TYPE (TREE_TYPE (method)),
-                 res_var, call);
+    call = build2 (MODIFY_EXPR, TREE_TYPE (TREE_TYPE (method)),
+                  res_var, call);
 
   TREE_SIDE_EFFECTS (call) = 1;
   CAN_COMPLETE_NORMALLY (call) = 1;
 
-  body = build (COMPOUND_EXPR, void_type_node, body, call);
+  body = build2 (COMPOUND_EXPR, void_type_node, body, call);
   TREE_SIDE_EFFECTS (body) = 1;
 
   /* Now free the environment we allocated.  */
-  call = build (CALL_EXPR, ptr_type_node,
-               build_address_of (soft_jnipopsystemframe_node),
-               build_tree_list (NULL_TREE, env_var),
-               NULL_TREE);
+  call = build3 (CALL_EXPR, ptr_type_node,
+                build_address_of (soft_jnipopsystemframe_node),
+                build_tree_list (NULL_TREE, env_var),
+                NULL_TREE);
   TREE_SIDE_EFFECTS (call) = 1;
   CAN_COMPLETE_NORMALLY (call) = 1;
-  body = build (COMPOUND_EXPR, void_type_node, body, call);
+  body = build2 (COMPOUND_EXPR, void_type_node, body, call);
   TREE_SIDE_EFFECTS (body) = 1;
 
-  /* Finally, do the return.  When compiling from source we rely on
-     patch_return to patch the return value -- because DECL_RESULT is
-     not set at the time this function is called.  */
-  if (from_class)
-    {
-      res_type = void_type_node;
-      if (res_var != NULL_TREE)
-       {
-         tree drt;
-         if (! DECL_RESULT (method))
-           abort ();
-         /* Make sure we copy the result variable to the actual
-            result.  We use the type of the DECL_RESULT because it
-            might be different from the return type of the function:
-            it might be promoted.  */
-         drt = TREE_TYPE (DECL_RESULT (method));
-         if (drt != TREE_TYPE (res_var))
-           res_var = build1 (CONVERT_EXPR, drt, res_var);
-         res_var = build (MODIFY_EXPR, drt, DECL_RESULT (method), res_var);
-         TREE_SIDE_EFFECTS (res_var) = 1;
-       }
-    }
-  else
+  /* Finally, do the return.  */
+  res_type = void_type_node;
+  if (res_var != NULL_TREE)
     {
-      /* This is necessary to get patch_return to run.  */
-      res_type = NULL_TREE;
-    }
-  body = build (COMPOUND_EXPR, void_type_node, body,
-               build1 (RETURN_EXPR, res_type, res_var));
+      tree drt;
+      if (! DECL_RESULT (method))
+       abort ();
+      /* Make sure we copy the result variable to the actual
+        result.  We use the type of the DECL_RESULT because it
+        might be different from the return type of the function:
+        it might be promoted.  */
+      drt = TREE_TYPE (DECL_RESULT (method));
+      if (drt != TREE_TYPE (res_var))
+       res_var = build1 (CONVERT_EXPR, drt, res_var);
+      res_var = build2 (MODIFY_EXPR, drt, DECL_RESULT (method), res_var);
+      TREE_SIDE_EFFECTS (res_var) = 1;
+    }
+
+  body = build2 (COMPOUND_EXPR, void_type_node, body,
+                build1 (RETURN_EXPR, res_type, res_var));
   TREE_SIDE_EFFECTS (body) = 1;
-
-  BLOCK_EXPR_BODY (block) = body;
-  return block;
+  
+  bind = build3 (BIND_EXPR, void_type_node, BLOCK_VARS (block), 
+                body, block);
+  return bind;
 }
 
 /* Expand an operation to extract from or store into a field.
@@ -2223,16 +2668,14 @@ build_jni_stub (method)
    FIELD_REF_INDEX is an index into the constant pool.  */
 
 static void
-expand_java_field_op (is_static, is_putting, field_ref_index)
-     int is_static;
-     int is_putting;
-     int field_ref_index;
-{
-  tree self_type = 
-      get_class_constant (current_jcf, 
-                         COMPONENT_REF_CLASS_INDEX (&current_jcf->cpool, 
-                                                    field_ref_index));
-  const char *self_name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (self_type)));
+expand_java_field_op (int is_static, int is_putting, int field_ref_index)
+{
+  tree self_type
+    = get_class_constant (current_jcf,
+                          COMPONENT_REF_CLASS_INDEX (&current_jcf->cpool,
+                          field_ref_index));
+  const char *self_name
+    = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (self_type)));
   tree field_name = COMPONENT_REF_NAME (&current_jcf->cpool, field_ref_index);
   tree field_signature = COMPONENT_REF_SIGNATURE (&current_jcf->cpool, 
                                                  field_ref_index);
@@ -2240,20 +2683,39 @@ expand_java_field_op (is_static, is_putting, field_ref_index)
   tree new_value = is_putting ? pop_value (field_type) : NULL_TREE;
   tree field_ref;
   int is_error = 0;
-  tree field_decl = lookup_field (&self_type, field_name);
+  tree original_self_type = self_type;
+  tree field_decl;
+  
+  if (! CLASS_LOADED_P (self_type))
+    load_class (self_type, 1);  
+  field_decl = lookup_field (&self_type, field_name);
   if (field_decl == error_mark_node)
     {
       is_error = 1;
     }
   else if (field_decl == NULL_TREE)
     {
-      error ("Missing field '%s' in '%s'",
-            IDENTIFIER_POINTER (field_name), self_name);
-      is_error = 1;
+      if (! flag_verify_invocations)
+       {
+         int flags = ACC_PUBLIC;
+         if (is_static)
+           flags |= ACC_STATIC;
+         self_type = original_self_type;
+         field_decl = add_field (original_self_type, field_name,
+                                 field_type, flags); 
+         DECL_ARTIFICIAL (field_decl) = 1;
+         DECL_IGNORED_P (field_decl) = 1;
+       }
+      else
+       {      
+         error ("missing field '%s' in '%s'",
+                IDENTIFIER_POINTER (field_name), self_name);
+         is_error = 1;
+      }
     }
   else if (build_java_signature (TREE_TYPE (field_decl)) != field_signature)
     {
-      error ("Mismatching signature for field '%s' in '%s'",
+      error ("mismatching signature for field '%s' in '%s'",
             IDENTIFIER_POINTER (field_name), self_name);
       is_error = 1;
     }
@@ -2275,31 +2737,33 @@ expand_java_field_op (is_static, is_putting, field_ref_index)
       if (FIELD_FINAL (field_decl))
        {
          if (DECL_CONTEXT (field_decl) != current_class)
-           error_with_decl (field_decl,
-                    "assignment to final field `%s' not in field's class");
+            error ("%Jassignment to final field '%D' not in field's class",
+                   field_decl, field_decl);
          else if (FIELD_STATIC (field_decl))
            {
              if (!DECL_CLINIT_P (current_function_decl))
-               warning_with_decl (field_decl, 
-             "assignment to final static field `%s' not in class initializer");
+               warning ("%Jassignment to final static field %qD not in "
+                         "class initializer",
+                         field_decl, field_decl);
            }
          else
            {
              tree cfndecl_name = DECL_NAME (current_function_decl);
              if (! DECL_CONSTRUCTOR_P (current_function_decl)
                  && !ID_FINIT_P (cfndecl_name))
-               warning_with_decl (field_decl, "assignment to final field `%s' not in constructor");
+                warning ("%Jassignment to final field '%D' not in constructor",
+                        field_decl, field_decl);
            }
        }
-      expand_assignment (field_ref, new_value, 0, 0);
+      java_add_stmt (build2 (MODIFY_EXPR, TREE_TYPE (field_ref),
+                            field_ref, new_value));
     }
   else
     push_value (field_ref);
 }
 
 void
-load_type_state (label)
-     tree label;
+load_type_state (tree label)
 {
   int i;
   tree vec = LABEL_TYPE_STATE (label);
@@ -2309,234 +2773,11 @@ load_type_state (label)
     type_map [i] = TREE_VEC_ELT (vec, i);
 }
 
-/* Do the expansion of a Java switch. With Gcc, switches are front-end
-   dependant things, but they rely on gcc routines. This function is
-   placed here because it uses things defined locally in parse.y. */
-
-static tree
-case_identity (t, v)
-     tree t __attribute__ ((__unused__));
-     tree v;
-{
-  return v;
-}
-
-/* Return the name of the vtable for an array of a given primitive
-   type.  */
-static tree
-get_primitive_array_vtable (tree elt)
-{
-  tree r;
-  if (elt == boolean_type_node)
-    r = boolean_array_vtable;
-  else if (elt == byte_type_node)
-    r = byte_array_vtable;
-  else if (elt == char_type_node)
-    r = char_array_vtable;
-  else if (elt == short_type_node)
-    r = short_array_vtable;
-  else if (elt == int_type_node)
-    r = int_array_vtable;
-  else if (elt == long_type_node)
-    r = long_array_vtable;
-  else if (elt == float_type_node)
-    r = float_array_vtable;
-  else if (elt == double_type_node)
-    r = double_array_vtable;
-  else
-    abort ();
-  return build_address_of (r);
-}
-
-struct rtx_def *
-java_lang_expand_expr (exp, target, tmode, modifier)
-     register tree exp;
-     rtx target;
-     enum machine_mode tmode;
-     enum expand_modifier modifier;
-{
-  tree current;
-
-  switch (TREE_CODE (exp))
-    {
-    case NEW_ARRAY_INIT:
-      {
-       rtx tmp;
-       tree array_type = TREE_TYPE (TREE_TYPE (exp));
-       tree element_type = TYPE_ARRAY_ELEMENT (array_type);
-       tree data_fld = TREE_CHAIN (TREE_CHAIN (TYPE_FIELDS (array_type)));
-       HOST_WIDE_INT ilength = java_array_type_length (array_type);
-       tree length = build_int_2 (ilength, 0);
-       tree init = TREE_OPERAND (exp, 0);
-       tree array_decl;
-
-       /* See if we can generate the array statically.  */
-       if (TREE_CONSTANT (init) && TREE_STATIC (exp)
-           && JPRIMITIVE_TYPE_P (element_type))
-         {
-           tree temp, value, init_decl;
-           struct rtx_def *r;
-           START_RECORD_CONSTRUCTOR (temp, object_type_node);
-           PUSH_FIELD_VALUE (temp, "vtable",
-                             get_primitive_array_vtable (element_type));
-           if (! flag_hash_synchronization)
-             PUSH_FIELD_VALUE (temp, "sync_info", null_pointer_node);
-           FINISH_RECORD_CONSTRUCTOR (temp);
-           START_RECORD_CONSTRUCTOR (value, array_type);
-           PUSH_SUPER_VALUE (value, temp);
-           PUSH_FIELD_VALUE (value, "length", length);
-           PUSH_FIELD_VALUE (value, "data", init);
-           FINISH_RECORD_CONSTRUCTOR (value);
-
-           init_decl = build_decl (VAR_DECL, generate_name (), array_type);
-           pushdecl_top_level (init_decl);
-           TREE_STATIC (init_decl) = 1;
-           DECL_INITIAL (init_decl) = value;
-           DECL_IGNORED_P (init_decl) = 1;
-           TREE_READONLY (init_decl) = 1;
-           rest_of_decl_compilation (init_decl, NULL, 1, 0);
-           TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (init_decl)) = 1;
-           init = build1 (ADDR_EXPR, TREE_TYPE (exp), init_decl);
-           r = expand_expr (init, target, tmode, modifier);
-           return r;
-         }
-
-       array_decl = build_decl (VAR_DECL, NULL_TREE, TREE_TYPE (exp));
-       expand_decl (array_decl);
-       tmp = expand_assignment (array_decl,
-                                build_new_array (element_type, length),
-                                1, 0);
-       if (TREE_CONSTANT (init)
-           && ilength >= 10 && JPRIMITIVE_TYPE_P (element_type))
-         {
-           tree init_decl;
-           init_decl = build_decl (VAR_DECL, generate_name (),
-                                   TREE_TYPE (init));
-           pushdecl_top_level (init_decl);
-           TREE_STATIC (init_decl) = 1;
-           DECL_INITIAL (init_decl) = init;
-           DECL_IGNORED_P (init_decl) = 1;
-           TREE_READONLY (init_decl) = 1;
-           rest_of_decl_compilation (init_decl, NULL, 1, 0);
-           TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (init_decl)) = 1;
-           init = init_decl;
-         }
-       expand_assignment (build (COMPONENT_REF, TREE_TYPE (data_fld),
-                                 build_java_indirect_ref (array_type, 
-                                         array_decl, flag_check_references), 
-                                 data_fld), init, 0, 0);
-       return tmp;
-      }
-    case BLOCK:
-      if (BLOCK_EXPR_BODY (exp))
-       {
-         tree local;
-         tree body = BLOCK_EXPR_BODY (exp);
-         /* Set to 1 or more when we found a static class
-             initialization flag. */
-         int found_class_initialization_flag = 0;
-
-         pushlevel (2);        /* 2 and above */
-         expand_start_bindings (0);
-         local = BLOCK_EXPR_DECLS (exp);
-         while (local)
-           {
-             tree next = TREE_CHAIN (local);
-             found_class_initialization_flag +=
-               LOCAL_CLASS_INITIALIZATION_FLAG_P (local);
-             layout_decl (local, 0);
-             expand_decl (pushdecl (local));
-             local = next;
-           }
-
-         /* Emit initialization code for test flags if we saw one. */
-         if (! always_initialize_class_p 
-             && current_function_decl
-             && found_class_initialization_flag)
-           hash_traverse 
-             (&DECL_FUNCTION_INIT_TEST_TABLE (current_function_decl),
-              emit_init_test_initialization, NULL);
-
-         /* Avoid deep recursion for long block.  */
-         while (TREE_CODE (body) == COMPOUND_EXPR)
-           {
-             expand_expr (TREE_OPERAND (body, 0), const0_rtx, VOIDmode, 0);
-             emit_queue ();
-             body = TREE_OPERAND (body, 1);
-           }
-         expand_expr (body, const0_rtx, VOIDmode, 0);
-         emit_queue ();
-         expand_end_bindings (getdecls (), 1, 0);
-         poplevel (1, 1, 0);
-         return const0_rtx;
-       }
-      return const0_rtx;
-
-    case CASE_EXPR:
-      {
-       tree duplicate;
-       if (pushcase (TREE_OPERAND (exp, 0), case_identity,
-                     build_decl (LABEL_DECL, NULL_TREE, NULL_TREE), 
-                     &duplicate) == 2)
-         {
-           EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (exp);
-           parse_error_context
-             (wfl_operator, "Duplicate case label: `%s'",
-              print_int_node (TREE_OPERAND (exp, 0)));
-         }
-       return const0_rtx;
-      }
-
-    case DEFAULT_EXPR:
-      pushcase (NULL_TREE, 0, 
-               build_decl (LABEL_DECL, NULL_TREE, NULL_TREE), NULL);
-      return const0_rtx;
-
-    case SWITCH_EXPR:
-      expand_start_case (0, TREE_OPERAND (exp, 0), int_type_node, "switch");
-      expand_expr_stmt (TREE_OPERAND (exp, 1));
-      expand_end_case (TREE_OPERAND (exp, 0));
-      return const0_rtx;
-
-    case TRY_EXPR:
-      /* We expand a try[-catch] block */
-
-      /* Expand the try block */
-      expand_eh_region_start ();
-      expand_expr_stmt (TREE_OPERAND (exp, 0));
-      expand_start_all_catch ();
-
-      /* Expand all catch clauses (EH handlers) */
-      for (current = TREE_OPERAND (exp, 1); current; 
-          current = TREE_CHAIN (current))
-       {
-         tree catch = TREE_OPERAND (current, 0);
-         tree decl = BLOCK_EXPR_DECLS (catch);
-         tree type = (decl ? TREE_TYPE (TREE_TYPE (decl)) : NULL_TREE);
-
-         expand_start_catch (type);
-         expand_expr_stmt (TREE_OPERAND (current, 0));
-         expand_end_catch ();
-       }
-      expand_end_all_catch ();
-      return const0_rtx;
-
-    case JAVA_EXC_OBJ_EXPR:
-      return expand_expr (build_exception_object_ref (TREE_TYPE (exp)),
-                         target, tmode, modifier);
-
-    default:
-      internal_error ("Can't expand %s", tree_code_name [TREE_CODE (exp)]);
-    }
-}
-
 /* Go over METHOD's bytecode and note instruction starts in
    instruction_bits[].  */
 
 void
-note_instructions (jcf, method)
-     JCF *jcf;
-     tree method;
+note_instructions (JCF *jcf, tree method)
 {
   int PC; 
   unsigned char* byte_ops;
@@ -2546,7 +2787,6 @@ note_instructions (jcf, method)
   jint INT_temp;
 
 #undef RET /* Defined by config/i386/i386.h */
-#undef AND /* Causes problems with opcodes for iand and land. */
 #undef PTR
 #define BCODE byte_ops
 #define BYTE_type_node byte_type_node
@@ -2639,6 +2879,7 @@ note_instructions (jcf, method)
   if (!saw_index)  NOTE_LABEL(oldpc + INT_temp);
 #define PRE_JSR(OPERAND_TYPE, OPERAND_VALUE) \
   saw_index = 0;  INT_temp = (OPERAND_VALUE); \
+  NOTE_LABEL (PC); \
   if (!saw_index)  NOTE_LABEL(oldpc + INT_temp);
 
 #define PRE_RET(OPERAND_TYPE, OPERAND_VALUE)  (void)(OPERAND_VALUE)
@@ -2679,9 +2920,7 @@ note_instructions (jcf, method)
 }
 
 void
-expand_byte_code (jcf, method)
-     JCF *jcf;
-     tree method;
+expand_byte_code (JCF *jcf, tree method)
 {
   int PC;
   int i;
@@ -2711,10 +2950,18 @@ expand_byte_code (jcf, method)
        }
     }  
 
-  if (! verify_jvm_instructions (jcf, byte_ops, length))
-    return;
+  if (flag_new_verifier)
+    {
+      if (! verify_jvm_instructions_new (jcf, byte_ops, length))
+        return;
+    }
+  else
+    {
+      if (! verify_jvm_instructions (jcf, byte_ops, length))
+       return;
+    }
 
-  /* Translate bytecodes to rtl instructions. */
+  /* Translate bytecodes */
   linenumber_pointer = linenumber_table;
   for (PC = 0; PC < length;)
     {
@@ -2723,7 +2970,7 @@ expand_byte_code (jcf, method)
          tree label = lookup_label (PC);
           flush_quick_stack ();
          if ((instruction_bits [PC] & BCODE_TARGET) != 0)
-           expand_label (label);
+           java_add_stmt (build1 (LABEL_EXPR, void_type_node, label));
          if (LABEL_VERIFIED (label) || PC == 0)
            load_type_state (label);
        }
@@ -2747,8 +2994,9 @@ expand_byte_code (jcf, method)
          if (dead_code_index != -1)
            {
               /* We've just reached the end of a region of dead code.  */
-              warning ("Unreachable bytecode from %d to before %d",
-                       dead_code_index, PC);
+             if (extra_warnings)
+               warning ("unreachable bytecode from %d to before %d",
+                        dead_code_index, PC);
               dead_code_index = -1;
             }
        }
@@ -2769,8 +3017,12 @@ expand_byte_code (jcf, method)
              linenumber_pointer += 4;
              if (pc == PC)
                {
-                 lineno = GET_u2 (linenumber_pointer - 2);
-                 emit_line_note (input_filename, lineno);
+                 int line = GET_u2 (linenumber_pointer - 2);
+#ifdef USE_MAPPED_LOCATION
+                 input_location = linemap_line_start (&line_table, line, 1);
+#else
+                 input_location.line = line;
+#endif
                  if (!(instruction_bits[PC] & BCODE_HAS_MULTI_LINENUMBERS))
                    break;
                }
@@ -2784,15 +3036,14 @@ expand_byte_code (jcf, method)
   if (dead_code_index != -1)
     {
       /* We've just reached the end of a region of dead code.  */
-      warning ("Unreachable bytecode from %d to the end of the method", 
-              dead_code_index);
+      if (extra_warnings)
+       warning ("unreachable bytecode from %d to the end of the method", 
+                dead_code_index);
     }
 }
 
 static void
-java_push_constant_from_pool (jcf, index)
-     JCF *jcf;
-     int index;
+java_push_constant_from_pool (JCF *jcf, int index)
 {
   tree c;
   if (JPOOL_TAG (jcf, index) == CONSTANT_String)
@@ -2801,7 +3052,7 @@ java_push_constant_from_pool (jcf, index)
       name = get_name_constant (jcf, JPOOL_USHORT1 (jcf, index));
       index = alloc_name_constant (CONSTANT_String, name);
       c = build_ref_from_constant_pool (index);
-      TREE_TYPE (c) = promote_type (string_type_node);
+      c = convert (promote_type (string_type_node), c);
     }
   else
     c = get_constant (jcf, index);
@@ -2809,10 +3060,8 @@ java_push_constant_from_pool (jcf, index)
 } 
 
 int
-process_jvm_instruction (PC, byte_ops, length)
-     int PC;
-     const unsigned char* byte_ops;
-     long length ATTRIBUTE_UNUSED;
+process_jvm_instruction (int PC, const unsigned char* byte_ops,
+                        long length ATTRIBUTE_UNUSED)
 { 
   const char *opname; /* Temporary ??? */
   int oldpc = PC; /* PC at instruction start. */
@@ -2821,8 +3070,14 @@ process_jvm_instruction (PC, byte_ops, length)
      replace the top of the stack with the thrown object reference */
   if (instruction_bits [PC] & BCODE_EXCEPTION_TARGET)
     {
-      tree type = pop_type (ptr_type_node);
-      push_value (build (JAVA_EXC_OBJ_EXPR, type));
+      /* Note that the new verifier will not emit a type map at all
+        for dead exception handlers.  In this case we just ignore
+        the situation.  */
+      if (! flag_new_verifier || (instruction_bits[PC] & BCODE_VERIFIED) != 0)
+       {
+         tree type = pop_type (promote_type (throwable_type_node));
+         push_value (build_exception_object_ref (type));
+       }
     }
 
   switch (byte_ops[PC++])
@@ -2837,15 +3092,15 @@ process_jvm_instruction (PC, byte_ops, length)
   {                                                                    \
     int saw_index = 0;                                                 \
     int index     = OPERAND_VALUE;                                     \
-    build_java_ret (find_local_variable (index, ptr_type_node, oldpc));        \
+    build_java_ret                                                     \
+      (find_local_variable (index, return_address_type_node, oldpc));  \
   }
 
-#define JSR(OPERAND_TYPE, OPERAND_VALUE)               \
-  {                                                    \
-    tree where = lookup_label (oldpc+OPERAND_VALUE);   \
-    tree ret   = lookup_label (PC);                    \
-    build_java_jsr (where, ret);                       \
-    load_type_state (ret);                             \
+#define JSR(OPERAND_TYPE, OPERAND_VALUE) \
+  {                                                \
+    /* OPERAND_VALUE may have side-effects on PC */ \
+    int opvalue = OPERAND_VALUE;                   \
+    build_java_jsr (oldpc + opvalue, PC);          \
   }
 
 /* Push a constant onto the stack. */
@@ -2925,46 +3180,24 @@ process_jvm_instruction (PC, byte_ops, length)
 #define LOOKUP_SWITCH \
   { jint default_offset = IMMEDIATE_s4;  jint npairs = IMMEDIATE_s4; \
     tree selector = pop_value (INT_type_node); \
-    tree duplicate, label; \
-    tree type = TREE_TYPE (selector); \
-    flush_quick_stack (); \
-    expand_start_case (0, selector, type, "switch statement");\
+    tree switch_expr = expand_java_switch (selector, oldpc + default_offset); \
     while (--npairs >= 0) \
       { \
        jint match = IMMEDIATE_s4; jint offset = IMMEDIATE_s4; \
-       tree value = build_int_2 (match, match < 0 ? -1 : 0); \
-       TREE_TYPE (value) = type; \
-       label =  build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); \
-       pushcase (value, convert, label, &duplicate); \
-       expand_java_goto (oldpc + offset); \
+       expand_java_add_case (switch_expr, match, oldpc + offset); \
       } \
-    label =  build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); \
-    pushcase (NULL_TREE, 0, label, &duplicate); \
-    expand_java_goto (oldpc + default_offset); \
-    expand_end_case (selector); \
   }
 
 #define TABLE_SWITCH \
   { jint default_offset = IMMEDIATE_s4; \
     jint low = IMMEDIATE_s4; jint high = IMMEDIATE_s4; \
     tree selector = pop_value (INT_type_node); \
-    tree duplicate, label; \
-    tree type = TREE_TYPE (selector); \
-    flush_quick_stack (); \
-    expand_start_case (0, selector, type, "switch statement");\
+    tree switch_expr = expand_java_switch (selector, oldpc + default_offset); \
     for (; low <= high; low++) \
       { \
         jint offset = IMMEDIATE_s4; \
-        tree value = build_int_2 (low, low < 0 ? -1 : 0); \
-        TREE_TYPE (value) = type; \
-        label =  build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); \
-        pushcase (value, convert, label, &duplicate); \
-        expand_java_goto (oldpc + offset); \
+       expand_java_add_case (switch_expr, low, oldpc + offset); \
       } \
-    label =  build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); \
-    pushcase (NULL_TREE, 0, label, &duplicate); \
-    expand_java_goto (oldpc + default_offset); \
-    expand_end_case (selector); \
   }
 
 #define INVOKE(MAYBE_STATIC, IS_INTERFACE) \
@@ -3029,16 +3262,17 @@ process_jvm_instruction (PC, byte_ops, length)
 
 /* internal macro added for use by the WIDE case 
    Added TREE_TYPE (decl) assignment, apbianco  */
-#define STORE_INTERNAL(OPTYPE, OPVALUE)                        \
-  {                                                    \
-    tree decl, value;                                  \
-    int var = OPVALUE;                                 \
-    tree type = OPTYPE;                                        \
-    value = pop_value (type);                          \
-    type = TREE_TYPE (value);                          \
-    decl = find_local_variable (var, type, oldpc);     \
-    set_local_type (var, type );                       \
-    expand_assignment (decl, value, 0, 0);             \
+#define STORE_INTERNAL(OPTYPE, OPVALUE)                                \
+  {                                                            \
+    tree decl, value;                                          \
+    int index = OPVALUE;                                       \
+    tree type = OPTYPE;                                                \
+    value = pop_value (type);                                  \
+    type = TREE_TYPE (value);                                  \
+    decl = find_local_variable (index, type, oldpc);           \
+    set_local_type (index, type);                              \
+    java_add_stmt (build2 (MODIFY_EXPR, type, decl, value));   \
+    update_aliases (decl, index, PC);                          \
   }
 
 #define STORE(OPERAND_TYPE, OPERAND_VALUE) \
@@ -3061,7 +3295,7 @@ process_jvm_instruction (PC, byte_ops, length)
     flush_quick_stack ();                      \
     c = build_java_monitor (call, o);          \
     TREE_SIDE_EFFECTS (c) = 1;                 \
-    expand_expr_stmt (c);                      \
+    java_add_stmt (c);                         \
   }
 
 #define SPECIAL_IINC(IGNORED) \
@@ -3125,9 +3359,7 @@ process_jvm_instruction (PC, byte_ops, length)
    CODE_OFFSET.  */
 
 static unsigned char
-peek_opcode_at_pc (jcf, code_offset, pc)
-    JCF *jcf;
-    int code_offset, pc;
+peek_opcode_at_pc (JCF *jcf, int code_offset, int pc)
 {
   unsigned char opcode;
   long absolute_offset = (long)JCF_TELL (jcf);
@@ -3163,9 +3395,8 @@ peek_opcode_at_pc (jcf, code_offset, pc)
    have allocated and filled properly.  */
 
 int
-maybe_adjust_start_pc (jcf, code_offset, start_pc, slot)
-     struct JCF *jcf;
-     int code_offset, start_pc, slot;
+maybe_adjust_start_pc (struct JCF *jcf, int code_offset,
+                      int start_pc, int slot)
 {
   int first, index, opcode;
   int pc, insn_pc;
@@ -3268,27 +3499,18 @@ maybe_adjust_start_pc (jcf, code_offset, start_pc, slot)
 */
 
 tree
-force_evaluation_order (node)
-     tree  node;
+force_evaluation_order (tree node)
 {
   if (flag_syntax_only)
     return node;
-  if (TREE_CODE_CLASS (TREE_CODE (node)) == '2')
-    {
-      if (TREE_SIDE_EFFECTS (TREE_OPERAND (node, 1)))
-       TREE_OPERAND (node, 0) = save_expr (TREE_OPERAND (node, 0));
-    }
-  else if (TREE_CODE (node) == CALL_EXPR
-           || TREE_CODE (node) == NEW_CLASS_EXPR
-           || (TREE_CODE (node) == COMPOUND_EXPR
-               && TREE_CODE (TREE_OPERAND (node, 0)) == CALL_EXPR
-               && TREE_CODE (TREE_OPERAND (node, 1)) == SAVE_EXPR)) 
+  if (TREE_CODE (node) == CALL_EXPR
+      || TREE_CODE (node) == NEW_CLASS_EXPR
+      || (TREE_CODE (node) == COMPOUND_EXPR
+         && TREE_CODE (TREE_OPERAND (node, 0)) == CALL_EXPR
+         && TREE_CODE (TREE_OPERAND (node, 1)) == SAVE_EXPR)) 
     {
       tree arg, cmp;
 
-      if (!TREE_OPERAND (node, 1))
-       return node;
-
       arg = node;
       
       /* Position arg properly, account for wrapped around ctors. */
@@ -3297,7 +3519,11 @@ force_evaluation_order (node)
       
       arg = TREE_OPERAND (arg, 1);
       
-      /* Not having a list of argument here is an error. */ 
+      /* An empty argument list is ok, just ignore it.  */
+      if (!arg)
+       return node;
+
+      /* Not having a list of arguments here is an error. */ 
       if (TREE_CODE (arg) != TREE_LIST)
         abort ();
 
@@ -3306,7 +3532,7 @@ force_evaluation_order (node)
        {
          tree saved = save_expr (force_evaluation_order (TREE_VALUE (arg)));
          cmp = (cmp == NULL_TREE ? saved :
-                build (COMPOUND_EXPR, void_type_node, cmp, saved));
+                build2 (COMPOUND_EXPR, void_type_node, cmp, saved));
          TREE_VALUE (arg) = saved;
        }
       
@@ -3315,7 +3541,9 @@ force_evaluation_order (node)
 
       if (cmp)
        {
-         cmp = save_expr (build (COMPOUND_EXPR, TREE_TYPE (node), cmp, node));
+         cmp = build2 (COMPOUND_EXPR, TREE_TYPE (node), cmp, node);
+         if (TREE_TYPE (cmp) != void_type_node)
+           cmp = save_expr (cmp);
          CAN_COMPLETE_NORMALLY (cmp) = CAN_COMPLETE_NORMALLY (node);
          TREE_SIDE_EFFECTS (cmp) = 1;
          node = cmp;
@@ -3324,36 +3552,95 @@ force_evaluation_order (node)
   return node;
 }
 
-/* Called for every element in DECL_FUNCTION_INIT_TEST_TABLE of a
-   method in order to emit initialization code for each test flag.  */
+/* EXPR_WITH_FILE_LOCATION are used to keep track of the exact
+   location where an expression or an identifier were encountered. It
+   is necessary for languages where the frontend parser will handle
+   recursively more than one file (Java is one of them).  */
 
-static bool
-emit_init_test_initialization (entry, key)
-  struct hash_entry *entry;
-  hash_table_key key ATTRIBUTE_UNUSED;
+tree
+build_expr_wfl (tree node,
+#ifdef USE_MAPPED_LOCATION
+               source_location location
+#else
+               const char *file, int line, int col
+#endif
+)
 {
-  struct init_test_hash_entry *ite = (struct init_test_hash_entry *) entry;
-  tree klass = build_class_ref ((tree) entry->key);
-  tree rhs;
+  tree wfl;
 
-  /* If the DECL_INITIAL of the test flag is set to true, it
-     means that the class is already initialized the time it
-     is in use. */
-  if (DECL_INITIAL (ite->init_test_decl) == boolean_true_node)
-    rhs = boolean_true_node;
-  /* Otherwise, we initialize the class init check variable by looking
-     at the `state' field of the class to see if it is already
-     initialized.  This makes things a bit faster if the class is
-     already initialized, which should be the common case.  */
-  else
-    rhs = build (GE_EXPR, boolean_type_node,
-                build (COMPONENT_REF, byte_type_node,
-                       build1 (INDIRECT_REF, class_type_node, klass),
-                       lookup_field (&class_type_node,
-                                     get_identifier ("state"))),
-                build_int_2 (JV_STATE_DONE, 0));
-
-  expand_expr_stmt (build (MODIFY_EXPR, boolean_type_node, 
-                          ite->init_test_decl, rhs));
-  return true;
+#ifdef USE_MAPPED_LOCATION
+  wfl = make_node (EXPR_WITH_FILE_LOCATION);
+  SET_EXPR_LOCATION (wfl, location);
+#else
+  static const char *last_file = 0;
+  static tree last_filenode = NULL_TREE;
+
+  wfl = make_node (EXPR_WITH_FILE_LOCATION);
+
+  EXPR_WFL_SET_LINECOL (wfl, line, col);
+  if (file != last_file)
+    {
+      last_file = file;
+      last_filenode = file ? get_identifier (file) : NULL_TREE;
+    }
+  EXPR_WFL_FILENAME_NODE (wfl) = last_filenode;
+#endif
+  EXPR_WFL_NODE (wfl) = node;
+  if (node)
+    {
+      if (IS_NON_TYPE_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (node))))
+       TREE_SIDE_EFFECTS (wfl) = TREE_SIDE_EFFECTS (node);
+      TREE_TYPE (wfl) = TREE_TYPE (node);
+    }
+
+  return wfl;
 }
+
+#ifdef USE_MAPPED_LOCATION
+tree
+expr_add_location (tree node, source_location location, bool statement)
+{
+  tree wfl;
+#if 0
+  /* FIXME. This optimization causes failures in code that expects an
+     EXPR_WITH_FILE_LOCATION.  E.g. in resolve_qualified_expression_name. */
+  if (node && ! (statement && flag_emit_class_files))
+    {
+      source_location node_loc = EXPR_LOCATION (node);
+      if (node_loc == location || location == UNKNOWN_LOCATION)
+       return node;
+      if (node_loc == UNKNOWN_LOCATION
+         && IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (node))))
+       {
+         SET_EXPR_LOCATION (node, location);
+         return node;
+       }
+    }
+#endif
+  wfl = make_node (EXPR_WITH_FILE_LOCATION);
+  SET_EXPR_LOCATION (wfl, location);
+  EXPR_WFL_NODE (wfl) = node;
+  if (statement && debug_info_level != DINFO_LEVEL_NONE)
+    EXPR_WFL_EMIT_LINE_NOTE (wfl) = 1;
+  if (node)
+    {
+      if (IS_NON_TYPE_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (node))))
+       TREE_SIDE_EFFECTS (wfl) = TREE_SIDE_EFFECTS (node);
+      TREE_TYPE (wfl) = TREE_TYPE (node);
+    }
+
+  return wfl;
+}
+#endif
+
+/* Build a node to represent empty statements and blocks. */
+
+tree
+build_java_empty_stmt (void)
+{
+  tree t = build_empty_stmt ();
+  CAN_COMPLETE_NORMALLY (t) = 1;
+  return t;
+}
+
+#include "gt-java-expr.h"