ISSN 1000-1239 CN 11-1777/TP

计算机研究与发展 ›› 2015, Vol. 52 ›› Issue (1): 141-155.doi: 10.7544/issn1000-1239.2015.20131166

• 软件技术 • 上一篇    下一篇



  1. 1(同济大学电子与信息工程学院 上海 200092); 2(上海科泰世纪科技有限公司 上海 201203); 3(江西财经大学信息管理学院 南昌 330029) (
  • 出版日期: 2015-01-01
  • 基金资助: 

A Compound Native Object Model Based on the Strategy of Cross-Language Object Migration

Huang Yukun1,3,Chen Rong1,2,Pei Xilong1,Cao Jing2   

  1. 1(Institute of Electronic and Information Engineering, Tongji University, Shanghai 200092); 2(Shanghai Kortide Century Technology, LTD, Shanghai 201203) ; 3(School of Information Technology, Jiangxi University of Finance and Economics, Nanchang 330029)
  • Online: 2015-01-01

摘要: Java本地调用接口(Java native interface, JNI)机制被广泛应用在移动应用开发领域.JNI机制中JNI接口函数被用于在本地代码中解析和转换Java端的数据类型和Java对象.然而,JNI接口函数的调用开销影响了程序运行的效率,其复杂的使用规范也是集成与复用第三方本地组件时的主要障碍.提出一种基于跨语言对象迁移策略的复合本地对象模型,能够实现有效减少本地调用程序中的JNI接口函数调用开销和有效利用已有本地组件的目的.详细讨论了复合本地对象的语言特性及其具体实现,并给出跨语言对象迁移规范以及开发实例.在Dalvik虚拟机中实现了该模型,通过实验证明该策略和模型能够有效改善JNI机制的不足.

关键词: Java本地调用接口, 跨语言, 本地组件, 元数据, Dalvik虚拟机

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.

Key words: Java native interface (JNI), cross-language, native component, metadata, Dalvik virtual machine