
Efficient Java Native Interface for Android based Mobile Devices by Preetham Chandrian A Thesis Presented in Partial Fulfillment of the Requirements for the Degree Master of Science Approved May 2011 by the Graduate Supervisory Committee: Yann-Hang Lee, Chair Hasan Davlcu Baoxin Li ARIZONA STATE UNIVERSITY August 2011 ABSTRACT Currently Java is making its way into the embedded systems and mobile devices like androids. The programs written in Java are compiled into machine independent binary class byte codes. A Java Virtual Machine (JVM) executes these classes. The Java platform additionally specifies the Java Native Interface (JNI). JNI allows Java code that runs within a JVM to interoperate with applications or libraries that are written in other languages and compiled to the host CPU ISA. JNI plays an important role in embedded system as it provides a mechanism to interact with libraries specific to the platform. This thesis addresses the overhead incurred in the JNI due to reflection and serialization when objects are accessed on android based mobile devices. It provides techniques to reduce this overhead. It also provides an API to access objects through its reference through pinning its memory location. The Android emulator was used to evaluate the performance of these techniques and we observed that there was 5 - 10 % performance gain in the new Java Native Interface. i To My Beloved Family ii ACKNOWLEDGEMENTS I would like to sincerely thank my advisor; Dr. Yann-Hang Lee, without whose guidance, encouragement and support, this thesis would not have been possible. I have gained a lot of knowledge about my field, improved my research skills and otherwise, working under him. In all it has been a very satisfying and a fulfilling experience. I would also like to thank Dr. Hasan Davulcu and Dr. Baoxin Li for their time and effort to help me fulfill my degree requirements; as part of my thesis committee. I am grateful to all my friends at Arizona State University who made me feel at home and making this stay an enjoyable experience. I am thankful to all my lab mates, especially Yaksh Sharma, Zhou Fang and Rohit Girme who helped me with my queries. Finally, I am indebted to my parents and my family. They all have constantly encouraged me and been understanding through all the tough times. I wish to express my utmost and deepest gratitude to them for being patient, warm and supportive. iii TABLE OF CONTENTS Page LIST OF TABLES……………………………………………………………….vii LIST OF FIGURES……………………………………………………………..viii CHAPTER 1 INTRODUCTION……………………………………………….........1 1.1 Motivation ............................................................................... 2 1.2 Document Outline ................................................................... 4 2 JAVA NATIVE INTERFACE (JNI) ...................................................... 6 2.1 Role of JNI .............................................................................. 6 2.2 Overview ................................................................................. 7 2.3 Native Method Arguments ..................................................... 9 2.4 The JNIEnv Interface Pointer ............................................... 10 2.5 JNI Functions ........................................................................ 11 3 ANDROID ARCHITECTURE .............................................................. 15 3.1 Application Framework ........................................................ 16 3.2 Android Runtime .................................................................. 17 3.3 Android Application Architecture ........................................ 20 4 RELATED WORK................................................................................. 21 4.1 JNI Bridge ............................................................................. 22 4.2 Interfacing Java to the Virtual Interface Architecture ......... 22 4.3 Jeannie ................................................................................... 23 iv CHAPTER Page 4.4 Inlining Java Native Calls At Runtime ................................ 24 4.5 Janet ....................................................................................... 24 4.6 Native Code Profiling ........................................................... 25 5 DESIGN .................................................................................................. 26 5.1 Class Structure ...................................................................... 26 5.2 Hashing JNI fields ................................................................ 29 5.3 Find Class .............................................................................. 31 5.4 Get Field ................................................................................ 34 5.5 Get Method ........................................................................... 36 5.6 Pinning object ....................................................................... 38 6 IMPLEMENTATION ............................................................................ 40 6.1 Implementation of hash function .......................................... 40 6.2 Implementation of GetFieldId .............................................. 42 6.3 Implementation of GetMethodId .......................................... 43 6.4 Implementation of pinObject and unpinObject ................... 44 6.5 Implementation of FindClass ............................................... 45 7 EVALUATION ...................................................................................... 47 7.1 Android Debug Bridge ........................................................ 48 7.2 Profiling results ..................................................................... 50 8 CONCLUSION ...................................................................................... 57 9 FUTURE WORK ................................................................................... 58 v CHAPTER Page REFERENCES .......................................................................................................... 59 vi LIST OF TABLES Table Page 1. JNI Function Table 1 .............................................................................12 2. JNI Function Table 2 .............................................................................13 3. JNI method profile .................................................................................50 4. Heap sort running time ..........................................................................51 5. Execution time for JetBoy .....................................................................54 6. Running Time for JetBoy with modified JNI ........................................54 7. JNI modified method profile for JetBoy………………………...........Error! Bookmark not defined. 8. Reference object access time. ............................................................ 56 vii LIST OF FIGURES Figure Page 1. Overview of JNI ......................................................................................4 2. Role of JNI ..............................................................................................6 3. Steps writing a JNI program ....................................................................9 4. The JNIEnv interface pointer ................................................................10 5. Thread local JNIEnv Interface Pointer .................................................. 11 6. Primitive array access ............................................................................14 7. Major Components of Android Applications ........................................15 8. Application Layer of Android ...............................................................16 9. Application Framework of Android Libraries .......................................16 10. Libraries Layer of Android ....................................................................17 11. Layers of Android Application ..............................................................18 12. Android Runtime Layer .........................................................................19 13. Linux Kernel in Android Hardware Abstraction Layer .........................19 14. Flow of findClass .................................................................................33 15. GetField workflow ................................................................................35 16. Get Method ............................................................................................37 17. Pinning object ........................................................................................39 18. JNI method Profiling .............................................................................51 19. Heap sort comparison graph ..................................................................52 20. Execution time of JetBoy ......................................................................53 viii Figure Page 21. Execution time for the Modified JNI JetBoy ........................................55 22: Execution time for Lunar Lander with Android JNI ............................... 55 23: Execution time for Lunar Lander with modified JNI ... Error! Bookmark not defined.56 ix CHAPTER 1 INTRODUCTION With the introduction of JavaME (Micro Edition) by Sun MicroSystem for mobile and embedded devices Java has rapidly acquired a significant amount of market share. Also the applications based on JavaME are portable across devices developers favor Java over other programming languages. The problems with using
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages70 Page
-
File Size-