출처: Android Open Source code, dalvik/doc/dexopt.hml

Dalvik Optimization and Verification


Dalvik Optimization and Verification with dexopt


  • class 데이터(특히 bytecode), 는 시스템 메모리 사용을 최소화하기 위해 프로세스간 공유함
  • app을 띄울때 응답성을 높이기 위해 overhead를 줄임
  • class 데이터를 각 개개별의 파일에 저장할 경우 낭비가 심하여, 이를 방지함
  • class 데이터 파싱을 하면 class 로딩 시에 많은 overhead가 발생하므로, C 타입의 data value로 처리하는게 유리함
  • Bytecode verification은 필요하나 느리므로, app의 실행외에 verify 하는 방향으로 추진
  • Bytecode 최적화는 속도와 배터리 수명을 위해 매우 중요함
  • 보안을 위해 프로세스는 공유 코드를 못 고침

일반적인 VM implementation은 compressed archive 에서 (uncompressed) individual classes를 꺼내와 heap에 저장함.
이는 곧, 모든 프로세스마다 각 class들의 카피를 가지고 있고, app이 시작할때 코드의 압축을 풀어야 하기 때문에 느림.  반면에 로컬 heap에 bytecode를 가지고 있으면, rewrite 하기 쉽다는 장점이 있음
 

결론적으로 다음과 같은 결과물이 필요하다.


  • multiple class들은 하나의 "DEX" file로 통합됨
  • DEX 파일은 read-only로 맵핑되며 프로세스간에 공유됨
  • Byte ordering 과 word alignment는 local system에 맞게 변경가능함
  • Bytecode verification은 필요하나 "pre-verify"를 함
  • bytecode를 rewrite해야 하는 최적화는 반드시 선행되어야 함

VM Operation


어플리케이션 코드는 어플이름.jar 혹은 어플이름.apk 로 시스템이 전달되는데, 이는 단지 어플이름.zip 에 meta-data를 첨가한 것이다.  Dalvik DEX data 파일은 항상 clases.dex라고 표기된다.

bytecode는 zip 형태로 데이터가 압축되어 있고, 파일의 시작이 word-aligned가 아닐 수 있으므로, 메모리 맵핑되거나 zip 파일로부터 곧바로 실행이 불가능하다.  그러므로 classes.dex를 압축해제 하고 필요한 다른 액션(예를 들어 realignment, optimization, verification등)을 취해줘야 한다.  그럼 누가 이런 결과물을 만들어내고 저장해야 하는가??


Preparation


"preapred" DEX file을 생성하는데는 적어도 3가지의 방법이 있다.


  1. VM 이 'Just-In-Time'(보통 JIT)을 통해 dalvik-cache 디렉터리에 결과물을 저장. desktop이나 engineering-only 디바이스에 적합하다.(dalvik-cache의 퍼미션 문제로 양산품에는 적용불가함)
  2. dalvik-cache에 쓸 권한을 가진 시스템 인스톨러가 어플리케이션이 처음 추가되었을 때 한다. 
  3. classes.dex를 제외한 관련 jar나 apk파일들을 이용해  빌드시스템이 선행적으로 진행한다. optimized DEX 파일은 오리지널 zip 아카이브 옆에 놓이며, 시스템 이미지의 일부분이 된다.

dalvik-cache 디렉터리는 $ANDROID_DATA/data/dalvik-cache이다.  이 디렉터리 안의 파일 이름은 source DEX의 full path를 사용하며, 이 디렉터리는 system을 owner로 0771 권한을 가지고 있다.  안의 optimized DEX 파일들은 system이 owner이며 application 이 gropu으로, 0644 권한을 가지고 있다.




'안드로이드 > 프레임워크' 카테고리의 다른 글

Bionic libc (2)  (0) 2012.11.08
Bionic libc  (0) 2012.10.30
안드로이드 init.rc (oom_adj값)  (0) 2012.09.27
안드로이드 바인더 ipc  (0) 2011.10.23
안드로이드 프레임워크 *Java에서 전처리기 사용하기*  (0) 2011.06.06
Posted by code cat
프로그래밍/JAVA2012. 8. 6. 10:41

https://developers.google.com/java-dev-tools/download-wbpro 에서 알려준 링크


Eclipse 3.7 (Indigo)


http://dl.google.com/eclipse/inst/d2wbpro/latest/3.7


를 사용하면 다음과 같이 인스톨이 제대로 되지 않는다.  


Cannot complete the install because one or more required items could not be found.



이는 WindowBuilder Pro에서 필요한 컴포넌트들이 WindowBuilder Pro 사이트에 존재하지 않아서 이다.


대신, eclipse Indigo 사이트에서 다운을 받아보자.



indigo관련 릴리즈들이 많아서 처음에 오래 걸린다.


리스트가 뜨면, Filter에 WindowBuilder 와 SWT 와 Swing 등으로 필터를 걸고 찾아서 인스톨 하면 된다.



'프로그래밍 > JAVA' 카테고리의 다른 글

OTA Package Utility  (0) 2013.11.25
Swing desiginer LookAndFeel 종류  (0) 2013.11.19
Java Generics  (0) 2012.10.01
ant 빌드가 안될 때  (0) 2011.10.19
Posted by code cat

최근에 svn 버젼을 보니 폴더마다 .svn이 사라진 거 같다.  그러나 아직 예전 .svn 저장소를 쓰는 이들을 위해 다음과 같은 명령어가 유용하게 쓰일 수 있겠다. 


(실제로, 얼마전 svn 으로 관리되는 코드를 git으로 바꿀 때 써먹었다.)


하위 폴더까지 .svn 지우기

 

rm -rf `find . -type d -name .svn`


Posted by code cat

tar 압출 풀기

tar xfj arm-2012.03-57-arm-none-linux-gnueabi-i686-pc-linux-gnu

 

/opt/ 밑으로 옮기기

mv arm-2012.03 /opt/


환경설정

vi ~/.bashrc

export PATH=/opt/arm-2012.03/bin:$PATH
# source ~/.bashrc

 

arm-none 정도 쳐보고 tab쳐서 나오면 패스 설정은 제대로 됬음을 확인 할 수 있다.

Posted by code cat


ctrl + q를 눌러주면 된다.  자세한 내용은 아래를 참조하자.

Screen CTRL-S Bug

When switching between terminals and text editors the occasional ctrl-s gets accidentally typed into the terminal. For along time I thought that this was a bug in screen but it is a standard terminal feature. Ctrl-s calls the software flow control method XOFF which stops the character flow to the terminal, which when you did not realise what you pressed just seems to freeze the terminal.

ctrl-q calls XON and starts the terminal again.

For a more permanent fix you can add this to your .bashrc (not sure how other shells are effected).

stty ixany

Which allows any character to call XON, so the character press is sent and displayed and you will never be aware of the terminal freezing.

If this does not work for you, or you also don't seem to be able to send ctrl-s ctrl-q commands to terminal applications you can use
stty stop undef To unmap ctrl-s
stty start undef To unmap ctrl-q

Or to stop XOFF and XON being sent from the keyboard but still allowing other software to send the commands use
stty ixoff -ixon
NB: ctrl-q can now be used to shutdown rtorrent

'리눅스 > 스크립트/유틸' 카테고리의 다른 글

.svn 지우기  (0) 2012.08.05
Code Sourcery 설치하기  (0) 2012.07.31
vi 검색한 내용 copy, paste 하기  (0) 2012.07.02
samba 로그인 정보 지우기/보기  (0) 2012.06.23
SVN in conflict  (0) 2012.06.21
Posted by code cat
리눅스/커널2012. 7. 20. 21:25
cache allocator 의 핵심:
1) 메모리를 각각 다른 사이즈의 오브젝트 들끼리 모아놓은 pool 들로 나누는 것
2) 메모리 할당에 대한 request가 오면 1)에서 맞는 사이즈를 가진 pool을 리턴

이런 pool들을 cache하고 하며 kmem_cache_t 의 타입으로 선언되어 있다. kmem_cache_t에는 cache에 대한 여러가지 정보를 담을 수 있는 변수들이 준비되어 있다.
kmem_cache_create()를 통하여 cache를 생성할 수 있다.
kmem_cache_create()는 caller에서 넘겨중 사이즈만한 cache를 생성하며 cache_cache라는 생성된 cache들의 global list에 넣는다.

cache_cache는 static kmem_cache_t 타입이며 시스템 전반적으로 cache들을 가지고 있다. 따라서 pool이 속해있는 object들의 사이즈는 sizeof(kmem_cache_t) 이다. 시스템 전반에 걸친 cache들에 대한 정보는 /proc/slabinfo에서 볼 수 있다. cache_cache외에도 cache들의 array 형태로 되어있는 일반적인 cache들이 있다. array마다 2배수로 커지는 사이즈 형태이며 각 사이즈별로 2개의 cache(일반 cache, DMA용 cache)가 있다. kmalloc()은 이 일반적인 cache들에서 맞는 사이즈의 cache를 찾고 __kmem_cache_alloc()으로 cache 오브젝트을 caller에게 넘겨주는 일을 한다.
유사하게 kfree() 은 __kmem_cache_free()으로 오브젝트를 cache에 돌려준다.

iPhone 에서 작성된 글입니다.

'리눅스 > 커널' 카테고리의 다른 글

boot memory allocator 의 필요성  (0) 2012.09.04
defunct 프로세스 죽이기  (0) 2012.08.16
리눅스커널 timestamp 찍는 법  (0) 2012.07.18
__user  (0) 2012.07.01
__initcall(), module_init()  (0) 2012.07.01
Posted by code cat
리눅스/커널2012. 7. 18. 07:42
linux kenel timestamp
--------------------------------------
include
include

char tbuf[50], *tp;
unsigned tlen;
unsigned long long t;
unsigned long nanosec_rem;
int this_cpu = smp_processor_id();

t = cpu_clock(this_cpu);
nanosec_rem = do_div(t, 1000000000);
tlen = sprintf(tbuf, "[%5lu.%06lu] ",
(unsigned long) t,
nanosec_rem / 1000);

iPhone 에서 작성된 글입니다.

'리눅스 > 커널' 카테고리의 다른 글

defunct 프로세스 죽이기  (0) 2012.08.16
kmalloc, cache allocator  (0) 2012.07.20
__user  (0) 2012.07.01
__initcall(), module_init()  (0) 2012.07.01
리눅스 커널 분석 시 아키텍쳐별 tag 및 cscope생성  (0) 2012.04.16
Posted by code cat
프로그래밍/C2012. 7. 3. 17:19

error: expected identifier before numeric constant


위와 같은 에러가 나는 이유

1. include로 헤더파일을 추가했는데 어디선가 같은 이름의 매크로가 꼬였을 때,

해결책 --> (에러 나는 라인의 매크로로 grep을 잡아보자!)


'프로그래밍 > C' 카테고리의 다른 글

include guard에 대해서  (0) 2012.09.24
구조체 초기화 방법  (0) 2012.08.21
정적 라이브러리, 동적 라이브러리 만들기  (0) 2012.04.04
sprintf 사용법  (0) 2012.04.03
sscanf 사용법  (0) 2012.03.28
Posted by code cat

vim에서 검색한 내용 copy & paste 하기


vim에서 search 한 내용만 골라서 copy를 하고 싶을 경우 다음과 같이 하면 된다.


qaq

:g/검색어/y A

:let @+ = @a


처음 라인에서는 레지스터 a를 비운다.  (저 명령어는 매크로를 기록할 때 쓰는 명령어이다.)

두번째 라인에서는 뭐.. 알다시피 검색어를 찾아서 A 레지스터에 넣는다.

세번째 라인에서는 레지스터 A를 클립보드에 카피한다.


vim에서 검색한 내용 지우기


이건 쉽다.


:g/검색어/d


따로 설명할 필요 없으리라 믿는다.



한가지 검색한 거를 제외하고 위의 작업을 하고 싶을 땐 어떻하면 좋을까???


inverse를 떠올리면 된다!


:v/검색어/d


알고나니 참 좋은 기능이다.

'리눅스 > 스크립트/유틸' 카테고리의 다른 글

Code Sourcery 설치하기  (0) 2012.07.31
screen에서 ctrl+s 잘못 눌러서 먹통 됐을 때...  (0) 2012.07.23
samba 로그인 정보 지우기/보기  (0) 2012.06.23
SVN in conflict  (0) 2012.06.21
cpio vs tar vs cp  (0) 2012.06.11
Posted by code cat
리눅스/커널2012. 7. 1. 11:25

__user 로 타입이 정의된 변수는 kernel space 밖에 있다는 걸 의미한다.


예를 들어,


char __user *buff


라고 하면, 이는 user space안에 char *buff라고 선언한 것이다.


이를 이용해 kernel과 user 공간 사이의 communication(예: read/write )을 할 때 편리하게 쓸 수 있다. 


이와 함께 쓰이는 함수가 대표적으로 copy_from_user 와 copy_to_user가 있겠다.



stackoverflow에 보니 아래와 같은 질문이 있었다.

http://stackoverflow.com/questions/4521551/what-are-the-implications-of-the-linux-user-macro


I was hoping someone could explain the nuances of the __user macro used in the linux kernel source.

First of all, the macro:
# define __user __attribute__((noderef, address_space(1)))

Now, after some googling I read that this macro allows one to designate a pointer as belonging to the user address space, and that it should not be dereferenced.

I may be missing some obvious facts, but could someone please explain the implications of such a macro? For instance, what is a good example of where this macro would be of use? Again, forgive me if I am missing something obvious.

To put this in some context, I came accross the macro while examining some USB code (linux/usbdevice_fs.h). I am only looking for a general understanding of this macros( or others like it) use within the kernel.

Thanks for looking!
c macros linux-kernel kernel link|edit|flag asked Dec 23 '10 at 18:46

Mr. Shickadance
1,155624

82% accept rate

2

See do_execve() source for good example. See how argv is used in count(). If you'd simply dereference (*argv[0]) or something, sparse(1) will warn about it. address_space says not all pointers are equal, requiring different (dereference) rules and should not be mixed. – adobriyan Dec 24 '10 at 17:12


2 Answers
active
oldest
votes
up vote
4
down vote
accepted
It allows tools like sparse to tell kernel developers that they're possibly using an untrusted pointer (or a pointer that may be invalid in the current virtual address mapping) improperly.link|edit|flag answered Dec 23 '10 at 18:59

Michael Burr
117k11123313




up vote
3
down vote
I think __user marks user space pointers and tells the developer/system not to trust it. If user gives you "invalid" pointer, then kernel tries to reference it (note that kernel can reference everywhere) and it can corrupt it's own space.

For example in "read"(in you usbdevice_fs.h) should provide you a (__user) buffer to write the result to. So you have to use copy_to_user, but not memcopy, strcpy or anything like this.

Note: This is not formal definition/description, but the only part I'm aware of.


__user로 선언된 변수는 dereference를 할 경우 어떤 동작을 일으킬지 모르는 것 같다.(untrusted pointer라는 문맥)  저렇게 함으로서 개발자(?)에게 __user로 선언된 변수를 deference하지 말라고 표시 하는 거 같다.

Posted by code cat