bazookier
unread,Nov 5, 2009, 7:47:12 AM11/5/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to android-porting
It's about a story of porting dalvik on icu4.2.
The simplest program is as following:
public class Main {
static public void main(String[] args) throws Exception {
System.out.print("A");
}
}
Even this simplest program has already done some stuff about icu.
getBytes方法:(java.lang.String)
|---defaultCharset()方法:(java.lang.String)
| |---doPrivileged(PrivilegedAction<T>,AccessControlContext)
(java.security.AccessController)
| | |---doPrivilegedImpl(PrivilegedAction<T>,AccessControlContext)
(java.security.AccessController)
| | |---currentThread()(java.lang.Thread)
| | | |---currentThread()(java.lang.VMThread)本地方法:
Dalvik_java_lang_VMThread_currentThread(InternalNative.c)
| | |---run()(org.apache.harmony.luni.util.PriviAction)
| | |---getProperty(String,String)(java.lang.System)
| | |---getSecurityManager()(java.lang.System)
| | |---checkPropertyAccess()(java.lang.SecurityManager)
| | | |---checkPermission()(java.lang.SecurityManager)
| | | |---checkPermission(java.security.AccessController)
| | | |---getContext()(java.security.AccessController)
| | | | |---getStackDomains()
(java.security.AccessController)本地方法:
Dalvik_java_security_AccessController_getStackDomains
(InternalNative.c)
| | | | |---AccessControlContext(ProtectionDomain[])
| | | | | |---用到了ArrayList的基本方法。所有关于ArrayList的本地方法都应该实
现。
| | | | |---getContext(Thread)
(org.apache.harmony.security.fortress.SecurityUtils)
| | | | | |---用到了WeakHashMap的基本方法。所有关于WeakHashMap的本地方法都
应该实现。
| | | | |---arraycopy()(java.lang.System)本地方法:
Dalvik_java_lang_System_arraycopy(InternalNative.c)
| | | | |---用到了DomainCombiner的基本方法。实现这个接口的类用到的本地方法都要实现。
| | | | |---
javax.security.auth.SubjectDomainCombiner用到了之前提到的一些类,不需要实现新的本地方法。其它实现它的
两个类都是测试类。
| | | |---implies(java.security.ProtectionDomain)
| | | |---getAccessiblePolicy()(java.security.Policy)
| | | | |---getDefaultProvider()(java.security.Policy)
| | | | |---doPrivileged(PrivilegedAction<T>)
(java.security.AccessController)
| | | | |---doPrivilegedImpl
(PrivilegedAction<T>,AccessControlContext)
(java.security.AccessController)
| | | | |---run()
(org.apache.harmony.security.fortress.PolicyUtils.SecurityPropertyAccessor)
| | | |---implies(java.util.PropertyPermission)
| | |---internalGetProperties(java.lang.System)
| | | |---SystemProperties()(java.lang.SystemProperties)
| | | |---preInit()(java.lang.SystemProperties)本地方法:
Dalvik_java_lang_SystemProperties_preInit(InternalNative.c)
| | | |---postInit()(java.lang.SystemProperties)本地方法:
Dalvik_java_lang_SystemProperties_postInit(InternalNative.c)
| | |---getProperty(java.util.Properties)用到了HashTable的基本方法。所有关于
HashTable的本地方法都应该实现。
| |---forName(String)(java.nio.charset.Charset)
| |---forNameInternal(String)(java.nio.charset.Charset)
| |---checkCharsetName(String)用到了String的基本方法。所有关于String的本地方法都应该实
现。
| |---getCachedCharset(String)用到了HashMap的基本方法。所有关于HashMap的本地方法都应该实
现。
| |---charsetForName(String)
(com.ibm.icu4jni.charset.CharsetProviderICU)
| | |---getICUCanonicalName(String)
(com.ibm.icu4jni.converters.NativeConverter)本地方法:getICUCanonicalName
(ConverterInterface.c)
| | |---openConverter(String)(com.ibm.icu4jni.converters)本地方法:
openConverter(ConverterInterface.c)
| | |---closeConverter(long)
(com.ibm.icu4jni.converters.NativeConverter)本地方法:closeConverter
(ConverterInterface.c)
| | |---getCharset(String)(com.ibm.icu4jni.charsetgetAliases)
| | |---getAliases(String)本地方法:getAliases
(ConverterInterface.c)
| | |---getJavaCanonicalName(String)本地方法:getJavaCanonicalName
(ConverterInterface.c)
| | |---CharsetICU(String,String,String[])
| | |---Charset(String,String[])用到了HashSet的基本方法。所有关于HashSet的本
地方法都应该实现。
| |---getContextClassLoader()用到了VMStack的基本方法。所有关于VMStack的本地方法都应该实
现。
|---wrap(CharSequence,int,int)(CharBuffer)
|---encode(CharBuffer)(Charset)
| |---getCachedCharsetEncoder(String)(Charset)
| |---encode(CharBuffer)(CharsetEncoder)
|---get()(java.nio.ByteBuffer) 是抽象方法,每个字符集有自己的实现。但是在Android里有几个java类是继承
这个类的。
|---java.nio.BaseByteBuffer抽象类
| |---java.nio.DirectByteBuffer最终是调用
getByte(int)本地方法:harmony_nio_getByteImpl
(org_apache_harmony_luni_platform_OSMemory.cpp)
| |---java.nio.HeapByteBuffer
|---java.nio.MappedByteBuffer抽象类
|---
java.nio.MappedByteBufferAdapter
Please ignore those Chinese characters.
We can see that
getCachedCharset(String) method(especially called in the encode method
in CharBuffer) created static members of HashMap to store built in
Charset, CharsetEncoder and CharsetDecoder.
The program runs to detect some memory leaks.
Because in those native functions it called openConverter but never
called closeConverter.
So it never released the memory when finished.
Even I modified the Charset class add such method into Charset class
private static void freeCachedTable()
{
cachedCharsetTable.clear();
cachedCharsetTable=null;
cachedCharsetDecoderTable.clear();
cachedCharsetDecoderTable=null;
cachedCharsetEncoderTable.clear();
cachedCharsetEncoderTable=null;
if (_builtInCharsets!=null)
_builtInCharsets.clear();
_builtInCharsets=null;
System.gc();
}
and called this method just before shutting down the vm or even add
dvmCollectGarbage(1);
to the vm C code to finish the vm.
Still find the memory leaks cause by openConverter without
closeConverter.
Is there a way to resolve this problem? Can anyone tell me?