swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: MessageProbe interferes with Java garbage collection in prete st 6?


From: Marshall, James A R
Subject: RE: MessageProbe interferes with Java garbage collection in prete st 6?
Date: Wed, 18 Sep 2002 14:45:55 +0100

Hello again,
  I tried upgrading to JDK 1.4.1, and that did not fix the problem. I have
also looked at the Swarm source (swarm-2002-05-14 which I assume is the
version used to build pretest 6), and with the proviso that I've no
experience of JNI programming and I don't know my way around the Swarm
source, it seems to me like it should be OK.
  Initially I thought that the problem may be the creation of a global
reference in the JNI without it's subsequent deletion, i.e. a call to
NewGlobalRef without a corresponding call to DeleteGlobalRef. However
looking at the source for MessageProbe, a call to longDynamicCallOn results
in a call to dynamicCallOn, which in turn
creates a new instance of FCall for that MessageProbe, or if one exists
already, calls updateTarget on it. It is in updateJavaTarget called from
updateTarget that the DeleteGlobalRef for the current target of that FCall
instance is found:

void
updateJavaTarget (FCall_c *self, JOBJECT target)
{
  if (self->fobjectPendingGlobalRefFlag)
    {
>      (*jniEnv)->DeleteGlobalRef (jniEnv, (jobject) self->gc_fobject);
      self->fobjectPendingGlobalRefFlag = NO;
    }
  self->gc_fobject = target;
  add_ffi_types (self);
}

where the NewGlobalRef for that object occured in setJavaMethodFromName
which is in turn called by all the setMethodFromName and
setMethodFromSelector methods, which are in turn invoked by the create
methods of FCall.
  This analysis is based on the assumption that these files have been built
with HAVE_JDK defined, however I can't find this definition in the sources I
have. Another thing that puzzles me is that while updateJavaTarget deletes
the old global reference it doesn't create a new one for the new target.
  I'm not sure how to proceed with this short of playing with GDB and
possibly recompiling the Swarm sources, which I'm reluctant to do judging by
the number of problems people have doing it. If anyone else familiar with
the JNI and/or these parts of the Swarm source could take a look that would
be helpful,
  Thanks,
        James

---
Dr James A R Marshall
Container World Project - http://www.ese.ic.ac.uk/research/containerworld/
Department of Earth Sciences and Engineering, Imperial College, London
Tel: +44 (0)20 7594 7493
Fax: +44 (0)20 7594 7444

>  -----Original Message-----
> From:         Marshall, James A R  
> Sent: 17 September 2002 11:39
> To:   'address@hidden'
> Subject:      MessageProbe interferes with Java garbage collection in
> pretest 6?
> 
> Hi,
>   just to let you all know that I've encountered a problem while using
> MessageProbes under Java in Swarm 2.2 pretest 6 (Windows 2000, JDK
> 1.3.1_02).
>   The problem is that using a MessageProbe to call a method on an instance
> of a class appears to leave Java's garbage collector unable to recycle
> that instance even when all references to the instance have apparently
> been lost. The problem is illustrated by the code below (it's short so I
> attached it). If you compile and run the code as is you should find that
> the finalize method of the class Test is called several times, as should
> be. However if you remove the comment before the call to the MessageProbe
> function doubleDynamicCallOn(...) the finalize method will never be
> called, implying the garbage collector could not recycle the objects
> created.
>   I'll investigate further by upgrading to a newer JDK, and looking at the
> Swarm source if necessary, and report back. This does seem to be an
> effective way to introduce a memory leak into your Java Swarm model
> though.
>       James
> 
> class ITM
> {
>       public static void main(String args[])
>       {
>               class Test
>               {
>                       int mValue;
> 
>                       public int getValue()
>                       {
>                               return mValue;
>                       }
> 
>                       public Test(int value)
>                       {
>                               mValue = value;
>                       }
> 
>                       public void finalize()
>                       {
>                               System.out.println("finalised");
>                       }
>               }
>               LinkedList list;
>               Test test = null;
>               MessageProbe probe = null;
>               ProbeMap probeMap = null;
>               int l1, l2, value;
> 
>               Globals.env.initSwarm("test", "0.0",
> "address@hidden", args);
>               list = new LinkedList();
>               for (l1 = 0; l1 < 10; l1++)
>               {
>                       for (l2 = 0; l2 < 100; l2++)
>                       {
>                               test = new Test(1);
>                               if (probeMap == null)
>                               {
>                                       probeMap =
> Globals.env.probeLibrary.getCompleteProbeMapForObject(test);
>                                       probe =
> probeMap.getProbeForMessage("getValue");
>                               }
> //                            value = probe.longDynamicCallOn(test);
>                               value = test.getValue();
>                               list.addFirst(test);
>                       }
>                       list.clear();
>                       Runtime.getRuntime().gc();
>               }
>       }
> }
> 
> ---
> Dr James A R Marshall
> Container World Project - http://www.ese.ic.ac.uk/research/containerworld/
> Department of Earth Sciences and Engineering, Imperial College, London
> Tel: +44 (0)20 7594 7493
> Fax: +44 (0)20 7594 7444
> 

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]