2007 2013 Kandroid
www.kandroid.org »
kandroid s/w fundamentals 교육 »
안드로이드 Library 
with Android and Dalvik at Google I/O
작성자 들풀
작성일 2008-06-02 (월) 22:05
ㆍ추천: 0  ㆍ조회: 2643      
IP: 221.xxx.120
출처 : http://blogs.sun.com/jrose/entry/with_android_and_dalvik_at 
 

with Android and Dalvik at Google I/O


Invited by some friends at Google, I went to Google I/O this week to find out about Android, and
specifically their Java story. I went to a few talks and had some excellent chats with various colleagues.

The top ten things I learned about Android and the Dalvik VM

  1. Android is a slimmed down Linux/JVM stack. They rewrote libc to be 200Kb, redoing
    speed-vs.-space optimizations, and throwing out C++ exceptions and C-level wide char support.
    (As far as the JVM is concerned, this reminds me of recent work we have done to “kernelize”
    HotSpot on Windows.)

  2. A special strength of the platform is their attention to detail about reducing the cost of private pages.
    Many pages are read-only mapped from files, which means they can be dropped from RAM
    at a moment’s notice. Many other pages are shared with only rare use of copy-on-write
    (e.g., between JVMs). (This is similar to the work we have done on HotSpot with class data sharing.)

  3. The first and main reason they give for using Harmony instead of OpenJDK is the GNU license (GPL).
    Cell phone makers want to link proprietary value-add code directly into the system (into JVM-based
    apps. and/or service processes), and they do not want to worry about copyleft. Perhaps there is some
    education needed here about the class path exception. (I know I don’t understand it; maybe they
    don’t either. And, their license wonks appear to have a well-considered preference for Apache 2
    over GPL+CPE.)

  4. The VM they have for Android 1.0 is very basic: A “malloc-like” heap, interpreter only. This means they
    still have many build-vs-buy decisions to make. I told them they should adopt Hotspot’s first-level JIT
    (C1), that we should work together on kernelization, and that it is time for a classfile format update
    anyway.

  5. Key reasons against using JVM bytecodes are interpreter complexity and dirty page footprint.
    The Dalvik bytecode design executes Java code in less power (fewer CPU and memory cycles) and
    with more compact linkage data structures (their constant pool replacement looks like that of Pack200,
    and reminds me of some recent experiments with adapting the JVM to load Pack archives directly).

  6. The VM uses “dex” files like Java cards use their own internal instruction sets. The tool chain does
    use class files, but there is a sizeable (100K 70K LOC) tool called “dx” that cooks JARs into DEX
    assemblies. The dex format is loaded into the phone, which then verifies and quickens the bytecodes
    and performs additional local optimizations.

  7. Something like the dx tool can be forced into the phone, so that Java code could in principle continue
    to generate bytecodes, yet have them be translated into a VM-runnable form. But, at present, Java code
    cannot be generated on the fly. This means Dalvik cannot run dynamic languages (JRuby, Jython,
    Groovy). Yet. (Perhaps the dex format needs a detuned variant which can be easily generated from
    bytecodes.)

  8. The “dx” tool turns classfiles into SSA and then (after reorganization) to dex files. However, optimizations
    are missing. Loop invariants must still be pulled up manually by programmers. The dex format is not
    known to be easily JIT-able, however the designers have given some thought to make it so. (Probably
    the dex format needs some work in this direction. Let’s do that, and standardize on it!)

  9. The dex format has the usual merged, typed constant pool with 32-bit clean indexes. (Cf. Pack200.)
    This work is likely to stimulate the Java world to update the classfile format standard in that direction.
    Hopefully we can do this in a way that benefits much of the ecosystem.

  10. People are thankful to Sun for past stewardship of Java, but are not seeing much guidance from Sun
    toward the future. At least, that is the story I heard. Whether that story is mere perception or an actual
    leadership vacuum, our actions with OpenJDK need to reverse it.

Bonus: The view from Yahoo

I also met Sam Pullara, and had a good long chat with him about (among other things) what Yahoo would like
to see JVMs do better. Here are my notes:

about NIO

  • Customers want simplified non-stateful buffers; buffer.flip is inscrutable.
  • Customers want poll not select. That is, when the data is ready, give it to the listener without an
    additional fetch, or else when the listener wakes up the data is likely to be gone again (swapped out).

about runaway JVMs

  • Need a way to watch for runaway memory and/or CPU usage
  • Customers want to kill a whole VM that goes off the rails. (Perhaps applets also.)
  • I noted that TLAB fill events are the right place to cut in a per-thread allocation monitor.
  • JMX is really helpful here. It can report memory threshold events.
  • So let’s add thread-specific ones, and CPU threshold events.

JVMs as sandboxes for bad old code

Customers are eager to use Java VMs as containers for sandboxing old C libraries. These libraries are often
non-reentrant and may age badly (crash, run out of memory) after heavy use. But server systems need to run
multiple instances of them, in order to scale across HW resources. It it not enough just to load one into your
JVM and wrap a thread around it.

Customers are sometimes desperate enough to use the “nested VM” hack (JVM interprets MIPS code generated
by gcc). Surely there is an opportunity here!
So why (I am asked) is there no action on isolates? They look to the customer like a no-brainer (like Android’s
zygote). In any case, it is clear to me we need better plumbing and monitoring for isolating such old code.
A better story could look like:
  • Keep pre-warmed JVM ready to form new isolates.
  • When we want to start up another instance of a C library, we fork a new isolate.
  • On the client VM side, we have some nice light RPC binding.
  • On the service VM side, we have swig-generated tight (unsafe) binding to the C library.
  • The service instance is monitored and can die or be killed if it misbehaves.

Crunchy search goodness

Sam showed me a cool Yahoo search plugin for sifting between versions of Java APIs. Here is an example query
for hashmap
, which probably does not work on your browser until the plugin is installed.


(Thanks, Sam and Dan, for sending some corrections. Any remaining errors are still my fault.)
이름아이콘 invain
2008-06-02 22:54

최근 M$ , Sun을 보면  외부에 공개할수 있는 블로그 홈페이지사이트들이 속속보이네요... 영업비밀(?)을 중요시하고 있는 우리나라의 벤더들과는 상당히 대조적인 모습들을 보고 어떻게 해석을 해야할지 본인스스로가 어지럽습니다.

jrose가 칼럼리스터 ...?? 에궁.. 모르는 키워드가 여기저기 있네요..
예) CPE , SSA , NIO

내용중에 기존 지식에서 약간 인상적이었던 것은 아래 내용입니다. 첫 구글폰이 시장에 나올때 모두 오픈소스화 되면 얼른 BSD's libc를 파악해 보아야겠습니다.
They rewrote libc to be 200Kb, redoing speed-vs.-space optimizations, and throwing out C++ exceptions and C-level wide char support.


JSR(Java Specification Requests ) 관련하여 Dalvik VM의 구현에 JSR 184/239 스펙에 대해서 완전 준수하는지 알았는데, 설마 JSR 296(Swing Application Framework prototype )스펙도 이미  완전히 준수되어 있는 걸까요?
예) https://appframework.dev.java.net/downloads/AppFramework-1.03-src.zip
   
이름아이콘 들풀
2008-06-02 23:20
ㅎㅎㅎ..역시 인베인님 최고입니다..
CPE, SSA, NIO 에 대해서도 빨리 덧글 달아주시리라 믿습니다..
   
 
덧글 쓰기 0
3500
※ 회원등급 레벨 0 이상 읽기가 가능한 게시판입니다.
    N     분류     제목    글쓴이 작성일 조회
안드로이드 Native Library 개요 [4] 들풀 2008-03-03 12303
48 GPL Source와 libc Library 를 통한 빌드 하늘끝사과 2012-12-12 641
47 네이티브 크로스 플랫폼인 citirne으로 개발한 쇼핑몰 app 소.. 씨트린매니저 2012-07-25 656
46 OpenCV Lib 활용 영상 인식 로봇 소스 공개 [2]+2 다이나믹링크 2012-04-15 2004
45 static - Dynamic library 참조 관련 [4] 반야심경 2012-02-06 1843
44 Android NDK OPENSLES 질문 공자 2012-02-06 1341
43 안드로이드 ALSA 리용 질문 마*스*터 2011-11-26 1448
42 네이버 지도 래핑 클래스 및 자바스크립트 인터페이스 클래스 .. minyk 2011-04-25 2290
41 [WorldRanking] 여러분의 게임에 랭킹 서비스를 추가하세요!.. [3] 도노치 2011-03-24 2191
40 안드로이드용 게시판 라이브러리 'App board' [6] 박현천 2010-08-15 5192
39 OpenCORE 2.07 릴리즈 [1]+2 인베인 2009-12-11 6379
38 Android Opencore [4]+1 GHOST 2009-01-12 9001
37 Flite( a small, fast run time synthesis engine) [1] 인베인 2008-12-13 2154
36 안드로이드 HAL - RIL(Radio Interface Layer) [13]+1 들풀 2008-12-04 17062
35 telephony.db쿼리로 안드로이드폰 준비업체 엿보기.. invain 2008-07-18 5056
34 Webkit Introduces New Javascript Interpreter(SquirrelFish) [4] invain 2008-06-04 9990
1234