WO2020192667A1 - 一种跨语言编译方法及设备 - Google Patents

一种跨语言编译方法及设备 Download PDF

Info

Publication number
WO2020192667A1
WO2020192667A1 PCT/CN2020/081000 CN2020081000W WO2020192667A1 WO 2020192667 A1 WO2020192667 A1 WO 2020192667A1 CN 2020081000 W CN2020081000 W CN 2020081000W WO 2020192667 A1 WO2020192667 A1 WO 2020192667A1
Authority
WO
WIPO (PCT)
Prior art keywords
language
language code
code
class
java
Prior art date
Application number
PCT/CN2020/081000
Other languages
English (en)
French (fr)
Inventor
蒋奕
陈永健
张超
赵俊民
张雁
Original Assignee
华为技术有限公司
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Priority to EP20776538.9A priority Critical patent/EP3937011A4/en
Publication of WO2020192667A1 publication Critical patent/WO2020192667A1/zh
Priority to US17/484,504 priority patent/US20220012029A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/51Source to source
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/47Retargetable compilers
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/43Checking; Contextual analysis
    • G06F8/433Dependency analysis; Data or control flow analysis
    • G06F8/434Pointers; Aliasing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/447Target code generation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45504Abstract machines for programme code execution, e.g. Java virtual machine [JVM], interpreters, emulators
    • G06F9/45516Runtime code conversion or optimisation
    • G06F9/4552Involving translation to a different instruction set architecture, e.g. just-in-time translation in a JVM

Definitions

  • This application relates to computer code compilation technology, and in particular to a cross-language hybrid compilation technology.
  • Java, JavaScript, Python, etc. all support mixed programming with C/C++.
  • C/C++ the native language code and non-native language code are invisible to each other during the compilation process. In this case, cross-function compilation optimization can only be performed within the scope of the same language function.
  • Java Virtual Machine Java programs are compiled into bytecodes independent of the machine and operating system.
  • the C/C++ program is compiled into a binary executable program related to the target machine.
  • Java programs and C/C++ programs are invisible to each other.
  • the Java bytecode is first interpreted and executed by the interpreter. When the number of times the same code is executed reaches a certain threshold, it will be compiled into a machine-related binary code, and then the compiled binary code will be executed.
  • Java functions call C/C++ functions through JNI
  • C/C++ functions call Java codes and access Java objects/Java objects through reflection mechanisms. Due to the need to be compatible with different VMs and the Java code and C/C++ code are invisible to each other, the Java Native Interface (JNI) and reflection mechanism must be implemented in the most conservative manner. Therefore, the overhead of JNI and reflection mechanism is huge.
  • JNI Java Native Interface
  • the present application provides a compilation method and device, which reduce the cost of calling each other between native language and non-native language methods during runtime of a compiled executable program.
  • the present application provides a compilation method, the method includes: obtaining source program code, the source program code includes a first language code and a second language code, the first language code includes the first method, the The second language code includes a second method, wherein the first language code is a local language, and the second language code is a non-native language.
  • the third language code includes a third method and a fourth method, the third method is generated according to the first method, the fourth method is generated according to the second method
  • the third language code further includes a fifth method, which is generated according to the first method and the second method or generated according to the third method and the fourth method, and The fifth method is used by the third method to invoke the fourth method through the fifth method or the fourth method to invoke the third method through the fifth method.
  • the third method can be an intermediate language, that is, the source code that contains the local language and the non-local language is converted into the same intermediate language.
  • the intermediate language contains methods that can be used to call each other between the methods corresponding to the local language and the non-local language. Because the compiler can obtain the method information of the local language and the non-local language at the same time through the intermediate language, when generating the calling method between the local language and the non-local language, the method can be called according to the method information of the local language and the non-local language. Optimization, thereby reducing the overhead of calling each other between native language and non-native language methods at runtime.
  • the method of the intermediate language will have a function attribute identifier, which is used to indicate whether the method of the intermediate language is converted from a local language or converted from a non-local language. This flag can be used when exiting the stack quickly when an exception occurs during operation.
  • the calling method in the intermediate language is used to combine the method transformed by the non-native language and the method transformed by the local language at runtime to jointly complete the method of the non-native language transformation and the local language transformation method. Between calls.
  • the method transformed from the non-local language and the method transformed from the local language can be integrated into the calling method by inline, so that at runtime, the calling method can be Independently realize the mutual call between the method transformed by non-local language and the method transformed by local language.
  • the fifth method in the third language code may be optimized based on the first language code, the second language code, or the generated third language code.
  • the fifth method when the fifth method is generated, it is determined whether the first method or the third method will be abnormal, and if so, the fifth method for the fourth method to call the third method is generated,
  • the fifth method includes an exception handling function.
  • This implementation method generates the calling function at the compilation stage, and only when the native language will generate an exception It contains the exception handling function, thereby reducing the exception handling overhead at runtime.
  • the first method accesses the object in the second language code, and if so, when the third language code is generated according to the source program code, the object reference table in the second language code is generated .
  • the first method can analyze the object reference in the second language code, create an object reference table on demand, and release the references that are no longer used in time. As a result, you can reduce the cost of creating an object reference table
  • the JNI interface pointer in the second language code, and if so, the JNI interface pointer is added to the parameters of the fifth method.
  • the third language code further includes the domain information of the class, the method information of the class, and the inheritance relationship of the class in the second language code.
  • a possible implementation manner is to determine the signature of the second method in the second language code according to the inheritance relationship of the class and the method information of the class, and the signature is used to indicate the second language code The name of the second method in and the class of the second method in, generate the fifth method according to the signature.
  • a sixth method is generated in the third language code, and the sixth method is used to access the domain in the second language code .
  • the data required for non-local language reflection is generated in the third language code, including metadata information of the class, domain information of the class, and method information of the class.
  • the interface function table of the class when the third language code is generated, can be generated.
  • the interface function table includes a hash table and a conflict elimination table, and the program is executed to the class at runtime.
  • An interface function uses the hash value of the function signature to search in the hash table, and if found, returns the function address; otherwise, uses the function signature to search in the conflict elimination table and returns the function address. Since the calculation of the interface function table and the function signature hash value is done at compile time, you can use variable-length hash tables and try to use multiple hash functions to reduce conflicts and reduce the size of the hash table to reduce memory The purpose of consuming and improving virtual call performance.
  • the third method and the fourth method include an identifier, and the identifier is used to indicate that the third method generates according to a local language or the fourth method generates according to a non-native language.
  • the embodiments of the present application also provide a compiling device that includes one or more functional units for implementing the foregoing method steps.
  • the device includes multiple functional units, these functional units are usually the same as the foregoing method steps.
  • the device includes an acquisition module for acquiring program source code, and the program source code includes local language code and non-local language code.
  • Generating module which is used to generate intermediate language code, to convert the native language methods and non-native language methods in the source code into intermediate language methods, and to generate the intermediate language for non-native language conversion The method of calling each other between the method and the method transformed by the local language.
  • Optimization module which is used to optimize the generated intermediate language.
  • Compiler module which is used to generate executable binary executable program according to the analyzed and optimized intermediate language to complete the compilation process.
  • the functional unit can be implemented by software programs or hardware or a combination of software and hardware.
  • the embodiments of the present application also provide a computer system.
  • the computer system includes at least one processor and a memory, where the memory is used to store a software program, and when the software program is executed by the processor, the processor of the computer system is used to execute the method of the first aspect or any A method in implementation.
  • an embodiment of the present application further provides a storage medium for storing a computer program, and when the computer program is executed by a processor, the processor is used to implement any one of the methods provided in the first aspect.
  • the computer program may include one or more program units for implementing each step of the method.
  • the local language and non-local languages are converted into intermediate languages, and the calling method is generated according to the method calling relationship between the local language and the non-local language, Used for mutual calls between methods in the intermediate language.
  • the compiler can obtain the method information of the local language and the non-local language at the same time through the intermediate language, when generating the calling method between the local language and the non-local language, the method can be called according to the method information of the local language and the non-local language. optimization.
  • the embodiment of the present application reduces the overhead of calling each other between native language and non-native language methods at runtime.
  • Figure 1 is a schematic diagram of the compilation process of the mixed programming source code taking the mixed compilation of Java and C/C++ as an example
  • FIG. 2 is a schematic structural diagram of a terminal device provided by an embodiment of the present application.
  • Fig. 3 is a schematic diagram of a running environment of a Java-based operating system provided by an embodiment of the present application
  • FIG. 4 is a flowchart of a method in the compilation phase provided by an embodiment of the present application.
  • Figure 5 is a schematic diagram of a class inheritance relationship provided by an embodiment of the present application.
  • FIG. 6 is a schematic diagram of a virtual function table of a class provided by an embodiment of the present application.
  • FIG. 7 is a schematic diagram of a type of interface function hash table and conflict elimination table provided by an embodiment of the present application.
  • FIG. 8 is a diagram of a code example provided by an embodiment of the present application.
  • FIG. 9 is another code example diagram provided by an embodiment of the present application.
  • FIG. 10 is a flowchart of an optimization process of an intermediate language provided by an embodiment of the present application.
  • FIG. 11 is a flowchart of another intermediate language optimization process provided by an embodiment of the present application.
  • FIG. 12 is a flowchart of another intermediate language optimization process provided by an embodiment of the present application.
  • Fig. 13 is a logical structure diagram of a compiling system provided by an embodiment of the present application.
  • Native Language also known as native language, refers to the development of a certain type of special equipment, only dedicated to the specified target equipment, can not be transplanted to other equipment, or even if it can be transplanted, but work efficiency Very low communication language or coding.
  • C/C++ language is a typical local language.
  • Non-native language also known as non-native language, refers to a programming language that realizes platform independence, that is, it can be used on a variety of different devices or platforms. Non-native languages can realize the versatility of the platform through the operating environment. For example, JAVA is a typical non-native language.
  • Java Virtual Machine is a virtual computer component that only exists in memory.
  • the JVM allows Java programs to be executed on different platforms instead of just being executed on the one platform for which the code is compiled. Java programs are compiled for the JVM.
  • Java can support applications for many types of data processing systems, which can include a variety of central processing units and operating system architectures.
  • the compiler In order to enable Java applications to be executed on different types of data processing systems, the compiler usually generates an architecture-neutral file format-the compiled code can be executed on many processors, provided that the Java runtime system exists.
  • the Java compiler generates bytecode instructions that are not specific to a specific computer architecture. Bytecode is a machine-independent code generated by a Java compiler and interpreted by a Java interpreter.
  • the Java interpreter is a module in the JVM that alternately decodes and executes one or more bytecodes. These bytecode instructions are designed to be easy to interpret on any machine, and are easy to be dynamically (on the fly) converted into native machine
  • Java language is designed to be platform-independent and mainly executed in a secure environment
  • programmers can use C-style calling conventions to use the compiled native language on the host operating system through the Java Native Interface (JNI), thereby Extend Java applications.
  • JNI Java Native Interface
  • Java applications can have full access to the host operating system, including reading or writing additional I/O devices, memory, etc.
  • Java programs can become platform-specific to complete tasks that are not normally allowed by the JVM.
  • the embodiments of the present application are used in the compilation of source code for hybrid programming.
  • the source code of mixed programming includes both local language code and non-local language code.
  • Local language and non-local language function methods in addition to calling their respective function methods, for example, local language methods call local language function methods or non-local language function methods call non-local language function methods, but local language function methods may also appear Mutual calls with non-native language function methods.
  • the existing compilation method since the native language and the non-native language are compiled independently of each other, when the native language is compiled, the non-native language is invisible to them; and when the non-native language is compiled, the native language is Is invisible.
  • Java Virtual Machine Java programs are compiled into Java bytecode independent of the machine and operating system.
  • the C/C++ program is compiled into a binary executable program related to the target machine.
  • Java programs and C/C++ programs are invisible to each other.
  • the Java bytecode is first interpreted and executed by the interpreter. When the number of times the same piece of code is executed reaches a certain threshold, it will be compiled into machine-related binary code immediately, and then the binary code after just-in-time compilation will be executed.
  • Java functions call C/C++ functions through JNI
  • C/C++ functions call Java codes and access Java objects/Java class objects through reflection mechanisms.
  • FIG. 2 shows an exemplary structural diagram of the terminal device 100.
  • the terminal device 100 includes: an application processor 101, a microcontroller unit (microcontroller unit, MCU) 103, a memory 105, a modem (modem) 107, a radio frequency (RF) module 109, and a wireless fidelity (Wireless -Fidelity, Wi-Fi for short) module 111, Bluetooth module 113, sensor 114, positioning module 150, input/output (I/O) device 115 and other components.
  • These components can communicate through one or more communication buses or signal lines.
  • the hardware structure shown in FIG. 1 does not constitute a limitation on the mobile phone, and the mobile phone 100 may include more or less components than those shown in the figure, or combine some components, or arrange different components.
  • the application processor 101 is the control center of the terminal 100, and uses various interfaces and buses to connect various components of the terminal device 100.
  • the processor 101 may include one or more processing units.
  • the memory 105 stores computer programs, such as the operating system 161 and application programs 163 shown in FIG. 2.
  • the application processor 101 is configured to execute a computer program in the memory 105 to implement functions defined by the computer program.
  • the application processor 101 executes an operating system 161 to implement various functions of the operating system on the terminal device 100.
  • the memory 105 also stores other data besides computer programs, such as data generated during the running of the operating system 161 and the application program 163.
  • the memory 105 is a non-volatile storage medium, and generally includes a memory and an external memory.
  • Memory includes, but is not limited to, random access memory (Random Access Memory, RAM), read-only memory (Read-Only Memory, ROM), or cache (cache).
  • External storage includes but is not limited to flash memory, hard disk, optical disk, universal serial bus (USB) disk, etc.
  • Computer programs are usually stored in external memory, and the processor loads the program from external memory to memory before executing the computer program.
  • the memory 105 may be independent and connected to the application processor 101 through a bus; the memory 105 and the application processor 101 may also be integrated into a chip subsystem.
  • MCU 103 is a co-processor used to acquire and process data from sensors 114.
  • the processing power and power consumption of MCU 103 are less than that of application processor 101, but it has the feature of "always on” and can be used in application processors.
  • 101 continuously collects and processes sensor data when it is in sleep mode to ensure the normal operation of the sensor with extremely low power consumption.
  • the MCU103 may be a sensor hub chip.
  • the sensor 114 may include a light sensor and a motion sensor.
  • the light sensor may include an ambient light sensor and a proximity sensor. The ambient light sensor can adjust the brightness of the display 151 according to the brightness of the ambient light, and the proximity sensor can turn off the power of the display screen when the terminal device 100 is moved to the ear .
  • the accelerometer sensor can detect the magnitude of acceleration in various directions (usually three axes), and can detect the magnitude and direction of gravity when stationary; the sensor 114 can also include a gyroscope, barometer, hygrometer, Other sensors such as thermometers, infrared sensors, etc. will not be described here.
  • the MCU 103 and the sensor 114 may be integrated on the same chip, or may be separate components, connected by a bus.
  • the Modem 107 and the radio frequency module 109 constitute the communication subsystem of the terminal device 100, which is used to implement the main functions of 3GPP, ETSI and other wireless communication standard protocols. Among them, Modem 107 is used for encoding and decoding, signal modulation and demodulation, and equalization.
  • the radio frequency module 109 is used for receiving and transmitting wireless signals.
  • the radio frequency module 109 includes but is not limited to an antenna, at least one amplifier, a coupler, a duplexer, and the like.
  • the radio frequency module 109 cooperates with the Modem 107 to realize the wireless communication function.
  • Modem 107 can be used as a standalone chip, or it can be combined with other chips or circuits to form a system-level chip or integrated circuit. These chips or integrated circuits can be applied to all terminal devices that implement wireless communication functions, including: mobile phones, computers, notebooks, tablets, routers, wearable devices, automobiles, home appliances, etc.
  • the terminal device 100 may also use the Wi-Fi module 111, the Bluetooth module 113, etc. to perform wireless communication.
  • the Wi-Fi module 111 is used to provide the terminal device 100 with network access that complies with Wi-Fi related standard protocols.
  • the terminal device 100 can access a Wi-Fi access point through the Wi-Fi module 111 to access the Internet.
  • the Wi-Fi module 111 can also be used as a Wi-Fi wireless access point, which can provide Wi-Fi network access for other terminal devices.
  • the Bluetooth module 113 is used to implement short-distance communication between the terminal device 100 and other terminal devices (such as mobile phones, smart watches, etc.).
  • the Wi-Fi module 111 in the embodiment of the present application may be an integrated circuit or a Wi-Fi chip, and the Bluetooth module 113 may be an integrated circuit or a Bluetooth chip.
  • the positioning module 150 is used to determine the geographic location of the terminal device 100. It is understandable that the positioning module 150 may specifically be a receiver of a positioning system such as a global positioning system (GPS), Beidou satellite navigation system, and Russian GLONASS.
  • GPS global positioning system
  • Beidou satellite navigation system Beidou satellite navigation system
  • Russian GLONASS Russian GLONASS
  • the Wi-Fi module 111, the Bluetooth module 113 and the positioning module 150 may be separate chips or integrated circuits, respectively, or they may be integrated together.
  • the Wi-Fi module 111, the Bluetooth module 113 and the positioning module 150 may be integrated on the same chip.
  • the Wi-Fi module 111, the Bluetooth module 113, the positioning module 150, and the MCU 103 may also be integrated into the same chip.
  • the input/output device 115 includes, but is not limited to: a display 151, a touch screen 153, an audio circuit 155, and so on.
  • the touch screen 153 can collect touch events on or near the user of the terminal device 100 (for example, the user uses a finger, a stylus or any other suitable object to operate on the touch screen 153 or near the touch screen 153), and Send the collected touch events to other devices (for example, the application processor 101).
  • the user's operation near the touch screen 153 can be referred to as a floating touch; through the floating touch, the user can select, move or drag a target (such as an icon, etc.) without directly touching the touch screen 153.
  • the touch screen 153 can be implemented in multiple types such as resistive, capacitive, infrared, and surface acoustic wave.
  • the display (also called a display screen) 151 is used to display information input by the user or information presented to the user.
  • the display can be configured in the form of a liquid crystal display, organic light emitting diode, etc.
  • the touch screen 153 can be overlaid on the display 151. When the touch screen 153 detects a touch event, it is transmitted to the application processor 101 to determine the type of the touch event, and then the application processor 101 can provide corresponding information on the display 151 according to the type of the touch event. Visual output.
  • the touch screen 153 and the display 151 are used as two independent components to realize the input and output functions of the terminal device 100, in some embodiments, the touch screen 153 and the display 151 can be integrated to realize the mobile phone 100 Input and output functions.
  • the touch screen 153 and the display 151 may be configured on the front of the terminal device 100 in the form of a full panel to achieve a frameless structure.
  • the audio circuit 1155, the speaker 116, and the microphone 117 may provide an audio interface between the user and the terminal device 100.
  • the audio circuit 109 can transmit the electrical signal converted from the received audio data to the speaker 113, which is converted into a sound signal for output by the speaker 113; on the other hand, the microphone 114 converts the collected sound signal into an electrical signal, and the audio circuit 109 After being received, it is converted into audio data, and then the audio data is sent to, for example, another terminal device through the Modem 107 and the radio frequency module 109, or the audio data is output to the memory 105 for further processing.
  • the terminal device 100 may also have a fingerprint recognition function.
  • a fingerprint collection device may be configured on the back of the terminal device 100 (for example, under the rear camera), or a fingerprint collection device may be configured on the front of the terminal device 100 (for example, under the touch screen 153).
  • a fingerprint collection device may be configured in the touch screen 153 to realize the fingerprint recognition function, that is, the fingerprint collection device may be integrated with the touch screen 153 to realize the fingerprint recognition function of the terminal device 100.
  • the fingerprint collection device is configured in the touch screen 153, may be a part of the touch screen 153, or may be configured in the touch screen 153 in other ways.
  • the main component of the fingerprint collection device in the embodiment of the present application is a fingerprint sensor, which can use any type of sensing technology, including but not limited to optical, capacitive, piezoelectric or ultrasonic sensing technology.
  • the operating system 161 carried by the terminal device 100 may be Or other operating systems, this embodiment of the application does not impose any restriction on this.
  • the terminal device 100 can be logically divided into a hardware layer, an operating system 161, and an application layer.
  • the hardware layer includes hardware resources such as the hardware processor 101, the microcontroller unit 105, the Modem 107, the Wi-Fi module 111, the sensor 114, and the positioning module 150 as described above.
  • the application layer 31 includes one or more applications, such as an application 163.
  • the application 163 may be any type of application such as a social application, an e-commerce application, or a browser.
  • the operating system 161, as a software middleware between the hardware layer and the application layer, is a computer program that manages and controls hardware and software resources.
  • the operating system 161 includes a kernel, a hardware abstraction layer (HAL) 25, a library and runtime, and a framework.
  • the kernel is used to provide underlying system components and services, such as: power management, memory management, thread management, hardware drivers, etc.; hardware drivers include Wi-Fi drivers, sensor drivers, positioning module drivers, etc.
  • the hardware abstraction layer encapsulates the kernel driver, provides an interface to the framework 29, and shields low-level implementation details.
  • the hardware abstraction layer runs in user space, while the kernel driver runs in kernel space.
  • the library and runtime are also called runtime libraries, which provide the required library files and execution environment for executable programs at runtime.
  • the library and the runtime include the Android Runtime (ART), the library, and the scene package runtime.
  • ART is a virtual machine or virtual machine instance that can convert bytecode of an application into machine code.
  • a library is a program library that provides support for executable programs at runtime, including browser engines (such as webkit), script execution engines (such as JavaScript engines), graphics processing engines, and so on.
  • the scene package runtime is the runtime environment of the scene package, which mainly includes the page execution environment (page context) and the script execution environment (script context).
  • the page execution environment parses the page code in html, css and other formats by calling the corresponding library.
  • the execution environment analyzes and executes code or executable files implemented by scripting languages such as JavaScript by calling the corresponding function library.
  • the framework is used to provide various basic public components and services for applications in the application layer 31, such as window management, location management, and so on.
  • the framework includes geofencing services, policy services, notification managers, etc.
  • the functions of the various components of the operating system 161 described above can all be implemented by the application processor 101 executing a program stored in the memory 105.
  • the terminal 100 may include fewer or more components than those shown in FIG. 2.
  • the terminal device shown in FIG. 2 only includes those that are more relevant to the multiple implementations disclosed in the embodiments of the present application. part.
  • the block diagram shows the relationship of various software components running in a computer system that can implement the present application.
  • the Java-based system includes a platform-specific operating system 302, which provides hardware and system support for software executed on a specific hardware platform.
  • JVM 304 is a software application that can be executed with the operating system.
  • the JVM 304 provides a Java runtime environment that has the ability to execute a Java application program 306.
  • the Java application or applet is a program, an applet, or a software component written in the Java programming language.
  • the computer system in which the JVM 304 runs may be similar to the data processing system 200 or the computer 100 described above. However, the JVM 304 can be implemented in a so-called Java chip with an embedded picoJava kernel, Java-on-silicon (java-on-silicon), or dedicated hardware on a Java processor.
  • the JVM At the center of the Java runtime environment is the JVM, which supports all aspects of the Java environment, including its architecture, security features, mobility across networks, and platform independence.
  • JVM is a virtual computer, that is, a computer that is specified abstractly.
  • the specification defines certain features that each JVM must implement, and has a range of design choices that can depend on the platform on which the JVM is designed to execute. For example, all JVMs must execute Java bytecode, and can use a series of techniques to execute instructions represented by bytecode.
  • the JVM can be implemented entirely in software or in hardware to some extent. This flexibility allows the design of different JVMs for mainframe computers and PDAs.
  • JVM is the name of a virtual computer component that actually executes Java programs. Java programs are not directly run by the central processing unit, but run by the JVM.
  • the JVM itself is a piece of software running on the processor.
  • the JVM allows Java programs to be executed on different platforms instead of just executing on the one platform for which the code is compiled. Java programs are compiled for the JVM.
  • Java can support applications for many types of data processing systems, which can include various central processing units and operating system architectures.
  • compilers typically generate architecture-neutral file formats.
  • the compiled code can be executed on many processors, as long as there is a Java runtime system.
  • the Java compiler generates bytecode instructions that are not specific to a specific computer architecture.
  • Bytecode is machine-independent code generated by a Java compiler and executed by a Java interpreter.
  • the Java interpreter is the part of the JVM that alternately decodes and interprets one or more bytecodes.
  • These bytecode instructions are designed to be easy to execute on any computer and easy to be dynamically (on the fly) converted to native machine code.
  • the bytecode can be converted to native code by a just-in-time (JIT) compiler.
  • the JVM loads the class file and executes the bytecode in it.
  • the class file is loaded by the class loader in the JVM.
  • the class loader loads the class file from the application and loads the class file from the Java application programming interface (API) required by the application.
  • API Java application programming interface
  • the execution engine that executes the bytecode can vary with different platforms and implementations.
  • Fig. 4 is a flow chart of a method of an embodiment of the present application. The method is applied in the compilation phase of program source code, and the details are as follows:
  • the obtained program source code is a program source code of mixed programming, including local language code and non-local language code.
  • the local language code contains the local language method
  • the non-local language contains the non-local language method. There are mutual calls between native language methods and non-native language methods.
  • S402 Generate an intermediate language code, and convert the native language method and the non-native language method in the source code into an intermediate language method.
  • the local language code and non-native language code in the program source code need to be converted into a common intermediate language representation, which is a kind of intermediate code.
  • the methods in the source code need to be converted into intermediate language methods.
  • the function body of the intermediate language method is the same for the intermediate language method converted from the native language and the non-native language method, and the difference lies in the scope of the function definition.
  • the intermediate language method corresponding to the native language method defines a global function
  • the intermediate language method corresponding to the non-native language method defines a class method in a class. Therefore, in the intermediate language method, the non-native language corresponding method retains the non-native language class information.
  • the native language C and the sub-native language Java respectively implement a method function foo in the code.
  • Java language and C/C++ language programs are first converted into a unified intermediate language representation. If C/C++ language defines a global foo function, and Java language defines a class method foo of the class internTest. After being transformed into an intermediate language identifier, the main difference between the Java language class method foo and the C/C++ language definition of the global function foo corresponding to the intermediate language method is that the definition of the class method retains the class information, and the first parameter of the function is this pointer. If a class method foo named internTest is defined in C++ language, and a class method foo of class internTest is defined in Java language, the method function body of the intermediate language converted by the two is the same, and the class information is also the same .
  • the method of the intermediate language will have a function attribute identifier, which is used to indicate whether the method of the intermediate language is converted from a local language or converted from a non-local language. This flag can be used when exiting the stack quickly when an exception occurs during operation.
  • the inheritance relationship (CHA) of the class can also be constructed in the intermediate language, for example, a virtual function table is generated in the intermediate language during the compilation stage according to the inheritance relationship.
  • CHA inheritance relationship
  • class B extend A ⁇ fooB(); ⁇
  • class C extend B ⁇ fooA(); ⁇
  • class D extend B ⁇ fooD(); ⁇
  • FIG. 5 The inheritance relationship of the four classes is shown in Figure 5.
  • Class B inherits class A
  • class C inherits class B
  • class D also inherits class B.
  • Figure 6 shows the virtual function table (VMT) of 4 classes.
  • VMT virtual function table
  • the index of the function in the virtual function table is also determined at compile time.
  • the process of performing virtual function timing is as follows: determine which class instance the object is, for example, determine which class instance a pointer is; use the function index in the virtual function table of the corresponding class Search to determine the function actually called; return the pointer of the function actually called.
  • the interface function table of the class can also be added to the intermediate language.
  • the interface function table contains a hash table and a conflict elimination table.
  • the function signature is used.
  • the hash value is searched in the hash table, and if found, the function address is returned; otherwise, the function signature is used to search in the conflict elimination table and the function address is returned.
  • class A implements B,C,D ⁇
  • Figure 7 depicts an example of the interface function hash table and conflict resolution table of class A.
  • the hash table fill the function pointer corresponding to fooC to the corresponding position according to the hash value of the function signature of fooC. If there is no function corresponding or there is more than one function corresponding (a conflict occurs), fill in 0.
  • the hash value of the signature of fooB is the same as the hash value of the signature of fooD, and the signature of each function and the corresponding function address are stored in the conflict elimination table.
  • data required for non-local language reflection is generated in the intermediate language code, including class metadata information, class domain information, and class method information.
  • the JNI interface functions such as GetMethodID and CallVoidMethod are converted into Intrinsic through the metadata information of the class, the domain information of the class, and the method information of the class, and the semantics of these Intrinsic can be known by the compiler.
  • box A shows a code example of C/C++ calling a Java function.
  • Box B, Box C, Box D respectively give the metadata information of the class generated in the intermediate language code at compile time, the method information of the class, and the data structure of the domain information of the class.
  • the function FindClass will search the ClassMetadata information of all classes, and find the ClassMetadata of the corresponding class by comparing the parameters and classname;
  • NewObjectA calls the Java method corresponding to con, and the pointer of the method is stored in addr in MethodMetadata to create a Java object;
  • GetFieldID finds the information of all the fields of the class through the fields in ClassMetadata, and then uses the second and third parameters (domain name, field type information) to find the corresponding field;
  • the function SetObjectField assigns a value to the fid field of the object jobj. If the field is a non-static field, the realOffset in the field information gives the offset of the field in the jobj object; if the field is static, the absAddress in the field information gives The address of the static domain.
  • the native language methods and non-native language methods that have a mutual calling relationship are mutually visible through the converted intermediate language methods during the compilation process . Therefore, based on the converted intermediate language method, the native language method and the non-native language method that originally have a mutual calling relationship can be analyzed and optimized, so as to generate an optimized method for mutual calling between the local language method and the non-native language method. .
  • the calling method in the intermediate language is used to combine the method transformed by the non-native language and the method transformed by the local language at runtime to jointly complete the method of the non-native language transformation and the local language transformation method. Between calls.
  • the method transformed from the non-local language and the method transformed from the local language can be integrated into the calling method by inline, so that at runtime, the calling method can be Independently realize the mutual call between the method transformed by non-local language and the method transformed by local language.
  • the following uses an example to illustrate how to generate in the intermediate language the calling method used for the mutual calling between the method converted from the non-native language and the method converted from the local language.
  • the Java class Callbacks declares to call a C/C++ function nativeMethod.
  • Box B describes the definition of the C/C++ function nativeMethod.
  • NativeMethod finally calls the class method callback of the Callbacks class by calling the JNI interface functions GetObjectClass, GetMethodID, and CallVoidMethod.
  • the function to be called can only be found through the parameter obj at runtime.
  • the method in box A and the method in box B are transformed into intermediate language representation, that is, for the compiler, the inheritance relationship of the Callbacks class and the definition of the function nativeMethod can be obtained at the same time.
  • the inheritance relationship of the Java-side Callbacks class can be passed to the C/C++ side through the compiler, and after the compiler knows the semantics of the JNI interface function, it can be analyzed to get that CallVoidMethod ultimately calls the class method callback of the Callbacks class. Therefore, the function in block C can be generated in the intermediate code. Compared with the nativeMethod function in box B, the function in box C deletes a parameter (JNI interface pointer) and the original JNI interface function call. The function in box C can be used to call each other between nativeMethod and non-native language method callback.
  • program analysis and optimization can also be performed on the Java and C/C++ functions in block A and block C.
  • the local language and non-local languages are converted into intermediate languages, and the calling method is generated according to the method calling relationship between the local language and the non-local language, Used for mutual calls between methods in the intermediate language.
  • the compiler can obtain the method information of the local language and the non-local language at the same time through the intermediate language, when generating the calling method between the local language and the non-local language, the calling method can be performed according to the method information of the local language and the non-local language. optimization.
  • the embodiment of the present application reduces the overhead of calling each other between native language and non-native language methods at runtime.
  • FIG. 10 it is an optimization process of an intermediate language provided by an embodiment of the present application. This embodiment is based on the embodiment described in FIG. 4, after being transformed into the intermediate code, a calling method for mutual invocation between the method used for non-native language conversion and the method converted from local language in the intermediate code is generated.
  • S1001 Determine whether an abnormality occurs in the local language method.
  • the compiler can determine whether the native language method will throw an exception when the native language method is called by the non-native language according to the converted native language method in the intermediate language.
  • an exception handling function is added to the calling method for calling the native language method in a non-native language. For example, in some examples, a call to checkPendingException can be added to the call function used for java to call C/C++ to implement the exception handling function.
  • the calling method when generating the calling method for non-native language invoking the native language, it will first determine whether the native language method will throw an exception when it is called by the non-native language, and then determine whether the method is being called according to the determination result Add exception handling function in.
  • the calling function is generated during the compilation stage, and exceptions are only generated in the native language.
  • the exception handling function is included only at the time, thereby reducing the exception handling overhead at runtime.
  • FIG. 11 it is another intermediate language optimization process provided by an embodiment of the invention. This embodiment is based on the embodiment described in FIG. 4, after being transformed into the intermediate code, a calling method for mutual invocation between the method used for non-native language conversion and the method converted from local language in the intermediate code is generated.
  • the compiler can determine whether the native language method will access the object in the non-native language according to the native language method that is called by the non-native language after conversion in the intermediate language.
  • Java objects In order to prevent Java objects from being recycled when C/C++ functions operate on Java objects, it is necessary to track all Java objects involved in the parameters. Usually these Java objects are composed of object reference tables.
  • object reference tables In the embodiment of the present application, when the intermediate code is generated, the reference situation of the Java object in the C/C++ program can be analyzed, the Java object reference table can be created on demand, and the references that are no longer used can be released in time. As a result, the cost of creating an object reference table can be reduced.
  • FIG. 12 it is another intermediate language optimization process provided by an embodiment of the invention.
  • This embodiment is based on the embodiment described in Figure 4, when the non-native language is Java, after being converted into the intermediate code, the method used for the non-native language conversion in the generated intermediate code and the method converted by the local language are called mutually Call method.
  • S1201. Determine whether the native language method accesses the JNI interface pointer in the Java code. If so, add the JNI interface pointer to the parameters of the method used for calling between the native language and the non-native language in the intermediate code; if not, , The JNI interface pointer is not added to the parameters of the calling method.
  • S1202. Determine whether the native language method accesses a Java object or a Java class object in the Java code, and if so, add the parameter of the method used for calling between the native language and the non-native language in the intermediate code. Java object or the Java class object; if it is not accessed, the Java object or the Java class object is not added to the parameters of the calling method.
  • the native language can be inlined into the calling method in the intermediate language or the method corresponding to the non-native language.
  • Java objects or Java class objects can reduce the call overhead caused by JNI interface pointers, Java objects or Java class objects.
  • FIG. 13 is a logical structure diagram of a compiling system 1300 provided by an embodiment of the present application.
  • the compiling system of this embodiment can be set on a compiler.
  • the system may include multiple logic units, each of which performs corresponding functions.
  • Logic units are divided according to the interaction of functions and information. It is understandable that each logic unit can be realized by software, or by hardware, and can be realized separately by different hardware, or by common hardware.
  • the division of logical units can also be adjusted according to different specific implementations, and the division in this embodiment is only exemplary. In this embodiment, the detailed description of each unit is as follows.
  • the obtaining module 1301 is used to obtain program source code, and the program source code includes local language code and non-native language code.
  • step S401 For the specific function implementation of the acquiring module, reference may be made to step S401 in the foregoing embodiment.
  • An intermediate language generation module 1302 which is used to generate intermediate language codes, and convert the native language methods and non-native language methods in the source code into intermediate language methods.
  • the intermediate language generation module 602 will have a function attribute identifier in the intermediate language method, which is used to indicate whether the intermediate language method is converted from a local language or converted from a non-local language. This flag can be used when exiting the stack quickly when an exception occurs during operation.
  • the intermediate language generation module 602 adds the interface function table of the class to the intermediate language.
  • the interface function table contains a hash table and a conflict elimination table.
  • the hash value of the function signature is searched in the hash table, and if found, the function address is returned; otherwise, the function signature is used to search in the conflict elimination table and the function address is returned.
  • the intermediate language generation module 602 generates data required for non-native language reflection in the intermediate language code, including metadata information of the class, domain information of the class, and method information of the class.
  • the JNI interface functions such as GetMethodID and CallVoidMethod are converted into Intrinsic through the metadata information of the class, the domain information of the class, and the method information of the class, and the semantics of these Intrinsic can be known by the compiler.
  • Invoke method generation module 1303, which is used to generate in the intermediate language an invoking method for mutual invocation between the method converted in the non-native language and the method converted in the local language.
  • the calling method in the intermediate language is used to combine the method transformed by the non-native language and the method transformed by the local language at runtime to jointly complete the method of the non-native language transformation and the local language transformation method. Between calls.
  • the method transformed from the non-local language and the method transformed from the local language can be integrated into the calling method by inline, so that at runtime, the calling method can be Independently realize the mutual call between the method transformed by non-local language and the method transformed by local language.
  • step S403 For calling the method generating module 1302, reference may be made to the description in step S403 in the foregoing embodiment.
  • the optimization module 1304 is used to optimize the generated intermediate language.
  • the optimization module 1304 is used to determine whether an exception occurs in the native language method, and if an exception occurs, an exception handling function is added to the calling method for calling the native language method in a non-native language.
  • the optimization module 1304 is used to determine whether the native language accesses objects in non-native languages, and if the native language method will access objects in non-native languages, the intermediate language code is generated based on the source program code. When generating non-native language code object reference table.
  • the optimization module 1304 is used to determine whether the native language method accesses the JNI interface pointer in the Java code, and if so, it is used in the intermediate code for the parameters of the calling method between native language and non-native language Add JNI interface pointer.
  • the optimization module 1304 is used to determine whether the native language method accesses Java objects or Java class objects in the Java code. If so, it is used in the intermediate code between native and non-native languages. Add the Java object or the Java class object to the parameters of the calling method.
  • optimization module 1304 For the optimization module 1304, reference may be made to the description in the method embodiment corresponding to FIG. 10, FIG. 11, and FIG.
  • Compilation module 1305, which is used to generate executable binary executable programs according to the analyzed and optimized intermediate language to complete the compilation process.
  • the local language and non-native language when compiling mixed source code containing local language and non-native language, the local language and non-native language are converted into intermediate language, and generated according to the method call relationship between local language and non-native language Invoking methods are used for mutual invocation between methods in the intermediate language. Because the compiler can obtain the method information of the local language and the non-local language at the same time through the intermediate language, when generating the calling method between the local language and the non-local language, the method can be called according to the method information of the local language and the non-local language. optimization. Compared with the prior art, the embodiment of the present application reduces the overhead of calling each other between native language and non-native language methods at runtime.
  • a method flow can also be implemented by hardware entity modules.
  • a programmable logic device Programmable Logic Device, PLD
  • PLD Programmable Logic Device
  • FPGA Field Programmable Gate Array
  • HDL Hardware Description Language
  • ABEL Advanced Boolean Expression Language
  • AHDL Altera Hardware Description Language
  • HDCal JHDL
  • Lava Lava
  • Lola MyHDL
  • PALASM RHDL
  • Verilog Verilog
  • modules or units can be implemented by computer chips or entities, or implemented by products with certain functions.
  • it can be implemented by the terminal system 100 corresponding to FIG. 2 described above.
  • a processor 101 and a memory 105 are connected through a bus.
  • the memory 105 can be used to store software programs, computer-executable programs, and modules, such as program instructions/modules corresponding to the method in any of the embodiments shown in FIGS. 4-12 of this application.
  • the processor 101 executes various functional applications and data processing of the computer device by running software programs, instructions, and modules stored in the memory 105, that is, realizes the above-mentioned method.
  • a typical implementation device is a computer.
  • the computer may be a personal computer, a server, a laptop computer, etc., for example.
  • the computing and communication capabilities of hardware devices will continue to increase. Therefore, it is foreseeable that in future technical implementations, various hardware devices with computing capabilities and communication capabilities will be used as the hardware devices of the aforementioned compilation system. For example, cellular phones, smart phones, personal digital assistants, media players, in-vehicle computers, IoT devices, navigation devices, gaming devices, tablet computers, etc.
  • the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, this application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
  • a computer-usable storage media including but not limited to disk storage, CD-ROM, optical storage, etc.
  • These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing equipment to work in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including the instruction device.
  • the device implements the functions specified in one process or multiple processes in the flowchart and/or one block or multiple blocks in the block diagram.
  • These computer program instructions can also be loaded on a computer or other programmable data processing equipment, so that a series of operation steps are executed on the computer or other programmable equipment to produce computer-implemented processing, so as to execute on the computer or other programmable equipment.
  • the instructions provide steps for implementing functions specified in a flow or multiple flows in the flowchart and/or a block or multiple blocks in the block diagram.
  • the process can be completed by a computer program instructing relevant hardware.
  • the program can be stored in a computer readable storage medium. , May include the processes of the foregoing method embodiments.
  • the aforementioned storage media include: ROM or random storage RAM, magnetic disks or optical discs and other media that can store program codes.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

本申请提供了一种跨语言编译的方法和装置。可用于本地语言和非本地语言,例如Java和C++之间的跨语言混合编译。通过获取包含本地语言和非本地语言的源程序代码,生成中间语言,中间语言中包含了基于本地语言和非本地语言的方法所生成的方法。在中间语言中生成调用方法,这些调用方法用于实现基于本地语言和非本地语言的方法所生成的方法之间的相互调用。降低编译后的可执行程序在运行时本地语言和非本地语言方法之间相互调用的开销。

Description

一种跨语言编译方法及设备
本申请要求于2019年3月25日提交中国国家知识产权局、申请号为201910228528.7、发明名称为“一种跨语言编译方法及设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及计算机代码编译技术,尤其涉及一种跨语言的混合编译技术。
背景技术
为了平衡开发效率和程序性能,本地语言和非本地语言混合编程成为一种趋势。例如:非本地语言Java,JavaScript,Python等都支持和C/C++混合编程。当编译混合编程的源代码时,由于在编译过程中,本地语言代码和非本地语言代码互相不可见。在这种情况下,跨函数的编译优化只能在同语言函数范围内进行。在Java虚拟机(Java Virtual Machine,JVM)中,Java程序被编译成与机器和操作系统无关的字节码。C/C++程序编译成目标机器相关的二进制可执行程序。在编译阶段,Java程序和C/C++程序互相不可见。在执行阶段,Java字节码首先通过解释器解释执行。当同一段代码被执行的次数达到某个阈值时,会被编译成机器相关的二进制代码,进而执行编译后的二进制代码。
在混合编程中,为了实现本地语言和非本地语言之间的函数调用,Java函数通过JNI调用C/C++函数,C/C++函数通过反射机制调用Java代码以及访问Java对象/Java类对象。由于要兼容不同的VM,并且Java代码和C/C++代码互相不可见,导致Java本地接口(Java Native Interface,JNI)和反射机制都必须采用最保守的实现方式。因此,JNI和反射机制的开销巨大。
发明内容
本申请提供一种编译方法和装置,降低编译后的可执行程序在运行时本地语言和非本地语言方法之间相互调用的开销。
第一方面,本申请提供了一种编译方法,该方法包括:获取源程序代码,源程序代码包括第一语言代码和第二语言代码,所述第一语言代码中包括第一方法,所述第二语言代码中包括第二方法,其中,所述第一语言代码为本地语言,所述第二语言代码为非本地语言。根据源程序代码生成第三语言代码,所述第三语言代码中包含第三方法和第四方法,所述第三方法根据所述第一方法所生成,所述第四方法根据第二方法所生成,所述第三语言代码还包括第五方法,所述第五方法根据所述第一方法和所述第二方法所生成或者根据所述第三方法和所述第四方法所生成,所述第五方法用于所述第三方法通过所述第五方法调用所述第四方法或者所述第四方法通过所述第五方法调用所述第三方法。
第三方法可以是一种中间语言,即将包含了本地语言和非本地语言的源程序代码转化为同一种中间语言。该中间语言中包含了可以用于在本地语言和非本地语言所对应的方法之间进行相互调用的方法。由于编译器通过中间语言可以同时获知本地语言 和非本地语言的方法信息,因此在生成本地语言与非本地语言之间的调用方法时,可以根据本地语言和非本地语言的方法信息对调用方法进行优化,从而降低了本地语言和非本地语言方法之间在运行时相互调用的开销。
在一些实现方式中,中间语言的方法中会带有一个函数属性标识,该标识用于指示中间语言的方法是由本地语言转化得到还是由非本地语言转化的倒的。该标识可以在在运行过程中出现异常时快速退栈时使用。
在一些实现方式中,中间语言中的调用方法用于在运行时结合非本地语言所转化的方法与本地语言所转化的方法,共同完成非本地语言所转化的方法与本地语言所转化的方法之间的调用。
在另一些实现方式中,在生成中间语言的调用方法时,非本地语言所转化的方法与本地语言所转化的方法可以通过内联的方式集成到调用方法中,从而在运行时,调用方法可以独立的实现非本地语言所转化的方法与本地语言所转化的方法之间的相互调用。
在生成第三语言代码中的第五方法时,可以基于第一语言代码、第二语言代码或者生成的第三语言代码对第三语言代码中的第五方法进行优化。
在一种实现方式中,生成第五方法时,判断所述第一方法或第三方法是否会出现异常,若是,则生成用于所述第四方法调用所述第三方法的第五方法,所述第五方法包含异常处理功能。相对于现有技术中调用本地语言方法时均需要在运行时调用异常处理来检查是否有未处理的异常对象,本实现方法在编译阶段即生成了调用函数,且仅在本地语言会产生异常时才包含异常处理功能,从而降低了运行时的异常处理开销。
在一种实现方式中,判断所述第一方法是否访问第二语言代码中的对象,若是,则在根据所述源程序代码生成第三语言代码时,生成第二语言代码中的对象引用表。在本实现方式中,可以在生成中间代码时,分析第一方法对第二语言代码中的对象引用情况,按需创建对象引用表,并及时释放不再使用的引用。由此,可以减少创建对象引用表所带来的开销
在一种实现方式中,判断所述第一方法是否访问第二语言代码中的JNI接口指针,若是,则在所述第五方法的参数中添加JNI接口指针。在另一种实现方式中,判断所述第一方法是否访问第二语言代码中的Java对象或者Java类对象,若是,则在所述第五方法的参数中添加所述Java对象或者所述Java类对象。从而,可以减少JNI接口指针、Java对象或者Java类对象所带来的调用开销。
在一种实现方式中,所述第三语言代码还包括所述第二语言代码中的类的域信息、类的方法信息以及类的继承关系。
其中,一种可能的实施方式为,根据所述类的继承关系和类的方法信息,确定所述第二方法在所述第二语言代码中的签名,所述签名用于指示第二语言代码中的所述第二方法的名称以及所述第二方法所在的类,根据所述签名生成所述第五方法。
在另一些可能的实施方式中,根据所述类的继承关系和类的域信息,在第三语言代码中生成第六方法,所述第六方法用于访问所述第二语言代码中的域。
在另一些可能的实施方式中,在第三语言代码中会生成非本地语言反射需要的数据,包括类的元数据信息,类的域信息,类的方法信息。
在另一些可能的实施方式中,还可以在在生成第三语言代码时,生成类的接口函数表,接口函数表包含一个哈希表和一个冲突消除表,在运行时程序执行到该类的一个接口函数,使用函数签名的哈希值在哈希表中查找,如果找到就返回函数地址;否则使用函数签名在冲突消除表中查找,并返回函数地址。由于接口函数表以及函数签名哈希值的计算都是在编译时刻完成的,所以可以使用变长的哈希表并尝试使用多种哈希函数来减少冲突降低哈希表的大小,达到降低内存消耗并提升虚拟调用性能的目的。
在一些实现方式中,所述第三方法和所述第四方法中包含有标识,所述标识用于指示所述第三方法根据本地语言生成或者指示所述第四方法根据非本地语言生成。
第二方面,本申请实施例还提供一种编译装置,该装置包含用于实现前述方法步骤的一个或多个功能单元,当该装置包含多个功能单元时,这些功能单元通常与前述方法步骤一一对应。举例来说,该装置包括了获取模块,该模块用于获取程序源代码,该程序源代码中包含本地语言代码和非本地语言代码。生成模块,该模块用于生成中间语言代码,将源代码中的本地语言的方法和非本地语言的方法转化为中间语言的方法,以及,用于在中间语言中生成用于非本地语言所转化的方法与本地语言所转化的方法之间相互调用的调用方法。优化模块,该模块用于对生成的中间语言进行优化。编译模块,该模块用于根据分析和优化后的中间语言,生成可执行的二进制可执行程序,完成编译过程。需要说明的是该功能单元可以全部采用软件程序或全部采用硬件或采用软硬件结合实现。
第三方面,本申请实施例还提供一种计算机系统。该计算机系统包括至少一个处理器和存储器,其中,该存储器用于存储软件程序,当所述软件程序被所述处理器执行时,该计算机系统的处理器用于执行前述第一方面的方法或者任意一个实现方式中的方法。
第四方面,本申请实施例还提供一种存储介质,用于存储计算机程序,当所述计算机程序被处理器执行时,所述处理器用于实现第一方面提供的任意一种方法。具体的,所述计算机程序可以包括用于实现方法各个步骤的一个或多个程序单元。
通过本申请实施例,在编译包含本地语言以及非本地语言的混合源代码时,通过将本地语言以及非本地语言转化为中间语言,并根据本地语言和非本地语言的方法调用关系生成调用方法,用于中间语言中的方法之间的相互调用。由于编译器通过中间语言可以同时获知本地语言和非本地语言的方法信息,因此在生成本地语言与非本地语言之间的调用方法时,可以根据本地语言和非本地语言的方法信息对调用方法进行优化。相对于现有技术,本申请实施例降低了本地语言和非本地语言方法之间在运行时相互调用的开销。
附图说明
为了更清楚地说明本申请实施例或背景技术中的技术方案,下面将对本申请实施例或背景技术中所需要使用的附图进行说明。
图1是以Java和C/C++的混合编译为例的混合编程的源代码的编译过程示意图;
图2是本申请实施例提供给的一种终端设备的结构示意图;
图3是本申请实施例提供的一种基于Java的操作系统的运行环境示意图;
图4是本申请实施例提供的一种编译阶段的方法流程图;
图5是本申请实施例提供的一种类的继承关系的示意图;
图6是本申请实施例提供的一种类的虚拟函数表的示意图;
图7是本申请实施例提供的一种类的接口函数哈希表和冲突消除表的示意图;
图8是本申请实施例提供的一种代码示例图;
图9是本申请实施例提供的又一种代码示例图;
图10是本申请实施例提供的一种中间语言的优化流程的流程图;
图11是本申请实施例提供的又一种中间语言的优化流程的流程图;
图12是本申请实施例提供的又一种中间语言的优化流程的流程图;
图13是本申请实施例提供的一种编译系统的逻辑结构图。
具体实施方式
为了方便对本申请实施例的理解,首先对本申请实施例中出现的一些技术名词进行解释。
本地语言(Native Language):又称为本机语言,指专门针对某类特别设备而开发,仅在规定的目标设备上专用,不能够移植到其他设备上使用,或者即使能够移植,但工作效率很低的通信语言或编码。例如C/C++语言即为一种典型的本地语言。
非本地语言:又称为非本机语言,指实现了平台无关性,即可以在多种不同的设备或者平台上的编程语言。非本地语言可以通过运行环境实现平台的通用性。例如JAVA即为一种典型的非本地语言。
Java虚拟机(JVM)是一种仅存在于存储器中的虚拟计算机组件。JVM允许Java程序在不同平台上被执行,而不是仅在为其编译代码的一个平台上被执行。Java程序是为JVM编译的。以这种方式,Java能够支持用于很多类型的数据处理系统的应用,这些数据处理系统可包含多种中央处理单元和操作系统体系结构。为了使得Java应用能在不同类型的数据处理系统上执行,编译器通常生成一体系结构中性的文件格式-编译的代码可在很多处理器上执行,倘若存在Java运行时系统地话。Java编译器生成非特定于具体计算机体系结构的字节码指令。字节码是由Java编译器生成并由Java解释器解释的独立于机器的代码。Java解释器是JVM中的交替地解码和执行一个或多个字节码的模块。这些字节码指令被设计为易于在任何机器上解释,并易于被动态地(on the fly)转换为本机机器码。
尽管Java语言被设计为是独立于平台的并主要在安全环境中执行,程序员可通过Java本机接口(JNI)使用C风格的调用约定来使用主机操作系统上的编译的本机语言,从而扩展Java应用。以这种方式,Java应用可具有对主机操作系统的完全访问权,包括对附加的I/O设备、存储器等的读或写。由于此,Java程序可以成为特定于平台的代价完成通过JVM通常不允许的任务。
当在编译的Java代码中通过JNI调用本机语言时,涉及到开销。例如,必须在运行时进行工作以便为进行调用准备该调用。一般而言,必须在调用本机函数时或之前加载包含该本机函数的本机库。也必须在运行时系统中解析(resolve)本机函数,并且必须更新相关的JVM数据结构以指示该本机函数的使用。
本申请实施例用于在对于混合编程的源代码的编译中。对于混合编程的源代码, 包括本地语言代码和非本地语言代码。本地语言和非本地语言的函数方法除了调用各自的函数方法,例如本地语言方法调用本地语言的函数方法或者非本地语言的函数方法调用非本地语言的函数方法外,还可能出现本地语言的函数方法与非本地语言的函数方法之间的相互调用。在现有的编译方法中,由于本地语言和非本地语言是相互独立进行编译的,在编译本地语言时,非本地语言对其是不可见的;而在编译非本地语言时,本地语言对其是不可见的。
参考图1,描述了以Java和C/C++的混合编译为例的混合编程的源代码的编译过程。在Java虚拟机(JVM)中,Java程序被编译成与机器和操作系统无关的Java字节码。C/C++程序编译成目标机器相关的二进制可执行程序。在编译阶段,Java程序和C/C++程序互相不可见。在执行阶段,Java字节码首先通过解释器解释执行。当同一段代码被执行的次数达到某个阈值时,会被即时编译成机器相关的二进制代码,进而执行即时编译后的二进制代码。Java函数通过JNI调用C/C++函数,C/C++函数通过反射机制调用Java代码以及访问Java对象/Java类对象。
图2示出了终端设备100的一个示例性的结构示意图。根据图2,终端设备100包括:应用处理器101、微控制器单元(microcontroller unit,MCU)103、存储器105、调制解调器(modem)107、射频(radio frequency,RF)模块109、无线保真(Wireless-Fidelity,简称Wi-Fi)模块111、蓝牙模块113、传感器114、定位模块150、输入/输出(input/output,I/O)设备115等部件。这些部件可通过一根或多根通信总线或信号线进行通信。本领域技术人员可以理解,图1中示出的硬件结构并不构成对手机的限定,手机100可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置。
下面结合图2对终端设备100的各个部件进行具体的介绍:
应用处理器101是终端100的控制中心,利用各种接口和总线连接终端设备100的各个部件。在一些实施例中,处理器101可包括一个或多个处理单元。
存储器105中存储有计算机程序,诸如图2所示的操作系统161和应用程序163。应用处理器101被配置用于执行存储器105中的计算机程序,从而实现该计算机程序定义的功能,例如应用处理器101执行操作系统161从而在终端设备100上实现操作系统的各种功能。存储器105还存储有除计算机程序之外的其他数据,诸如操作系统161和应用程序163运行过程中产生的数据。存储器105为非易失性存储介质,一般包括内存和外存。内存包括但不限于随机存取存储器(Random Access Memory,RAM),只读存储器(Read-Only Memory,ROM),或高速缓存(cache)等。外存包括但不限于闪存(flash memory)、硬盘、光盘、通用串行总线(universal serial bus,USB)盘等。计算机程序通常被存储在外存上,处理器在执行计算机程序前会将该程序从外存加载到内存。
存储器105可以是独立的,通过总线与应用处理器101相连接;存储器105也可以和应用处理器101集成到一个芯片子系统。
MCU 103是用于获取并处理来自传感器114的数据的协处理器,MCU 103的处理能力和功耗小于应用处理器101,但具有“永久开启(always on)”的特点,可以在应用处理器101处于休眠模式时持续收集以及处理传感器数据,以极低的功耗保障传 感器的正常运行。在一个实施例中,MCU103可以为sensor hub芯片。传感器114可以包括光传感器、运动传感器。具体地,光传感器可包括环境光传感器及接近传感器,其中,环境光传感器可根据环境光线的明暗来调节显示器151的亮度,接近传感器可在终端设备100移动到耳边时,关闭显示屏的电源。作为运动传感器的一种,加速计传感器可检测各个方向上(一般为三轴)加速度的大小,静止时可检测出重力的大小及方向;传感器114还可以包括陀螺仪、气压计、湿度计、温度计、红外线传感器等其它传感器,在此不再赘述。MCU 103和传感器114可以集成到同一块芯片上,也可以是分离的元件,通过总线连接。
Modem 107以及射频模块109构成了终端设备100通信子系统,用于实现3GPP、ETSI等无线通信标准协议的主要功能。其中,Modem 107用于编解码、信号的调制解调、均衡等。射频模块109用于无线信号的接收和发送,射频模块109包括但不限于天线、至少一个放大器、耦合器、双工器等。射频模块109配合Modem 107实现无线通信功能。Modem 107可以作为单独的芯片,也可以与其他芯片或电路在一起形成系统级芯片或集成电路。这些芯片或集成电路可应用于所有实现无线通信功能的终端设备,包括:手机、电脑、笔记本、平板、路由器、可穿戴设备、汽车、家电设备等。
终端设备100还可以使用Wi-Fi模块111,蓝牙模块113等来进行无线通信。Wi-Fi模块111用于为终端设备100提供遵循Wi-Fi相关标准协议的网络接入,终端设备100可以通过Wi-Fi模块111接入到Wi-Fi接入点,进而访问互联网。在其他一些实施例中,Wi-Fi模块111也可以作为Wi-Fi无线接入点,可以为其他终端设备提供Wi-Fi网络接入。蓝牙模块113用于实现终端设备100与其他终端设备(例如手机、智能手表等)之间的短距离通信。本申请实施例中的Wi-Fi模块111可以是集成电路或Wi-Fi芯片等,蓝牙模块113可以是集成电路或者蓝牙芯片等。
定位模块150用于确定终端设备100的地理位置。可以理解的是,定位模块150具体可以是全球定位系统(global position system,GPS)或北斗卫星导航系统、俄罗斯GLONASS等定位系统的接收器。
Wi-Fi模块111,蓝牙模块113和定位模块150分别可以是单独的芯片或集成电路,也可以集成到一起。例如,在一个实施例中,Wi-Fi模块111,蓝牙模块113和定位模块150可以集成到同一芯片上。在另一个实施例中,Wi-Fi模块111,蓝牙模块113、定位模块150以及MCU 103也可以集成到同一芯片中。
输入/输出设备115包括但不限于:显示器151、触摸屏153,以及音频电路155等等。
其中,触摸屏153可采集终端设备100的用户在其上或附近的触摸事件(比如用户使用手指、触控笔等任何适合的物体在触摸屏153上或在触控屏触摸屏153附近的操作),并将采集到的触摸事件发送给其他器件(例如应用处理器101)。其中,用户在触摸屏153附近的操作可以称之为悬浮触控;通过悬浮触控,用户可以在不直接接触触摸屏153的情况下选择、移动或拖动目标(例如图标等)。此外,可以采用电阻式、电容式、红外线以及表面声波等多种类型来实现触摸屏153。
显示器(也称为显示屏)151用于显示用户输入的信息或展示给用户的信息。可以采用液晶显示屏、有机发光二极管等形式来配置显示器。触摸屏153可以覆盖在显 示器151之上,当触摸屏153检测到触摸事件后,传送给应用处理器101以确定触摸事件的类型,随后应用处理器101可以根据触摸事件的类型在显示器151上提供相应的视觉输出。虽然在图2中,触摸屏153与显示器151是作为两个独立的部件来实现终端设备100的输入和输出功能,但是在某些实施例中,可以将触摸屏153与显示器151集成而实现手机100的输入和输出功能。另外,触摸屏153和显示器151可以以全面板的形式配置在终端设备100的正面,以实现无边框的结构。
音频电路1155、扬声器116、麦克风117可提供用户与终端设备100之间的音频接口。音频电路109可将接收到的音频数据转换后的电信号,传输到扬声器113,由扬声器113转换为声音信号输出;另一方面,麦克风114将收集的声音信号转换为电信号,由音频电路109接收后转换为音频数据,再通过Modem 107和射频模块109将音频数据发送给比如另一终端设备,或者将音频数据输出至存储器105以便进一步处理。
另外,终端设备100还可以具有指纹识别功能。例如,可以在终端设备100的背面(例如后置摄像头的下方)配置指纹采集器件,或者在终端设备100的正面(例如触摸屏153的下方)配置指纹采集器件。又例如,可以在触摸屏153中配置指纹采集器件来实现指纹识别功能,即指纹采集器件可以与触摸屏153集成在一起来实现终端设备100的指纹识别功能。在这种情况下,该指纹采集器件配置在触摸屏153中,可以是触摸屏153的一部分,也可以以其他方式配置在触摸屏153中。本申请实施例中的指纹采集器件的主要部件是指纹传感器,该指纹传感器可以采用任何类型的感测技术,包括但不限于光学式、电容式、压电式或超声波传感技术等。
进一步地,终端设备100搭载的操作系统161可以为
Figure PCTCN2020081000-appb-000001
或者其它操作系统,本申请实施例对此不作任何限制。
以搭载
Figure PCTCN2020081000-appb-000002
操作系统的终端设备100为例,终端设备100从逻辑上可划分为硬件层、操作系统161,以及应用层。硬件层包括如上所述的硬件处理器101、微控制器单元105、Modem 107、Wi-Fi模块111、传感器114、定位模块150等硬件资源。应用层31包括一个或多个应用程序,比如应用程序163,应用程序163可以为社交类应用、电子商务类应用、浏览器等任意类型的应用程序。操作系统161作为硬件层和应用层之间的软件中间件,是管理和控制硬件与软件资源的计算机程序。
在一个实施例中,操作系统161包括内核,硬件抽象层(hardware abstraction layer,HAL)25、库和运行时(libraries and runtime)以及框架(framework)。其中,内核用于提供底层系统组件和服务,例如:电源管理、内存管理、线程管理、硬件驱动程序等;硬件驱动程序包括Wi-Fi驱动、传感器驱动、定位模块驱动等。硬件抽象层是对内核驱动程序的封装,向框架29提供接口,屏蔽低层的实现细节。硬件抽象层运行在用户空间,而内核驱动程序运行在内核空间。
库和运行时也叫做运行时库,它为可执行程序在运行时提供所需要的库文件和执行环境。在一个实施例中,库与运行时包括安卓运行时(Android Runtime,ART),库,以及场景包运行时。ART是能够把应用程序的字节码转换为机器码的虚拟机或虚拟机实例。库是为可执行程序在运行时提供支持的程序库,包括浏览器引擎(比如webkit)、脚本执行引擎(比如JavaScript引擎)、图形处理引擎等。场景包运行时是 场景包的运行环境,主要包括页面执行环境(page context)和脚本执行环境(script context),其中,页面执行环境通过调用相应的库解析html、css等格式的页面代码,脚本执行环境通过调用相应的功能库解析执行JavaScript等脚本语言实现的代码或可执行文件。
框架用于为应用层31中的应用程序提供各种基础的公共组件和服务,比如窗口管理、位置管理等等。在一个实施例中,框架包括地理围栏服务,策略服务,通知管理器等。
以上描述的操作系统161的各个组件的功能均可以由应用处理器101执行存储器105中存储的程序来实现。
所属领域的技术人员可以理解终端100可包括比图2所示的更少或更多的部件,图2所示的该终端设备仅包括与本申请实施例所公开的多个实现方式更加相关的部件。
参照图3,该框图示出了在可实现本申请的计算机系统内运行的各软件组件的关系。基于Java的系统包含特定于平台的操作系统302,该操作系统为在特定硬件平台上执行的软件提供了硬件和系统支持。JVM 304是一个可与操作系统一起执行的软件应用。JVM 304提供了Java运行时环境,该环境具有执行Java应用程序306的能力,所述Java应用或小应用程序是以Java编程语言编写的程序、小服务程序、或软件组件。JVM 304在其中运行的计算机系统可以类似于以上描述的数据处理系统200或计算机100。然而,JVM 304可在具有嵌入的picoJava内核的所谓的Java芯片、硅上Java(java-on-silicon)、或Java处理器上的专用的硬件中实现。
在Java运行时环境的中心的是JVM,该JVM支持Java的环境的所有方面,包括其体系结构、安全特征、跨网络的移动性、和平台独立性。
JVM是一虚拟计算机,即被抽象地规定的计算机。该规范定义了每个JVM必须实现的某些特征,并具有可取决于JVM被设计为在其上执行的平台的一定范围的设计选择。例如,所有JVM必须执行Java字节码,并可使用一系列技术来执行由字节码代表的指令。JVM可完全在软件中实现或在某种程度上在硬件中实现。这种灵活性允许为大型计算机和PDA设计不同的JVM。
JVM是实际执行Java程序的虚拟计算机组件的名称。Java程序不是直接由中央处理器运行的,而是由JVM运行的,JVM本身是运行在处理器上的一个软件。JVM允许Java程序在不同的平台上执行,而不是仅在为其编译代码的一个平台上执行。Java程序是为JVM编译的。以这种方式,Java能够支持用于很多类型的数据处理系统的应用,这些数据处理系统可包含各种中央处理单元和操作系统体系结构。为了使Java应用能在不同类型的数据处理系统上执行,编译器典型地生成体系结构中性的文件格式编译的代码可在很多处理器上执行,只要存在Java运行时系统即可。Java编译器生成非特定于具体计算机体系结构的字节码指令。字节码是由Java编译器生成并由Java解释器执行的独立于机器的代码。Java解释器是交替地解码和解释一个或多个字节码的、JVM的部分。这些字节码指令被设计为易于在任何计算机上执行并易于被动态地(on the fly)转换为本机机器码。字节码可由即时(JIT)编译器转换为本机代码。
JVM加载类文件并执行其中的字节码。类文件是由JVM中的类加载器加载的。类加载器从应用加载类文件并从应用所需要Java应用编程接口(API)加载类文件。执 行字节码的执行引擎可随不同的平台和实现而不同。
图4是本申请实施例的一种方法流程图,本方法应用在程序源代码的编译阶段,具体如下:
S401,获取程序源代码,该程序源代码中包含本地语言代码和非本地语言代码。
获取的程序源代码为混合编程的程序源代码,包含了本地语言代码和非本地语言代码。本地语言代码中包含本地语言方法,而非本地语言中包含非本地语言方法。本地语言方法与非本地语言方法之间存在相互调用。
S402,生成中间语言代码,将源代码中的本地语言的方法和非本地语言的方法转化为中间语言的方法。
在编译过程中,需要将程序源代码中的本地语言代码和非本地语言代码转化为共同的中间语言表示,中间语言表示即一种中间代码。将地语言代码和非本地语言代码转化为共同的中间语言,需要先将源代码中的方法转化为中间语言的方法。在转化成中间语言表示时,对于本地语言和非本地语言的方法转化成的中间语言的方法,中间语言方法的函数体相同,区别在于函数定义的范围。例如,本地语言方法对应的中间语言方法定义的是一个全局函数,而非本地语言方法对应的中间语言方法定义的是一个类中的一个类方法。因此,在中间语言的方法中,对于非本地语言对应的方法,保留了非本地语言的类信息。
以Java与C/C++的为例,本地语言C和分本地语言Java在代码中分别实现了一个方法函数foo。在编译过程中,Java语言和C/C++语言程序首先被转换成统一中间语言表示。如果C/C++语言定义的是一个全局foo函数,而Java语言定义的是类internTest的一个类方法foo。则转化成中间语言标识后,Java语言的类方法foo与C/C++语言定义的全局函数foo对应的中间语言的方法主要的区别是类方法的定义保留了类信息,函数的第一个参数是this指针。如果在C++语言中定义了一个类名为internTest的类方法foo,而Java语言定义的是类internTest的一个类方法foo,则两者转化为的中间语言的方法函数体相同,且类信息也相同。
在一些实现方式中,中间语言的方法中会带有一个函数属性标识,该标识用于指示中间语言的方法是由本地语言转化得到还是由非本地语言转化的倒的。该标识可以在在运行过程中出现异常时快速退栈时使用。
在一些实现方式中,还可以在中间语言中构建类的继承关系(CHA),例如,根据继承关系在编译阶段在中间语言中生成虚拟函数表。例如,以图5为例,4个类的定义如下:
class A{fooA();}
class B extend A{fooB();}
class C extend B{fooA();}
class D extend B{fooD();}
4个类的继承关系如图5所示,类B继承了类A,类C继承了类B,类D也继承了类B。图6给出了4个类的虚拟函数表(VMT)。在虚拟函数调用点,函数在虚拟函数表中的索引也是在编译时刻确定的。中间语言在运行时执行过程中,当进行虚拟函数调时的流程如下:判断对象是哪个类的实例,例如,判断一个指针是那一个类的实 例;使用函数索引在对应类的虚拟函数表中查找,从而确定实际调用的函数;返回实际调用的函数指针。
在一些实现方式中,还可以在中间语言中增加类的接口函数表,接口函数表包含一个哈希表和一个冲突消除表,在运行时程序执行到该类的一个接口函数,使用函数签名的哈希值在哈希表中查找,如果找到就返回函数地址;否则使用函数签名在冲突消除表中查找,并返回函数地址。
例如,在编译Java程序的时候搜集一个类实现的所有接口。由于多继承的关系,对于接口函数不能像类继承中的函数一样排序进而生成函数表。对一个类实现的所有接口函数,在编译时根据函数签名生成哈希表,哈希表中保存对应函数指针。当有冲突发生的时候,就构建一个冲突消除表来保存函数签名及对应的函数指针。例如,下面给出了了A实现的3个接口,从中可以知道类A需要实现fooB,fooC和fooD等3个接口函数:
interface B{fooB();}
interface C{fooC();}
interface D{fooD();}
class A implements B,C,D{}
图7描述了类A的接口函数哈希表和冲突消除表的示例。在哈希表中,根据fooC的函数签名的哈希值,把fooC对应的函数指针填到相应的位置。没有函数对应或者有一个以上函数对应(有冲突发生)的位置填0。当有冲突发生时,例如fooB的签名的哈希值和fooD的签名的哈希值一样,冲突消除表中保存各个函数的签名及对应的函数地址。由于接口函数表以及函数签名哈希值的计算都是在编译时刻完成的,所以可以使用变长的哈希表并尝试使用多种哈希函数来减少冲突降低哈希表的大小,达到降低内存消耗并提升虚拟调用性能的目的。
结合图7中间语言代码在执行过程中,下面的方法流程描述了接口函数表是如何使用的。
S701、判断对象是哪个类的实例;
S702、根据函数签名的哈希值在对应类的哈希表中查找,如果找到就返回函数指针,否则在冲突消除表中用函数签名查找;
S703、返回实际调用的函数指针。
在一些实现方式中,在中间语言代码中会生成非本地语言反射需要的数据,包括类的元数据信息,类的域信息,类的方法信息。例如当非本地语言为Java时,通过类的元数据信息,类的域信息,类的方法信息,把GetMethodID、CallVoidMethod等JNI接口函数转换成Intrinsic,并且这些Intrinsic的语义能够编译器所知。
例如,图8中,框A给出了一个C/C++调用Java函数的代码示例。框B、框C、框D分别给出了编译时在中间语言代码中生成的类的元数据信息,类的方法信息,类的域信息的数据结构。在中间语言代码执行的过程中:
1)函数FindClass会搜索所有类的ClassMetadata信息,通过比较参数和classname,来找到对应的类的ClassMetadata;
2)函数GetMethodID通过ClassMetadata中的methods找到该类的所有方法的信 息,然后利用第2、3个参数(函数名字,函数参数和返回值信息)找到对应的方法;
3)函数NewObjectA调用con对应的Java方法,方法的指针保存在MethodMetadata中的addr里面,创建一个Java对象;
4)调用类中的mid对应的类方法;
5)函数GetFieldID通过ClassMetadata中的fields找到该类的所有域的信息,然后利用第2、3个参数(域名字,域类型信息)找到对应的域;
6)函数SetObjectField为对象jobj的fid域赋值,如果域是非静态域,域信息中的realOffset给出了该域在jobj对象中的偏移量;如果域是静态的,域信息中的absAddress给出了该静态域的地址。
S403,在中间语言中生成用于非本地语言所转化的方法与本地语言所转化的方法之间相互调用的调用方法。
通过将本地语言和非本地语言的方法均转换为了中间语言方法,因此,对于存在相互调用关系的本地语言方法和非本地语言方法,在编译过程中通过转换后的中间语言方法而实现了相互可见。因此可以基于转换后的中间语言方法,对原本存在相互调用关系的本地语言方法和非本地语言方法进行分析优化,从而生成优化后的用于地语言方法和非本地语言方法之间相互调用的方法。
在一些实现方式中,中间语言中的调用方法用于在运行时结合非本地语言所转化的方法与本地语言所转化的方法,共同完成非本地语言所转化的方法与本地语言所转化的方法之间的调用。
在另一些实现方式中,在生成中间语言的调用方法时,非本地语言所转化的方法与本地语言所转化的方法可以通过内联的方式集成到调用方法中,从而在运行时,调用方法可以独立的实现非本地语言所转化的方法与本地语言所转化的方法之间的相互调用。
下面通过一个示例来说明如何在中间语言中生成用于非本地语言所转化的方法与本地语言所转化的方法之间相互调用的调用方法。
如图9所示,在图9中,描述了Java的类Callbacks声明了调用一个C/C++函数nativeMethod。框B描述了C/C++函数nativeMethod的定义,nativeMethod通过调用JNI接口函数GetObjectClass、GetMethodID和CallVoidMethod最终调用Callbacks类的类方法callback。对于标准的JNI,只能在运行时通过参数obj找到要调用的函数。在本示例中,由于框A中的方法与框B中的方法均转化成了中间语言表示,即对于编译器而言,可以同时获取到Callbacks类的继承关系以及函数nativeMethod的定义。因此,可以通过编译器把Java端Callbacks类的继承关系传递给C/C++端,并且编译器知道JNI接口函数语义后,可以分析得到CallVoidMethod最终调用的是Callbacks类的类方法callback。因此,在中间代码中可以生成如框C中的函数。相对于框B中的nativeMethod函数,框C中的函数删除了一个参数(JNI接口指针)以及原有的JNI接口函数调用。框C中的函数,即可用于本地语言方法nativeMethod和非本地语言方法callback之间的相互调用。
在一些实现方式中,还可以对框A和框C中的Java和C/C++函数实施程序分析和优化。首先把nativeMethod内联到main函数中,然后把callback函数也内联到main 函数中,最终得到框D所示的函数。
S404,根据分析和优化后的中间语言,生成可执行的二进制可执行程序,完成编译过程。
通过本申请实施例,在编译包含本地语言以及非本地语言的混合源代码时,通过将本地语言以及非本地语言转化为中间语言,并根据本地语言和非本地语言的方法调用关系生成调用方法,用于中间语言中的方法之间的相互调用。由于编译器通过中间语言可以同时获知本地语言和非本地语言的方法信息,因此在生成本地语言与非本地语言之间的调用方法时,可以根据本地语言和非本地语言的方法信息对调用方法进行优化。相对于现有技术,本申请实施例降低了本地语言和非本地语言方法之间在运行时相互调用的开销。
在本实施例的基础上,下面通过几个实施例来说明生成中间语言过程中,对中间语言的方法进行分析和优化,从而生成用于地语言方法和非本地语言方法之间相互调用的方法。
参考图10,是本申请实施例提供的一种中间语言的优化流程。该实施例基于图4所述实施例中,转化为中间代码后,生成中间代码中用于非本地语言所转化的方法与本地语言所转化的方法之间相互调用的调用方法。
S1001,判断本地语言方法中是否会出现异常。
编译器根据中间语言中转换后的被非本地语言所调用的本地语言方法,可以确定本地语言方法在被非本地语言调用时,是否会抛出异常。
S1002,如果会出现异常,则在用于非本地语言调用该本地语言方法的调用方法中增加异常处理功能。例如,在一些示例中,可以在用于java调用C/C++的调用函数中,增加调用checkPendingException来实现异常处理功能。
S1003,如果不会出现异常,则调用方法中不包含异常处理功能。
通过该实施例,在生成用于非本地语言调用本地语言的调用方法时,会先确定确定本地语言方法在被非本地语言调用时,是否会抛出异常,再根据确定结果判断是否在调用方法中增加异常处理功能。相对于现有技术中Java调用本地语言方法时均需要在运行时调用异常处理来检查是否有未处理的异常对象,本实施例在编译阶段即生成了调用函数,且仅在本地语言会产生异常时才包含异常处理功能,从而降低了运行时的异常处理开销。
参考图11,是发明实施例提供的又一种中间语言的优化流程。该实施例基于图4所述实施例中,转化为中间代码后,生成中间代码中用于非本地语言所转化的方法与本地语言所转化的方法之间相互调用的调用方法。
S1101、判断所述本地语言是否访问非本地语言中的对象
编译器根据中间语言中转换后的被非本地语言所调用的本地语言方法,可以确定本地语言方法是否会访问非本地语言中的对象。
S1102、如果本地语言方法会访问非本地语言中的对象,则在根据所述源程序代码生成中间语言代码时,生非本地语言代码中的对象引用表。
S1103、如果本地语言方法不会访问非本地语言中的对象,则在根据所述源程序代码生成中间语言代码时,不生成非本地语言代码中的对象引用表。
为了防止C/C++函数操作Java对象的时候Java对象被回收,需要对所有参数涉及的Java对象进行跟踪。通常这些Java对象会被组成对象引用表。在本申请实施例中,可以在生成中间代码时,分析C/C++程序中对Java对象的引用情况,按需创建Java对象引用表,并及时释放不再使用的引用。由此,可以减少创建对象引用表所带来的开销。
参考图12,是发明实施例提供的又一种中间语言的优化流程。该实施例基于图4所述实施例中,当非本地语言为Java时,转化为中间代码后,生成中间代码中用于非本地语言所转化的方法与本地语言所转化的方法之间相互调用的调用方法。
S1201、判断所述本地语言的方法是否访问Java代码中的JNI接口指针,若是,则在中间代码中用于本地语言与非本地语言之间的调用方法的参数中添加JNI接口指针;若不访问,则不在调用方法的参数中添加JNI接口指针。
S1202、判断所述本地语言的方法是否访问Java代码中的Java对象或者Java类对象,若是,则在所述中间代码中用于本地语言与非本地语言之间的调用方法的参数中添加所述Java对象或者所述Java类对象;若不访问,则不在所述调用方法的参数中添加所述Java对象或者所述Java类对象。
在一些实现方式中,可以将本地语言内联到中间语言中的调用方法或者非本地语言对应的方法中。
在本实施例中,再生成中间代码时,根据本地语言的方法是否访问Java代码中的JNI接口指针或者访问Java代码中的Java对象或者Java类对象,从而确定是否在调用方法中添加JNI接口指针、Java对象或者Java类对象,相对于现有技术,可以减少JNI接口指针、Java对象或者Java类对象所带来的调用开销。
上述详细阐述了本申请实施例的方法,下面提供了本申请实施例的装置。
请参见图13,图13是本申请实施例提供的一种编译系统1300的逻辑结构图,本实施例的编译系统可以设置于编译器上。该系统可以包括多个逻辑单元,各个逻辑单元执行相应的功能。逻辑单元是根据功能和信息的交互进行划分的,可以理解的,各个逻辑单元可以通过软件实现,也可以通过硬件实现,可以通过不同的硬件分别实现,也可以通过共同的硬件实现。此外,逻辑单元的划分也可以根据不同的具体实施方式进行调整,在本实施例中的划分方式仅仅是示例性的。在本实施例中,各个单元的详细描述如下。
获取模块1301,该模块用于获取程序源代码,该程序源代码中包含本地语言代码和非本地语言代码。
获取模块的具体功能实现,可以参考前述实施例中的S401步骤。
中间语言生成模块1302,该模块用于生成中间语言代码,将源代码中的本地语言的方法和非本地语言的方法转化为中间语言的方法。
在一些实现方式中,中间语言生成模块602会在中间语言的方法中带有一个函数 属性标识,该标识用于指示中间语言的方法是由本地语言转化得到还是由非本地语言转化的倒的。该标识可以在在运行过程中出现异常时快速退栈时使用。
在一些实现方式中,中间语言生成模块602在中间语言中增加类的接口函数表,接口函数表包含一个哈希表和一个冲突消除表,在运行时程序执行到该类的一个接口函数,使用函数签名的哈希值在哈希表中查找,如果找到就返回函数地址;否则使用函数签名在冲突消除表中查找,并返回函数地址。
在一些实现方式中,中间语言生成模块602在中间语言代码中会生成非本地语言反射需要的数据,包括类的元数据信息,类的域信息,类的方法信息。例如当非本地语言为Java时,通过类的元数据信息,类的域信息,类的方法信息,把GetMethodID、CallVoidMethod等JNI接口函数转换成Intrinsic,并且这些Intrinsic的语义能够编译器所知。
中间语言生成模块1302可以参考前述实施例中的S402步骤中的描述。
调用方法生成模块1303,该模块用于在中间语言中生成用于非本地语言所转化的方法与本地语言所转化的方法之间相互调用的调用方法。
在一些实现方式中,中间语言中的调用方法用于在运行时结合非本地语言所转化的方法与本地语言所转化的方法,共同完成非本地语言所转化的方法与本地语言所转化的方法之间的调用。
在另一些实现方式中,在生成中间语言的调用方法时,非本地语言所转化的方法与本地语言所转化的方法可以通过内联的方式集成到调用方法中,从而在运行时,调用方法可以独立的实现非本地语言所转化的方法与本地语言所转化的方法之间的相互调用。
调用方法生成模块1302可以参考前述实施例中的S403步骤中的描述。
优化模块1304,该模块用于对生成的中间语言进行优化。
在一些实现方式中,优化模块1304用于判断本地语言方法中是否会出现异常,如果会出现异常,则在用于非本地语言调用该本地语言方法的调用方法中增加异常处理功能。
在一些实现方式中,优化模块1304用于判断所述本地语言是否访问非本地语言中的对象,如果本地语言方法会访问非本地语言中的对象,则在根据所述源程序代码生成中间语言代码时,生非本地语言代码中的对象引用表。
在一些实现方式中,优化模块1304用于判断所述本地语言的方法是否访问Java代码中的JNI接口指针,若是,则在中间代码中用于本地语言与非本地语言之间的调用方法的参数中添加JNI接口指针。
在一些实现方式中,优化模块1304用于判断所述本地语言的方法是否访问Java代码中的Java对象或者Java类对象,若是,则在所述中间代码中用于本地语言与非本地语言之间的调用方法的参数中添加所述Java对象或者所述Java类对象。
优化模块1304可以参考前述图10、图11、图12所对应的方法实施例中的描述。
编译模块1305,该模块用于根据分析和优化后的中间语言,生成可执行的二进制可执行程序,完成编译过程。
通过本申请实施例所提供的,在编译包含本地语言以及非本地语言的混合源代码 时,通过将本地语言以及非本地语言转化为中间语言,并根据本地语言和非本地语言的方法调用关系生成调用方法,用于中间语言中的方法之间的相互调用。由于编译器通过中间语言可以同时获知本地语言和非本地语言的方法信息,因此在生成本地语言与非本地语言之间的调用方法时,可以根据本地语言和非本地语言的方法信息对调用方法进行优化。相对于现有技术,本申请实施例降低了本地语言和非本地语言方法之间在运行时相互调用的开销。
随着技术的发展,设计人员几乎都通过将改进的方法流程编程到硬件电路中来得到相应的硬件电路结构。因此,一个方法流程也可以用硬件实体模块来实现。例如,可编程逻辑器件(Programmable Logic Device,PLD)(例如现场可编程门阵列(Field Programmable Gate Array,FPGA))就是这样一种集成电路,其逻辑功能由用户对器件编程来确定。由设计人员自行编程来把一个数字系统“集成”在一片PLD上,而不需要请芯片制造厂商来设计和制作专用的集成电路芯片。而且,如今,取代手工地制作集成电路芯片,这种编程也多半改用“逻辑编译器(logic compiler)”软件来实现,它与程序开发撰写时所用的软件编译器相类似,而要编译之前的原始代码也得用特定的编程语言来撰写,此称之为硬件描述语言(Hardware Description Language,HDL),而HDL也并非仅有一种,而是有许多种,如ABEL(Advanced Boolean Expression Language)、AHDL(Altera Hardware Description Language)、Confluence、CUPL(Cornell University Programming Language)、HDCal、JHDL(Java Hardware Description Language)、Lava、Lola、MyHDL、PALASM、RHDL(Ruby Hardware Description Language)等,目前最普遍使用的是VHDL(Very-High-Speed Integrated Circuit Hardware Description Language)与Verilog。本领域技术人员也应该清楚,只需要将方法流程用上述几种硬件描述语言稍作逻辑编程并编程到集成电路中,就可以很容易得到实现该逻辑方法流程的硬件电路。
上述实施例阐明模块或单元,具体可以由计算机芯片或实体实现,或者由具有某种功能的产品来实现。例如,可以通过前述图2所对应的终端系统100来实现。图2中以一个处理器101与存储器105通过总线连接。存储器105作为一种计算机可读存储介质,可用于存储软件程序、计算机可执行程序以及模块,如本申请图4-12任一所示实施例中的方法对应的程序指令/模块。处理器101通过运行存储在存储器105中的软件程序、指令以及模块,从而执行计算机设备的各种功能应用以及数据处理,即实现上述的方法。
在另一些实现方式中一种典型的实现设备为计算机。具体的,计算机例如可以为个人计算机、服务器、膝上型计算机等。但是,随着技术的发展,硬件设备的计算能力和通信能力会不断增强。因此,可以预见的,在将来的技术实现中,各类具备计算能力和通信能力的硬件设备作为前述所描述的编译系统的硬件设备。例如蜂窝电话、智能电话、个人数字助理、媒体播放器、车载电脑、物联网设备、导航设备、游戏设备、平板计算机等。
为了描述的方便,描述以上装置时以功能分为各种单元分别描述。当然,在实施本申请时可以把各单元的功能在同一个或多个软件和/或硬件中实现。
本领域内的技术人员应明白,本申请的实施例可提供为方法、系统、或计算机程 序产品。因此,本申请可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本申请可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。
本申请是参照根据本申请实施例的方法、设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。
这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,该流程可以由计算机程序来指令相关的硬件完成,该程序可存储于计算机可读取存储介质中,该程序在执行时,可包括如上述各方法实施例的流程。而前述的存储介质包括:ROM或随机存储记忆体RAM、磁碟或者光盘等各种可存储程序代码的介质。

Claims (21)

  1. 一种编译方法,其特征在于,所述方法包括:
    获取源程序代码,所述源程序代码包括第一语言代码和第二语言代码,所述第一语言代码中包括第一方法,所述第二语言代码中包括第二方法,其中,所述第一语言代码为本地语言,所述第二语言代码为非本地语言;
    根据所述源程序代码生成第三语言代码,所述第三语言代码中包含第三方法和第四方法,所述第三方法根据所述第一方法所生成,所述第四方法根据第二方法所生成,所述第三语言代码还包括第五方法,所述第五方法根据所述第一方法和所述第二方法所生成或者根据所述第三方法和所述第四方法所生成,所述第五方法用于所述第三方法通过所述第五方法调用所述第四方法或者所述第四方法通过所述第五方法调用所述第三方法。
  2. 根据权利要求1所述方法,其特征在于,根据所述源程序代码生成第三语言代码具体包括:
    确定所述第一方法或第三方法会出现异常;
    生成用于所述第四方法调用所述第三方法的第五方法,所述第五方法包含异常处理功能。
  3. 根据权利要求1所述方法,其特征在于,根据所述源程序代码生成所述第三语言代码还包括:
    确定所述第一方法访问所述第二语言代码中的对象;
    在根据所述源程序代码生成第三语言代码时,生成所述第二语言代码中所述对象的对象引用表。
  4. 根据权利要求1所述方法,其特征在于,所述第二语言代码为Java语言代码,根据所述源程序代码生成第三语言代码时还包括:
    确定所述第一方法访问所述第二语言代码中的Java本地接口JNI指针;
    在所述第五方法的参数中添加JNI指针。
  5. 根据权利要求1所述方法,其特征在于,所述第二语言代码为Java语言代码,根据所述源程序代码生成第三语言代码时还包括:
    确定所述第一方法是否访问所述第二语言代码中的Java对象或者Java类对象;
    在所述第五方法的参数中添加所述Java对象或者所述Java类对象。
  6. 根据权利要求1-5任意一项所述方法,其特征在于,所述第三语言代码还包括所述第二语言代码中的类的域信息、类的方法信息以及类的继承关系。
  7. 根据权利要求6所述方法,其特征在于,根据所述源程序代码生成第三语言代码时,生成所述第五方法包括:
    根据所述类的继承关系和类的方法信息,确定所述第二方法在所述第二语言代码中的签名,所述签名用于指示所述第二语言代码中的所述第二方法的名称以及所述第二方法所在的类,根据所述签名生成所述第五方法。
  8. 根据权利要求6所述方法,其特征在于,根据所述源程序代码生成所述第三语言代码还包括:
    根据所述类的继承关系和类的域信息,生成第六方法,所述第六方法用于访问所述第二语言代码中的域。
  9. 根据权利要求1-8中任一所述方法,其特征在于,所述第三方法和所述第四方法中包含有标识,所述标识用于指示所述第三方法根据本地语言生成或者指示所述第四方法根据非本地语言生成。
  10. 一种编译装置,其特征在于,所述装置包括:
    获取模块,用于获取源程序代码,所述源程序代码包括第一语言代码和第二语言代码,所述第一语言代码中包括第一方法,所述第二语言代码中包括第二方法,其中,所述第一语言代码为本地语言,所述第二语言代码为非本地语言;
    生成模块,用于根据所述源程序代码生成第三语言代码,所述第三语言代码中包含第三方法和第四方法,所述第三方法根据所述第一方法所生成,所述第四方法根据第二方法所生成,所述第三语言代码还包括第五方法,所述第五方法根据所述第一方法和所述第二方法所生成或者根据所述第三方法和所述第四方法所生成,所述第五方法用于所述第三方法通过所述第五方法调用所述第四方法或者所述第四方法通过所述第五方法调用所述第三方法。
  11. 根据权利要求10所述装置,其特征在于,所述生成模块根据所述源程序代码生成第三语言代码具体包括:
    确定所述第一方法或第三方法会出现异常;
    生成用于所述第四方法调用所述第三方法的第五方法,所述第五方法包含异常处理功能。
  12. 根据权利要求10所述装置,其特征在于,所述生成模块根据所述源程序代码生成所述第三语言代码还包括:
    确定所述第一方法访问所述第二语言代码中的对象;
    在根据所述源程序代码生成第三语言代码时,生成所述第二语言代码中所述对象的对象引用表。
  13. 根据权利要求10所述装置,其特征在于,所述第二语言代码为Java语言代码,所述生成模块根据所述源程序代码生成第三语言代码时还包括包括:
    确定所述第一方法访问所述第二语言代码中的Java本地接口JNI指针;
    在所述第五方法的参数中添加JNI指针。
  14. 根据权利要求10所述装置,其特征在于,所述第二语言代码为Java语言代码,
    所述生成模块根据所述源程序代码生成第三语言代码时还包括:
    确定所述第一方法是否访问所述第二语言代码中的Java对象或者Java类对象;
    在所述第五方法的参数中添加所述Java对象或者所述Java类对象。
  15. 根据权利要求10-14中任意一项所述装置,其特征在于,所述第三语言代码还包括所述第二语言代码中的类的域信息、类的方法信息以及类的继承关系。
  16. 根据权利要求15所述装置,其特征在于,所述生成模块根据所述源程序代码生成第三语言代码时,生成所述第五方法时具体包括:
    根据所述类的继承关系和类的方法信息,确定所述第二方法在所述第二语言代码中的签名,所述签名用于指示第二语言代码中的所述第二方法的名称以及所述第二方法所在的类,根据所述签名生成所述第五方法。
  17. 根据权利要求15所述装置,其特征在于,所述生成模块根据所述源程序代码生 成所述第三语言代码还用于:
    根据所述类的继承关系和类的域信息,生成第六方法,所述第六方法用于访问所述第二语言代码中的域。
  18. 根据权利要求10-17中任一所述装置,其特征在于,所述第三方法和所述第四方法中包含有标识,所述标识用于指示所述第三方法根据本地语言生成或者指示所述第四方法根据非本地语言生成。
  19. 一种编译装置,其特征在于,所述编译装置包括处理器和存储器,
    所述存储器存储有可执行程序指令;
    所述处理器读取所述存储器中的所述可执行程序指令以执行权利要求1-9中任意一个权利要求所述方法。
  20. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质存储有指令,当所述指令在计算机上运行时,用于执行权利要求1-9中任一项所述的方法。
  21. 一种计算机程序,其特征在于,当所述计算机程序被计算机执行时,用于执行权利要求1-9中任一项所述的方法。
PCT/CN2020/081000 2019-03-25 2020-03-25 一种跨语言编译方法及设备 WO2020192667A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
EP20776538.9A EP3937011A4 (en) 2019-03-25 2020-03-25 INTERLINGUAL COMPILATION METHOD AND DEVICE
US17/484,504 US20220012029A1 (en) 2019-03-25 2021-09-24 Cross-language compilation method and device

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910228528.7A CN111736838A (zh) 2019-03-25 2019-03-25 一种跨语言编译方法及设备
CN201910228528.7 2019-03-25

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US17/484,504 Continuation US20220012029A1 (en) 2019-03-25 2021-09-24 Cross-language compilation method and device

Publications (1)

Publication Number Publication Date
WO2020192667A1 true WO2020192667A1 (zh) 2020-10-01

Family

ID=72609610

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/081000 WO2020192667A1 (zh) 2019-03-25 2020-03-25 一种跨语言编译方法及设备

Country Status (4)

Country Link
US (1) US20220012029A1 (zh)
EP (1) EP3937011A4 (zh)
CN (1) CN111736838A (zh)
WO (1) WO2020192667A1 (zh)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20230057055A1 (en) * 2020-03-19 2023-02-23 Oracle International Corporation Modeling foreign functions using executable references
US11875168B2 (en) 2020-03-19 2024-01-16 Oracle International Corporation Optimizing execution of foreign method handles on a virtual machine

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US11681508B2 (en) * 2020-08-24 2023-06-20 Cisco Technology, Inc. Source code analysis to map analysis perspectives to events
CN117406999A (zh) * 2021-10-14 2024-01-16 华为技术有限公司 语言互操作方法、装置、存储介质及程序产品
CN113703732B (zh) * 2021-11-01 2022-02-11 深圳易帆互动科技有限公司 一种游戏后端多语言开发的实现方法

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103077011A (zh) * 2012-10-09 2013-05-01 华为技术有限公司 一种在JavaScript脚本语言中预生成机器码指令的方法和装置
US20170046137A1 (en) * 2015-08-10 2017-02-16 Oracle International Corporation Mechanism for increasing the performance of multiple language programs by inserting called language ir into the calling language
CN106775616A (zh) * 2016-11-10 2017-05-31 中国电子科技集团公司第二十八研究所 基于C++与Java混合编程的分布式服务系统
CN107341010A (zh) * 2017-06-26 2017-11-10 华中科技大学 一种C/C++与COStream混合编程方法和可视化编译系统

Family Cites Families (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6110226A (en) * 1998-02-19 2000-08-29 Cygnus Solutions Java development environment using optimizing ahead-of-time compiler
CA2267482C (en) * 1999-03-30 2004-08-10 Ibm Canada Limited-Ibm Canada Limitee Report program language source code translation to object-oriented language source code which emulates report program language behaviour
US8332828B2 (en) * 2002-11-20 2012-12-11 Purenative Software Corporation System for translating diverse programming languages
US7490320B2 (en) * 2005-02-18 2009-02-10 International Business Machines Corporation Method and apparatus for transforming Java Native Interface function calls into simpler operations during just-in-time compilation
US7730522B2 (en) * 2005-05-16 2010-06-01 Microsoft Corporation Self-registering objects for an IPC mechanism
US8296745B2 (en) * 2007-12-31 2012-10-23 Oracle America, Inc. Method and apparatus for portable stub generation
US8776033B2 (en) * 2010-12-23 2014-07-08 International Business Machines Corporation Batch dispatch of java native interface calls
JP6119535B2 (ja) * 2013-09-30 2017-04-26 富士通株式会社 トレース方法、処理プログラム、および情報処理装置

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103077011A (zh) * 2012-10-09 2013-05-01 华为技术有限公司 一种在JavaScript脚本语言中预生成机器码指令的方法和装置
US20170046137A1 (en) * 2015-08-10 2017-02-16 Oracle International Corporation Mechanism for increasing the performance of multiple language programs by inserting called language ir into the calling language
CN106775616A (zh) * 2016-11-10 2017-05-31 中国电子科技集团公司第二十八研究所 基于C++与Java混合编程的分布式服务系统
CN107341010A (zh) * 2017-06-26 2017-11-10 华中科技大学 一种C/C++与COStream混合编程方法和可视化编译系统

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
See also references of EP3937011A4 *

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20230057055A1 (en) * 2020-03-19 2023-02-23 Oracle International Corporation Modeling foreign functions using executable references
US11875168B2 (en) 2020-03-19 2024-01-16 Oracle International Corporation Optimizing execution of foreign method handles on a virtual machine
US12008351B2 (en) * 2020-03-19 2024-06-11 Oracle International Corporation Modeling foreign functions using executable references

Also Published As

Publication number Publication date
CN111736838A (zh) 2020-10-02
US20220012029A1 (en) 2022-01-13
EP3937011A4 (en) 2022-05-04
EP3937011A1 (en) 2022-01-12

Similar Documents

Publication Publication Date Title
WO2020192667A1 (zh) 一种跨语言编译方法及设备
US10367822B2 (en) Restrictive access control for modular reflection
US11366643B2 (en) Generating dynamic modular proxies
US10140119B2 (en) Modular serialization
US10789047B2 (en) Returning a runtime type loaded from an archive in a module system
US11645129B2 (en) Dynamically-imposed field and method type restrictions for managed execution environments
US8464226B2 (en) System and method for interoperating with foreign objects from a host computing environment
KR20220113372A (ko) 통합된 참조물 및 2차 객체 표시
US10891214B2 (en) Transferring a debug configuration amongst carrier threads for debugging a carried thread
US20190196799A1 (en) Metadata application constraints within a module system based on modular dependencies
US11347487B2 (en) Confining reflective access based on module boundaries
US20160364830A1 (en) Asynchronous translation of computer program resources in graphics processing unit emulation
US11543976B2 (en) Methods for reducing unsafe memory access when interacting with native libraries
US11803487B2 (en) Transitioning between thread-confined memory segment views and shared memory segment views
CN113495869B (zh) 文件系统空间的调整方法、装置和电子设备
US10891213B2 (en) Converting between a carried thread and a carrier thread for debugging the carried thread
CN111736925A (zh) 引用计数的实现方法和装置
WO2017034652A1 (en) Restrictive access control for modular reflection

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20776538

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

ENP Entry into the national phase

Ref document number: 2020776538

Country of ref document: EP

Effective date: 20211006