Journal of Computer Applications ›› 2024, Vol. 44 ›› Issue (7): 2151-2159.DOI: 10.11772/j.issn.1001-9081.2023070968

• Computer software technology • Previous Articles     Next Articles

Automatic foreign function interface generation method based on source code analysis

Shuo SUN1, Wei ZHANG1,2,3, Wendi FENG1(), Yuwei ZHANG4   

  1. 1.Computer School,Beijing Information Science and Technology University,Beijing 100101,China
    2.Beijing Advanced Innovation Center for Future Blockchain and Privacy Computing (Beijing Information Science and Technology University),Beijing 100101,China
    3.Beijing Laboratory of National Economic Security Early-warning Engineering (Beijing Information Science and Technology University),Beijing 100101,China
    4.School of Computer Science,Peking University,Beijing 100871,China
  • Received:2023-07-19 Revised:2023-09-25 Accepted:2023-09-25 Online:2023-10-26 Published:2024-07-10
  • Contact: Wendi FENG
  • About author:SUN Shuo, born in 1999, M. S. candidate. His research interests include operating system kernels, computer networks.
    ZHANG Wei, born in 1980, Ph. D., professor. His research interests include network and data security, hardware-software co-design.
    ZHANG Yuwei, born in 1994, Ph. D., assistant research fellow. His research interests include artificial intelligence, intelligent software testing.
    First author contact:FENG Wendi, born in 1994, Ph. D., associate professor. His research interests include mobile edge computing, software-defined networks, network function virtualization.
  • Supported by:
    National Key R&D Program of China(2022YFC3320900);R&D Program of Beijing Municipal Education Commission(KM202311232005);Beijing Advanced Innovation Center for Future Blockchain and Privacy Computing, and Beijing Laboratory of National Economic Security Early-warning Engineering

基于源码分析的自动化外部函数接口生成方法

孙蒴1, 张伟1,2,3, 冯温迪1(), 张俞炜4   

  1. 1.北京信息科技大学 计算机学院, 北京 100101
    2.北京未来区块链与隐私计算高精尖中心(北京信息科技大学), 北京 100101
    3.国家经济安全预警工程北京实验室(北京信息科技大学), 北京 100101
    4.北京大学 计算机学院, 北京 100871
  • 通讯作者: 冯温迪
  • 作者简介:孙蒴(1999—),男,河北任丘人,硕士研究生,主要研究方向:操作系统内核、计算机网络;
    张伟(1980—),男,山东临清人,教授,博士,主要研究方向:网络和数据安全、软硬件协同设计;
    张俞炜(1994—),男,福建福州人,助理研究员,博士,CCF会员,主要研究方向:人工智能、智能软件测试。
    第一联系人:冯温迪(1994—),男,山东菏泽人,副教授,博士,主要研究方向:移动边缘计算、软件定义网络、网络功能虚拟化;
  • 基金资助:
    国家重点研发计划项目(2022YFC3320900);北京市教育委员会科研计划项目(KM202311232005);“北京未来区块链与隐私计算高精尖中心”和“国家经济安全预警工程北京实验室”资助

Abstract:

Foreign Function Interface (FFI) is a fundamental method to invoke interfaces provided in other programming languages. Focusing on huge amount of manual coding required when using FFI, an Automatic Foreign function Interface Generation (AFIG) method was proposed. The reverse source code analysis technique based on abstract syntax tree was employed by AFIG to accurately retrieve the multilingual intermediate representation from library binaries, in which function interface information was uniformly described. Based on the representation, the multilingual conversion rule matrix could be utilized by different platform code generators to automatically generate FFI codes for various platforms without handcrafting. To further reduce generation time usage, a dependency analysis-based task aggregation strategy was proposed, by which tasks with dependencies were consolidated as monolithic ones. Hence, blocking and deadlocks were efficiently eliminated, and load balancing and scalability on multi-core systems were achieved, accordingly. Experimental results indicate that AFIG achieves a reduction of 98.14% for FFI developing codes and 41.95% for testing codes compared to manual coding method; under the same task, AFIG further reduces development cost by 61.27% compared to SWIG (Simplified Wrapper and Interface Generator). And the code generation efficiency of AFIG increases linearly with the increase of computing resources.

Key words: Foreign Function Interface (FFI), code generation, dependency elimination, parallel processing, static analysis

摘要:

外部函数接口(FFI)是解决一种编程语言调用其他语言函数库的主要方法。针对使用FFI技术时需要大量人工编码的问题,提出自动化外部函数接口生成(AFIG)方法。该方法利用基于抽象语法树的源码逆向分析技术,从被封装的库文件中精准提取出用于描述函数接口信息的多语言融合的统一表示。基于此统一表示,不同平台的代码生成器可利用多语言转换规则矩阵,全自动化地生成不同平台的FFI相关代码。为解决FFI代码生成中的效率低下问题,设计了一种基于依赖分析的任务聚合策略,通过把存在依赖的任务聚合为新的任务,有效消除了FFI代码任务在并行下的阻塞与死锁,从而实现任务在多核系统下的可扩展与负载均衡。实验结果表明:与人工编码相比,AFIG方法减少了FFI开发中98.14%的开发编码量以及41.95%的测试编码量;与现有的SWIG (Simplified Wrapper and Interface Generator)方法相比,在同等任务下可减少61.27%的开发成本;且生成效率随着计算资源的增加呈线性增长。

关键词: 外部函数接口, 代码生成, 依赖消除, 并行处理, 静态分析

CLC Number: