Abstract:
The Java native interface (JNI) mechanism, which is designed to handle the interaction between native code and Java code, is currently widely utilized to develop mobile applications. However, JNI is observed hardly from perfection in two points: on one hand, the overhead of invoking functions of JNI interfaces heavily affects programs’ runtime performance; on the other hand, the complexity of the JNI’s programming specification prevents the integration and reusing of third party native components in Java code. To solve these problems, a new strategy is advised to migrate objects between Java components and native components by injecting necessary information of native objects into high-level objects. Guided by this strategy, a model of compound native objects (CNO) is proposed to integrate a Java object and a native object into a compound object which share same metadata maintained by Java class objects. Therefore the CNO model could literally reduce the overheads for the time saving of data type conversions, and lessen down the programming burden of the bridging code. A prototype of the CNO model is implemented on the basis of the Dalvik virtual machine such that Java could reuse third-party components in a dynamical and efficient way. Experiments show that the CNO model outweighs JNI in better performance of accessing native methods.