This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: valgrind and CNI


David Blasby writes:
 > Thanks for the quick reply.
 > 
 > I'm using:
 > valgrind-2.2.0
 > gcj (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)
 > 
 > I was originally using valgrind to make sure that GCJ wasnt garbage
 > collecting my Java objects when I passed them from C++ to C.  For
 > example, I use Geometry.h (created using gcjh) in the C++ library, but
 > a "typedef struct Geometry Geometry;" in the "C" program.
 > 
 > Java creates an Object, hands it off to the C++ library as a Geometry*
 > class, then gets passed as a pointer to the "C" program.  I thought
 > the garbage collector might collect the java object between the time
 > it leaves the C++ library and arrives at the "C" program.

It might.  gcj allocates its own objects, and only scans items
reachable from its roots.  In addition, it conservatively scans the
stack.  If you want to ensure that a gcj object is not reclaimed, you
should make very sure that it is reachable from a Java object
somewhere: this is as easy as declaring a static reference in some
Java class and pointing it at the object you want not to be reclaimed.

Andrew.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]