public inbox for java-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug libgcj/23353] New: clone() copies internal lock data with hash synchronization off
@ 2005-08-12 12:14 mdeters at morgandeters dot com
2005-08-12 16:40 ` [Bug libgcj/23353] " cvs-commit at gcc dot gnu dot org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: mdeters at morgandeters dot com @ 2005-08-12 12:14 UTC (permalink / raw)
To: java-prs
The memcpy() call in the clone() method in libjava/java/lang/natObject.cc
copies the sync_info member (when hash synchronization is off). When the lock
has been held at least once, sync_info is non-NULL and therefore the original
and cloned objects are associated to the same lock. The locks should be
distinct (as they are with hash synchronization on).
I've confirmed this bug in 3.3.3 and 4.0.1 and it looks like it's in HEAD too.
I used only configure options --enable-languages=c,c++,java
--disable-hash-synchronization --prefix=...
The test below starts two threads that acquire locks on two *different* objects
(one the clone of the other). There is lock contention with gcj <= 4.0.1 when
hash synch is disabled; however, both locks should be able to be held
simultaneously. A (minimally-tested) patch to 4.0.1 follows the test class;
this patch just sets sync_info to an uninitialized state in all objects that
are the result of a clone().
class SynchTest {
public static void main(String[] args) throws CloneNotSupportedException {
// same behavior occurs with non-array objects; we use arrays because
// they're easy & cloneable
final Object[] o1 = new Object[0];
synchronized(o1) {
System.out.println("acquired (and now releasing) o1 lock");
}
final Object[] o2 = (Object[]) o1.clone();
System.out.println("cloned o1 -> o2");
System.out.println("o1 == " + o1);
System.out.println("o2 == " + o2);
System.out.println();
System.out.println("performing sync test...");
System.out.println("expect both locks to be held simultaneously");
new Thread() {
public void run() {
System.out.println("t2 entering o2 lock");
synchronized(o2) {
System.out.println(" t2 entered o2 lock");
try {
Thread.sleep(2000);
} catch(InterruptedException ie) {
ie.printStackTrace();
}
System.out.println(" t2 exiting o2 lock");
}
System.out.println("t2 exited o2 lock");
}
}.start();
System.out.println("t1 entering o1 lock");
synchronized(o1) {
System.out.println(" t1 entered o1 lock");
try {
Thread.sleep(2000);
} catch(InterruptedException ie) {
ie.printStackTrace();
}
System.out.println(" t1 exiting o1 lock");
}
System.out.println("t1 exited o1 lock");
}
}
diff -Nurp gcc-4.0.1/libjava/java/lang/natObject.cc
gcc-4.0.1-fixed/libjava/java/lang/natObject.cc
--- gcc-4.0.1/libjava/java/lang/natObject.cc Fri May 13 19:43:09 2005
+++ gcc-4.0.1-fixed/libjava/java/lang/natObject.cc Fri Aug 12 05:52:54
2005
@@ -104,6 +104,10 @@ java::lang::Object::clone (void)
}
memcpy ((void *) r, (void *) this, size);
+#ifndef JV_HASH_SYNCHRONIZATION
+ // guarantee that the locks associated to the two objects are distinct
+ r->sync_info = 0;
+#endif
return r;
}
--
Summary: clone() copies internal lock data with hash
synchronization off
Product: gcc
Version: 4.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: libgcj
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mdeters at morgandeters dot com
CC: gcc-bugs at gcc dot gnu dot org,java-prs at gcc dot gnu
dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23353
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug libgcj/23353] clone() copies internal lock data with hash synchronization off
2005-08-12 12:14 [Bug libgcj/23353] New: clone() copies internal lock data with hash synchronization off mdeters at morgandeters dot com
@ 2005-08-12 16:40 ` cvs-commit at gcc dot gnu dot org
2005-08-12 16:41 ` tromey at gcc dot gnu dot org
2005-08-12 16:43 ` cvs-commit at gcc dot gnu dot org
2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-08-12 16:40 UTC (permalink / raw)
To: java-prs
------- Additional Comments From cvs-commit at gcc dot gnu dot org 2005-08-12 16:40 -------
Subject: Bug 23353
CVSROOT: /cvs/gcc
Module name: gcc
Changes by: tromey@gcc.gnu.org 2005-08-12 16:40:32
Modified files:
libjava : ChangeLog
libjava/java/lang: natObject.cc
Log message:
2005-08-12 Morgan Deters <mdeters@morgandeters.com>
PR libgcj/23353:
* java/lang/natObject.cc (clone): Clear sync_info.
Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/ChangeLog.diff?cvsroot=gcc&r1=1.3716&r2=1.3717
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/lang/natObject.cc.diff?cvsroot=gcc&r1=1.34&r2=1.35
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23353
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug libgcj/23353] clone() copies internal lock data with hash synchronization off
2005-08-12 12:14 [Bug libgcj/23353] New: clone() copies internal lock data with hash synchronization off mdeters at morgandeters dot com
2005-08-12 16:40 ` [Bug libgcj/23353] " cvs-commit at gcc dot gnu dot org
@ 2005-08-12 16:41 ` tromey at gcc dot gnu dot org
2005-08-12 16:43 ` cvs-commit at gcc dot gnu dot org
2 siblings, 0 replies; 4+ messages in thread
From: tromey at gcc dot gnu dot org @ 2005-08-12 16:41 UTC (permalink / raw)
To: java-prs
------- Additional Comments From tromey at gcc dot gnu dot org 2005-08-12 16:41 -------
I checked in the fix.
Thanks
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |FIXED
Target Milestone|--- |4.0.2
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23353
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug libgcj/23353] clone() copies internal lock data with hash synchronization off
2005-08-12 12:14 [Bug libgcj/23353] New: clone() copies internal lock data with hash synchronization off mdeters at morgandeters dot com
2005-08-12 16:40 ` [Bug libgcj/23353] " cvs-commit at gcc dot gnu dot org
2005-08-12 16:41 ` tromey at gcc dot gnu dot org
@ 2005-08-12 16:43 ` cvs-commit at gcc dot gnu dot org
2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-08-12 16:43 UTC (permalink / raw)
To: java-prs
------- Additional Comments From cvs-commit at gcc dot gnu dot org 2005-08-12 16:43 -------
Subject: Bug 23353
CVSROOT: /cvs/gcc
Module name: gcc
Branch: gcc-4_0-branch
Changes by: tromey@gcc.gnu.org 2005-08-12 16:43:09
Modified files:
libjava : ChangeLog
libjava/java/lang: natObject.cc
Log message:
2005-08-12 Morgan Deters <mdeters@morgandeters.com>
PR libgcj/23353:
* java/lang/natObject.cc (clone): Clear sync_info.
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.88&r2=1.3391.2.89
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/lang/natObject.cc.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.33.10.1&r2=1.33.10.2
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23353
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-08-12 16:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-12 12:14 [Bug libgcj/23353] New: clone() copies internal lock data with hash synchronization off mdeters at morgandeters dot com
2005-08-12 16:40 ` [Bug libgcj/23353] " cvs-commit at gcc dot gnu dot org
2005-08-12 16:41 ` tromey at gcc dot gnu dot org
2005-08-12 16:43 ` cvs-commit at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).