2025년 3월 27일부터 AOSP를 빌드하고 기여하려면 aosp-main
대신 android-latest-release
를 사용하는 것이 좋습니다. 자세한 내용은 AOSP 변경사항을 참고하세요.
Android 런타임 및 Dalvik
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Android 런타임(ART)은 Android의 앱 및 일부 시스템 서비스에서 사용하는 관리형 런타임입니다. ART와 그 전의 Dalvik은 원래 Android 프로젝트용으로 특별히 제작된 것입니다. ART는 런타임으로서 Dalvik Executable(DEX) 형식 및 DEX 바이트 코드 사양을 실행합니다.
ART와 Dalvik은 DEX 바이트 코드를 실행하는 호환 가능한 런타임이므로, Dalvik용으로 개발된 앱은 ART로 실행 시에도 작동해야 합니다. 그러나 Dalvik에서 작동하는 기술 중 일부는 ART에서 작동하지 않습니다. 가장 중요한 문제에 관한 자세한 내용은 Android 런타임(ART)에서 앱 동작 확인을 참고하세요.
ART 기능
다음은 ART에서 구현된 몇 가지 주요 기능입니다.
AOT(Ahead-of-time) 컴파일
ART는 앱 성능을 개선할 수 있는 AOT 컴파일을 도입했습니다. ART는 설치 시간 확인도 Dalvik보다 엄격합니다.
설치 시 ART는 기기의 dex2oat 도구를 사용하여 앱을 컴파일합니다. 이 유틸리티는 DEX 파일을 입력으로 받아서 대상 기기에서 실행할 수 있는 컴파일된 앱을 생성합니다. 유틸리티는 모든 유효한 DEX 파일을 어려움 없이 컴파일할 수 있어야 합니다. 그러나 일부 후처리 도구는 Dalvik에서 허용되지만 ART에서는 컴파일할 수 없는 무효한 파일을 생성합니다. 자세한 내용은 가비지 컬렉션 문제 해결을 참고하세요.
가비지 컬렉션 개선
가비지 컬렉션(GC)은 리소스 집약적이므로 앱 성능을 저하시켜 화면 끊김, UI 응답성 부족 등의 문제를 유발할 수 있습니다. ART에서는 다음과 같은 여러 가지 방법으로 가비지 컬렉션을 개선합니다.
- 단일 GC 일시중지가 있는 동시 실행 설계
- 백그라운드 메모리 사용량 및 조각화를 줄이기 위한 동시 복사
- 힙 크기와 무관한 GC 일시중지 길이
- 최근 할당된 단기 객체를 정리하는 특별한 경우 총 GC 시간이 짧아지는 컬렉터
- 동시 가비지 컬렉션이 더욱 적절한 때에 실행되기 때문에 일반적인 사용 사례에서
GC_FOR_ALLOC
이벤트가 거의 발생하지 않도록 하는 개선된 가비지 컬렉션 에르고노믹스
개발 및 디버깅 개선
ART에서는 앱 개발 및 디버깅을 개선하기 위해 다양한 기능을 제공합니다.
샘플링 프로파일러 지원
지금까지 개발자는 앱 실행 트레이싱을 위한 Traceview 도구를 프로파일러로 사용했습니다. Traceview는 유용한 정보를 제공하지만 Dalvik상의 결과가 메서드 호출당 오버헤드에 의해 왜곡되며 Traceview를 사용하면 런타임 성능에 큰 영향을 미칩니다.
ART에는 이러한 제한사항이 없는 전용 샘플링 프로파일러에 관한 지원이 추가되었습니다. 이렇게 하면 속도를 크게 떨어뜨리지 않으면서 앱 실행을 더욱 정확하게 확인할 수 있습니다. 샘플링 지원은 KitKat 버전의 Dalvik용 Traceview에 추가되었습니다.
디버깅 기능 추가 지원
ART는 특히 모니터 및 가비지 컬렉션 관련 기능에서 새로운 디버깅 옵션을 다수 지원합니다. 예를 들어 개발자는 다음을 할 수 있습니다.
- 스택 트레이스에 어떤 잠금이 있는지 확인한 다음 잠금이 있는 스레드로 이동합니다.
- 특정 클래스에 라이브 인스턴스가 얼마나 있는지 묻고 인스턴스 확인을 요청한 뒤 객체를 유지하는 참조를 확인합니다.
- 특정 인스턴스와 관련하여 중단점 등의 이벤트를 필터링합니다.
- 'method-exit' 이벤트를 사용하여 종료 시 메서드가 반환한 값을 확인합니다.
- 특정 필드가 액세스 또는 수정될 때 프로그램 실행을 정지하도록 필드 watchpoint를 설정합니다.
예외 및 비정상 종료 보고서의 진단 세부정보 개선
ART는 런타임 예외가 발생할 때 최대한 많은 컨텍스트와 세부정보를 제공합니다. ART는 java.lang.ClassCastException
, java.lang.ClassNotFoundException
, java.lang.NullPointerException
과 관련하여 확장된 예외 세부정보를 제공합니다.
Dalvik의 이후 버전에서는 java.lang.ArrayIndexOutOfBoundsException
및 java.lang.ArrayStoreException
과 관련하여 확장된 예외 세부정보가 제공되었으며 현재는 배열의 크기와 범위를 벗어난 오프셋이 포함됩니다. ART도 이와 같은 정보를 제공합니다.
예를 들어 java.lang.NullPointerException
은 이제 앱에서 작성하려고 했던 필드 또는 앱에서 호출하려고 했던 메서드 등 앱이 null 포인터로 실행하려고 했던 작업에 관한 정보를 표시합니다. 다음은 몇 가지 일반적인 예입니다.
java.lang.NullPointerException: Attempt to write to field 'int
android.accessibilityservice.AccessibilityServiceInfo.flags' on a null object
reference
java.lang.NullPointerException: Attempt to invoke virtual method
'java.lang.String java.lang.Object.toString()' on a null object reference
또한 ART는 앱 네이티브 비정상 종료 보고서에 Java 및 네이티브 스택 정보를 모두 포함시키기 때문에 더 풍부한 컨텍스트 정보를 제공합니다.
문제 신고
앱 JNI 문제 이외의 원인으로 문제가 발생한 경우 Android 오픈소스 프로젝트 Issue Tracker를 통해 신고해 주세요. 가능한 경우 adb bugreport
와 Google Play 스토어의 앱으로 연결되는 링크를 포함해 주세요. 또는 가능한 경우 문제를 재현하는 APK를 첨부해 주세요.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# Android runtime and Dalvik\n\nAndroid runtime (ART) is the managed runtime used by apps and some system\nservices on Android. ART and its predecessor Dalvik were originally created\nspecifically for the Android project. ART as the runtime executes the Dalvik\nexecutable (DEX) format and DEX bytecode specification.\n\nART and Dalvik are compatible runtimes running DEX bytecode, so apps\ndeveloped for Dalvik should work when running with ART. However, some\ntechniques that work on Dalvik do not work on ART. For information about the\nmost important issues, see [Verifying\napp behavior on the Android runtime (ART)](http://developer.android.com/guide/practices/verifying-apps-art.html).\n\nART features\n------------\n\nHere are some of the major features implemented by ART.\n\n### Ahead-of-time (AOT) compilation\n\nART introduces ahead-of-time (AOT) compilation, which can improve app\nperformance. ART also has tighter install-time verification than Dalvik.\n\nAt install time, ART compiles apps using the on-device\n**dex2oat** tool. This utility accepts [DEX](/docs/core/runtime/dex-format) files as input and generates\na compiled app executable for the target device. The utility should be able to\ncompile all valid DEX files without difficulty. However, some post-processing\ntools produce invalid files that may be tolerated by Dalvik but cannot be\ncompiled by ART. For more information, see [Addressing\nGarbage Collection Issues](http://developer.android.com/guide/practices/verifying-apps-art.html#GC_Migration).\n\n### Improved garbage collection\n\nGarbage collection (GC) is very resource intensive, which can impair an app's performance,\nresulting in choppy display, poor UI responsiveness, and other problems. ART improves garbage\ncollection in several ways:\n\n- Mostly concurrent design with a single GC pause\n- Concurrent copying to reduce background memory usage and fragmentation\n- The length of the GC pause is independent of the heap size\n- Collector with lower total GC time for the special case of cleaning up recently-allocated, short-lived objects\n- Improved garbage collection ergonomics, making concurrent garbage collections more timely, which makes [`GC_FOR_ALLOC`](http://developer.android.com/tools/debugging/debugging-memory.html#LogMessages) events extremely rare in typical use cases\n\n### Development and debugging improvements\n\nART offers a number of features to improve app development and debugging.\n\n#### Support for sampling profiler\n\nHistorically, developers have used the [Traceview](http://developer.android.com/tools/help/traceview.html)\ntool (designed for tracing\napp execution) as a profiler. While Traceview gives useful information,\nits results on Dalvik have been skewed by the per-method-call overhead, and use\nof the tool noticeably affects run time performance.\n\nART adds support for a dedicated sampling profiler that does not have these\nlimitations. This gives a more accurate view of app execution without\nsignificant slowdown. Sampling support was added to Traceview for\nDalvik in the KitKat release.\n\n#### Support for more debugging features\n\nART supports a number of new debugging options, particularly in monitor- and\ngarbage collection-related functionality. For example, you can:\n\n- See what locks are held in stack traces, then jump to the thread that holds a lock.\n- Ask how many live instances there are of a given class, ask to see the instances, and see what references are keeping an object live.\n- Filter events (like breakpoint) for a specific instance.\n- See the value returned by a method when it exits (using \"method-exit\" events).\n- Set field watchpoint to suspend the execution of a program when a specific field is accessed and/or modified.\n\n#### Improved diagnostic detail in exceptions and crash reports\n\nART gives you as much context and detail as possible when runtime exceptions\noccur. ART provides expanded exception detail for [java.lang.ClassCastException](http://developer.android.com/reference/java/lang/ClassCastException.html),\n[java.lang.ClassNotFoundException](http://developer.android.com/reference/java/lang/ClassNotFoundException.html),\nand [java.lang.NullPointerException](http://developer.android.com/reference/java/lang/NullPointerException.html).\n(Later versions of Dalvik provided expanded exception detail for [java.lang.ArrayIndexOutOfBoundsException](http://developer.android.com/reference/java/lang/ArrayIndexOutOfBoundsException.html)\nand [java.lang.ArrayStoreException](http://developer.android.com/reference/java/lang/ArrayStoreException.html),\nwhich now include the size of the array and the out-of-bounds offset, and ART\ndoes this as well.)\n\nFor example, [java.lang.NullPointerException](http://developer.android.com/reference/java/lang/NullPointerException.html)\nnow shows information about what the app was trying to do with the null pointer,\nsuch as the field the app was trying to write to, or the method it was trying to\ncall. Here are some typical examples: \n\n```\njava.lang.NullPointerException: Attempt to write to field 'int\nandroid.accessibilityservice.AccessibilityServiceInfo.flags' on a null object\nreference\n``` \n\n```\njava.lang.NullPointerException: Attempt to invoke virtual method\n'java.lang.String java.lang.Object.toString()' on a null object reference\n```\n\nART also provides improved context information in app native crash reports,\nby including both Java and native stack information.\n\nReport problems\n---------------\n\nIf you run into any issues that aren't due to app JNI issues, report\nthem through the [Android Open Source\nProject Issue Tracker](/docs/setup/contribute/report-bugs#platform). Include an `adb bugreport` and link to\nthe app in Google Play store if available. Otherwise, if possible, attach an\nAPK that reproduces the issue.\n| **Reminder:** Issues (including attachments) are publicly visible."]]