Cross-Language Compilation Through a Common Intermediate Language

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

In mixed language programming, the overheads of mutual invocation between native and non-native language functions are high due to the need for separate compilation and the use of mechanisms like JNI and reflection, which are inefficient and resource-intensive.

Innovation Solution

Convert both native and non-native language functions into a common intermediate language, allowing the compiler to optimize invocation functions based on both languages' function information, reducing overheads by generating optimized invocation functions and exception handling directly in the compilation process.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Adaptability or versatility

If separate compilation processes are used for native and non-native languages, then language compatibility and independence are maintained, but invocation overheads increase and performance deteriorates

Engineering Contradiction:
Improvelanguage compatibilityVSAvoidinvocation efficiency
Core Design Contradiction:
Adaptability or versatilityVSProductivity

Solution Approach 1:

The patent merges the compilation processes of native and non-native languages by converting both to a common intermediate representation (IR). This allows the compiler to perform cross-language optimizations and generate optimized invocation functions that reduce runtime overhead, while still maintaining the independence and compatibility benefits of separate language processing through the IR abstraction layer.

Inventive Principle:
Principle #5Merging (Combining)

2Reliability

If conservative implementation of JNI and reflection mechanisms is used, then language independence and compatibility are ensured, but overheads in invocation and exception handling increase

Engineering Contradiction:
Improvelanguage independenceVSAvoidinvocation overhead
Core Design Contradiction:
ReliabilityVSLoss of time

Solution Approach 1:

The patent performs preliminary actions during the compilation phase by converting both native and non-native functions to intermediate representation and generating optimized invocation functions ahead of time. This preliminary optimization eliminates the need for conservative runtime checks and overhead in JNI and reflection mechanisms, while still ensuring language independence through the IR abstraction.

Inventive Principle:
Principle #10Preliminary action

3Ease of manufacture

If cross-language optimization is performed within same language function scope, then compilation simplicity is maintained, but optimization effectiveness is limited

Engineering Contradiction:
Improvecompilation simplicityVSAvoidoptimization effectiveness
Core Design Contradiction:
Ease of manufactureVSManufacturing precision

Solution Approach 1:

The patent introduces an intermediate representation (IR) as a mediator between native and non-native languages. This IR serves as a common language that both language types can be converted to, enabling cross-language optimization while maintaining compilation simplicity. The IR acts as an intermediary that preserves the benefits of separate language processing while allowing effective cross-language optimization.

Inventive Principle:
Principle #24Intermediary (Mediator)

Data Source

PatentEP3937011B1Cross-language compiling method and device
Publication Date: 2025.09.17 HUAWEI TECH CO LTD
  • EP3937011B1 patent drawingFigure 1
  • EP3937011B1 patent drawingFigure 2
  • EP3937011B1 patent drawingFigure 3~4

AI summary

This application provides a cross-language compilation method and apparatus. The method and the apparatus can be used for both a native language and a non-native language. For example, the method and the apparatus can be used for cross-language mixed compilation between Java and C++. An intermediate language is generated by obtaining source program code that includes the native language and the non-native language. The intermediate language includes Methods generated based on a native language Method and a non-native language Method. An invocation Method is generated in the intermediate language. These Methods are used to implement mutual invocation between the Methods generated based on the native language Method and the non-native language Method. This reduces overheads of the mutual invocation between the native language Method and the non-native language Method when an executable program obtained after compilation is running.