WO2017095257A1 - Automatic code virtualization for a compiler - Google Patents

Automatic code virtualization for a compiler Download PDF

Info

Publication number
WO2017095257A1
WO2017095257A1 PCT/RU2015/000846 RU2015000846W WO2017095257A1 WO 2017095257 A1 WO2017095257 A1 WO 2017095257A1 RU 2015000846 W RU2015000846 W RU 2015000846W WO 2017095257 A1 WO2017095257 A1 WO 2017095257A1
Authority
WO
WIPO (PCT)
Prior art keywords
virtualization
code
virtualizer
type
virtualize
Prior art date
Application number
PCT/RU2015/000846
Other languages
French (fr)
Inventor
Alexander Vladimirovich SLESARENKO
Maxim Viktorovich GEKK
Xuecang ZHANG
Original Assignee
Huawei Technologies Co., Ltd.
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 Huawei Technologies Co., Ltd. filed Critical Huawei Technologies Co., Ltd.
Priority to CN201580085075.7A priority Critical patent/CN108369499B/en
Priority to PCT/RU2015/000846 priority patent/WO2017095257A1/en
Publication of WO2017095257A1 publication Critical patent/WO2017095257A1/en

Links

Classifications

    • 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/436Semantic checking
    • G06F8/437Type checking
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/443Optimisation
    • 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/311Functional or applicative languages; Rewrite languages

Definitions

  • the present patent application relates to the field of automatic code virtualization for a compiler.
  • the present application relates to a system and a method for virtualization of a code and a corresponding compiler for object-oriented language.
  • Code virtualization is one of necessary step which has to be done before staged evaluation.
  • staged evaluation refers to a special technique of code evaluation that allows domain-specific optimizations.
  • Code virtualization abstracts types and language constructions from their representations. Code to be virtualized can be virtualized manually by a programmer or automatically by a compiler.
  • a system for virtualization of a code comprising
  • a virtualizer which is configured to be coupled to the at least one data source and which is configured to
  • the present system for virtualization of a code advantageously may be configured to perform the following steps:
  • the system may comprise a new compiler phase and input data for the compiler phase.
  • One of the advantages of the present invention is the feasibility of domain-specific optimization without any kind of modifications of original source code.
  • the virtualizer is configured to identify the scope of the virtualization of the code by examining a marker provided within the code, wherein the marker is
  • the virtualizer is configured to identify the scope of the virtualization of the code by examining a configuration file as provided by the at least one data source, wherein the configuration file comprises:
  • the virtualizer is configured to virtualize the type definition in terms of a plurality of primitive type definitions.
  • the virtualizer is configured to virtualize the type usage, wherein, if the type usage is unknown, the virtualizer is configured to infer the type usage.
  • the virtualizer is configured to virtualize the type usage by classifying the type usage. This provides the effect that the type usage will be visible in the graph intermediate representation at staged evaluation. This advantageously provides an improved virtualization. Visibility in the graph during staged evaluation allows to apply optimization rules. How the rules are defined is not covered by this invention, any method is applicable as long as it is compatible with staged evaluation, in particular, it can be done using the approach described in the application PCT/RU2014/000652.
  • the virtualizer is configured to classify the type usage by considering the visibility at a staged evaluation of the code. This provides the effect of a domain- specific optimization.This advantageously provides an improved feasibility of the domain-specific optimization without modifications of original source code.
  • This classification means that the type information can be used to dynamically select different sets for optimization rules (classes of rules). By such classification, the rules can be connected to the properties of the particular domain, thus providing domain- specific optimization.
  • the virtualizer is configured to perform the polymorphic embedding by wrapping the type usage and by applying a Rep type constructor. This provides the effect that an enhanced polymorphic embedding is provided.
  • virtualization allows to perform polymorphic embedding automatically. An improved performance of code virtualization is achieved.
  • the virtualizer is configured to provide a subsequent method call of the methods of the created dynamic proxy and to provide a construction of new graph nodes for an intermediate representation by means of a subsequent execution of an invocation handler associated with the created dynamic proxy.
  • the virtualizer is configured to virtualize the method call into the function call that creates a dynamic proxy, wherein a subsequent method call of the methods of the dynamic proxy and a subsequent execution of an invocation handler associated with dynamic proxy results in a construction of new graph nodes of an intermediate representation.
  • the virtualizer is configured to virtualize a subexpression of the source code into a virtualized code whose execution produces a symbol of a node. This allows to perform virtualization of any parts in the source code within the virtualization scope.
  • the virtualizer is configured to virtualize a subexpression of the source program into the symbol by an implicit virtualization due to a language facility or by an explicit virtualization using a virtualizer phase.
  • implicit virtualization due to a language facility or by an explicit virtualization using a virtualizer phase.
  • language facilities such as implicit conversions in Scala which may simplify implementation of code virtualization.
  • the virtualizer is configured to virtualize a subexpression of the source program into the symbol using a proxy factory and to provide a proxy object for the resulting symbol, wherein preferably the proxy object is used to handle the method call. This allows for implementing execution of virtualized code in a reusable way, and thus to simplify the virtualization procedure.
  • the virtualizer is configured to produce virtualized program code, which during execution is constructed to:
  • iv) update the symbol table by adding one or more records with the IR nodes and return one of the designated symbols as result of the proxy method call.
  • the virtualizer is configured to perform a domain-specific optimization for the virtualization of the code. This allows to optimize a program during the execution of the virtualization algorithm/procedure. This can save time, memory consumption and improve performance characteristics of the virtualized code.
  • the present invention relates to a method for virtualization of a code, wherein the method is used to operate a system according to the first aspect as such or according to any one of the preceding implementation forms of the first aspect.
  • the method further comprises the following steps of:
  • the present invention relates to a compiler for object-oriented language configured to perform the method according to the second aspect as such or according to any one of the preceding implementation forms of the second aspect.
  • the present invention relates to computer program configured to operate a method according to the second aspect as such or according to any of the preceding implementation forms of the second aspect.
  • DSP Digital Signal Processor
  • ASIC application specific integrated circuit
  • field-programmable gate array which is an integrated circuit designed to be configured by a customer or a designer after manufacturing and configured and designed to perform the methods of the present invention.
  • the present invention can be implemented in adapted digital electronic circuitry, or in adapted computer hardware, firmware, software, or in combinations thereof, e.g. in available hardware of adapted mobile devices or in new hardware dedicated for processing the methods described herein.
  • Fig. 1 shows a schematic diagram of a compiler for explaining the present invention
  • Fig. 2 shows a schematic diagram of a compiler with code virtualization for explaining the present invention
  • Fig. 3 shows a schematic diagram of a staged evaluation of method call for explaining the present invention
  • Fig. 4 shows a schematic diagram of a system for virtualization of a code according to an exemplary embodiment of the present invention
  • Fig. 5 shows a schematic diagram of a method for virtualization of a code according to an exemplary embodiment of the present invention
  • Fig. 6 shows a schematic diagram of an example of HotSpot annotations according to an exemplary embodiment of the present invention
  • Fig. 7 shows a schematic diagram of virtualizer inputs according to an exemplary embodiment of the present invention.
  • Fig. 8 shows a schematic diagram of an example of non-virtualized constant according to an exemplary embodiment of the present invention
  • Fig. 9 shows a schematic diagram of an example of virrualized constant according to an exemplary embodiment of the present invention.
  • Fig. 10 shows a schematic diagram of an evaluation of toRep(O) according to an exemplary embodiment of the present invention
  • Fig. 1 1 shows a schematic diagram of a virtualization of type definition according to an exemplary embodiment of the present invention
  • Fig. 12 shows a schematic diagram of an example of non-virtualized type usages according to exemplary an embodiment of the present invention
  • Fig. 13 shows a schematic diagram of an example of virtualized type usages according to an exemplary embodiment of the present invention
  • Fig. 14 shows a schematic diagram of a staged evaluation of method call according to an exemplary embodiment of the present invention
  • Fig. 15 shows a schematic diagram of an example of hot spots according to an exemplary embodiment of the present invention.
  • Fig. 16 shows a schematic diagram of an example of kernel generation according to an exemplary embodiment of the present invention.
  • Fig. 17 shows a schematic diagram of benchmarks for Intel Xeon E5606 for explaining the present invention
  • Fig. 18 demonstrates achieved speed up of generated kernels comparing to original code
  • Fig. 19 shows a schematic diagram of a system for virtualization of a code according to an exemplary embodiment of the present invention.
  • Fig. 20 shows a schematic diagram of a method for virtualization of a code according to an exemplary embodiment of the present invention.
  • DSL domain- specific language
  • type system as used by the present invention may refer to the following: In programming languages, a type system is a collection of rules that assign a property called a type to the various construct—such as variables, expressions, functions or modules— that a computer program is composed of.
  • executable code as used by the present invention may refer to the following: A sequence of instructions to be executed by a processor to perform a given task, the processor can be software program - interpreter.
  • executable machine code may refer to the following: A particular case of executable code; and/or a sequence of machine code instructions to be executed by a CPU to perform a given task.
  • compiler as used by the present invention may refer to the following: A computer program that takes source code of source program and produces executable machine code.
  • tree data structure may refer to the following: A data structure that simulates a hierarchical tree structure with a set of linked nodes.
  • intermediate representation may refer to the following: A data structure that is used inside a compiler for representing the source program and allows analysis and transformation before outputting the executable machine code. Typically this is a graph or a tree data structure with some specific information inside nodes. As the intermediate representation contains all the information needed to evaluate the program, if given the input data, we can say about the evaluation of the intermediate representation as an equivalent way to execute the program.
  • source program may refer to the following: A computer program that is used as an input to the compiler. It is translated into executable machine code.
  • staged code as used by the present invention may refer to the following: Staged code for a source program P is a program P' such that evaluation of P' produces intermediate representation, which is semantically equivalent to the program P.
  • staged evaluation may refer to the following: Evaluation of a program that is separated into two stages: 1) IR generation, 2) IR execution. In staged evaluation, instead of resulting data value, the result of executing the program is an IR.
  • Fig. 1 shows a schematic diagram of a compiler for explaining the present invention.
  • Code virtualization is one of the necessary steps which may have to be done before staged evaluation. The last one is a special technique of a code evaluation that allows domain-specific optimizations.
  • Code virtualization abstracts types and language constructions from their representations as shown in Fig. 1. Code can be virtualized manually by a programmer or automatically by a compiler.
  • the present invention according to an exemplary embodiment describes a method of code virtualization automatically performed by the compiler.
  • the structure of a programming language implementation comprises the following blocks executed in following order as stages:
  • Fig. 2 shows a schematic diagram of a compiler with code virtualization for explaining the present invention.
  • FIG. 2 Another structure which is based on non-traditional subdivision into two parts - frontend and backend - as shown in Fig. 2, where:
  • the frontend has an additional phase called "code virtualization”.
  • the backend is replaced by the staged evaluator, followed by an optimizer, a code generator and an execution of target code.
  • the approach may support two-phase development workflow where first phase is logic validation and second phase is profiling and generation of production code as shown in Fig. 2. On the second phase, the user has an option to tune the optimization engine by exploiting the properties of the domain.
  • FIG. 3 shows a schematic diagram of a staged evaluation of method call for explaining the present invention.
  • staged evaluation as shown in Fig. 3 used by the present invention is applicable to object-oriented languages. This trait impacts on virtualization of method calls showed below:
  • v) produce a new symbol by invoking of the method of the node.
  • a node has the same interface as its symbol's proxy. This is achieved by type system of the source language and virtualization, which preserves type soundness.
  • vi) update the symbol table by adding association of new symbol with its node.
  • Fig. 4 shows a schematic diagram of a system for virtualization of a code according to an embodiment of the present invention.
  • the system for virtualization of a code may be configured to perform the following steps:
  • the system may comprise a new compiler phase and three input data for the phase.
  • the system can be depicted schematically as shown in Fig. 4.
  • a general purpose compiler for object-oriented language comprising a new phase which creates a virtualized copy of the abstract syntactic tree, AST, automatically.
  • the virtualized AST has special properties that allow evaluating the code in staged mode
  • the compiler phase may get the AST of an original language, a scope of virtualization and already virtualized libraries, and produces virtualized AST for the scope of virtualization.
  • the new phase enriches the original AST by performing virtualization of:
  • the system 100 for virtualization of a code may comprise at least one data source 102 and a virtualizer 101.
  • the virtualizer 101 is configured to be coupled to the at least one data source
  • the virtualizer 101 is further configured to identify a scope of the virtualization of the code by defining virtualization parameters.
  • the virtualizer 101 is further configured to virtualize constants by passing each constant to a polymorphic function according to the defined virtualization parameters.
  • the virtualizer 101 is further configured to virtualize constants by passing the constants, e.g. the constants to be virtualized, to the polymorphic function according to the defined virtualization parameters.
  • the virtualizer 101 is further configured to virtualize a type definition and/or a type usage by polymorphic embedding according to the defined virtualization parameters.
  • the virtualizer 101 is further configured to virtualize a method call into a function call by creating a dynamic proxy and by wrapping a receiver object of the method call into the created dynamic proxy, according to the defined virtualization parameters.
  • the virtualizer 101 may be further configured to virtualize a method call by wrapping a receiver object of the method call into a proxy and by transforming the method call into method call of the wrapped proxy, according to the defined virtualization parameters.
  • Fig. 5 shows a schematic diagram of a method for virtualization of a code according to an embodiment of the present invention.
  • the steps as shown in Fig. 5 comprise: identifying a virtualization scope, step 0, virtualizing constants, step 1, virtualizing type definitions, step 2, virtualizing type usages, step 3, and virtualizing method calls, step 4.
  • the virtualizing of type definitions of step 2 may comprise a conditional inquiry, step 2.1 whether the type definition to be virtualized is virtualizable, e.g. is it possible to virtualize it. If yes, the type definition may be virtualized, steps 2.2, if not, a type wrapper may be defined, step 2.3.
  • the virtualizing of type usages of step 3 may comprise, inferring a type as step 3.0, classifying the type as step 3.1, a conditional inquiry, step 3.2 whether the type usage should be virtualized, and finally, if yes, a virtualization of the type usage, step 3.3.
  • Fig. 5 illustrates the method for virtualization of a code according to an embodiment of the present invention with some sub-steps.
  • Fig. 6 shows a schematic diagram of an example of HotSpot annotations according to an embodiment of the present invention.
  • the virtualizer 101 may be configured to identify a scope of virtualization and parameters of virtualization.
  • one of necessary input is original code which may contain special markers, for example annotations, attributes or special comments. These markers are configured to bound pieces of code and may look like in the Fig. 6.
  • Fig. 7 shows a schematic diagram of virtualizer inputs according to an embodiment of the present invention.
  • Fig. 7 shows another input of virtualizer is a configuration file.
  • the input file may contain:
  • Fig. 8 shows a schematic diagram of an example of non-virtualized constant according to an embodiment of the present invention.
  • constant virtualization may be performed by passing a constant as a parameter to a special polymorphic function, for instance in terms of monomorphic functions that accept a concrete type.
  • constant literal 0 is passed the polymorphic function toRep. This example assumes that the compiler infers type of the constant automatically.
  • Fig. 9 shows a schematic diagram of an example of virtualized constant according to an embodiment of the present invention.
  • the toRep function updates the symbol table by adding new record.
  • the record may link a symbol assigned to the constant and its node in graph intermediate representation.
  • Fig. 10 shows a schematic diagram of an evaluation of toRep(O) according to an embodiment of the present invention.
  • toRep(O) assigns a new symbol SymO to the constant 0 and adds a new record to the symbol table.
  • the actions may be performed during evaluation of the code showed in the Fig. 9.
  • Fig. 11 shows a schematic diagram of a virtualization of type definition according to an embodiment of the present invention.
  • the virtualizing of type definitions of step 2 may comprise a conditional inquiry, step 2.1 whether the type definition to be virtualized is virtualizable, e.g. is it possible to virtualize it. If yes, the type definition may be virtualized, steps 2.2, if not, a type wrapper may be defined, step 2.3.
  • Fig. 1 1 shows the step of virtualizing type definitions, step 2.
  • the virtualizing of type definitions may be performed by polymorphic embedding according to the defined virtualization parameters
  • a type may be defined in terms of its composition of more primitive types.
  • Type definition may introduce type's representation and a set of operations manipulating these representations.
  • the compiler may consider the following questions in terms of a conditional statement:
  • the compiler should apply the steps i) to iv) of the method to the type definition. If the virtualization of the type is impossible for some reasons or an answer to one of the questions above is "no", the compiler may wrap the type by applying the corresponding method for code virtualization.
  • Fig. 12 shows a schematic diagram of an example of non-virtualized type usages according to an embodiment of the present invention.
  • Fig. 12 shows a schematic diagram of virtualizing a type usage, corresponding to step iii) of the method.
  • the example as shown in Fig. 12 depicts non-virtualized types written by a programmer.
  • the aim of the step may be for instance the virtualization of Array[Array[Double]], Array[Double] and inferred types for values matrix and vector, and for the r parameter.
  • the compiler may follow the steps P0 to P3 below to virtualize a type usage:
  • PI Classify the type. Should the type be visible in graph IR at staged evaluation (regular type) or not (type class).
  • Fig. 13 shows a schematic diagram of an example of virtualized type usages according to an exemplary embodiment of the present invention.
  • Fig. 13 demonstrates this transformation or virtualization for original code as shown in Fig. 12.
  • Fig. 14 shows a schematic diagram of a staged evaluation of method call according to an exemplary embodiment of the present invention.
  • Fig. 14 shows a schematic diagram of a virtualization of method calls.
  • the visualization may be performed by using a method that is called during staged evaluation:
  • the virtualization of the method call is performed by wrapping the receiver object of the method call into function call that may create a dynamic proxy.
  • the receiver of a method call in source program code after performing the virtualization will be for instance a symbol, for instance of some node, thus it may be not possible to call method of the symbol directly, instead the symbol is wrapped in a proxy, and the method of the proxy is called.
  • the vres symbol may be wrapped by a special proxy factory. It could be done implicitly due to language facilities or explicitly by the virtualizer phase.
  • the proxyFactory may produce a new factory proxy VRes for the vres symbol.
  • the .items call may be handled by the proxy VRes.
  • the handler may take method objects and method's arguments as parameters.
  • the handler may search a record in the symbol table which has a link to IR node - vresNode.
  • the handler may invoke the items method of vresNode. It is possible because a symbol has same interface as its node a priori. This invocation implemented using some dynamic invocation mechanism, for example using Java Reflection.
  • the last invoke may update the symbol table by adding new record with IR node and its symbol related to the vres.items method call.
  • the described method shows that the compiler doesn't have to modify method calls in common cases.
  • Fig. 15 shows a schematic diagram of an example of hot spots according to an embodiment of the present invention.
  • One of the advantages of the present invention is the feasibility of domain- specific optimization without modifications of original source code. Let's consider an example of multiplication of a matrix by a vector.
  • a developer of the program figures out the ddmvm function may be for instance actively used in the program and may represent a bottleneck de-facto. And he/she wants to eliminate abstraction overhead and applies some domain-specific optimization to this piece of code.
  • the ddmvm function is marked by a special annotation as a HotSpot which is handled by the compiler extended by a new phase - also referred to as a "virtualizer".
  • the virtualizer may take the abstract syntactic tree, AST, of the ddmvm function and may apply the method of virtualization proposed by the present invention.
  • the result of the transformation is a plurality of virtual spots. Their textual representation is depicted in the Fig. 15. After code virtualization, special kernels can be generated for the hot spots. This process is showed schematically in the Fig. 16.
  • Fig. 16 shows a schematic diagram of an example of kernel generation according to an embodiment of the present invention.
  • Fig. 16 shows a schematic diagram of the next phase of the compiler generates optimized kernel for the ddmvm function.
  • the "Substitution" phase may replace the body of the original function by the call of the generated kernel.
  • Fig. 17 shows a schematic diagram of benchmarks for Intel Xeon E5606 for explaining the present invention.
  • the table in the Fig. 17 has measurements for original code ("Scala”), kernel generated in imperative style in Scala language and kernel in C++ language. The measurements were done on GNU/Linux, Scala 2.11.6 and gcc 4.7.4 for one CPU core.
  • Fig. 17 shows a schematic diagram of benchmarks for Intel Xeon E5606 for explaining the present invention.
  • Fig. 18 demonstrates the achieved speed up of generated kernels comparing to original code.
  • Fig. 19 shows a schematic diagram of a system for virtualization of a code according to an embodiment of the present invention.
  • the system 100 for virtualization of a code may comprise at least one data source 102 and a virtualizer 101.
  • Fig. 20 shows a schematic diagram of a flowchart diagram of a method for virtualization of a code according to an embodiment of the present invention.
  • Fig. 20 shows a schematic diagram of a flowchart diagram of a method which is used to operate the system 100.
  • the method further comprises the following steps.
  • identifying SI a scope of the virtualization by defining virtualization parameters may be performed.
  • virtualizing S2 constants by passing each constant to a polymorphic function according to the defined virtualization parameters may be performed.
  • a type definition and a type usage by polymorphic embedding according to the defined virtualization parameters may be performed.
  • a method call into a function call by creating a dynamic proxy and by wrapping a receiver object of the method call into the created dynamic proxy, according to the defined virtualization parameters may be performed.
  • the present disclosure also supports a computer program product including computer executable code or computer executable instructions that, when executed, causes at least one computer to execute the performing and computing steps described herein.
  • a computer program may be stored or distributed on a suitable medium, such as an optical storage medium or a solid-state medium supplied together with or as part of other hardware, but may also be distributed in other forms, such as via the Internet or other wired or wireless telecommunication systems.

Abstract

The present invention relates to a system (100) for virtualization of a code, the system (100) comprising: i) at least one data source (102); and ii) a virtualizer (101), which is configured to be coupled to the at least one data source (102) and which is configured to identify a scope of the virtualization of the code by defining virtualization parameters; virtualize constants by passing each constant to a polymorphic function according to the defined virtualization parameters; virtualize a type definition and/or a type usage by polymorphic embedding according to the defined virtualization parameters; and virtualize a method call into a function call by creating a dynamic proxy and by wrapping a receiver object of the method call into the created dynamic proxy, according to the defined virtualization parameters.

Description

AUTOMATIC CODE VIRTUALIZATION FOR A COMPILER
TECHNICAL FIELD
The present patent application relates to the field of automatic code virtualization for a compiler.
In particular, the present application relates to a system and a method for virtualization of a code and a corresponding compiler for object-oriented language.
BACKGROUND
Code virtualization is one of necessary step which has to be done before staged evaluation. The term staged evaluation refers to a special technique of code evaluation that allows domain-specific optimizations. Code virtualization abstracts types and language constructions from their representations. Code to be virtualized can be virtualized manually by a programmer or automatically by a compiler.
SUMMARY AND DESCRIPTION
It is the object of the present invention to provide an improved system and an improved method for virtualization of a code.
This object is achieved by the features of the independent claims. Further implementation forms are apparent from the dependent claims, the description and the figures.
According to a first aspect, a system for virtualization of a code is provided, the system comprising
i) at least one data source; and
ii) a virtualizer, which is configured to be coupled to the at least one data source and which is configured to
- identify a scope of the virtualization of the code by defining virtualization parameters;
- virtualize constants by passing each constant to a polymorphic function according to the defined virtualization parameters;
- virtualize a type definition and/or a type usage by polymorphic embedding according to the defined virtualization parameters; and
- virtualize a method call into a function call by creating a dynamic proxy and by wrapping a receiver object of the method call into the created dynamic proxy, according to the defined virtualization parameters. In other words, the present system for virtualization of a code advantageously may be configured to perform the following steps:
i) identifying a virtualization scope; and/or
ii) virtualizing constants; and/or
iii) virtualizing type definitions; and/or
iv) virtualizing type usages; and/or
v) virtualizing method calls.
In other words, the system may comprise a new compiler phase and input data for the compiler phase. One of the advantages of the present invention is the feasibility of domain-specific optimization without any kind of modifications of original source code.
In a first possible implementation form of the system according to the first aspect, the virtualizer is configured to identify the scope of the virtualization of the code by examining a marker provided within the code, wherein the marker is
i) an annotation; and/or
ii) an attribute; and/or
iii) a part of the virtualization parameters.
This advantageously provides an improved auto virtualization phase since the virtualizer may precisely identify the scope of virtualization and the parameters of virtualization using the markers of the code to be virtualized.
In a second possible implementation form of the system according to the first aspect as such or according to the first implementation form of the first aspect, the virtualizer is configured to identify the scope of the virtualization of the code by examining a configuration file as provided by the at least one data source, wherein the configuration file comprises:
i) the virtualization parameters; and/or
ii) a set of type definitions to be virtualized; and/or
iii) a set of type usages to be virtualized; and/or
iv) a set of virtualized libraries used for the virtualization.
This advantageously provides the effect that a type's representation and a set of operations manipulating these representations of the type are used and that more types are available for code virtualization. In this way configuration files can be used to specify how much of the source code should be virtualized without touching the code itself. This can be important when the code cannot be changed for some reasons.
In a third possible implementation form of the system according to the first aspect as such or according to any one of the preceding implementation forms of the first aspect, the virtualizer is configured to virtualize the type definition in terms of a plurality of primitive type definitions. By allowing to virtualize the type definition in terms of a plurality of primitive type definitions, a flexible configuration is provided, which allows to configure which types should be virtualized and which should not. This advantageously provides an increased performance.
In a fourth possible implementation form of the system according to the first aspect as such or according to any one of the preceding implementation forms of the first aspect, the virtualizer is configured to virtualize the type usage, wherein, if the type usage is unknown, the virtualizer is configured to infer the type usage.
In a fifth possible implementation form of the system according to the first aspect as such or according to any one of the preceding implementation forms of the first aspect, the virtualizer is configured to virtualize the type usage by classifying the type usage. This provides the effect that the type usage will be visible in the graph intermediate representation at staged evaluation. This advantageously provides an improved virtualization. Visibility in the graph during staged evaluation allows to apply optimization rules. How the rules are defined is not covered by this invention, any method is applicable as long as it is compatible with staged evaluation, in particular, it can be done using the approach described in the application PCT/RU2014/000652.
In a sixth possible implementation form of the system according to the first aspect as such or according to any one of the preceding implementation forms of the first aspect, the virtualizer is configured to classify the type usage by considering the visibility at a staged evaluation of the code. This provides the effect of a domain- specific optimization.This advantageously provides an improved feasibility of the domain-specific optimization without modifications of original source code. This classification means that the type information can be used to dynamically select different sets for optimization rules (classes of rules). By such classification, the rules can be connected to the properties of the particular domain, thus providing domain- specific optimization.
In a seventh possible implementation form of the system according to the first aspect as such or according to any one of the preceding implementation forms of the first aspect, the virtualizer is configured to perform the polymorphic embedding by wrapping the type usage and by applying a Rep type constructor. This provides the effect that an enhanced polymorphic embedding is provided. In particular virtualization allows to perform polymorphic embedding automatically. An improved performance of code virtualization is achieved.
In an eighth possible implementation form of the system according to the first aspect as such or according to any one of the preceding implementation forms of the first aspect, the virtualizer is configured to provide a subsequent method call of the methods of the created dynamic proxy and to provide a construction of new graph nodes for an intermediate representation by means of a subsequent execution of an invocation handler associated with the created dynamic proxy. This advantageously provides for a virtualized code which is very similar to the original code, simplifies the virtualization procedure, and makes staged evaluation applicable for any method call in source code. In the end an improved performance of code virtualization is achieved.
In a possible implementation form of the system according to the first aspect as such or according to any one of the preceding implementation forms of the first aspect, the virtualizer is configured to virtualize the method call into the function call that creates a dynamic proxy, wherein a subsequent method call of the methods of the dynamic proxy and a subsequent execution of an invocation handler associated with dynamic proxy results in a construction of new graph nodes of an intermediate representation. This advantageously provides for obtaining a virtulized code very similar to original code, for simplifying the virtualization procedure, and for making staged evaluation applicable for any method call in source code. An improved performance of code virtualization is thus achieved.
In a ninth possible implementation form of the system according to the first aspect as such or according to any one of the preceding implementation forms of the first aspect, the virtualizer is configured to virtualize a subexpression of the source code into a virtualized code whose execution produces a symbol of a node. This allows to perform virtualization of any parts in the source code within the virtualization scope.
In a tenth possible implementation form of the system according to the first aspect as such or according to any one of the preceding implementation forms of the first aspect, the virtualizer is configured to virtualize a subexpression of the source program into the symbol by an implicit virtualization due to a language facility or by an explicit virtualization using a virtualizer phase. There are language facilities such as implicit conversions in Scala which may simplify implementation of code virtualization.
In an eleventh possible implementation form of the system according to the first aspect as such or according to any one of the preceding implementation forms of the first aspect, the virtualizer is configured to virtualize a subexpression of the source program into the symbol using a proxy factory and to provide a proxy object for the resulting symbol, wherein preferably the proxy object is used to handle the method call. This allows for implementing execution of virtualized code in a reusable way, and thus to simplify the virtualization procedure.
In a twelfth possible implementation form of the system according to the first aspect as such or according to any one of the preceding implementation forms of the first aspect, the virtualizer is configured to produce virtualized program code, which during execution is constructed to:
i) handle a non-virtualized method call by calling a method of the proxy, wherein objects and/or arguments of the method are used as parameters of the proxy method call; and/or
ii) search a record in the symbol table comprising a link from a symbol to an IR node; and/or
iii) invoke the method of the found IR node; and/or
iv) update the symbol table by adding one or more records with the IR nodes and return one of the designated symbols as result of the proxy method call.
This advantageously provides for an efficient implementation of virtualized code execution and to simplify thus the virtualization algorithm/procedure.
In a further possible implementation form of the system according to the first aspect as such or according to any one of the preceding implementation forms of the first aspect, the virtualizer is configured to perform a domain-specific optimization for the virtualization of the code. This allows to optimize a program during the execution of the virtualization algorithm/procedure. This can save time, memory consumption and improve performance characteristics of the virtualized code.
According to a second aspect, the present invention relates to a method for virtualization of a code, wherein the method is used to operate a system according to the first aspect as such or according to any one of the preceding implementation forms of the first aspect.
In a first possible implementation form of the method according to the second aspect as such, the method further comprises the following steps of:
- identifying a scope of the virtualization by defining virtualization parameters;
- virtualizing a constants by passing each constant to a polymorphic function according to the defined virtualization parameters;
- virtualizing a type definition and a type usage by polymorphic embedding according to the defined virtualization parameters; and
- virtualizing a method call into a function call by creating a dynamic proxy and by wrapping a receiver object of the method call into the created dynamic proxy, according to the defined virtualization parameters. This advantageously provides an improved code virtualization of the source program.
According to a third aspect, the present invention relates to a compiler for object-oriented language configured to perform the method according to the second aspect as such or according to any one of the preceding implementation forms of the second aspect.
According to a fourth aspect, the present invention relates to computer program configured to operate a method according to the second aspect as such or according to any of the preceding implementation forms of the second aspect.
The methods, systems and devices described herein may be implemented as software in a Digital Signal Processor, DSP, in a micro-controller or in any other side- processor or as hardware circuit within an application specific integrated circuit, ASIC or in a field-programmable gate array which is an integrated circuit designed to be configured by a customer or a designer after manufacturing and configured and designed to perform the methods of the present invention.
The present invention can be implemented in adapted digital electronic circuitry, or in adapted computer hardware, firmware, software, or in combinations thereof, e.g. in available hardware of adapted mobile devices or in new hardware dedicated for processing the methods described herein.
These and other aspects of the present invention will become apparent from and be elucidated with reference to the embodiments described hereinafter. A more complete appreciation of the present invention and the attendant advantages thereof will be more clearly understood with reference to the following schematic drawings.
BRIEF DESCRIPTION OF THE DRAWINGS
Further embodiments of the present invention will be described with respect to the following figures, in which:
Fig. 1 shows a schematic diagram of a compiler for explaining the present invention;
Fig. 2 shows a schematic diagram of a compiler with code virtualization for explaining the present invention;
Fig. 3 shows a schematic diagram of a staged evaluation of method call for explaining the present invention;
Fig. 4 shows a schematic diagram of a system for virtualization of a code according to an exemplary embodiment of the present invention;
Fig. 5 shows a schematic diagram of a method for virtualization of a code according to an exemplary embodiment of the present invention;
Fig. 6 shows a schematic diagram of an example of HotSpot annotations according to an exemplary embodiment of the present invention;
Fig. 7 shows a schematic diagram of virtualizer inputs according to an exemplary embodiment of the present invention;
Fig. 8 shows a schematic diagram of an example of non-virtualized constant according to an exemplary embodiment of the present invention;
Fig. 9 shows a schematic diagram of an example of virrualized constant according to an exemplary embodiment of the present invention;
Fig. 10 shows a schematic diagram of an evaluation of toRep(O) according to an exemplary embodiment of the present invention;
Fig. 1 1 shows a schematic diagram of a virtualization of type definition according to an exemplary embodiment of the present invention; Fig. 12 shows a schematic diagram of an example of non-virtualized type usages according to exemplary an embodiment of the present invention;
Fig. 13 shows a schematic diagram of an example of virtualized type usages according to an exemplary embodiment of the present invention;
Fig. 14 shows a schematic diagram of a staged evaluation of method call according to an exemplary embodiment of the present invention;
Fig. 15 shows a schematic diagram of an example of hot spots according to an exemplary embodiment of the present invention;
Fig. 16 shows a schematic diagram of an example of kernel generation according to an exemplary embodiment of the present invention;
Fig. 17 shows a schematic diagram of benchmarks for Intel Xeon E5606 for explaining the present invention;
Fig. 18 demonstrates achieved speed up of generated kernels comparing to original code;
Fig. 19 shows a schematic diagram of a system for virtualization of a code according to an exemplary embodiment of the present invention; and
Fig. 20 shows a schematic diagram of a method for virtualization of a code according to an exemplary embodiment of the present invention.
DETAILED DESCRIPTION OF EMBODIMENTS OF THE INVENTION
In the associated figures, identical reference signs denote identical or at least equivalent elements, parts, units or steps. In addition, it should be noted that all of the accompanying drawings are not to scale.
The technical solutions in the embodiments of the present invention are described clearly and completely in the following with detailed reference to the accompanying drawings in the embodiments of the present invention.
The term "DSL" as used by the present invention may refer to a domain- specific language, DSL, which is a computer language specialized to a particular application domain.
The term "type system" as used by the present invention may refer to the following: In programming languages, a type system is a collection of rules that assign a property called a type to the various construct— such as variables, expressions, functions or modules— that a computer program is composed of. The term "executable code" as used by the present invention may refer to the following: A sequence of instructions to be executed by a processor to perform a given task, the processor can be software program - interpreter.
The term "executable machine code" as used by the present invention may refer to the following: A particular case of executable code; and/or a sequence of machine code instructions to be executed by a CPU to perform a given task.
The term "compiler" as used by the present invention may refer to the following: A computer program that takes source code of source program and produces executable machine code.
The term "tree data structure" as used by the present invention may refer to the following: A data structure that simulates a hierarchical tree structure with a set of linked nodes.
The term "intermediate representation, IR" as used by the present invention may refer to the following: A data structure that is used inside a compiler for representing the source program and allows analysis and transformation before outputting the executable machine code. Typically this is a graph or a tree data structure with some specific information inside nodes. As the intermediate representation contains all the information needed to evaluate the program, if given the input data, we can say about the evaluation of the intermediate representation as an equivalent way to execute the program.
The term "source program" as used by the present invention may refer to the following: A computer program that is used as an input to the compiler. It is translated into executable machine code.
The term "staged code" as used by the present invention may refer to the following: Staged code for a source program P is a program P' such that evaluation of P' produces intermediate representation, which is semantically equivalent to the program P.
The term "staged evaluation" as used by the present invention may refer to the following: Evaluation of a program that is separated into two stages: 1) IR generation, 2) IR execution. In staged evaluation, instead of resulting data value, the result of executing the program is an IR.
Fig. 1 shows a schematic diagram of a compiler for explaining the present invention.
Code virtualization is one of the necessary steps which may have to be done before staged evaluation. The last one is a special technique of a code evaluation that allows domain-specific optimizations.
Code virtualization abstracts types and language constructions from their representations as shown in Fig. 1. Code can be virtualized manually by a programmer or automatically by a compiler.
The present invention according to an exemplary embodiment describes a method of code virtualization automatically performed by the compiler.
As shown in Fig. 1, according to an exemplary embodiment, the structure of a programming language implementation comprises the following blocks executed in following order as stages:
i) parsing
ii) elaboration, for instance name and type resolution
iii) optimization
iv) code generation
v) execution of target code in hardware or in an interpreter
Fig. 2 shows a schematic diagram of a compiler with code virtualization for explaining the present invention.
Another structure which is based on non-traditional subdivision into two parts - frontend and backend - as shown in Fig. 2, where:
i) The frontend has an additional phase called "code virtualization".
ii) The backend is replaced by the staged evaluator, followed by an optimizer, a code generator and an execution of target code.
The approach may support two-phase development workflow where first phase is logic validation and second phase is profiling and generation of production code as shown in Fig. 2. On the second phase, the user has an option to tune the optimization engine by exploiting the properties of the domain.
This processing eliminates duplication of efforts made by every programmer when developing of parallel programs. Also, it is easy to add alternative frontends for already existing backend by exposing compiler backend as API. And also, it is possible to combine many backends in single frontend. Fig. 3 shows a schematic diagram of a staged evaluation of method call for explaining the present invention.
The staged evaluation as shown in Fig. 3 used by the present invention is applicable to object-oriented languages. This trait impacts on virtualization of method calls showed below:
i) wrap the symbol by a special proxy factory.
ii) create a (dynamic) proxy for the symbol.
iii) invoke the method call handler of the proxy.
iv) look up a node in the symbol table that is matched to the symbol.
v) produce a new symbol by invoking of the method of the node. By construction, a node has the same interface as its symbol's proxy. This is achieved by type system of the source language and virtualization, which preserves type soundness. vi) update the symbol table by adding association of new symbol with its node.
Fig. 4 shows a schematic diagram of a system for virtualization of a code according to an embodiment of the present invention.
The system for virtualization of a code may be configured to perform the following steps:
i) identify virtualization scope
ii) virtualize constants
iii) virtualize type definitions
iv) virtualize type usages
v) virtualize method calls
The system may comprise a new compiler phase and three input data for the phase. The system can be depicted schematically as shown in Fig. 4.
According to an exemplary embodiment of the present invention, advantageously, a general purpose compiler for object-oriented language is provided comprising a new phase which creates a virtualized copy of the abstract syntactic tree, AST, automatically.
According to an exemplary embodiment of the present invention, the virtualized AST has special properties that allow evaluating the code in staged mode
According to an exemplary embodiment of the present invention, the compiler phase may get the AST of an original language, a scope of virtualization and already virtualized libraries, and produces virtualized AST for the scope of virtualization.
According to an exemplary embodiment of the present invention, the new phase enriches the original AST by performing virtualization of:
i) constants; and/or
ii) type definitions and type usage; and/or
iii) method calls.
The system 100 for virtualization of a code may comprise at least one data source 102 and a virtualizer 101.
The virtualizer 101 is configured to be coupled to the at least one data source
102.
The virtualizer 101 is further configured to identify a scope of the virtualization of the code by defining virtualization parameters.
The virtualizer 101 is further configured to virtualize constants by passing each constant to a polymorphic function according to the defined virtualization parameters.
According to an exemplary embodiment of the present invention, only a part of the constants may be virtualized and only each of these constants may be passed. In other words, the virtualizer 101 is further configured to virtualize constants by passing the constants, e.g. the constants to be virtualized, to the polymorphic function according to the defined virtualization parameters.
The virtualizer 101 is further configured to virtualize a type definition and/or a type usage by polymorphic embedding according to the defined virtualization parameters.
The virtualizer 101 is further configured to virtualize a method call into a function call by creating a dynamic proxy and by wrapping a receiver object of the method call into the created dynamic proxy, according to the defined virtualization parameters.
The virtualizer 101 may be further configured to virtualize a method call by wrapping a receiver object of the method call into a proxy and by transforming the method call into method call of the wrapped proxy, according to the defined virtualization parameters.
Fig. 5 shows a schematic diagram of a method for virtualization of a code according to an embodiment of the present invention.
The steps as shown in Fig. 5 comprise: identifying a virtualization scope, step 0, virtualizing constants, step 1, virtualizing type definitions, step 2, virtualizing type usages, step 3, and virtualizing method calls, step 4.
The virtualizing of type definitions of step 2 may comprise a conditional inquiry, step 2.1 whether the type definition to be virtualized is virtualizable, e.g. is it possible to virtualize it. If yes, the type definition may be virtualized, steps 2.2, if not, a type wrapper may be defined, step 2.3.
The virtualizing of type usages of step 3 may comprise, inferring a type as step 3.0, classifying the type as step 3.1, a conditional inquiry, step 3.2 whether the type usage should be virtualized, and finally, if yes, a virtualization of the type usage, step 3.3.
Fig. 5 illustrates the method for virtualization of a code according to an embodiment of the present invention with some sub-steps.
Fig. 6 shows a schematic diagram of an example of HotSpot annotations according to an embodiment of the present invention.
According to an exemplary embodiment of the present invention, first of all, an auto virtualization phase, the virtualizer 101 may be configured to identify a scope of virtualization and parameters of virtualization.
According to an embodiment of the present invention, one of necessary input is original code which may contain special markers, for example annotations, attributes or special comments. These markers are configured to bound pieces of code and may look like in the Fig. 6.
Fig. 7 shows a schematic diagram of virtualizer inputs according to an embodiment of the present invention.
Fig. 7 shows another input of virtualizer is a configuration file. According to an embodiment of the present invention the input file may contain:
i) Parameters of virtualization. The configuration file as shown in Fig. 7 defines C++ compiler for hotspots and optimization options;
ii) Set of types that must be virtualized, also shown in Fig. 11.
iii) Set of already virtualized libraries that can be used in virtualization scopes. Fig. 8 shows a schematic diagram of an example of non-virtualized constant according to an embodiment of the present invention.
According to an exemplary embodiment of the present invention, constant virtualization may be performed by passing a constant as a parameter to a special polymorphic function, for instance in terms of monomorphic functions that accept a concrete type.
According to an exemplary embodiment of the present invention as shown in Fig. 8 and in Fig. 9, constant literal 0 is passed the polymorphic function toRep. This example assumes that the compiler infers type of the constant automatically.
Fig. 9 shows a schematic diagram of an example of virtualized constant according to an embodiment of the present invention.
According to an exemplary embodiment of the present invention, when the virtualized code is evaluated, the toRep function updates the symbol table by adding new record. The record may link a symbol assigned to the constant and its node in graph intermediate representation.
Fig. 10 shows a schematic diagram of an evaluation of toRep(O) according to an embodiment of the present invention.
According to an exemplary embodiment of the present invention, as shown in Fig. 10, it is demonstrated that toRep(O) assigns a new symbol SymO to the constant 0 and adds a new record to the symbol table. The actions may be performed during evaluation of the code showed in the Fig. 9.
Fig. 11 shows a schematic diagram of a virtualization of type definition according to an embodiment of the present invention.
The virtualizing of type definitions of step 2 may comprise a conditional inquiry, step 2.1 whether the type definition to be virtualized is virtualizable, e.g. is it possible to virtualize it. If yes, the type definition may be virtualized, steps 2.2, if not, a type wrapper may be defined, step 2.3.
Fig. 1 1 shows the step of virtualizing type definitions, step 2. The virtualizing of type definitions may be performed by polymorphic embedding according to the defined virtualization parameters
According to an exemplary embodiment of the present invention, a type may be defined in terms of its composition of more primitive types. Type definition may introduce type's representation and a set of operations manipulating these representations. To determine the way of type virtualization, the compiler may consider the following questions in terms of a conditional statement:
i). Is abstract syntactic tree of the type available for virtualization? ii). Is the type chosen in the configuration file for virtualization?
According to an exemplary embodiment of the present invention, if answers to both questions are "yes", the compiler should apply the steps i) to iv) of the method to the type definition. If the virtualization of the type is impossible for some reasons or an answer to one of the questions above is "no", the compiler may wrap the type by applying the corresponding method for code virtualization.
Fig. 12 shows a schematic diagram of an example of non-virtualized type usages according to an embodiment of the present invention.
Fig. 12 shows a schematic diagram of virtualizing a type usage, corresponding to step iii) of the method.
According to an exemplary embodiment of the present invention, the example as shown in Fig. 12 depicts non-virtualized types written by a programmer. The aim of the step may be for instance the virtualization of Array[Array[Double]], Array[Double] and inferred types for values matrix and vector, and for the r parameter.
According to an exemplary embodiment of the present invention, the compiler may follow the steps P0 to P3 below to virtualize a type usage:
P0. This is an optional step. If type is unknown, the compiler should infer actual type.
PI. Classify the type. Should the type be visible in graph IR at staged evaluation (regular type) or not (type class).
P2. If the type is identified as a type class, a stop virtualization of this type usage is performed.
P3. If the type should be virtualized, wrap the type by applying polymorphic embedding technique. The Rep polymorphic type is used for wrapping. For instance, Array[Double] should be transformed to Rep[Array[Double]].
Fig. 13 shows a schematic diagram of an example of virtualized type usages according to an exemplary embodiment of the present invention.
Fig. 13 demonstrates this transformation or virtualization for original code as shown in Fig. 12.
Fig. 14 shows a schematic diagram of a staged evaluation of method call according to an exemplary embodiment of the present invention.
Fig. 14 shows a schematic diagram of a virtualization of method calls. The visualization may be performed by using a method that is called during staged evaluation:
According to an exemplary embodiment of the present invention, the virtualization of the method call is performed by wrapping the receiver object of the method call into function call that may create a dynamic proxy.
According to an exemplary embodiment of the present invention, the receiver of a method call in source program code after performing the virtualization will be for instance a symbol, for instance of some node, thus it may be not possible to call method of the symbol directly, instead the symbol is wrapped in a proxy, and the method of the proxy is called.
Evaluation of the vres.items method call in staged mode goes through the following steps:
Ql . The vres symbol may be wrapped by a special proxy factory. It could be done implicitly due to language facilities or explicitly by the virtualizer phase.
Q2. The proxyFactory may produce a new factory proxy VRes for the vres symbol.
Q3. The .items call may be handled by the proxy VRes. The handler may take method objects and method's arguments as parameters.
Q4. The handler may search a record in the symbol table which has a link to IR node - vresNode.
Q5. The handler may invoke the items method of vresNode. It is possible because a symbol has same interface as its node a priori. This invocation implemented using some dynamic invocation mechanism, for example using Java Reflection.
Q6. As a result the last invoke may update the symbol table by adding new record with IR node and its symbol related to the vres.items method call.
The described method shows that the compiler doesn't have to modify method calls in common cases.
Fig. 15 shows a schematic diagram of an example of hot spots according to an embodiment of the present invention.
One of the advantages of the present invention is the feasibility of domain- specific optimization without modifications of original source code. Let's consider an example of multiplication of a matrix by a vector.
A developer of the program figures out the ddmvm function may be for instance actively used in the program and may represent a bottleneck de-facto. And he/she wants to eliminate abstraction overhead and applies some domain-specific optimization to this piece of code.
According to an embodiment of the present invention, the ddmvm function is marked by a special annotation as a HotSpot which is handled by the compiler extended by a new phase - also referred to as a "virtualizer". The virtualizer may take the abstract syntactic tree, AST, of the ddmvm function and may apply the method of virtualization proposed by the present invention.
According to an embodiment of the present invention, the result of the transformation is a plurality of virtual spots. Their textual representation is depicted in the Fig. 15. After code virtualization, special kernels can be generated for the hot spots. This process is showed schematically in the Fig. 16.
Fig. 16 shows a schematic diagram of an example of kernel generation according to an embodiment of the present invention.
Fig. 16 shows a schematic diagram of the next phase of the compiler generates optimized kernel for the ddmvm function. The "Substitution" phase may replace the body of the original function by the call of the generated kernel.
Fig. 17 shows a schematic diagram of benchmarks for Intel Xeon E5606 for explaining the present invention.
The table in the Fig. 17 has measurements for original code ("Scala"), kernel generated in imperative style in Scala language and kernel in C++ language. The measurements were done on GNU/Linux, Scala 2.11.6 and gcc 4.7.4 for one CPU core.
Fig. 17 shows a schematic diagram of benchmarks for Intel Xeon E5606 for explaining the present invention.
Fig. 18 demonstrates the achieved speed up of generated kernels comparing to original code. Fig. 19 shows a schematic diagram of a system for virtualization of a code according to an embodiment of the present invention.
The system 100 for virtualization of a code may comprise at least one data source 102 and a virtualizer 101.
Fig. 20 shows a schematic diagram of a flowchart diagram of a method for virtualization of a code according to an embodiment of the present invention.
Fig. 20 shows a schematic diagram of a flowchart diagram of a method which is used to operate the system 100.
The method further comprises the following steps.
As a first step of the method, identifying SI a scope of the virtualization by defining virtualization parameters may be performed.
As a second step of the method virtualizing S2 constants by passing each constant to a polymorphic function according to the defined virtualization parameters may be performed.
As a third step of the method virtualizing S3 a type definition and a type usage by polymorphic embedding according to the defined virtualization parameters may be performed.
As a fourth step of the method virtualizing S4 a method call into a function call by creating a dynamic proxy and by wrapping a receiver object of the method call into the created dynamic proxy, according to the defined virtualization parameters may be performed.
As a further step of the method virtualizing a method call into a function call by creating a dynamic proxy and by wrapping a receiver object of the method call into the created dynamic proxy, according to the defined virtualization parameters may be performed.
From the foregoing, it will be apparent to those skilled in the art that a variety of methods, systems, computer programs on recording media, and the like, are provided.
The present disclosure also supports a computer program product including computer executable code or computer executable instructions that, when executed, causes at least one computer to execute the performing and computing steps described herein. Many alternatives, modifications, and variations will be apparent to those skilled in the art in light of the above teachings. Of course, those skilled in the art readily recognize that there are numerous applications of the invention beyond those described herein.
While the present invention has been described with reference to one or more particular embodiments, those skilled in the art recognize that many changes may be made thereto without departing from the scope of the present invention. It is therefore to be understood that within the scope of the appended claims and their equivalents, the inventions may be practiced otherwise than as specifically described herein.
In the claims, the word "comprising" does not exclude other elements or steps, and the indefinite article "a" or "an" does not exclude a plurality. A single processor or other unit may fulfill the functions of several items recited in the claims.
The mere fact that certain measures are recited in mutually different dependent claims does not indicate that a combination of these measured cannot be used to advantage. A computer program may be stored or distributed on a suitable medium, such as an optical storage medium or a solid-state medium supplied together with or as part of other hardware, but may also be distributed in other forms, such as via the Internet or other wired or wireless telecommunication systems.

Claims

PATENT CLAIMS
1. A system (100) for virtualization of a code, the system (100) comprising:
i) at least one data source (102); and
ii) a virtualizer (101), which is configured to be coupled to the at least one data source (102) and which is configured to
- identify a scope of the virtualization of the code by defining virtualization parameters;
- virtualize constants by passing each constant to a polymorphic function according to the defined virtualization parameters;
- virtualize a type definition and/or a type usage by polymorphic embedding according to the defined virtualization parameters; and
- virtualize a method call into a function call by creating a dynamic proxy and by wrapping a receiver object of the method call into the created dynamic proxy according to the defined virtualization parameters.
2. The system (100) according to claim 1 ,
wherein the virtualizer (101) is configured to identify the scope of the virtualization of the code by examining a marker provided within the code, wherein the marker is
i) an annotation; and/or
ii) an attribute; and/or
iii) a part of the virtualization parameters.
3. The system (100) according to one of the preceding claims,
wherein the virtualizer (101) is configured to identify the scope of the virtualization of the code by examining a configuration file as provided by the at least one data source (102), wherein the configuration file comprises:
i) the virtualization parameters; and/or
ii) a set of type definitions to be virtualized; and/or
iii) a set of type usages to be virtualized; and/or
iv) a set of virtualized libraries used for the virtualization.
4. The system (100) according to one of the preceding claims, wherein the virtualizer (101) is configured to virtualize the type definition in terms of a plurality of primitive type definitions.
5. The system (100) according to one of the preceding claims,
wherein the virtualizer (101) is configured to virtualize the type usage, wherein, if the type usage is unknown, the virtualizer (101) is configured to infer the type usage.
6. The system (100) according to one of the preceding claims,
wherein the virtualizer (101) is configured to virtualize the type usage by classifying the type usage.
7. The system (100) according to claim 6,
wherein the virtualizer (101) is configured to classify the type usage by considering the visibility at a staged evaluation of the code.
8. The system (100) according to one of the preceding claims,
wherein the virtualizer (101) is configured to perform the polymorphic embedding by wrapping the type usage and by applying a Rep-type constructor.
9. The system (100) according to one of the preceding claims,
wherein the virtualizer (101) is configured to provide a subsequent method call of the methods of the created dynamic proxy and to provide a construction of new graph nodes for an intermediate representation by means of a subsequent execution of an invocation handler associated with the created dynamic proxy.
10. The system (100) according to one of the preceding claims,
wherein the virtualizer (101) is configured to virtualize a subexpression of the source code into virtualized code whose execution produces a symbol of a node.
11. The system (100) according claim 10,
wherein the virtualizer (101) is configured to virtualize a subexpression of the source program into the symbol by an implicit virtualization due to a language facility or by an explicit virtualization using a virtualizer phase.
12. The system (100) according to claim 11 ,
wherein the virtualizer (101) is configured to virtualize a subexpression of the source program into the symbol using a proxy factory and to provide a proxy object for the resulting symbol, wherein preferably the proxy object is used to handle the method call.
13. The system (100) according to one of the preceding claims, wherein the virtualizer (101) is configured to produce virtualized program code, which during execution is constructed to:
i) handle a non-virtualized method call by calling a method of the proxy, wherein objects and/or arguments of the method are used as parameters of the proxy method call; and/or
ii) search a record in the symbol table comprising a link from a symbol to an IR node; and/or
iii) invoke the method of the found IR node; and/or
iv) update the symbol table by adding one or more records with the IR nodes and return one of the designated symbols as result of the proxy method call.
14. The system (100) according to one of the preceding claims,
wherein the virtualizer (101) is configured to perform a domain-specific optimization for the virtualization of the code.
15. A method for virtualization of a code, the method used to operate a system (100) according to one of the preceding claims 1 to 14.
16. The method according to claim 15, wherein the method further comprises the following steps of:
- identifying (SI) a scope of the virtualization by defining virtualization parameters;
- virtualizing (S2) constants by passing each constant to a polymorphic function according to the defined virtualization parameters;
- virtualizing (S3) a type definition and a type usage by polymorphic embedding according to the defined virtualization parameters; and
- virtualizing (S4) a method call into a function call by creating a dynamic proxy and by wrapping a receiver object of the method call into the created dynamic proxy according to the defined virtualization parameters.
17. A compiler for object-oriented language configured to perform the method according to one of the preceding claims 15 to 16.
18. A computer program configured to operate a method according to one of the preceding claims 15 to 16 when executed on a computer.
PCT/RU2015/000846 2015-12-04 2015-12-04 Automatic code virtualization for a compiler WO2017095257A1 (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN201580085075.7A CN108369499B (en) 2015-12-04 2015-12-04 Code virtualization system and method
PCT/RU2015/000846 WO2017095257A1 (en) 2015-12-04 2015-12-04 Automatic code virtualization for a compiler

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/RU2015/000846 WO2017095257A1 (en) 2015-12-04 2015-12-04 Automatic code virtualization for a compiler

Publications (1)

Publication Number Publication Date
WO2017095257A1 true WO2017095257A1 (en) 2017-06-08

Family

ID=56464265

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/RU2015/000846 WO2017095257A1 (en) 2015-12-04 2015-12-04 Automatic code virtualization for a compiler

Country Status (2)

Country Link
CN (1) CN108369499B (en)
WO (1) WO2017095257A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2019199197A1 (en) 2018-04-12 2019-10-17 Huawei Technologies Co., Ltd. A system and a method of fast java object materialization from database data

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113626773B (en) * 2020-05-06 2024-04-02 上海蜚语信息科技有限公司 Code protection method based on intermediate language

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2001079997A1 (en) * 2000-04-17 2001-10-25 Codemesh, Inc. A method of and system for sharing components between programming languages

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5838980A (en) * 1994-01-18 1998-11-17 Sybase, Inc. Compilation and virtual machine arrangement and process for source code including pre-runtime executable language structure constructs
CN103365665A (en) * 2013-07-25 2013-10-23 成都品果科技有限公司 Application program transplantation method based on virtual instruction

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2001079997A1 (en) * 2000-04-17 2001-10-25 Codemesh, Inc. A method of and system for sharing components between programming languages

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
ALEXANDER SLESARENKO ET AL: "First-class isomorphic specialization by staged evaluation", GENERIC PROGRAMMING, ACM, 2 PENN PLAZA, SUITE 701 NEW YORK NY 10121-0701 USA, 26 August 2014 (2014-08-26), pages 35 - 46, XP058054974, ISBN: 978-1-4503-3042-8, DOI: 10.1145/2633628.2633632 *
ALEXANDER SLESARENKO: "Lightweight Polytypic Staging: a new approach to Nested Data Parallelism in Scala", PROCEEDINGS OF THE 3RD ANNUAL SCALA WORKSHOP, APRIL 17-18, 2012, LONDON, UK, 17 April 2012 (2012-04-17), pages 1 - 12, XP055189311, Retrieved from the Internet <URL:http://days2012.scala-lang.org/sites/days2012/files/slesarenko_polystage.pdf> [retrieved on 20150513] *
ROMPF TIARK ET AL: "Scala-Virtualized: linguistic reuse for deep embeddings", HIGHER-ORDER AND SYMBOLIC COMPUTATION, KLUWER ACADEMIC PUBLISHER, NORWELL, MA, US, vol. 25, no. 1, 20 September 2013 (2013-09-20), pages 165 - 207, XP035456375, ISSN: 1388-3690, [retrieved on 20130920], DOI: 10.1007/S10990-013-9096-9 *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2019199197A1 (en) 2018-04-12 2019-10-17 Huawei Technologies Co., Ltd. A system and a method of fast java object materialization from database data
US11934422B2 (en) 2018-04-12 2024-03-19 Huawei Technologies Co., Ltd. System and a method of fast java object materialization from database data

Also Published As

Publication number Publication date
CN108369499A (en) 2018-08-03
CN108369499B (en) 2021-04-20

Similar Documents

Publication Publication Date Title
KR101099212B1 (en) An intermediate representation for multiple exception handling models
CN110149800B (en) Apparatus for processing abstract syntax tree associated with source code of source program
US10331824B2 (en) Dynamically loaded system-level simulation
US8930285B2 (en) Composite production rules
JP5740349B2 (en) Expression transformation in a computer environment
Chambers Object-oriented programming, functional programming and R
US7890942B2 (en) Array value substitution and propagation with loop transformations through static analysis
van Beusekom et al. Formalising the Dezyne modelling language in mCRL2
Antoy et al. A new functional-logic compiler for curry: Sprite
CN108369499B (en) Code virtualization system and method
WO2017065631A1 (en) Method and system for transforming a source code into a target code on a computer
JP6651974B2 (en) Information processing apparatus, compiling method and compiler program
Moyen et al. Loop quasi-invariant chunk detection
Kiss et al. Generic deriving of generic traversals
Naus et al. A formal semantics for P-Code
Romeikat et al. Translation of QVT relations into QVT operational mappings
CN116266119A (en) Method, apparatus and article of manufacture for generating usage-dependent code embeddings
JP7410269B2 (en) Automated verification of high-level construct optimization using test vectors
JP5600301B2 (en) System representation and handling technology
Tetzel et al. Efficient compilation of regular path queries
Koopman et al. Operational machine specification in a functional programming language
CN117234466B (en) Enterprise management software development method, system, equipment and storage medium
US8621447B1 (en) Systems and methods for dynamic struct variable creation including inline declaration with dynamic keys
Abrahamsson A Verified Theorem Prover for Higher-Order Logic
AU2016100581A4 (en) Compilation method for linking region-specific computer logic

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: 15879265

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 15879265

Country of ref document: EP

Kind code of ref document: A1