Bug 19285 - Interfaces not initialized by static field access
Summary: Interfaces not initialized by static field access
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.1
Assignee: Andrew Haley
URL:
Keywords: wrong-code
Depends on:
Blocks: 12725
  Show dependency treegraph
 
Reported: 2005-01-06 02:19 UTC by Bryce McKinlay
Modified: 2005-05-10 21:03 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-01-06 14:21:32


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bryce McKinlay 2005-01-06 02:19:31 UTC
Consider the following test case:

public class Test implements RuntimeConstants
{
  public static void main(String[] args)
  {
    System.out.println(foo[0]);
  }
}

interface RuntimeConstants 
{
  static int foo[] = {1};    
}

Older bytecode compilers would implement the access to "foo" like so:

  3: getstatic <Field RuntimeConstants.foo int[]>

However, presumably for reasons of binary compatibility, bytecode produced by
some modern Java compilers (javac 1.5.0 with "-target" >= 1.3) does the following:

  3: getstatic <Field Test.foo int[]>

When "foo" is actually in an interface, there is a problem for GCJ because we
have no way to ensure that the interface gets initialized when it is accessed.
Initialization of a class does not itself cause initialization of its
superinterfaces.
Comment 1 Bryce McKinlay 2005-01-06 02:19:44 UTC
gij also fails to execute this bytecode:

$ gij Test
Exception in thread "main" java.lang.IncompatibleClassChangeError: field
Test.foo was not found.
   at Test.main (Test.java:5)

Comment 2 Tom Tromey 2005-01-06 02:56:05 UTC
This is somewhat related to PR 18868, which has to do
with field lookup in this situation.
For the interpreter this seems simple to fix.
For indirect-dispatch, the init-class call needs to
somehow use the really-declaring class as found during linking.
Comment 3 Andrew Pinski 2005-01-06 14:21:32 UTC
Confirmed.
Comment 4 GCC Commits 2005-04-29 18:35:49 UTC
Subject: Bug 19285

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	aph@gcc.gnu.org	2005-04-29 18:35:37

Modified files:
	libjava        : prims.cc link.cc ChangeLog 
	libjava/include: jvm.h 

Log message:
	2005-04-27  Andrew Haley  <aph@redhat.com>
	
	PR java/19285
	* prims.cc (_Jv_ResolvePoolEntry): New function.
	* include/jvm.h (_Jv_Linker::find_field): New arg: found_class.
	* link.cc (_Jv_Linker::find_field): New arg: found_class.
	(resolve_pool_entry): Initialize the class in which a field is
	found.
	(link_symbol_table): Pass new arg to found_class.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/prims.cc.diff?cvsroot=gcc&r1=1.110&r2=1.111
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/link.cc.diff?cvsroot=gcc&r1=1.13&r2=1.14
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/ChangeLog.diff?cvsroot=gcc&r1=1.3578&r2=1.3579
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/include/jvm.h.diff?cvsroot=gcc&r1=1.83&r2=1.84

Comment 5 GCC Commits 2005-04-29 18:42:58 UTC
Subject: Bug 19285

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	aph@gcc.gnu.org	2005-04-29 18:42:50

Modified files:
	gcc/java       : java-tree.h expr.c decl.c class.c constants.c 
	                 ChangeLog 

Log message:
	2005-04-28  Andrew Haley  <aph@redhat.com>
	
	PR java/19285
	* java-tree.h (soft_resolvepoolentry_node): New.
	(alloc_constant_fieldref): Declare.
	* expr.c (expand_java_field_op): Don't call class_init for
	accesses to static fields with indirect dispatch.
	* builtins.c (initialize_builtins): Add "__builtin_expect".
	* decl.c (soft_resolvepoolentry_node): New variable.
	(java_init_decl_processing): Create a decl for
	"_Jv_ResolvePoolEntry".
	* class.c (build_fieldref_cache_entry): New function.
	(build_static_field_ref): Rewrite for indirect dispatch.
	* constants.c (find_name_and_type_constant_tree): New function.
	(alloc_constant_fieldref): Likewise.
	(build_constants_constructor): Handle CONSTANT_Fieldref and
	CONSTANT_NameAndType.
	
	PR java/21115
	* expr.c (force_evaluation_order): Convert outgoing args smaller
	than integer.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/java-tree.h.diff?cvsroot=gcc&r1=1.229&r2=1.230
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/expr.c.diff?cvsroot=gcc&r1=1.222&r2=1.223
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/decl.c.diff?cvsroot=gcc&r1=1.218&r2=1.219
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/class.c.diff?cvsroot=gcc&r1=1.224&r2=1.225
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/constants.c.diff?cvsroot=gcc&r1=1.40&r2=1.41
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/ChangeLog.diff?cvsroot=gcc&r1=1.1601&r2=1.1602

Comment 6 GCC Commits 2005-04-29 18:43:44 UTC
Subject: Bug 19285

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	aph@gcc.gnu.org	2005-04-29 18:43:25

Modified files:
	gcc/java       : builtins.c 

Log message:
	2005-04-28  Andrew Haley  <aph@redhat.com>
	
	PR java/19285
	* java-tree.h (soft_resolvepoolentry_node): New.
	(alloc_constant_fieldref): Declare.
	* expr.c (expand_java_field_op): Don't call class_init for
	accesses to static fields with indirect dispatch.
	* builtins.c (initialize_builtins): Add "__builtin_expect".
	* decl.c (soft_resolvepoolentry_node): New variable.
	(java_init_decl_processing): Create a decl for
	"_Jv_ResolvePoolEntry".
	* class.c (build_fieldref_cache_entry): New function.
	(build_static_field_ref): Rewrite for indirect dispatch.
	* constants.c (find_name_and_type_constant_tree): New function.
	(alloc_constant_fieldref): Likewise.
	(build_constants_constructor): Handle CONSTANT_Fieldref and
	CONSTANT_NameAndType.
	
	PR java/21115
	* expr.c (force_evaluation_order): Convert outgoing args smaller
	than integer.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/builtins.c.diff?cvsroot=gcc&r1=1.29&r2=1.30

Comment 7 GCC Commits 2005-05-09 13:41:54 UTC
Subject: Bug 19285

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	aph@gcc.gnu.org	2005-05-09 13:32:30

Modified files:
	libjava        : ChangeLog prims.cc link.cc 
	libjava/include: jvm.h 

Log message:
	2005-04-27  Andrew Haley  <aph@redhat.com>
	
	PR java/19285
	* prims.cc (_Jv_ResolvePoolEntry): New function.
	* include/jvm.h (_Jv_Linker::find_field): New arg: found_class.
	* link.cc (_Jv_Linker::find_field): New arg: found_class.
	(resolve_pool_entry): Initialize the class in which a field is
	found.
	(link_symbol_table): Pass new arg to found_class.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.3391.2.59&r2=1.3391.2.60
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/prims.cc.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.104.2.3&r2=1.104.2.4
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/link.cc.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.10.2.2&r2=1.10.2.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/include/jvm.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.77.2.3&r2=1.77.2.4

Comment 8 GCC Commits 2005-05-09 13:48:21 UTC
Subject: Bug 19285

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	aph@gcc.gnu.org	2005-05-09 13:34:33

Modified files:
	libjava/java/lang: Class.h 

Log message:
	2005-04-27  Andrew Haley  <aph@redhat.com>
	
	PR java/19285
	* prims.cc (_Jv_ResolvePoolEntry): New function.
	* include/jvm.h (_Jv_Linker::find_field): New arg: found_class.
	* link.cc (_Jv_Linker::find_field): New arg: found_class.
	(resolve_pool_entry): Initialize the class in which a field is
	found.
	(link_symbol_table): Pass new arg to found_class.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/lang/Class.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.78.2.1&r2=1.78.2.2

Comment 9 GCC Commits 2005-05-09 14:00:07 UTC
Subject: Bug 19285

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	aph@gcc.gnu.org	2005-05-09 13:50:01

Modified files:
	gcc/java       : ChangeLog java-tree.h expr.c builtins.c decl.c 
	                 class.c constants.c 

Log message:
	2005-04-28  Andrew Haley  <aph@redhat.com>
	
	PR java/19285
	* java-tree.h (soft_resolvepoolentry_node): New.
	(alloc_constant_fieldref): Declare.
	* expr.c (expand_java_field_op): Don't call class_init for
	accesses to static fields with indirect dispatch.
	* builtins.c (initialize_builtins): Add "__builtin_expect".
	* decl.c (soft_resolvepoolentry_node): New variable.
	(java_init_decl_processing): Create a decl for
	"_Jv_ResolvePoolEntry".
	* class.c (build_fieldref_cache_entry): New function.
	* class.c (build_static_field_ref): New function.
	(build_static_field_ref): Rewrite for indirect dispatch.
	* constants.c (find_name_and_type_constant_tree): New function.
	(alloc_constant_fieldref): Likewise.
	(build_constants_constructor): Handle CONSTANT_Fieldref and
	CONSTANT_NameAndType.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.1556.2.18&r2=1.1556.2.19
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/java-tree.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.226&r2=1.226.8.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/expr.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.218.4.3&r2=1.218.4.4
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/builtins.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.29&r2=1.29.4.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/decl.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.209.4.2&r2=1.209.4.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/class.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.220.8.1&r2=1.220.8.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/constants.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.40&r2=1.40.34.1

Comment 10 Tom Tromey 2005-05-10 21:03:12 UTC
Fix checked in.