Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android & Dalvik - Get the size of an object

Tags:

As we all know Java 5 introduced the ability for Instrumentation to get the size of an object with ease. Is there such a method on Android and Dalvik?

The java.lang.instrument package is not available on Android.

like image 691
Kevin Parker Avatar asked Jan 25 '12 20:01

Kevin Parker


People also ask

Is Android good or Apple?

Apple and Google both have fantastic app stores. But Android is far superior at organizing apps, letting you put important stuff on the home screens and hide less useful apps in the app drawer. Also, Android's widgets are much more useful than Apple's.

What's meant by Android?

Android OS is a Linux-based mobile operating system that primarily runs on smartphones and tablets. The Android platform includes an operating system based upon the Linux kernel, a GUI, a web browser and end-user applications that can be downloaded.

Who is the owner of Android?

Android Inc., was bought by the American search engine company Google Inc., in 2005. At Google, the Android team decided to base their project on Linux, an open source operating system for personal computers.

What is Android's latest operating system?

The latest version of Android OS is 12, released in October 2021. Learn more about OS 12, including its key features. Older versions of Android include: Tiramisu (OS 13)


1 Answers

For what it's worth, I have looked at the Dalvik VM source code and can not find any stable API to get the size of an Object. If you want to take a look yourself, the size of an object is stored in ClassObject::objectSize : size_t, see dalvik/vm/oo/Object.h.

There is, however, internal APIs to get the size of an Object. It is used by DDMS to report detailed information about object sizes. But, since the API is internal, it is likely to change between different versions of Android. Plus, the API is sends raw byte[] data around, and is client/server based and not a simple library call, so it will be extremely awkward to use. If you want to take a look, start in dvmAllocObject() in dalvik/vm/alloc/Alloc.cpp and the dvmTrackAllocation() call.

To sum it up: there is unfortunately not any readily usable, stable API to get the size of an Object in the Dalvik VM.

like image 133
Martin Nordholts Avatar answered Sep 21 '22 17:09

Martin Nordholts