Index: java/parse.y =================================================================== --- java/parse.y (revision 113470) +++ java/parse.y (working copy) @@ -11044,7 +11044,7 @@ { case INVOKE_VIRTUAL: dtable = invoke_build_dtable (0, args); - func = build_invokevirtual (dtable, method); + func = build_invokevirtual (dtable, method, TREE_VALUE (args)); break; case INVOKE_NONVIRTUAL: @@ -11074,7 +11074,7 @@ case INVOKE_INTERFACE: dtable = invoke_build_dtable (1, args); - func = build_invokeinterface (dtable, method); + func = build_invokeinterface (dtable, method, TREE_VALUE (args)); break; default: Index: java/Make-lang.in =================================================================== --- java/Make-lang.in (revision 113470) +++ java/Make-lang.in (working copy) @@ -1,6 +1,6 @@ # Top level -*- makefile -*- fragment for the GNU compiler for the Java(TM) # language. -# Copyright (C) 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. +# Copyright (C) 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. #This file is part of GCC. @@ -104,7 +104,8 @@ java/zextract.o java/jcf-io.o java/win32-host.o java/jcf-parse.o java/mangle.o \ java/mangle_name.o java/builtins.o java/resource.o \ java/jcf-write.o java/buffer.o java/check-init.o java/jcf-depend.o \ - java/jcf-path.o java/boehm.o java/java-gimplify.o + java/jcf-path.o java/boehm.o java/java-gimplify.o \ + java/tree-ssa-devirt.o GCJH_OBJS = java/gjavah.o java/jcf-io.o java/jcf-depend.o java/jcf-path.o \ java/win32-host.o java/zextract.o version.o errors.o ggc-none.o \ Index: java/java-tree.def =================================================================== --- java/java-tree.def (revision 113470) +++ java/java-tree.def (working copy) @@ -39,7 +39,7 @@ DEFTREECODE (NEW_CLASS_EXPR, "new_class_expr", tcc_expression, 3) /* Defines `this' as an expression. */ -DEFTREECODE (THIS_EXPR, "this", tcc_unary, 0) +DEFTREECODE (THIS_EXPR, "this", tcc_expression, 0) /* A labeled block. Operand 0 is the label that will be generated to mark the end of the block. Operand 1 is the labeled block body. */ Index: java/jcf-write.c =================================================================== --- java/jcf-write.c (revision 113470) +++ java/jcf-write.c (working copy) @@ -1430,6 +1430,9 @@ switch (TREE_CODE (exp)) { + case OBJ_TYPE_REF: + generate_bytecode_insns (OBJ_TYPE_REF_EXPR (exp), target, state); + break; case BLOCK: if (BLOCK_EXPR_BODY (exp)) { Index: java/ChangeLog from Tom Tromey * java-tree.def (THIS_EXPR): Now tcc_expression. * check-init.c (check_init): Handle OBJ_TYPE_REF. * jcf-write.c (generate_bytecode_insns): Handle OBJ_TYPE_REF. * java-tree.h (build_invokevirtual, build_invokeinterface): Updated. * expr.c (build_invokevirtual): Added 'this_value' argument. Wrap result in OBJ_TYPE_REF. (build_invokeinterface): Likewise. (expand_invoke): Updated. * parse.y (patch_invoke): Updated for changes to build_invokevirtual and build_invokeinterface. Index: java/expr.c =================================================================== --- java/expr.c (revision 113470) +++ java/expr.c (working copy) @@ -2157,7 +2157,7 @@ } tree -build_invokevirtual (tree dtable, tree method) +build_invokevirtual (tree dtable, tree method, tree this_value) { tree func; tree nativecode_ptr_ptr_type_node @@ -2180,7 +2180,7 @@ { /* 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 + from the vtable base to a method, regardless of any extra words inserted at the start of the vtable. */ method_index = DECL_VINDEX (method); method_index = size_binop (MULT_EXPR, method_index, @@ -2198,16 +2198,21 @@ else func = build1 (INDIRECT_REF, nativecode_ptr_type_node, func); + if (!flag_emit_class_files && !flag_indirect_dispatch) + func = build3 (OBJ_TYPE_REF, TREE_TYPE (func), func, this_value, method); + return func; } static GTY(()) tree class_ident; + tree -build_invokeinterface (tree dtable, tree method) +build_invokeinterface (tree dtable, tree method, tree this_value) { tree lookup_arg; tree interface; tree idx; + tree result; /* We expand invokeinterface here. */ @@ -2254,9 +2259,13 @@ 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); + result = build3 (CALL_EXPR, ptr_type_node, + build_address_of (soft_lookupinterfacemethod_node), + lookup_arg, NULL_TREE); + if (!flag_emit_class_files && !flag_indirect_dispatch) + result = build3 (OBJ_TYPE_REF, TREE_TYPE (result), result, + this_value, method); + return result; } /* Expand one of the invoke_* opcodes. @@ -2424,9 +2433,9 @@ tree dtable = invoke_build_dtable (opcode == OPCODE_invokeinterface, arg_list); if (opcode == OPCODE_invokevirtual) - func = build_invokevirtual (dtable, method); + func = build_invokevirtual (dtable, method, TREE_VALUE (arg_list)); else - func = build_invokeinterface (dtable, method); + func = build_invokeinterface (dtable, method, TREE_VALUE (arg_list)); } if (TREE_CODE (func) == ADDR_EXPR) Index: java/lang.c =================================================================== --- java/lang.c (revision 113470) +++ java/lang.c (working copy) @@ -1,5 +1,5 @@ /* Java(TM) language-specific utility routines. - Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 + Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GCC. @@ -47,6 +47,8 @@ #include "opts.h" #include "options.h" +extern void init_devirt (void); + static bool java_init (void); static void java_finish (void); static unsigned int java_init_options (unsigned int, const char **); @@ -593,6 +595,7 @@ no_unit_at_a_time_default = 1; jcf_path_init (); + init_devirt (); return CL_Java; } Index: java/java-tree.h =================================================================== --- java/java-tree.h (revision 113470) +++ java/java-tree.h (working copy) @@ -1,6 +1,6 @@ /* Definitions for parsing and type checking for the GNU compiler for the Java(TM) language. - Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 + Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GCC. @@ -1244,8 +1244,8 @@ extern tree build_known_method_ref (tree, tree, tree, tree, tree); extern tree build_class_init (tree, tree); extern int attach_init_test_initialization_flags (void **, void *); -extern tree build_invokevirtual (tree, tree); -extern tree build_invokeinterface (tree, tree); +extern tree build_invokevirtual (tree, tree, tree); +extern tree build_invokeinterface (tree, tree, tree); extern tree build_jni_stub (tree); extern tree invoke_build_dtable (int, tree); extern tree build_field_ref (tree, tree, tree);