CN110275710A - Method and system for checking consistency of Java local interface, storage medium and terminal - Google Patents
Method and system for checking consistency of Java local interface, storage medium and terminal Download PDFInfo
- Publication number
- CN110275710A CN110275710A CN201910497314.XA CN201910497314A CN110275710A CN 110275710 A CN110275710 A CN 110275710A CN 201910497314 A CN201910497314 A CN 201910497314A CN 110275710 A CN110275710 A CN 110275710A
- Authority
- CN
- China
- Prior art keywords
- jni
- parameter information
- native
- java
- module
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/31—Programming languages or programming paradigms
- G06F8/315—Object-oriented languages
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/43—Checking; Contextual analysis
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Engineering & Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Computing Systems (AREA)
- Devices For Executing Special Programs (AREA)
Abstract
本发明提供一种Java本地接口一致性检查方法及系统、存储介质及终端,包括以下步骤:在编译阶段引入记录函数的JNI参数信息的插件;在Native库生成过程中,由所述插件对生成的Native库进行修改,以使所述Native库中增加所述JNI参数信息;JVM运行时,在JNI动态链接过程中,比较Native中的JNI参数信息和Java中的JNI参数信息是否一致,并在一致时通过所述JNI动态链接。本发明的Java本地接口一致性检查方法及系统、存储介质及终端,在Native库链接阶段由JVM检查Native库中的symbol的完整信息,以确保Java声明中的接口与Native中的实现完全一致,并在不一致的情况下,立即抛出异常,从而避免出现不可预知的行为。
The present invention provides a Java local interface consistency checking method and system, a storage medium and a terminal, comprising the following steps: introducing a plug-in for recording JNI parameter information of a function at the compilation stage; Modify the Native library of the Native library so that the JNI parameter information is added in the Native library; when the JVM is running, in the JNI dynamic link process, compare whether the JNI parameter information in the Native is consistent with the JNI parameter information in Java, and When consistent, dynamically link via the JNI. In the Java local interface consistency check method and system, storage medium and terminal of the present invention, the complete information of the symbol in the Native library is checked by the JVM at the Native library link stage, to ensure that the interface in the Java declaration is completely consistent with the implementation in the Native, And in the case of inconsistency, an exception is thrown immediately to avoid unpredictable behavior.
Description
技术领域technical field
本发明涉及IT的技术领域,特别是涉及一种Java本地接口一致性检查方法及系统、存储介质及终端。The invention relates to the technical field of IT, in particular to a Java local interface consistency checking method and system, a storage medium and a terminal.
背景技术Background technique
Java本地接口(Java Native Interface,JNI)是一种编程框架,提供了若干的应用程序编程接口(Application Programming Interface,API)实现了Java和其他语言的通信(主要是C&C++)。从Java1.1开始,JNI标准成为Java平台的一部分,它允许Java代码和其他语言写的代码进行交互。JNI一开始是为了本地已编译语言,尤其是C和C++而设计的,但是并不妨碍使用其他编程语言,只要调用约定受支持就可以。使用Java与本地已编译的代码交互,通常会丧失平台可移植性。但是,有些情况下这样做是可以接受的,甚至是必须的。例如,使用一些旧的库与硬件、操作系统进行交互,或者为了提高程序的性能。JNI标准至少要保证本地代码能工作在任何Java虚拟机环境。The Java Native Interface (JNI) is a programming framework that provides several application programming interfaces (Application Programming Interface, API) to realize the communication between Java and other languages (mainly C&C++). Starting with Java 1.1, the JNI standard has become part of the Java platform, which allows Java code to interact with code written in other languages. JNI was originally designed for native compiled languages, especially C and C++, but does not prevent the use of other programming languages, as long as the calling convention is supported. Using Java to interact with natively compiled code often results in a loss of platform portability. However, there are situations where it is acceptable, or even necessary, to do so. For example, use some old library to interact with hardware, operating system, or to improve the performance of the program. The JNI standard at least guarantees that native code can work in any Java virtual machine environment.
具体地,Java程序通过JNI可以调用Native程序,反之亦然。Native程序通常由C/C++或者汇编语言编写而成,这使得联合Java与C/C++/ASM等多语言开发成为可能。很多时候都需要诉诸于JNI,例如想在JAVA层面去控制硬件,或者使用一些Native算法优化库,甚至是有时候是需要直接访问底层操作系统的一些服务。Specifically, a Java program can call a Native program through JNI, and vice versa. Native programs are usually written in C/C++ or assembly language, which makes it possible to develop multiple languages such as Java and C/C++/ASM. In many cases, it is necessary to resort to JNI, for example, if you want to control the hardware at the JAVA level, or use some Native algorithm optimization libraries, or sometimes even need to directly access some services of the underlying operating system.
具体地,JNI的示例如下:Specifically, an example of JNI is as follows:
由上可知,Native部分包含一个头文件与一个实现文件,Java部分包含接口的声明,Native库的加载与调用。It can be seen from the above that the Native part includes a header file and an implementation file, the Java part includes the declaration of the interface, and the loading and calling of the Native library.
由于Java代码与Native代码分开编译、打包或链接。如果发生了Native接口实现与Java声明接口之间不一致的问题,则没有办法在编译阶段发现这个问题。Since the Java code is compiled, packaged or linked separately from the Native code. If there is an inconsistency between the Native interface implementation and the Java declared interface, there is no way to find this problem at the compilation stage.
更可怕的是,对于C语言实现的JNI来说,即使在Native库加载过程中也没有办法发现此问题。这会导致在程序运行过程中出现不可预料的问题。What's even more frightening is that for the JNI implemented in C language, there is no way to find this problem even during the loading process of the Native library. This can cause unexpected problems during program execution.
现有技术中缺乏有效的JNI一致性检查方案。通常的做法是在Java中声明Native方法,然后利用Javah等工具生成Native code头文件,Native引用该头文件并按照接口定义进行实现,然后让Native code编译器识别接口不一致的现象。上述做法可以一定程度上避免JNI不一致的问题。但是,很多时候开发者并不会按照这个开发流程进行开发,甚至很多开发者完全手动开发Native。由于编码上的失误与测试上的不严密,导致这种不一致的JNI被部属,直到运行时发生不确定的行为。There is no effective JNI consistency check scheme in the prior art. The usual practice is to declare the Native method in Java, and then use tools such as Javah to generate the Native code header file. Native references the header file and implements it according to the interface definition, and then lets the Native code compiler identify the interface inconsistency. The above approach can avoid the problem of JNI inconsistency to a certain extent. However, in many cases, developers do not follow this development process, and many developers even develop Native completely manually. Due to coding errors and loose testing, this inconsistent JNI is deployed until undefined behavior occurs at runtime.
发明内容Contents of the invention
鉴于以上所述现有技术的缺点,本发明的目的在于提供一种Java本地接口一致性检查方法及系统、存储介质及终端,在Native库链接阶段由Java虚拟机(Java VirtualMachine,JVM)检查Native库中的symbol的完整信息,以确保Java声明中的接口与Native中的实现完全一致,并在不一致的情况下,立即抛出异常,从而避免出现不可预知的行为。In view of the above-mentioned shortcoming of the prior art, the object of the present invention is to provide a kind of Java local interface consistency checking method and system, storage medium and terminal, check Native by Java Virtual Machine (Java Virtual Machine, JVM) in Native library link stage The complete information of the symbol in the library ensures that the interface in the Java declaration is completely consistent with the implementation in Native, and in case of inconsistency, an exception is thrown immediately to avoid unpredictable behavior.
为实现上述目的及其他相关目的,本发明提供一种Java本地接口一致性检查方法,包括以下步骤:在编译阶段引入记录函数的JNI参数信息的插件;在Native库生成过程中,由所述插件对生成的Native库进行修改,以使所述Native库中增加所述JNI参数信息;JVM运行时,在JNI动态链接过程中,比较Native中的JNI参数信息和Java中的JNI参数信息是否一致,并在一致时通过所述JNI动态链接。In order to achieve the above object and other related objects, the present invention provides a method for checking the consistency of Java local interface, comprising the following steps: introducing a plug-in for recording the JNI parameter information of the function at the compilation stage; The generated Native library is modified to increase the JNI parameter information in the Native library; when the JVM is running, in the JNI dynamic link process, compare whether the JNI parameter information in the Native is consistent with the JNI parameter information in Java, And dynamically link via said JNI when consistent.
于本发明一实施例中,当Native中的JNI参数信息和Java中的JNI参数信息不一致时,立即抛出异常。In an embodiment of the present invention, when the JNI parameter information in Native is inconsistent with the JNI parameter information in Java, an exception is thrown immediately.
于本发明一实施例中,还包括建立基于函数名到JNI参数信息的索引,以在JNI动态链接过程中根据函数名获取对应的Native中的JNI参数信息。In an embodiment of the present invention, it also includes establishing an index based on the function name to the JNI parameter information, so as to obtain the corresponding JNI parameter information in Native according to the function name during the JNI dynamic linking process.
于本发明一实施例中,还包括在Native库中增加一个段,并将所述JNI参数信息记录到所述段中。In an embodiment of the present invention, it also includes adding a segment in the Native library, and recording the JNI parameter information into the segment.
对应地,本发明提供一种Java本地接口一致性检查系统,包括引入模块、修改模块和检查模块;Correspondingly, the present invention provides a Java local interface consistency check system, including an import module, a modification module and a check module;
所述引入模块用于在编译阶段引入记录函数的JNI参数信息的插件;The import module is used to introduce a plug-in for recording the JNI parameter information of the function during the compilation phase;
所述修改模块用于在Native库生成过程中,由所述插件对生成的Native库进行修改,以使所述Native库中增加所述JNI参数信息;The modification module is used to modify the generated Native library by the plug-in during the generation of the Native library, so that the JNI parameter information is added in the Native library;
所述检查模块用于JVM运行时,在JNI动态链接过程中,比较Native中的JNI参数信息和Java中的JNI参数信息是否一致,并在一致时通过所述JNI动态链接。The inspection module is used for JVM runtime, and compares whether the JNI parameter information in Native is consistent with the JNI parameter information in Java during the JNI dynamic linking process, and passes through the JNI dynamic link when they are consistent.
于本发明一实施例中,所述检测模块还用于当Native中的JNI参数信息和Java中的JNI参数信息不一致时,立即抛出异常。In an embodiment of the present invention, the detection module is further configured to immediately throw an exception when the JNI parameter information in Native is inconsistent with the JNI parameter information in Java.
于本发明一实施例中,所述引入模块还用于建立基于函数名到JNI参数信息的索引,以在JNI动态链接过程中根据函数名获取对应的Native中的JNI参数信息。In an embodiment of the present invention, the import module is also used to establish an index based on the function name to the JNI parameter information, so as to obtain the corresponding JNI parameter information in Native according to the function name during the JNI dynamic linking process.
于本发明一实施例中,所述修改模块还用于在Native库中增加一个段,并将所述JNI参数信息记录到所述段中。In an embodiment of the present invention, the modification module is further configured to add a segment in the Native library, and record the JNI parameter information into the segment.
本发明提供一种存储介质,其上存储有计算机程序,该程序被处理器执行时实现上述的Java本地接口一致性检查方法。The present invention provides a storage medium on which a computer program is stored, and when the program is executed by a processor, the above method for checking the consistency of the Java local interface is realized.
最后,本发明提供一种终端,包括处理器及存储器;Finally, the present invention provides a terminal, including a processor and a memory;
所述存储器用于存储计算机程序;The memory is used to store computer programs;
所述处理器用于执行所述存储器存储的计算机程序,以使所述终端执行上述的Java本地接口一致性检查方法。The processor is configured to execute the computer program stored in the memory, so that the terminal executes the above Java native interface consistency checking method.
如上所述,本发明的Java本地接口一致性检查方法及系统、存储介质及终端,具有以下有益效果:As mentioned above, the Java local interface consistency check method and system, storage medium and terminal of the present invention have the following beneficial effects:
(1)在Native库链接阶段由JVM检查Native库中的symbol的完整信息,以确保Java声明中的接口与Native中的实现完全一致;(1) In the Native library linking stage, the JVM checks the complete information of the symbol in the Native library to ensure that the interface in the Java declaration is completely consistent with the implementation in Native;
(2)在运行时对JNI一致性进行准确的检查,并在Java声明中的接口与Native中的实现不一致的情况下,立即抛出异常,完全可以避免由于JNI不一致所引起的程序不确定性行为。(2) Accurately check the JNI consistency at runtime, and throw an exception immediately when the interface in the Java statement is inconsistent with the implementation in Native, which can completely avoid the program uncertainty caused by JNI inconsistency Behavior.
附图说明Description of drawings
图1显示为本发明的Java本地接口一致性检查方法于一实施例中的流程图;Fig. 1 is shown as the flow chart of the Java local interface consistency check method in an embodiment of the present invention;
图2显示为本发明的Java本地接口一致性检查系统于一实施例中的结构示意图;Fig. 2 shows the structural representation of the Java native interface consistency checking system in an embodiment of the present invention;
图3显示为本发明的终端于一实施例中的结构示意图。FIG. 3 is a schematic structural diagram of a terminal of the present invention in an embodiment.
组件标号说明Component designation description
21 引入模块21 import module
22 修改模块22 Modification module
23 检查模块23 Check module
31 处理器31 processors
32 存储器32 memory
具体实施方式Detailed ways
以下通过特定的具体实例说明本发明的实施方式,本领域技术人员可由本说明书所揭露的内容轻易地了解本发明的其他优点与功效。本发明还可以通过另外不同的具体实施方式加以实施或应用,本说明书中的各项细节也可以基于不同观点与应用,在没有背离本发明的精神下进行各种修饰或改变。Embodiments of the present invention are described below through specific examples, and those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various modifications or changes can be made to the details in this specification based on different viewpoints and applications without departing from the spirit of the present invention.
本发明的Java本地接口一致性检查方法及系统、存储介质及终端在Java系统的Native库链接阶段由JVM检查Native库中的symbol的完整信息,以确保Java声明中的接口与Native中的实现完全一致,并在不一致的情况下,立即抛出异常,从而避免出现不可预知的行为,保证了系统运行的稳定性。The Java local interface consistency check method and system, storage medium and terminal of the present invention check the complete information of the symbol in the Native library by the JVM at the Native library link stage of the Java system, to ensure that the interface in the Java statement is completely consistent with the realization in the Native Consistent, and in the case of inconsistency, an exception is thrown immediately, thereby avoiding unpredictable behavior and ensuring the stability of the system operation.
如图1所示,于一实施例中,本发明的Java本地接口一致性检查方法包括以下步骤:As shown in Figure 1, in one embodiment, the Java local interface consistency check method of the present invention comprises the following steps:
步骤S1、在编译阶段引入记录函数的JNI参数信息的插件。Step S1, introducing a plug-in for recording the JNI parameter information of the function in the compilation stage.
具体地,JNI的链接过程中,JVM会先查找symbol对应的JNI实现。对于C++来说,其symbol是mangling name,其由编译器根据函数名和参数信息生成,这本身已经包含了参数信息,所以可以确保在symbol查找成功的情况下JNI的一致性。而对于C语言来说,其编译器并不会由参数信息产生mangling name。因此,本发明在C编译阶段引入插件。该插件可以记录函数的JNI参数信息,并建立基于函数名到JNI参数信息的索引。Specifically, during the JNI linking process, the JVM will first search for the JNI implementation corresponding to the symbol. For C++, its symbol is mangling name, which is generated by the compiler based on the function name and parameter information, which itself already contains parameter information, so it can ensure the consistency of JNI when the symbol search is successful. For the C language, its compiler does not generate mangling names from parameter information. Therefore, the present invention introduces plug-ins in the C compilation stage. The plug-in can record the JNI parameter information of the function, and build an index based on the function name to the JNI parameter information.
步骤S2、在Native库生成过程中,由所述插件对生成的Native库进行修改,以使所述Native库中增加所述JNI参数信息。Step S2. During the generation of the native library, the plug-in modifies the generated native library, so that the JNI parameter information is added to the native library.
于本发明一实施例中,由所述插件对生成的Native库进行修改时,在Native库中增加一个段,并将所述JNI参数信息记录到所述段中。In an embodiment of the present invention, when the generated Native library is modified by the plug-in, a segment is added to the Native library, and the JNI parameter information is recorded in the segment.
步骤S3、JVM运行时,在JNI动态链接过程中,比较Native中的JNI参数信息和Java中的JNI参数信息是否一致,并在一致时通过所述JNI动态链接。Step S3, when the JVM is running, compare whether the JNI parameter information in Native is consistent with the JNI parameter information in Java during the JNI dynamic linking process, and dynamically link through the JNI if they are consistent.
具体地,在JNI动态链接过程中,首先基于函数名到JNI参数信息的索引,在JNI动态链接过程中根据函数名获取对应的Native中的JNI参数信息;然后比较Native中的JNI参数信息和Java中的JNI参数信息是否一致。其中,当二者一致时,通过JNI动态链接;当二者不一致时,立即抛出异常,从而避免由于JNI不一致所引起的程序不确定性行为。Specifically, in the JNI dynamic linking process, firstly, based on the index of the function name to the JNI parameter information, the JNI parameter information in the corresponding Native is obtained according to the function name in the JNI dynamic linking process; and then the JNI parameter information in the Native is compared with the Java Whether the JNI parameter information in is consistent. Among them, when the two are consistent, they are dynamically linked through JNI; when they are inconsistent, an exception is thrown immediately, thereby avoiding the program's uncertain behavior caused by JNI inconsistency.
如图2所示,于一实施例中,本发明的Java本地接口一致性检查系统包括引入模块21、修改模块22和检查模块23。As shown in FIG. 2 , in one embodiment, the Java native interface consistency check system of the present invention includes an import module 21 , a modification module 22 and a check module 23 .
引入模块21用于在编译阶段引入记录函数的JNI参数信息的插件。The import module 21 is used to import a plug-in that records JNI parameter information of a function during the compilation phase.
具体地,JNI的链接过程中,JVM会先查找symbol对应的JNI实现。对于C++来说,其symbol是mangling name,其由编译器根据函数名和参数信息生成,这本身已经包含了参数信息,所以可以确保在symbol查找成功的情况下JNI的一致性。而对于C语言来说,其编译器并不会由参数信息产生mangling name。因此,本发明在C编译阶段引入插件。该插件可以记录函数的JNI参数信息,并建立基于函数名到JNI参数信息的索引。Specifically, during the JNI linking process, the JVM will first search for the JNI implementation corresponding to the symbol. For C++, its symbol is a mangling name, which is generated by the compiler based on the function name and parameter information, which itself already contains parameter information, so it can ensure the consistency of JNI when the symbol search is successful. For the C language, its compiler does not generate mangling names from parameter information. Therefore, the present invention introduces plug-ins in the C compilation stage. The plug-in can record the JNI parameter information of the function, and build an index based on the function name to the JNI parameter information.
修改模块22与引入模块21相连,用于在Native库生成过程中,由所述插件对生成的Native库进行修改,以使所述Native库中增加所述JNI参数信息。The modification module 22 is connected with the introduction module 21, and is used for modifying the generated Native library by the plug-in during the generation process of the Native library, so that the JNI parameter information is added to the Native library.
于本发明一实施例中,由所述插件对生成的Native库进行修改时,在Native库中增加一个段,并将所述JNI参数信息记录到所述段中。In an embodiment of the present invention, when the generated Native library is modified by the plug-in, a segment is added to the Native library, and the JNI parameter information is recorded in the segment.
检查模块23与修改模块22相连,用于JVM运行时,在JNI动态链接过程中,比较Native中的JNI参数信息和Java中的JNI参数信息是否一致,并在一致时通过所述JNI动态链接。The checking module 23 is connected with the modifying module 22, and is used for JNI dynamic linking process when JVM is running, comparing whether the JNI parameter information in Native is consistent with the JNI parameter information in Java, and passing through the JNI dynamic link when consistent.
具体地,在JNI动态链接过程中,首先基于函数名到JNI参数信息的索引,在JNI动态链接过程中根据函数名获取对应的Native中的JNI参数信息;然后比较Native中的JNI参数信息和Java中的JNI参数信息是否一致。其中,当二者一致时,通过JNI动态链接;当二者不一致时,立即抛出异常,从而避免由于JNI不一致所引起的程序不确定性行为。Specifically, in the JNI dynamic linking process, firstly, based on the index of the function name to the JNI parameter information, the JNI parameter information in the corresponding Native is obtained according to the function name in the JNI dynamic linking process; and then the JNI parameter information in the Native is compared with the Java Whether the JNI parameter information in is consistent. Among them, when the two are consistent, they are dynamically linked through JNI; when they are inconsistent, an exception is thrown immediately, thereby avoiding the program's uncertain behavior caused by JNI inconsistency.
需要说明的是,应理解以上装置的各个模块的划分仅仅是一种逻辑功能的划分,实际实现时可以全部或部分集成到一个物理实体上,也可以物理上分开。且这些模块可以全部以软件通过处理组件调用的形式实现;也可以全部以硬件的形式实现;还可以部分模块通过处理组件调用软件的形式实现,部分模块通过硬件的形式实现。例如,x模块可以为单独设立的处理组件,也可以集成在上述装置的某一个芯片中实现,此外,也可以以程序代码的形式存储于上述装置的存储器中,由上述装置的某一个处理组件调用并执行以上x模块的功能。其它模块的实现与之类似。此外这些模块全部或部分可以集成在一起,也可以独立实现。这里所述的处理组件可以是一种集成电路,具有信号的处理能力。在实现过程中,上述方法的各步骤或以上各个模块可以通过处理器组件中的硬件的集成逻辑电路或者软件形式的指令完成。It should be noted that it should be understood that the division of each module of the above device is only a division of logical functions, and may be fully or partially integrated into one physical entity or physically separated during actual implementation. And these modules can all be implemented in the form of calling software through processing components; they can also be realized in the form of hardware; some modules can also be realized in the form of calling software through processing components, and some modules can be realized in the form of hardware. For example, the x module can be a separate processing component, and can also be integrated in a chip of the above-mentioned device. In addition, it can also be stored in the memory of the above-mentioned device in the form of program code, and can be implemented by a certain processing component of the above-mentioned device. Call and execute the function of the above x module. The implementation of other modules is similar. In addition, all or part of these modules can be integrated together, and can also be implemented independently. The processing component described here may be an integrated circuit with signal processing capability. In the implementation process, each step of the above method or each module above can be completed by an integrated logic circuit of hardware in the processor component or an instruction in the form of software.
例如,以上这些模块可以是被配置成实施以上方法的一个或多个集成电路,例如:一个或多个特定集成电路(Application Specific Integrated Circuit,简称ASIC),或,一个或多个微处理器(Digital Singnal Processor,简称DSP),或,一个或者多个现场可编程门阵列(Field Programmable Gate Array,简称FPGA)等。再如,当以上某个模块通过处理组件调度程序代码的形式实现时,该处理组件可以是通用处理器,例如中央处理器(Central Processing Unit,简称CPU)或其它可以调用程序代码的处理器。再如,这些模块可以集成在一起,以片上系统(system-on-a-chip,简称SOC)的形式实现。For example, the above modules may be one or more integrated circuits configured to implement the above method, for example: one or more specific integrated circuits (Application Specific Integrated Circuit, referred to as ASIC), or, one or more microprocessors ( Digital Signal Processor (DSP for short), or one or more Field Programmable Gate Arrays (Field Programmable Gate Array, FPGA for short), etc. For another example, when one of the above modules is implemented in the form of a processing component scheduler code, the processing component may be a general-purpose processor, such as a central processing unit (Central Processing Unit, CPU for short) or other processors that can call program codes. For another example, these modules can be integrated together and implemented in the form of a system-on-a-chip (SOC for short).
本发明的存储介质上存储有计算机程序,该程序被处理器执行时实现上述的Java本地接口一致性检查方法。所述存储介质包括:ROM、RAM、磁盘、U盘、存储卡或者光盘等各种可以存储程序代码的介质。The computer program is stored on the storage medium of the present invention, and when the program is executed by the processor, the above-mentioned method for checking the consistency of the Java local interface is realized. The storage medium includes: various media capable of storing program codes such as ROM, RAM, magnetic disk, U disk, memory card or optical disk.
如图3所示,于一实施例中,本发明的终端包括:处理器31及存储器32。As shown in FIG. 3 , in an embodiment, the terminal of the present invention includes: a processor 31 and a memory 32 .
所述存储器32用于存储计算机程序。The memory 32 is used to store computer programs.
所述存储器32包括:ROM、RAM、磁盘、U盘、存储卡或者光盘等各种可以存储程序代码的介质。The memory 32 includes various media capable of storing program codes such as ROM, RAM, magnetic disk, U disk, memory card or optical disk.
所述处理器31与所述存储器32相连,用于执行所述存储器32存储的计算机程序,以使所述终端执行上述的Java本地接口一致性检查方法。The processor 31 is connected to the memory 32, and is used to execute the computer program stored in the memory 32, so that the terminal executes the above Java native interface consistency checking method.
优选地,所述处理器31可以是通用处理器,包括中央处理器(Central ProcessingUnit,简称CPU)、网络处理器(Network Processor,简称NP)等;还可以是数字信号处理器(Digital Signal Processor,简称DSP)、专用集成电路(Application SpecificIntegrated Circuit,简称ASIC)、现场可编程门阵列(Field Programmable Gate Array,简称FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。Preferably, the processor 31 can be a general-purpose processor, including a central processing unit (Central Processing Unit, referred to as CPU), a network processor (Network Processor, referred to as NP), etc.; it can also be a digital signal processor (Digital Signal Processor, DSP for short), Application Specific Integrated Circuit (ASIC for short), Field Programmable Gate Array (Field Programmable Gate Array, FPGA for short) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
综上所述,本发明的Java本地接口一致性检查方法及系统、存储介质及终端在Native库链接阶段由JVM检查Native库中的symbol的完整信息,以确保Java声明中的接口与Native中的实现完全一致;在运行时对JNI一致性进行准确的检查,并在Java声明中的接口与Native中的实现不一致的情况下,立即抛出异常,完全可以避免由于JNI不一致所引起的程序不确定性行为。所以,本发明有效克服了现有技术中的种种缺点而具高度产业利用价值。In summary, the Java local interface consistency check method and system, storage medium and terminal of the present invention check the complete information of the symbol in the Native library by the JVM at the Native library link stage, to ensure that the interface in the Java statement is consistent with the symbol in the Native The implementation is completely consistent; the JNI consistency is accurately checked at runtime, and when the interface in the Java declaration is inconsistent with the implementation in Native, an exception is thrown immediately, which can completely avoid program uncertainty caused by JNI inconsistency sexual behavior. Therefore, the present invention effectively overcomes various shortcomings in the prior art and has high industrial application value.
上述实施例仅例示性说明本发明的原理及其功效,而非用于限制本发明。任何熟悉此技术的人士皆可在不违背本发明的精神及范畴下,对上述实施例进行修饰或改变。因此,举凡所属技术领域中具有通常知识者在未脱离本发明所揭示的精神与技术思想下所完成的一切等效修饰或改变,仍应由本发明的权利要求所涵盖。The above-mentioned embodiments only illustrate the principles and effects of the present invention, but are not intended to limit the present invention. Anyone skilled in the art can modify or change the above-mentioned embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or changes made by those skilled in the art without departing from the spirit and technical ideas disclosed in the present invention should still be covered by the claims of the present invention.
Claims (10)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910497314.XA CN110275710B (en) | 2019-06-10 | 2019-06-10 | Method and system for checking consistency of Java local interface, storage medium and terminal |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910497314.XA CN110275710B (en) | 2019-06-10 | 2019-06-10 | Method and system for checking consistency of Java local interface, storage medium and terminal |
Publications (2)
Publication Number | Publication Date |
---|---|
CN110275710A true CN110275710A (en) | 2019-09-24 |
CN110275710B CN110275710B (en) | 2023-07-14 |
Family
ID=67962055
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201910497314.XA Active CN110275710B (en) | 2019-06-10 | 2019-06-10 | Method and system for checking consistency of Java local interface, storage medium and terminal |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN110275710B (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112822193A (en) * | 2021-01-05 | 2021-05-18 | 网易(杭州)网络有限公司 | Application communication method, device, equipment and storage medium |
Citations (15)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6066181A (en) * | 1997-12-08 | 2000-05-23 | Analysis & Technology, Inc. | Java native interface code generator |
US6295643B1 (en) * | 1998-12-10 | 2001-09-25 | International Business Machines Corporation | Method and apparatus for improving java virtual machine performance using persistent execution information |
US20030110024A1 (en) * | 2001-06-21 | 2003-06-12 | Broussard Scott J. | Standardized interface between java virtual machine classes and a host operating environment |
US20050028155A1 (en) * | 2002-12-02 | 2005-02-03 | Samsung Electronics Co., Ltd. | Java execution device and Java execution method |
CN1848088A (en) * | 2005-02-18 | 2006-10-18 | 国际商业机器公司 | Method and apparatus for transforming java native interface function calls into simpler operations during just-in-time compilation |
US20090172652A1 (en) * | 2007-12-31 | 2009-07-02 | Simon Douglas N | Method And Apparatus For Portable Stub Generation |
US20120159477A1 (en) * | 2010-12-17 | 2012-06-21 | Oracle International Corporation | System and method for providing direct socket i/o for java in a virtual machine |
CN103368673A (en) * | 2013-07-17 | 2013-10-23 | 工业和信息化部电信传输研究所 | Conformance testing adapter based on TTCN-3 |
CN103546342A (en) * | 2013-10-18 | 2014-01-29 | 工业和信息化部电信传输研究所 | A terminal consistency test method and API interface universal adapter used for the method |
WO2015192637A1 (en) * | 2014-06-17 | 2015-12-23 | 北京奇虎科技有限公司 | Method and apparatus for reinforced protection of software installation package |
WO2016119548A1 (en) * | 2015-01-27 | 2016-08-04 | 北京奇虎科技有限公司 | Method for preventing software decompilation, and method and apparatus for preventing decompilation software from starting |
US9483283B1 (en) * | 2014-11-20 | 2016-11-01 | Apptimize, Inc. | Enhanced code callback |
WO2017107706A1 (en) * | 2015-12-25 | 2017-06-29 | 北京奇虎科技有限公司 | Elf file protection method and system based on arm instruction virtualization |
CN107871066A (en) * | 2016-09-28 | 2018-04-03 | 传化物流集团有限公司 | Code compiling method and device based on Android system |
US20190087210A1 (en) * | 2017-09-20 | 2019-03-21 | Citrix Systems, Inc. | Java native interface and windows universal app hooking |
-
2019
- 2019-06-10 CN CN201910497314.XA patent/CN110275710B/en active Active
Patent Citations (15)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6066181A (en) * | 1997-12-08 | 2000-05-23 | Analysis & Technology, Inc. | Java native interface code generator |
US6295643B1 (en) * | 1998-12-10 | 2001-09-25 | International Business Machines Corporation | Method and apparatus for improving java virtual machine performance using persistent execution information |
US20030110024A1 (en) * | 2001-06-21 | 2003-06-12 | Broussard Scott J. | Standardized interface between java virtual machine classes and a host operating environment |
US20050028155A1 (en) * | 2002-12-02 | 2005-02-03 | Samsung Electronics Co., Ltd. | Java execution device and Java execution method |
CN1848088A (en) * | 2005-02-18 | 2006-10-18 | 国际商业机器公司 | Method and apparatus for transforming java native interface function calls into simpler operations during just-in-time compilation |
US20090172652A1 (en) * | 2007-12-31 | 2009-07-02 | Simon Douglas N | Method And Apparatus For Portable Stub Generation |
US20120159477A1 (en) * | 2010-12-17 | 2012-06-21 | Oracle International Corporation | System and method for providing direct socket i/o for java in a virtual machine |
CN103368673A (en) * | 2013-07-17 | 2013-10-23 | 工业和信息化部电信传输研究所 | Conformance testing adapter based on TTCN-3 |
CN103546342A (en) * | 2013-10-18 | 2014-01-29 | 工业和信息化部电信传输研究所 | A terminal consistency test method and API interface universal adapter used for the method |
WO2015192637A1 (en) * | 2014-06-17 | 2015-12-23 | 北京奇虎科技有限公司 | Method and apparatus for reinforced protection of software installation package |
US9483283B1 (en) * | 2014-11-20 | 2016-11-01 | Apptimize, Inc. | Enhanced code callback |
WO2016119548A1 (en) * | 2015-01-27 | 2016-08-04 | 北京奇虎科技有限公司 | Method for preventing software decompilation, and method and apparatus for preventing decompilation software from starting |
WO2017107706A1 (en) * | 2015-12-25 | 2017-06-29 | 北京奇虎科技有限公司 | Elf file protection method and system based on arm instruction virtualization |
CN107871066A (en) * | 2016-09-28 | 2018-04-03 | 传化物流集团有限公司 | Code compiling method and device based on Android system |
US20190087210A1 (en) * | 2017-09-20 | 2019-03-21 | Citrix Systems, Inc. | Java native interface and windows universal app hooking |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112822193A (en) * | 2021-01-05 | 2021-05-18 | 网易(杭州)网络有限公司 | Application communication method, device, equipment and storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN110275710B (en) | 2023-07-14 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN106462412B (en) | Structure identification of dynamically generated pattern-based classes | |
US5909580A (en) | Development system and methods with direct compiler support for detecting invalid use and management of resources and memory at runtime | |
US5907709A (en) | Development system with methods for detecting invalid use and management of resources and memory at runtime | |
US8458681B1 (en) | Method and system for optimizing the object code of a program | |
US8141035B2 (en) | Method for accessing internal states of objects in object oriented programming | |
US8578357B2 (en) | Endian conversion tool | |
US8429632B1 (en) | Method and system for debugging merged functions within a program | |
US20250199785A1 (en) | Compilation methods, compilers, and wasm virtual machines | |
CN114490103B (en) | Method, device and electronic device for calling operating system interface | |
CN113791767B (en) | Byte code modification method and device | |
US9141351B2 (en) | Indicators for resources with idempotent close methods in software programs | |
CN110609687A (en) | Compiling method, device, electronic equipment and storage medium | |
CN111399842B (en) | Code compiling method and device | |
CN111240987B (en) | Method and device for detecting migration program, electronic equipment and computer readable storage medium | |
CN114416057B (en) | Project code packaging method and device, terminal equipment and storage medium | |
CN108197020A (en) | Plug-in unit method of calibration, electronic equipment and computer storage media | |
CN110275710B (en) | Method and system for checking consistency of Java local interface, storage medium and terminal | |
CN101002174A (en) | Method for loading software with an intermediate object oriented language in a portable device | |
CN111367512B (en) | A method and device for creating Android library module dependencies in application development | |
US9141343B2 (en) | Indicators for resources with close methods that do not complete erroneously in software programs | |
CN116719531B (en) | Object conversion method, system and medium based on runtime bytecode editing | |
US20240036887A1 (en) | Intercepting calls to a dynamic library | |
CN114237770A (en) | A microservice link invocation method, system, device and medium | |
Császár et al. | Building fast and reliable reverse engineering tools with Frida and Rust | |
CN112631650A (en) | Plug-in version information checking method, computing device and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant | ||
CP03 | Change of name, title or address | ||
CP03 | Change of name, title or address |
Address after: 100037 No. 31, Fuchengmenwai Street, Xicheng District, Beijing 4th Floor, Room 429D Patentee after: Tianyi Payment Technology Co.,Ltd. Country or region after: China Address before: 429D, 4th Floor, No. 31 Fuchengmenwai Street, Xicheng District, Beijing Patentee before: TIANYI ELECTRONIC COMMERCE Co.,Ltd. Country or region before: China |