Bug 1305 - [JSR133] GCJ ignores volatile modifier
Summary: [JSR133] GCJ ignores volatile modifier
Status: SUSPENDED
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 27908 (view as bug list)
Depends on:
Blocks:
 
Reported: 2000-12-20 12:18 UTC by jeff.sturm
Modified: 2006-08-28 16:52 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-09-23 22:54:58


Attachments
ReadAfterWrite.java (1.11 KB, application/octet-stream)
2003-05-21 15:16 UTC, jeff.sturm
Details

Note You need to log in before you can comment on or make changes to this bug.
Description jeff.sturm 2000-12-20 12:18:51 UTC
GCJ doesn't implement volatile behavior as outlined in
JLS ch. 17 (or at all, evidently).

Ch. 17 specifies that loads and stores of volatile variables
must be consistent, atomic and sequential.  On some
multiprocessors, gcj-compiled code fails all tests.

Bill Pugh and Doug Lea are credited with discovering this
disrepancy between the JLS and existing JVMs (all current
VMs including those from Sun fail some of the tests.)  This
test case and others are available on Bill's site:

http://www.cs.umd.edu/~pugh/java/memoryModel

Release:
CVS trunk (071300)

Environment:
Linux 2.2 SMP

How-To-Repeat:
Run the attached program on a multiprocessor (SMP) host.
It will test for proper sequential access to volatile
variables.  Any inconsistencies will be reported to stdout.

I tested ReadAfterWrite on a quad-PPro running a Linux 2.2
SMP kernel.
Comment 1 jeff.sturm 2000-12-20 12:18:51 UTC
Fix:
Insert a store barrier instruction before and after volatile
loads and stores.

Note that atomic loads and stores of volatile doubles and
longs will be difficult to implement correctly on many
32-bit architectures, including x86.
Comment 2 Dara Hazeghi 2003-05-11 20:04:19 UTC
From: Dara Hazeghi <dhazeghi@yahoo.com>
To: apbianco@gcc.gnu.org, gcc-gnats@gcc.gnu.org, jeff.sturm@appnet.com
Cc:  
Subject: Re: java/1305: GCJ ignores volatile modifier
Date: Sun, 11 May 2003 20:04:19 -0700

 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit- 
 trail&database=gcc&pr=1305
 
 Hello,
 
 this problem was reported against gcc cvs (20000730). Would it be  
 possible to determine if it is still present in current 3.3 branch or  
 mainline, and update this report accordingly? Thanks,
 
 Dara
 

Comment 3 Dara Hazeghi 2003-05-12 11:02:16 UTC
From: Dara Hazeghi <dhazeghi@yahoo.com>
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: Re: java/1305: GCJ ignores volatile modifier
Date: Mon, 12 May 2003 11:02:16 -0700

 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit- 
 trail&database=gcc&pr=1305
 
 Hans Boehm says:
 
 "I think 1305 still needs to remain open.  It's not clear that this can
 be fixed completely until JSR133 finishes its job, and it becomes clear
 what the Java memory model really is.  (I'm one of the participants,
 and we have been trying.  It's not easy.)"
 
 So this PR should stay open.
 
 Dara
Comment 4 Andrew Pinski 2003-11-16 10:10:54 UTC
Suspending as there is an open "DR" (JSR) about this one bug.
Comment 5 Andrew Pinski 2005-04-25 20:28:12 UTC
http://gee.cs.oswego.edu/dl/jmm/cookbook.html
Changing to New as JSR133 was voted on and approved in September.
Comment 6 Casey Marshall 2006-06-07 02:52:18 UTC
*** Bug 27908 has been marked as a duplicate of this bug. ***
Comment 7 Andrew Haley 2006-06-13 12:44:06 UTC
Subject: Bug 1305

Author: aph
Date: Tue Jun 13 12:43:56 2006
New Revision: 114609

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114609
Log:
2006-06-09  Andrew Haley  <aph@redhat.com>

        PR java/1305
        PR java/27908
        * builtins.c (initialize_builtins): Add __sync_synchronize().
        * class.c (add_field): Mark volatile fields.
        * java-gimplify.c (java_gimplify_expr): Call new functions to
        handle self-modifying exprs and COMPONENT_REFs.
        (java_gimplify_component_ref): New.
        (java_gimplify_modify_expr): Add handling for volatiles.


Modified:
    trunk/gcc/java/ChangeLog
    trunk/gcc/java/builtins.c
    trunk/gcc/java/class.c
    trunk/gcc/java/java-gimplify.c

Comment 8 Andrew Haley 2006-06-13 12:52:25 UTC
Note that this patch has some problems.  In particular, it doesn't work with BC-compiled code.  Also, on x86 it doesn't insert memory barrier instructions, but this is arguably a bug in __sync_synchronize() rather than a problem with this patch.
Comment 9 Andrew Haley 2006-06-19 17:38:19 UTC
Subject: Bug 1305

Author: aph
Date: Mon Jun 19 17:38:08 2006
New Revision: 114778

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114778
Log:
2006-06-19  Andrew Haley  <aph@redhat.com>

        PR java/1305
        PR java/27908
        * expr.c (java_modify_addr_for_volatile): New function.
        (expand_java_field_op): Handle volatile fields.
        * java-gimplify.c (java_gimplify_component_ref): Call
        java_modify_addr_for_volatile to give the field_ref the correct
        volatile type.
        (java_gimplify_modify_expr): Likewise.
        * java-tree.h (java_modify_addr_for_volatile): New decl.


Modified:
    trunk/gcc/java/ChangeLog
    trunk/gcc/java/expr.c
    trunk/gcc/java/java-gimplify.c
    trunk/gcc/java/java-tree.h