Just An Application

May 28, 2012

Adventures In Distributed Garbage Collection: Part Fifteen – Post Unbind System State

Filed under: Android, Android Internals, Java, Mobile Java, Services — Tags: , , , , — Simon Lewis @ 8:41 am

1.0 Object State

Once the client has unbound from the Fastnet Service then on the basis of the source code and given that it was the only client and that it specified the BIND_AUTO_CREATE flag when binding to the Fastnet Service, we would expect that

  • the ActivityManagerService would no longer hold a reference to the ServiceRecord representing the Fastnet Service via the mServices instance variable,

  • the ProcessRecord representing the Service process would no longer hold a reference to the ServiceRecord representing the Fastnet Service via
    services instance variable,

  • the ProcessRecord representing the Service client process would no longer hold a reference to the ConnectionRecord representing the connection to the Fastnet Service via the connections instance variable,

  • the ActivityRecord representing the Service client Activity would no longer hold a reference to the ConnectionRecord representing the connection to the Fastnet Service via the connections instance variable

  • the ServiceRecord object representing the Fastnet Service would no longer be present in the Java heap, nor would the associated IntentBindRecord and AppBindRecord objects

  • the ConnectionRecord object represnting the binding to the Fastnet Service from the Service client process would no longer be present in the Java heap.

2.0 dumpsys Output

Below are excerpts from the output of the dumpsys command run immediately after the client has unbound from the Fastnet Service.
In some cases the output has been slightly re-formatted for clarity.

2.1 ProcessRecords

2.1.1 Service Client ProcessRecord

    ...

    *APP* UID 10054 ProcessRecord{4067a100 293:xper.service.fastnet.client/10054}
      dir=/data/app/xper.service.fastnet.client-2.apk \
	  publicDir=/data/app/xper.service.fastnet.client-2.apk \
          data=/data/data/xper.service.fastnet.client
      packageList=[xper.service.fastnet.client]
      thread=android.app.ApplicationThreadProxy@406c1890 curReceiver=null
      pid=293 starting=false lastPss=0
      lastActivityTime=-6m18s641ms lruWeight=253489 keeping=true hidden=false empty=false
      oom: max=15 hidden=7 curRaw=0 setRaw=0 cur=0 set=0
      curSchedGroup=0 setSchedGroup=0
      setIsForeground=false foregroundServices=false forcingToForeground=null
      persistent=false removed=false
      adjSeq=248 lruSeq=57
      lastRequestedGc=-6m18s642ms lastLowMemory=-6m18s642ms reportLowMemory=false
      activities=[HistoryRecord{407ad2d8 xper.service.fastnet.client/.FastnetClientActivity}]
      conProviders={ContentProviderRecord{4051bc78 com.android.providers.settings.SettingsProvider}=1}
	
    ...

As expected the ProcessRecord [0x4067a100] representing the Service client process has no associated connections.

2.1.2 Service ProcessRecord

    ...

    *APP* UID 10053 ProcessRecord{4076e000 301:xper.service.fastnet/10053}
      dir=/data/app/xper.service.fastnet-2.apk \
	      publicDir=/data/app/xper.service.fastnet-2.apk data=/data/data/xper.service.fastnet
      packageList=[xper.service.fastnet]
      thread=android.app.ApplicationThreadProxy@4077e2a0 curReceiver=null
      pid=301 starting=false lastPss=0
      lastActivityTime=-6m11s99ms lruWeight=141059 keeping=false hidden=true empty=true
      oom: max=15 hidden=7 curRaw=7 setRaw=7 cur=7 set=7
      curSchedGroup=1 setSchedGroup=1
      setIsForeground=false foregroundServices=false forcingToForeground=null
      persistent=false removed=false
      adjSeq=248 lruSeq=60
      lastWakeTime=0 time used=0
      lastCpuTime=0 time used=0
      lastRequestedGc=-29s98ms lastLowMemory=-6m11s10ms reportLowMemory=false
	  
    ...

As expected the ProcessRecord [0x4076e000] representing the Service process has no associated services.

2.2 ActivityRecord

    Activities in Current Activity Manager State:
      * TaskRecord{4070aa90 #3 A xper.service.fastnet.client}
        clearOnBackground=false numActivities=1 rootWasReset=true
        affinity=xper.service.fastnet.client
        intent={act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] \
            flg=0x10200000 cmp=xper.service.fastnet.client/.FastnetClientActivity bnds=[83,316][157,395]}
        realActivity=xper.service.fastnet.client/.FastnetClientActivity
        lastActiveTime=253499 (inactive for 378s)
        * Hist #1: HistoryRecord{407ad2d8 xper.service.fastnet.client/.FastnetClientActivity}
            packageName=xper.service.fastnet.client processName=xper.service.fastnet.client
            launchedFromUid=10001 app=ProcessRecord{4067a100 293:xper.service.fastnet.client/10054}
            Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 \
			    cmp=xper.service.fastnet.client/.FastnetClientActivity bnds=[83,316][157,395] }
            frontOfTask=true task=TaskRecord{4070aa90 #3 A xper.service.fastnet.client}
            taskAffinity=xper.service.fastnet.client
            realActivity=xper.service.fastnet.client/.FastnetClientActivity
            base=/data/app/xper.service.fastnet.client-2.apk/data/app/xper.service.fastnet.client-2.apk \
            data=/data/data/xper.service.fastnet.client
            labelRes=0x7f040001 icon=0x7f020000 theme=0x0
            stateNotNeeded=false componentSpecified=true isHomeActivity=false
                configuration={ scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=1 \
                layout=18 uiMode=17 seq=4}
            launchFailed=false haveState=false icicle=null
            state=RESUMED stopped=false delayedResume=false finishing=false
            keysPaused=false inHistory=true launchMode=0
            fullscreen=true visible=true frozenBeforeDestroy=false thumbnailNeeded=false idle=true
            waitingVisible=false nowVisible=true
            connections=[]
       ...

As expected the ActivityRecord [0x4070aa90] representing the Activity running in the Service client process has no associated connections.

3.0 Java Heap State

As before we already have the dumpsys output, but again we can use the the state of the Java heap of the System process to double-check our understanding of the source code.

This graph was generated from a Java heap dump of the System process taken after the Service client has unbound from the Fastnet Service .

Like its counterpart here it was generated using the ServiceRecord object [0x406f89b8] representing the Fastnet Service as the root. As before greyed out nodes have been filtered, that is, one or more instance variables have been omitted for clarity.

This is another problematic graph. If the ServiceRecord object [0x406f89b8] is no longer in the Java heap it should not be possible to generate a graph with it as the root.

Evidently the graph exists therefore the assumption is wrong. So what is referencing it ? According to MAT there is a single GC Root of type Native Stack.

This is an identical situation to the previous one and whilest it is possible that on one occasion there was a transient reference from native code at exactly the point the Java heap dump was taken, two occasions in two separate processes is beginning to look like carelessness on somebody’s part !


Copyright (c) 2012 By Simon Lewis. All Rights Reserved.

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: