You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "Sylvain MARIE (JIRA)" <ji...@apache.org> on 2008/10/13 11:14:46 UTC

[jira] Commented: (FELIX-733) Exception when uninstalling a bundle that contains a native library (and loaded it at bundle startup).

    [ https://issues.apache.org/jira/browse/FELIX-733?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12638985#action_12638985 ] 

Sylvain MARIE commented on FELIX-733:
-------------------------------------

Thank you Karl. I tried your patch ; unfortunately it doesn't work: the content class loader is not garbaged out when the gc() are called.
The FIX below makes your patch work but maybe one should check why the ContentLoaderImpl is itself no garbaged out...

Second thing: you pached the BundleArchive.dispose() method but I saw that other methods
also call deleteDirectoryTree(). Maybe we should patch deleteDirectoryTree directly ?

If you need it I can send you my test bundle in order for you to test your patches.

Cheers

Sylvain

------------------FIX------------

class ContentLoaderImpl.java :

public synchronized void close()
    {
        m_content.close();
        for (int i = 0; (m_contentPath != null) && (i < m_contentPath.length); i++)
        {
            m_contentPath[i].close();
        }
        for (int i = 0; (m_fragmentContents != null) && (i < m_fragmentContents.length); i++)
        {
            m_fragmentContents[i].close();
        }
        // FIX SMA release content class loader
        m_classLoader = null;
        // END FIX sma
    }

> Exception when uninstalling a bundle that contains a native library (and loaded it at bundle startup).
> ------------------------------------------------------------------------------------------------------
>
>                 Key: FELIX-733
>                 URL: https://issues.apache.org/jira/browse/FELIX-733
>             Project: Felix
>          Issue Type: Improvement
>          Components: Framework
>         Environment: WinXP, eclipse, sun jdk 1.5 or 1.6
>            Reporter: Sylvain MARIE
>            Assignee: Karl Pauls
>            Priority: Minor
>         Attachments: native.patch
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Here is a short description of the problem and how I managed to fix it. Don't hesitate to contact me for details
> or to tell me if something here is wrong ! Cheers. Sylvain.
> 1- bundle "foo" embeds a native library "lib.dll" and declares it in its manifest, with appropriate platform declaration (os, version, processor).
> 2- foo's activator loads that library in the start(bc) method - with System.loadLibrary(...).
> 3- the library loads succesfully (this can be checked with e.g. processExplorer or pmap)
> 4- the bundle is stopped.
> 5- the bundle is uninstalled. 
> > ERROR: org.apache.felix.framework.cache.BundleArchive: Unable to delete archive directory
> Why does this happen :
> - step 4: the library is not unloaded because foo's contentclassloader is still alive. This is normal.
> - step 5: automatic package refresh : all bundles from uninstalled list are garbaged. Method 
> Felix.garbageCollectBundle attemps to remove the bundle archive from the cache, but
> the dll file is still in use => ERROR. The dll is still in use because foo's contentclassloader has not yet
> been garbaged out.
> How to fix this:  
> --------------------
> We need the ContentClassLoader to be garbaged out. So first release all
> references to foo's activator, then release all references to the ContentClassLoader itself,
> and finally do a System.gc() before attempting to remove the bundle from the cache.
> Two methods are impacted: ContentLoaderImpl.close() and Felix.garbageCollectBundle(...)
> ContentLoaderImpl.java
> -----------------------------------
> public synchronized void close()
>     {
>         ...
>         ...
>         
>         // FIX SMA : release content class loader
>         m_classLoader = null;
>     }
> Felix.java
> -------------
> private void garbageCollectBundle(FelixBundle bundle) throws Exception
>     {
>     	
>         ....
>         
>         // FIX SMA : release reference to the activator
>         bundle.getInfo().setActivator(null);
>         
>         // Do the garbage collection either systematically, or only if native libraries were loaded, or ... 
>         System.gc(); // this destroys the activator, the contentclassloader, and unloads the dll.
>         // end FIX SMA
>         
>         // Remove the bundle from the cache.
>         m_cache.remove(m_cache.getArchive(bundle.getBundleId()));
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.