US20180129488A1 - Optimized execution of dynamic languages - Google Patents

Optimized execution of dynamic languages Download PDF

Info

Publication number
US20180129488A1
US20180129488A1 US15/863,797 US201815863797A US2018129488A1 US 20180129488 A1 US20180129488 A1 US 20180129488A1 US 201815863797 A US201815863797 A US 201815863797A US 2018129488 A1 US2018129488 A1 US 2018129488A1
Authority
US
United States
Prior art keywords
function
type
type signature
signature
cache
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Abandoned
Application number
US15/863,797
Inventor
Solomon Boulos
Jeremy SUGERMAN
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Google LLC
Original Assignee
Google LLC
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 Google LLC filed Critical Google LLC
Priority to US15/863,797 priority Critical patent/US20180129488A1/en
Publication of US20180129488A1 publication Critical patent/US20180129488A1/en
Abandoned legal-status Critical Current

Links

Images

Classifications

    • 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/60Software deployment
    • 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/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4482Procedural
    • G06F9/4484Executing subprograms
    • 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
    • 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/45529Embedded in an application, e.g. JavaScript in a Web browser

Definitions

  • Dynamic languages such as PHP: Hypertext Preprocessor (PHP), Python, Ruby, and Perl have been adopted heavily for web development and applications development because they allow for high developer productivity due to their flexibility in comparison to static languages such as C, Java, or C++. However, this flexibility typically leads to significantly slower execution of these languages over static languages.
  • PHP Hypertext Preprocessor
  • Python Python
  • Ruby Ruby
  • Perl have been adopted heavily for web development and applications development because they allow for high developer productivity due to their flexibility in comparison to static languages such as C, Java, or C++. However, this flexibility typically leads to significantly slower execution of these languages over static languages.
  • Dynamic languages such as PHP: Hypertext Preprocessor (PHP), Python, Ruby, and Perl have been adopted heavily for web development and applications development because they allow for high developer productivity due to their flexibility in comparison to static languages such as C, Java, or C++. However, this flexibility typically leads to significantly slower execution of these languages over static languages.
  • PHP Hypertext Preprocessor
  • Python Python
  • Ruby Ruby
  • Perl have been adopted heavily for web development and applications development because they allow for high developer productivity due to their flexibility in comparison to static languages such as C, Java, or C++. However, this flexibility typically leads to significantly slower execution of these languages over static languages.
  • the disclosed subject matter relates to a method for optimizing execution of dynamic language code, the method including identifying a first dynamic language function call during runtime, the function call including one or more argument values for one or more arguments of the function.
  • the method may further include calculating a type signature for the one or more argument values of the function.
  • the method may further include determine if a function associated with the type signature is stored in a cache.
  • the method may further include looking up the function in the cache when the function associated with the type signature is stored in the cache.
  • the method may further include dynamically calling the function associated with the type signature when the function for the type signature is not stored in the cache.
  • the disclosed subject matter also relates to a system including one or more processors and a machine-readable medium comprising instructions stored therein, which when executed by the processors, cause the processors to perform operations including identifying a first dynamic language function call during runtime, the function call including one or more argument values for the one or more arguments of the function.
  • the operations may further include determining a type for each of the one or more argument values.
  • the operations may further include generating a type signature for the function according to the type for each of the one or more argument values.
  • the operations may further include identifying a function associated with the type signature.
  • the operations may further include generating code based on the identified function, in response to the function call.
  • Other aspects can be embodied in corresponding systems and apparatus, including computer program products.
  • the disclosed subject matter also relates to a machine-readable medium including instructions stored therein, which when executed by a machine, cause the machine to perform operations including identifying a first dynamic language function call during runtime, the function call including one or more argument values for the one or more arguments of the function.
  • the operations may further include determining a type for each of the one or more argument values.
  • the operations may further include generating a type signature for the function according to the type for each of the one or more argument values.
  • the operations may further include determining if a function associated with the type signature is stored in a cache.
  • the operations may further include looking up the function in the cache when the function associated with the type signature is stored in the cache.
  • the operations may further include dynamically calling the function associated with the type signature when the function for the type signature is not stored in the cache.
  • FIG. 1 illustrates an example client-server network environment, which provides for generation of specialized intermediate representation (“IR”) and optimized generation of machine code at runtime.
  • IR intermediate representation
  • FIG. 2 illustrates an example application server for use in facilitating optimized generation of machine code at runtime.
  • FIG. 3 illustrates a flow diagram of an example process for generating IR from a PHP code block (e.g., a function).
  • a PHP code block e.g., a function
  • FIG. 4 illustrates a flow diagram of an example process for optimizing runtime generation of machine code by generating specialized type signature specific functions at runtime.
  • FIG. 5 conceptually illustrates an electronic system with which some implementations of the subject technology are implemented.
  • Dynamic languages allow for more flexibility due to their dynamic nature.
  • Several features of dynamic languages contribute to their productive characteristics. For example, these languages allow for runtime typing and the ability to evaluate new data as code dynamically (e.g., “eval” in PHP and JavaScript). These characteristics allow developers to write code that can be used more flexibility than static code written in static languages such as C, Java, or C++.
  • the dynamic languages enable more flexible development practices by allowing developers to conditionally generate new executable code from existing code at runtime to handle novel data.
  • Static languages may enforce compile time static typing and may not allow dynamic code execution.
  • static languages the types of functions and variables are typically known at compile time, and the full scope of executable code is usually known by the compiler. Accordingly, a static language can be translated to machine code efficiently prior to a program's execution.
  • IR intermediate representation
  • the present disclosure provides a method and system for optimizing execution of dynamic languages through generating machine code for a code block including condition code that allows for dynamic generation of machine code for specific functions.
  • intermediate representation of code can be generated for a code block, where one or more operations may be predefined.
  • the IR includes a special lazy call for each conditional operation. The lazy call within the IR allows for execution of the code such that it does not compile the operation (e.g., function) unless the operation is ran during execution.
  • the lazy call allows for the entire code block to be translated into IR, while allowing for the conditional portions of the code to be excluded from compilation unless and until the portion needs to be executed (e.g., the condition is satisfied).
  • the condition portions of the call need not be compiled causing waste of resources, unless and until, the condition is satisfied.
  • the dynamic nature of the code is preserved, while allowing for processing of other portions of the code that are static in nature and thus can be processed and translated before run time.
  • inline caching allows for dynamically resolving function calls at runtime.
  • a function call is conditional and resolves at runtime depending on a condition (e.g., a dynamic value of an input to the function)
  • the logical function call is transformed to a lookup into a table of table of function pointer, and thus, dynamically looks up the function at runtime.
  • the call to look up the function at runtime either returns the function, or throws an error if the function is not found.
  • Inline caching further improves the dynamic function call by only calling the function once and caching the function (e.g., within a function table) once it's been called.
  • specialized versions of the functions can be generated based on the type of arguments for the function. That is, instead of generating a single function call that handles all argument types, a version optimized function call that takes into account the possible argument types (e.g., the most likely argument types) for the function may be called. Once specialized function calls are generated, they can be easily mapped to machine instructions for the specific argument type.
  • One approach is to build a polymorphic inline cache which creates a function that compares the object's argument type against a small number of previously used argument type. For each of the previously used argument types, a specialized function is provided.
  • a non-specialized implementation may generate a single version of the function Square that can handle any type for argument $x.
  • the function can be optimized based on the specific type of argument $x (e.g., whether $x is an integer, as in the first call, or a float, as in the second call).
  • $x is an integer, as in the first call, or a float, as in the second call.
  • the specialization can be achieved by generating the inline cache from the polymorphic in its arguments as follows:
  • a separate specialized function may be generated for a set of argument types of a function.
  • a type signature may be calculated for an argument at runtime and checked dynamically.
  • For each type signatures specialized function may be generated separately at runtime.
  • each specialized function associated with the unique type signature may be stored as a separate entry in a cache (e.g., as a separate table entry in the function table).
  • the type signatures can be computed ahead of time and cached for later retrieval.
  • a type signature can be computed (e.g., a bitmask of the argument types) and checked dynamically, as follows:
  • the signatures and FnTable values can be emitted directly as literal immediate values in the machine code (initially as sentinel values that cannot be matched, so that GetFunctionPointer is called).
  • SIG0 and FnTable[] on demand from memory, allowing them to be modified without changing the underlying machine code.
  • type signature and function table entry can be looked up on demand from memory, allowing them to be modified without changing the underlying machine code.
  • specializations are provided for a limited set of argument types (e.g., two or three of the most common argument types for a function).
  • type inference may be performed to determine the possible or most likely argument types for a function and specializations may be performed according to the type inference.
  • the number of specialized functions for each function may be limited. For example, the specialization may be limited to two specializations plus a generic function.
  • FIG. 1 illustrates an example client-server network environment, which provides for generation of specialized intermediate representation (“IR”) and optimized generation of machine code at runtime.
  • the network environment 100 includes a number of clients 102 and 104 communicably connected to an application server 110 .
  • application server 110 can be any system or device having a processor, a memory and communications capability for facilitating optimized generation of machine code at runtime.
  • FIG. 2 illustrated in more detail below, illustrates an example application server 110 .
  • clients 102 and 104 can be any client issuing web requests to the application server 110 .
  • client 102 may be a mobile client and client 104 may be a browser client (e.g., web browser). Communications between the clients 102 and 104 and server 110 may be facilitated through various communication protocols (e.g., the HTTP protocol).
  • Network 120 can be a public communication network (e.g., the Internet, cellular data network, dialup modems over a telephone network) or a private communications network (e.g., private LAN, leased lines).
  • the network 120 can include, for example, any one or more of a personal area network (PAN), a local area network (LAN), a campus area network (CAN), a metropolitan area network (MAN), a wide area network (WAN), a broadband network (BBN), the Internet, and the like.
  • PAN personal area network
  • LAN local area network
  • CAN campus area network
  • MAN metropolitan area network
  • WAN wide area network
  • BBN broadband network
  • the network 120 can include, but is not limited to, any one or more of the following network topologies, including a bus network, a star network, a ring network, a mesh network, a star-bus network, tree or hierarchial network, and the like. Further, network 120 can include, but is not limited to, any one or more of the following network topologies, including a bus network, a star network, a ring network, a mesh network, a star-bus network, a tree or hierarchial network, and the like.
  • FIG. 2 illustrates an example application server 200 for use in facilitating optimized generation of machine code at runtime.
  • the application server 200 may be used as the application server 110 described above with respect to FIG. 1 .
  • application server 200 includes a dynamic language runtime module 201 , a plugins module 202 , a caching module 203 , a standard library module 204 , an http module 205 and a management module 206 .
  • Runtime module 201 includes logic for facilitating optimized generation of machine code at runtime.
  • runtime module 201 includes logic for generating specialized IR.
  • the plugins module 202 includes a memory for storing a set of dynamic language plugins for use during code generation and/or runtime execution.
  • plugins stored within the plugin module 201 may, for example, provide extensions and/or additional functionality to the dynamic language.
  • the plugins may include plugins for communicating with databases such as SQL or SQL server, and/or plugins for parsing XML, and other extended functionality.
  • Caching module 203 facilitates storing data for facilitating optimized generation of machine code at runtime.
  • caching module 203 may include memory for storing type set and/or location sets for one or more functions, operations and/or variables generated according to various methods and processes described herein.
  • caching module 203 may further facilitate storing per request and/or across request information for facilitating optimized generation of machine code at runtime (e.g., a page request).
  • caching module 203 may store function tables for storing specialize function code for one or more functions.
  • the caching module may further store type signatures and/or type sets for one or more arguments of a function.
  • Standard library module 204 may store one or more predefined functions and/or operations for the dynamic language.
  • the standard library module 204 includes memory for storing a wide range of built-in modules that provide access to system functionality, as well as modules that provide standardized solutions (e.g., built-in operations).
  • the modules may provide abstractions of existing core language to provide platform neutrality.
  • HTTP module 205 may include logic for responding to requests from one or more clients (e.g., clients 102 and/or 104 ).
  • HTTP module 205 may include logic for responding to requests for webpages.
  • the logic may include logic for setting up a connection, communicating with one or more clients for accessing request from and/or responding to clients, etc.
  • the HTTP module may further include information such as HTTP error codes and/or other information for communicating with one or more clients via the HTTP protocol.
  • Management module 206 provides operations and/or developer functionality.
  • the management module 206 may store one or more debuggers, profilers, stat counters, loggers, etc.
  • FIG. 3 illustrates a flow diagram of an example process 300 for generating IR from a PHP code block (e.g., a function).
  • PHP e.g., a function
  • the use of PHP is for exemplary purposes. While the example flow diagram illustrates a PHP file, it should be understood by one of ordinary skill in the art that same or similar steps may represent generation of IR for other dynamic languages.
  • a code block (e.g., file) is first parsed.
  • the code block file.php is illustrated as being parsed. Parsing the code block results in generating a CFG as shown in block 302 .
  • High level optimizations are next performed on the CFG as shown in block 303 (e.g., combining ECHO “Hi” and ECHO “there! ⁇ n” into ECHO “hi there! ⁇ n”).
  • LLVM IR is generated from the optimized CFG.
  • other processes may be performed to optimize generation of IR.
  • type set and location set inferences may be performed according to processes described herein to optimize generation of IR (e.g., to allow for specialized IR based on specific types and locations of expressions with a code block such as file.php). Additionally, specialized or partial specialization of code (e.g., based on type or location inferences) may be performed. Once IR is generated, further optimizations (e.g., standard and/or traditional compiler optimizations) may be performed at the IR level.
  • caching may be performed to avoid re-compilation of a code block both at the file and/or function level, so that code generation need not be duplicated.
  • one or more tables are generated to keep track of previously compiled files, functions, etc.
  • the table(s) may be inserted into a cache (e.g., within caching module 203 ).
  • a function table may stored one or more functions and/or specialized functions generated during runtime.
  • a table may store type signatures calculated for an argument and/or function.
  • the system may determine if file.php was previously compiled into machine code (e.g., stored within caching module 203 ) and has not been modified since. If so, the compiled machine code is accessed and executed. Otherwise, the file is compiled (or re-compiled) and the compiled file may be stored within the cache (e.g., within a file table within the cache module 203 ). Similarly, the system may determine if the function Dolt( ) within the file.php has been previously compiled and has not been modified since. If so, the complied machine code is accessed and executed. Otherwise, the function is compiled (or re-compiled) and the compiled function may be stored within the cache (e.g., within a file table within the cache module 203 ).
  • FIG. 4 illustrates a flow diagram of an example process 400 for optimizing runtime generation of machine code by generating specialized type signature specific functions at runtime.
  • a first call to a dynamic language function is detected at runtime.
  • the function call includes one or more argument values for each of the one of more arguments of the function, where each argument value is of a specific type.
  • a type signature of the one or more argument values is calculated.
  • a second function may be called to calculate the type signature for arguments of a function call.
  • the type signature is calculated dynamically.
  • the determination introduces a delay into the process. However, in some examples, the delay may be reduced by performing type inference for one or more functions, such that the argument type for arguments of a function is known before the function is called at run-time.
  • Type set inferences may be performed according to various sources of type information including signature of builtins (e.g., defined return types), return types computed for user functions, argument types from call-time function specialization and rules of the language (e.g., certain operations always return certain types).
  • signature of builtins e.g., defined return types
  • return types computed for user functions e.g., return types computed for user functions
  • argument types from call-time function specialization e.g., certain operations always return certain types.
  • type sets may be generated for arguments of a function using forward data flow analysis.
  • a control flow graph (CFG) is generated for the function.
  • the CFG generates one or more basic blocks each comprising a set of operations. Each basic block represents a straight-line portion of the code block without any jumps or jump targets. Some operations may include one or more variables. In another example, an operation may not include a variable.
  • the CFG may be used to infer a type and/or location set for one or more operations and/or variables of the CFG.
  • forward dataflow analysis traverses all paths within the CFG to infer type sets for arguments of the function, according to some implementations.
  • Type flowing includes determining, in some examples, traversing the CFG to determine the type of the operation and/or variables within the operation for each operation of the CFG can be inferred through forward dataflow analysis.
  • the type set for each argument of the function may be set to undefined at the beginning of the forward flow analysis.
  • each operation of the CFG is analyzed to determine if types for the arguments of the function may be reduced to one or more known types (a “type set”).
  • the forward dataflow analyses runs until convergence which occurs when the input states to all basic blocks of the CFG no longer change.
  • the process tor calculating type signature can be optimized, such that the delay is minimal or not significant
  • the type signature calculation may be entirely eluded. However, even where the type inference provides a set of possible argument types, the bitwise operations required to compote the type signature are reduced.
  • a first table storing type information generated based on forward data flow analysis may be checked to determine type inference information for the function and/or arguments of the function. If the type information provides a single type for an argument the type signature is determined as the single type. If more than one possible type is provided in the type set for an argument of the function, the type signature calculation may include determining which of the possible types the argument type is. Otherwise, if no type information is provided, the type signature calculation may include determining a type of the arguments of the function from all possible argument types.
  • a simple bit mask of a specific number of bits (e.g., 4 bits) per argument may be used, to support types for all function arguments in a single, compact signature.
  • the specialization may be limited by the number of arguments within the function (e.g., to 16 arguments). For example, for functions with more than a threshold number of arguments (e.g., 16 arguments), specialization may not be performed.
  • type signatures for one or more arguments of the function may be cached and retrieved in future function calls to the same function.
  • a check may be performed to determine if the argument type for a function call is previously determined and cached.
  • step 403 it is determined if a specialized function for the type signature determined in step 402 , is available in a cache.
  • a specialized function may be stored as a separate entry within a function table.
  • the lookup includes a function lookup including an identifier of the type signature to determine if a specialized function for the specific type signature is cached.
  • only specialized functions for a limited number of type signatures may be generated, and for the remaining type signatures a generic function may be generated and/or used during runtime.
  • the function table look up looks for the generic function.
  • step 403 it is determined that a specialized function (or generic function where only limited specialized functions are generated), is available in a cache, the specialized function (or generic function) is accessed and used during runtime to perform the function call.
  • a specialized function or generic function where only limited specialized functions are generated
  • a call is made to look up or generate the specialized (or generic) function for the specific type signature calculated in step 402 dynamically at runtime.
  • the specialized function for the specific type signature may be generated dynamically at runtime, based on the generic function and the specific argument type associated with the type signature.
  • the specialized (or generic) function is received and stored within a cache.
  • the specialized function may then be retrieved and used when the function is called at runtime with the specific type signature.
  • Computer readable storage medium also referred to as computer readable medium.
  • processing unit(s) e.g., one or more processors, cores of processors, or other processing units
  • processing unit(s) e.g., one or more processors, cores of processors, or other processing units
  • Examples of computer readable media include, but are not limited to, CD-ROMs, flash drives, RAM chips, hard drives, EPROMs, etc.
  • the computer readable media does not include carrier waves and electronic signals passing wirelessly or over wired connections.
  • the term “software” is meant to include firmware residing in read-only memory or applications stored in magnetic storage, which can be read into memory for processing by a processor.
  • multiple software aspects of the subject disclosure can be implemented as sub-parts of a larger program while remaining distinct software aspects of the subject disclosure.
  • multiple software aspects can also be implemented as separate programs.
  • any combination of separate programs that together implement a software aspect described her is within the scope of the subject disclosure.
  • the software programs when installed to operate on one or more electronic systems, define one or more specific machine implementations that execute and perform the operations of the software programs.
  • a computer program (also known as a program, software, software application, script, or code) can be written in any form of programming language, including compiled or interpreted languages, declarative or procedural languages, and it can be deployed in any form, including as a standalone program or as a module, component, subroutine, object, or other unit suitable for use in a computing environment.
  • a computer program may, but need not, correspond to a file in a file system.
  • a program can be stored in a portion of a file that holds other programs or data (e.g., one or more scripts stored in a markup language document), in a single file dedicated to the program in question, or in multiple coordinated files (e.g., files that store one or more modules, sub programs, or portions of code).
  • a computer program can be deployed to be executed on one computer or on multiple computers that are located at one site or distributed across multiple sites and interconnected by a communication network.
  • FIG. 5 conceptually illustrates an electronic system with which some implementations of the subject technology are implemented.
  • Electronic system 500 can be a server, computer, phone, PDA, laptop, tablet computer, television with one or more processors embedded therein or coupled thereto, or any other sort of electronic device.
  • Such an electronic system includes various types of computer readable media and interfaces for various other types of computer readable media.
  • Electronic system 500 includes a bus 508 , processing unit(s) 512 , a system memory 504 , a read-only memory (ROM) 510 , a permanent storage device 502 , an input device interface 514 , an output device interface 506 , and a network interface 516 .
  • processing unit(s) 512 includes a bus 508 , processing unit(s) 512 , a system memory 504 , a read-only memory (ROM) 510 , a permanent storage device 502 , an input device interface 514 , an output device interface 506 , and a network interface 516 .
  • Bus 508 collectively represents all system, peripheral, and chipset buses that communicatively connect the numerous internal devices of electronic system 500 .
  • bus 508 communicatively connects processing unit(s) 512 with ROM 510 , system memory 504 , and permanent storage device 502 .
  • processing unit(s) 512 retrieves instructions to execute and data to process in order to execute the processes of the subject disclosure.
  • the processing unit(s) can be a single processor or a multi-core processor in different implementations.
  • ROM 510 stores static data and instructions that are needed by processing unit(s) 512 and other modules of the electronic system.
  • Permanent storage device 502 is a read-and-write memory device. This device is a non-volatile memory unit that stores instructions and data even when electronic system 500 is off. Some implementations of the subject disclosure use a mass-storage device (such as a magnetic or optical disk and its corresponding disk drive) as permanent storage device 502 .
  • system memory 504 is a read-and-write memory device. However, unlike storage device 502 , system memory 504 is a volatile read-and-write memory, such a random access memory. System memory 504 stores some of the instructions and data that the processor needs at runtime. In some implementations, the processes of the subject disclosure are stored in system memory 504 , permanent storage device 502 , and/or ROM 510 .
  • the various memory units include instructions for generation of specialized intermediate representation (“IR”) and optimized generation of machine code at runtime according to various implementations. From these various memory units, processing unit(s) 512 retrieves instructions to execute and data to process in order to execute the processes of some implementations.
  • IR intermediate representation
  • Bus 508 also connects to input and output device interfaces 514 and 506 .
  • Input device interface 514 enables the user to communicate information and select commands to the electronic system.
  • Input devices used wit input device interface 514 include, for example, alphanumeric keyboards and pointing devices (also called “cursor control devices”).
  • Output device interfaces 506 enables, for example, the display of images generated by the electronic system 500 .
  • Output devices used with output device interface 506 include, for example, printers and display devices, such as cathode ray tubes (CRT) or liquid crystal displays (LCD). Some implementations include devices such as a touchscreen that functions as both input and output devices.
  • CTR cathode ray tubes
  • LCD liquid crystal displays
  • bus 508 also couples electronic system 500 to a network (not shown) through a network interface 516 .
  • the computer can be a part of a network of computers (such as a local area network (“LAN”), a wide area network (“WAN”), or an Intranet, or a network of networks, such as the Internet. Any or all components of electronic system 500 can be used in conjunction with the subject disclosure.
  • Some implementations include electronic components, such as mircoprocessors, storage and memory that store computer program instructions in a machine-readable or computer-readable medium (alternatively referred to as computer-readable storage media, machine-readable media, or machine-readable storage media).
  • computer-readable media include RAM, ROM, read-only compact discs (CD-ROM), recordable compact discs (CD-R), rewritable compact discs (CD-RW), read-only digital versatile discs (e.g., DVD-ROM, dual-layer DVD-ROM), a variety of recordable/rewritable DVDs (e.g., DVD-RAM, DVD-RW, DVD+RW, etc.), flash memory (e.g., SD cards, mini-SD cards, micro-SD cards, etc.), magnetic and/or solid state hard drives, read-only and recordable Blu-Ray® discs, ultra density optical discs, any other optical or magnetic media, and floppy disks.
  • CD-ROM compact discs
  • CD-R recordable compact discs
  • the computer-readable media can store a computer program that is executable by at least one processing unit and includes sets of instructions for performing various operations.
  • Examples of computer programs or computer code include machine code, such as is produced by a compiler, and files including higher-level code that are executed by a computer, an electronic component, or a microprocessor using an interpreter.
  • ASICs application specific integrated circuits
  • FPGAs field programmable gate arrays
  • integrated circuits execute instructions that are stored on the circuit itself.
  • the terms “computer”, “server”, “processor”, and “memory” all refer to electronic or other technological devices. These terms exclude people or groups of people.
  • display or displaying means displaying on an electronic device.
  • computer readable medium and “computer readable media” are entirely restricted to tangible, physical objects that store information in a form that is readable by a computer. These terms exclude any wireless signals, wired download signals, and any other ephemeral signals.
  • implementations of the subject matter described in this specification can be implemented on a computer having a display device, e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor, for displaying information to the user and a keyboard and a pointing device, e.g., a mouse or a trackball, by which the user can provide input to the computer.
  • a display device e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor
  • keyboard and a pointing device e.g., a mouse or a trackball
  • Other kinds of devices can be used to provide for interaction with a user as well; for example, feedback provided to the user can be any form of sensory feedback, e.g., visual feedback, auditory feedback, or tactile feedback; and input from the user can be received in any form, including acoustic, speech, or tactile input.
  • a computer can interact with a user by sending documents to and receiving documents from a device that is used
  • Implementations of the subject matter described in this specification can be implemented in a computing system that includes a back end component, e.g., as a data server, or that includes a middleware component, e.g., an application server, or that includes a front end component, e.g., a client computer having a graphical user interface or a Web browser through which a user can interact with an implementation of the subject matter described in this specification, or any combination of one or more such back end, middleware, or front end components.
  • the components of the system can be interconnected by any form or medium of digital data communication, e.g., a communication network.
  • Examples of communication networks include a local area network (“LAN”) and a wide area network (“WAN”), an inter-network (e.g., the Internet), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks).
  • LAN local area network
  • WAN wide area network
  • inter-network e.g., the Internet
  • peer-to-peer networks e.g., ad hoc peer-to-peer networks.
  • the computing system can include clients and servers.
  • a client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other.
  • a server transmits data (e.g., an HTML page) to a client device (e.g., for purposes of displaying data to and receiving user input from a user interacting with the client device).
  • client device e.g., for purposes of displaying data to and receiving user input from a user interacting with the client device.
  • Data generated at the client device e.g., a result of the user interaction
  • a phrase such as an “aspect” does not imply that such aspect is essential to the subject technology or that such aspect applies to all configurations of the subject technology.
  • a disclosure relating to an aspect may apply to all configurations, or one or more configurations.
  • a phrase such as an aspect may refer to one or more aspects and vice versa.
  • a phrase such as a “configuration” does not imply that such configuration is essential to the subject technology or that such configuration applies to all configurations of the subject technology.
  • a disclosure relating to a configuration may apply to all configurations, or one or more configurations.
  • a phrase such as a configuration may refer to one or more configurations and vice versa.

Abstract

In one aspect, a method for optimizing executing of dynamic language code is provided, the method includes identifying a first dynamic language function call during runtime, the function call including argument values for one or more arguments of the function, calculating a type signature for the one or more argument values of the function, determining if a function associated with the type signature is stored in a cache, looking up the function in the cache when the function associated with the type signature is stored in the cache and dynamically calling the function associated with the type signature when the specialized function for the type signature is not stored in the cache.

Description

    BACKGROUND
  • Dynamic languages such as PHP: Hypertext Preprocessor (PHP), Python, Ruby, and Perl have been adopted heavily for web development and applications development because they allow for high developer productivity due to their flexibility in comparison to static languages such as C, Java, or C++. However, this flexibility typically leads to significantly slower execution of these languages over static languages.
  • Dynamic languages such as PHP: Hypertext Preprocessor (PHP), Python, Ruby, and Perl have been adopted heavily for web development and applications development because they allow for high developer productivity due to their flexibility in comparison to static languages such as C, Java, or C++. However, this flexibility typically leads to significantly slower execution of these languages over static languages.
  • SUMMARY
  • The disclosed subject matter relates to a method for optimizing execution of dynamic language code, the method including identifying a first dynamic language function call during runtime, the function call including one or more argument values for one or more arguments of the function. The method may further include calculating a type signature for the one or more argument values of the function. The method may further include determine if a function associated with the type signature is stored in a cache. The method may further include looking up the function in the cache when the function associated with the type signature is stored in the cache. The method may further include dynamically calling the function associated with the type signature when the function for the type signature is not stored in the cache. Other aspects can be embodied in corresponding systems and apparatus, including computer program products.
  • The disclosed subject matter also relates to a system including one or more processors and a machine-readable medium comprising instructions stored therein, which when executed by the processors, cause the processors to perform operations including identifying a first dynamic language function call during runtime, the function call including one or more argument values for the one or more arguments of the function. The operations may further include determining a type for each of the one or more argument values. The operations may further include generating a type signature for the function according to the type for each of the one or more argument values. The operations may further include identifying a function associated with the type signature. The operations may further include generating code based on the identified function, in response to the function call. Other aspects can be embodied in corresponding systems and apparatus, including computer program products.
  • The disclosed subject matter also relates to a machine-readable medium including instructions stored therein, which when executed by a machine, cause the machine to perform operations including identifying a first dynamic language function call during runtime, the function call including one or more argument values for the one or more arguments of the function. The operations may further include determining a type for each of the one or more argument values. The operations may further include generating a type signature for the function according to the type for each of the one or more argument values. The operations may further include determining if a function associated with the type signature is stored in a cache. The operations may further include looking up the function in the cache when the function associated with the type signature is stored in the cache. The operations may further include dynamically calling the function associated with the type signature when the function for the type signature is not stored in the cache. Other aspects can be embodied in corresponding systems and apparatus, including computer program products.
  • It is understood that other configurations of the subject technology will become readily apparent from the following detailed description, where various configurations of the subject technology are shown and described by way of illustration. As will be realized, the subject technology is capable of other and different configurations and its several details are capable of modification in various other respects, all without departing from the scope of the subject technology. Accordingly, the drawings and detailed description are to be regarded as illustrative in nature and not as restrictive.
  • BRIEF DESCRIPTION OF THE DRAWINGS
  • Certain features of the subject technology are set forth in the appended claims. However, for purpose of explanation, several implementations of the subject technology are set forth in the following figures.
  • FIG. 1 illustrates an example client-server network environment, which provides for generation of specialized intermediate representation (“IR”) and optimized generation of machine code at runtime.
  • FIG. 2 illustrates an example application server for use in facilitating optimized generation of machine code at runtime.
  • FIG. 3 illustrates a flow diagram of an example process for generating IR from a PHP code block (e.g., a function).
  • FIG. 4 illustrates a flow diagram of an example process for optimizing runtime generation of machine code by generating specialized type signature specific functions at runtime.
  • FIG. 5 conceptually illustrates an electronic system with which some implementations of the subject technology are implemented.
  • DETAILED DESCRIPTION
  • The detailed description set forth below is intended as a description of various configurations of the subject technology and is not intended to represent the only configurations in which the subject technology may be practiced. The appended drawings are incorporated herein and constitute a part of the detailed description. The detailed description includes specific details for the purpose of providing a thorough understanding of the subject technology. However, it will be clear and apparent that the subject technology is not limited to the specific details set forth herein and may be practiced without these specific details.
  • Dynamic languages allow for more flexibility due to their dynamic nature. Several features of dynamic languages contribute to their productive characteristics. For example, these languages allow for runtime typing and the ability to evaluate new data as code dynamically (e.g., “eval” in PHP and JavaScript). These characteristics allow developers to write code that can be used more flexibility than static code written in static languages such as C, Java, or C++. For example, the dynamic languages enable more flexible development practices by allowing developers to conditionally generate new executable code from existing code at runtime to handle novel data.
  • Typically the execution of these languages is significantly slower than that of static languages because the types of variables and functions and full scope of executable code for dynamic languages is not statically known.
  • Static languages may enforce compile time static typing and may not allow dynamic code execution. For those static languages, the types of functions and variables are typically known at compile time, and the full scope of executable code is usually known by the compiler. Accordingly, a static language can be translated to machine code efficiently prior to a program's execution.
  • In the case of a dynamic language, the full scope of the executable code is not known, and the types of many functions and variables may not be known until the moment the code is executed. For these reasons a dynamic language cannot be completely converted to machine code prior to execution. In addition, even runtime translation to machine code is often impractical for these dynamic languages because the just-in-time compilation process may itself require significant execution resources leading to diminished performance during execution. Accordingly, generating machine code efficiently prior to execution is often difficult. The need for significant execution resources for machine code translation during runtime leads to diminished performance during execution.
  • To facilitate more optimized machine code generation and runtime execution, methods and systems are provided for facilitating generation of specialized intermediate representation (“IR”).
  • The present disclosure provides a method and system for optimizing execution of dynamic languages through generating machine code for a code block including condition code that allows for dynamic generation of machine code for specific functions. In certain aspects intermediate representation of code can be generated for a code block, where one or more operations may be predefined. To allow for generation of IR for an entire block while accounting for dynamic components within the code block such as functions that might not run during execution (e.g., because of a conditional loop), the IR includes a special lazy call for each conditional operation. The lazy call within the IR allows for execution of the code such that it does not compile the operation (e.g., function) unless the operation is ran during execution.
  • The lazy call allows for the entire code block to be translated into IR, while allowing for the conditional portions of the code to be excluded from compilation unless and until the portion needs to be executed (e.g., the condition is satisfied). Thus, in some implementations, the condition portions of the call need not be compiled causing waste of resources, unless and until, the condition is satisfied. In this manner, the dynamic nature of the code is preserved, while allowing for processing of other portions of the code that are static in nature and thus can be processed and translated before run time.
  • Once the condition is satisfied at runtime, however, the function has to be resolved. In dynamic languages (e.g., PHP), function calls are not resolvable statically (e.g., ahead of runtime) and instead need to be resolved dynamically at runtime. In order to efficiently resolve these function calls at runtime various techniques may be employed. For example, inline caching allows for dynamically resolving function calls at runtime. Using inline caching, when a function call is conditional and resolves at runtime depending on a condition (e.g., a dynamic value of an input to the function), the logical function call is transformed to a lookup into a table of table of function pointer, and thus, dynamically looks up the function at runtime. In one example, the call to look up the function at runtime either returns the function, or throws an error if the function is not found. Inline caching further improves the dynamic function call by only calling the function once and caching the function (e.g., within a function table) once it's been called.
  • To further optimize the function call, specialized versions of the functions can be generated based on the type of arguments for the function. That is, instead of generating a single function call that handles all argument types, a version optimized function call that takes into account the possible argument types (e.g., the most likely argument types) for the function may be called. Once specialized function calls are generated, they can be easily mapped to machine instructions for the specific argument type. One approach is to build a polymorphic inline cache which creates a function that compares the object's argument type against a small number of previously used argument type. For each of the previously used argument types, a specialized function is provided.
  • For example, with respect to the following example function:
  • <?php
    function Squares($x) { return $x * $x; }
    Square(10);
    Square(12.0);
    ?>
  • A non-specialized implementation may generate a single version of the function Square that can handle any type for argument $x. However, the function can be optimized based on the specific type of argument $x (e.g., whether $x is an integer, as in the first call, or a float, as in the second call). By specializing the function based on the argument type, the code generated for the function can be much more efficient.
  • In one example, the specialization can be achieved by generating the inline cache from the polymorphic in its arguments as follows:
  • if ($arg->type == Int) {
     %f = Square_Int;
    } else if ($arg->type == Float) {
     %f = Square_Float;
    } else {
     %f = Square_General;
    }
  • However, this would require that specialized functions are built ahead of time and can be called from the inline cache, where each time, the conditional is checked to call the correct specialized function.
  • To allow for dynamic specialization and further optimize the process, instead of a single function including specialized functions for the different argument types, a separate specialized function may be generated for a set of argument types of a function. In one example, a type signature may be calculated for an argument at runtime and checked dynamically. For each type signatures specialized function may be generated separately at runtime. Once generated, each specialized function associated with the unique type signature may be stored as a separate entry in a cache (e.g., as a separate table entry in the function table). In some examples, the type signatures can be computed ahead of time and cached for later retrieval.
  • For example, for the above function, a type signature can be computed (e.g., a bitmask of the argument types) and checked dynamically, as follows:
  • typeSig = . . . ComputeTypeSignature from args . . . ;
    if (typeSig == SIG0) {
     %f = FnTable[“Square”, 0];
    } else if (typeSig == SIG1) {
     %f = FnTable[“Square”, 1];
    } . . . {
     %f = GetFunctionPointer(“Square”, typeSig);
    }
  • Where [SIG0, SIG1, . . . ], are possible type signatures for the function.
  • For code-generation systems where machine code replacement is possible, the signatures and FnTable values can be emitted directly as literal immediate values in the machine code (initially as sentinel values that cannot be matched, so that GetFunctionPointer is called). However, with systems such as LLVM's JIT or other systems that cannot edit the machine code once generated, we lookup SIG0 and FnTable[] on demand from memory, allowing them to be modified without changing the underlying machine code.
  • Thus, the type signature and function table entry can be looked up on demand from memory, allowing them to be modified without changing the underlying machine code. In some examples, specializations are provided for a limited set of argument types (e.g., two or three of the most common argument types for a function). In one example, type inference may be performed to determine the possible or most likely argument types for a function and specializations may be performed according to the type inference. In some examples, the number of specialized functions for each function may be limited. For example, the specialization may be limited to two specializations plus a generic function.
  • Using call specialization, the code of the function as well as all downstream callees of the function can be optimized.
  • FIG. 1 illustrates an example client-server network environment, which provides for generation of specialized intermediate representation (“IR”) and optimized generation of machine code at runtime. The network environment 100 includes a number of clients 102 and 104 communicably connected to an application server 110.
  • According to some aspects, application server 110 can be any system or device having a processor, a memory and communications capability for facilitating optimized generation of machine code at runtime. FIG. 2, described in more detail below, illustrates an example application server 110.
  • In some example implementations, clients 102 and 104 can be any client issuing web requests to the application server 110. In the example of FIG. 1, client 102 may be a mobile client and client 104 may be a browser client (e.g., web browser). Communications between the clients 102 and 104 and server 110 may be facilitated through various communication protocols (e.g., the HTTP protocol).
  • In one example, the communication between application server 110 and clients 102 and 104 may be through a network 120. Network 120 can be a public communication network (e.g., the Internet, cellular data network, dialup modems over a telephone network) or a private communications network (e.g., private LAN, leased lines). The network 120 can include, for example, any one or more of a personal area network (PAN), a local area network (LAN), a campus area network (CAN), a metropolitan area network (MAN), a wide area network (WAN), a broadband network (BBN), the Internet, and the like. Further, the network 120 can include, but is not limited to, any one or more of the following network topologies, including a bus network, a star network, a ring network, a mesh network, a star-bus network, tree or hierarchial network, and the like. Further, network 120 can include, but is not limited to, any one or more of the following network topologies, including a bus network, a star network, a ring network, a mesh network, a star-bus network, a tree or hierarchial network, and the like.
  • FIG. 2 illustrates an example application server 200 for use in facilitating optimized generation of machine code at runtime. In one example, the application server 200 may be used as the application server 110 described above with respect to FIG. 1. In some implementations, application server 200 includes a dynamic language runtime module 201, a plugins module 202, a caching module 203, a standard library module 204, an http module 205 and a management module 206.
  • Runtime module 201 includes logic for facilitating optimized generation of machine code at runtime. In one example, runtime module 201 includes logic for generating specialized IR.
  • In one example, the plugins module 202 includes a memory for storing a set of dynamic language plugins for use during code generation and/or runtime execution. In one example, plugins stored within the plugin module 201 may, for example, provide extensions and/or additional functionality to the dynamic language. For example, the plugins may include plugins for communicating with databases such as SQL or SQL server, and/or plugins for parsing XML, and other extended functionality.
  • Caching module 203 facilitates storing data for facilitating optimized generation of machine code at runtime. For example, caching module 203 may include memory for storing type set and/or location sets for one or more functions, operations and/or variables generated according to various methods and processes described herein. In one example, caching module 203 may further facilitate storing per request and/or across request information for facilitating optimized generation of machine code at runtime (e.g., a page request). For example, caching module 203 may store function tables for storing specialize function code for one or more functions. In one example, the caching module may further store type signatures and/or type sets for one or more arguments of a function.
  • Standard library module 204 may store one or more predefined functions and/or operations for the dynamic language. In one example, the standard library module 204 includes memory for storing a wide range of built-in modules that provide access to system functionality, as well as modules that provide standardized solutions (e.g., built-in operations). For example, in some examples, the modules may provide abstractions of existing core language to provide platform neutrality.
  • In some examples, HTTP module 205 may include logic for responding to requests from one or more clients (e.g., clients 102 and/or 104). For example, HTTP module 205 may include logic for responding to requests for webpages. The logic may include logic for setting up a connection, communicating with one or more clients for accessing request from and/or responding to clients, etc. The HTTP module may further include information such as HTTP error codes and/or other information for communicating with one or more clients via the HTTP protocol.
  • Management module 206 provides operations and/or developer functionality. For example, the management module 206 may store one or more debuggers, profilers, stat counters, loggers, etc.
  • FIG. 3 illustrates a flow diagram of an example process 300 for generating IR from a PHP code block (e.g., a function). The use of PHP is for exemplary purposes. While the example flow diagram illustrates a PHP file, it should be understood by one of ordinary skill in the art that same or similar steps may represent generation of IR for other dynamic languages.
  • As shown in block 301, a code block (e.g., file) is first parsed. Here, the code block file.php is illustrated as being parsed. Parsing the code block results in generating a CFG as shown in block 302. High level optimizations are next performed on the CFG as shown in block 303 (e.g., combining ECHO “Hi” and ECHO “there!\n” into ECHO “hi there!\n”). Next, in block 304, LLVM IR is generated from the optimized CFG. In some examples, in addition to high level optimizations of the CFG, other processes may be performed to optimize generation of IR. For example, type set and location set inferences may be performed according to processes described herein to optimize generation of IR (e.g., to allow for specialized IR based on specific types and locations of expressions with a code block such as file.php). Additionally, specialized or partial specialization of code (e.g., based on type or location inferences) may be performed. Once IR is generated, further optimizations (e.g., standard and/or traditional compiler optimizations) may be performed at the IR level.
  • In some examples caching may be performed to avoid re-compilation of a code block both at the file and/or function level, so that code generation need not be duplicated. In one example, one or more tables are generated to keep track of previously compiled files, functions, etc. The table(s), may be inserted into a cache (e.g., within caching module 203). For example, a function table may stored one or more functions and/or specialized functions generated during runtime. In another example, a table may store type signatures calculated for an argument and/or function.
  • For example, in the present example, the system may determine if file.php was previously compiled into machine code (e.g., stored within caching module 203) and has not been modified since. If so, the compiled machine code is accessed and executed. Otherwise, the file is compiled (or re-compiled) and the compiled file may be stored within the cache (e.g., within a file table within the cache module 203). Similarly, the system may determine if the function Dolt( ) within the file.php has been previously compiled and has not been modified since. If so, the complied machine code is accessed and executed. Otherwise, the function is compiled (or re-compiled) and the compiled function may be stored within the cache (e.g., within a file table within the cache module 203).
  • FIG. 4 illustrates a flow diagram of an example process 400 for optimizing runtime generation of machine code by generating specialized type signature specific functions at runtime.
  • In step 401, a first call to a dynamic language function is detected at runtime. In one example, the function call includes one or more argument values for each of the one of more arguments of the function, where each argument value is of a specific type.
  • In step 402, a type signature of the one or more argument values is calculated. In one example, a second function may be called to calculate the type signature for arguments of a function call. In one example, the type signature is calculated dynamically. In some examples, the determination introduces a delay into the process. However, in some examples, the delay may be reduced by performing type inference for one or more functions, such that the argument type for arguments of a function is known before the function is called at run-time.
  • Type set inferences may be performed according to various sources of type information including signature of builtins (e.g., defined return types), return types computed for user functions, argument types from call-time function specialization and rules of the language (e.g., certain operations always return certain types).
  • Accordingly, type sets may be generated for arguments of a function using forward data flow analysis. In one example, a control flow graph (CFG) is generated for the function. The CFG generates one or more basic blocks each comprising a set of operations. Each basic block represents a straight-line portion of the code block without any jumps or jump targets. Some operations may include one or more variables. In another example, an operation may not include a variable. The CFG may be used to infer a type and/or location set for one or more operations and/or variables of the CFG.
  • For example, forward dataflow analysis traverses all paths within the CFG to infer type sets for arguments of the function, according to some implementations. Type flowing includes determining, in some examples, traversing the CFG to determine the type of the operation and/or variables within the operation for each operation of the CFG can be inferred through forward dataflow analysis.
  • In one example, when performing forward data flow analysis for the function, the type set for each argument of the function may be set to undefined at the beginning of the forward flow analysis. Next, each operation of the CFG is analyzed to determine if types for the arguments of the function may be reduced to one or more known types (a “type set”). The forward dataflow analyses runs until convergence which occurs when the input states to all basic blocks of the CFG no longer change.
  • In some examples, for functions where type inference has been, performed, and possible argument types are known, the process tor calculating type signature can be optimized, such that the delay is minimal or not significant In some examples, where the type inference provides only a single possible argument type for arguments of the function, the type signature calculation may be entirely eluded. However, even where the type inference provides a set of possible argument types, the bitwise operations required to compote the type signature are reduced.
  • Accordingly, in some examples, during step 402, a first table storing type information generated based on forward data flow analysis may be checked to determine type inference information for the function and/or arguments of the function. If the type information provides a single type for an argument the type signature is determined as the single type. If more than one possible type is provided in the type set for an argument of the function, the type signature calculation may include determining which of the possible types the argument type is. Otherwise, if no type information is provided, the type signature calculation may include determining a type of the arguments of the function from all possible argument types.
  • In one example, to keep the calculated signatures compact, a simple bit mask of a specific number of bits (e.g., 4 bits) per argument may be used, to support types for all function arguments in a single, compact signature. In one example, the specialization may be limited by the number of arguments within the function (e.g., to 16 arguments). For example, for functions with more than a threshold number of arguments (e.g., 16 arguments), specialization may not be performed.
  • In one example, once calculated, type signatures for one or more arguments of the function may be cached and retrieved in future function calls to the same function. In some examples, when the function call is received, and before determining a type signature, in step 402, a check may be performed to determine if the argument type for a function call is previously determined and cached.
  • In step 403, it is determined if a specialized function for the type signature determined in step 402, is available in a cache. In one example, for each type signature calculated for a function, a specialized function may be stored as a separate entry within a function table. In some examples, the lookup includes a function lookup including an identifier of the type signature to determine if a specialized function for the specific type signature is cached. In one example, only specialized functions for a limited number of type signatures may be generated, and for the remaining type signatures a generic function may be generated and/or used during runtime. In one example, where the type signature is not a type signature associated with a specialized function, the function table look up looks for the generic function.
  • If, in step 403, it is determined that a specialized function (or generic function where only limited specialized functions are generated), is available in a cache, the specialized function (or generic function) is accessed and used during runtime to perform the function call.
  • Otherwise, in step 404, a call is made to look up or generate the specialized (or generic) function for the specific type signature calculated in step 402 dynamically at runtime. In one example, where the type signature requires a specialized function, the specialized function for the specific type signature may be generated dynamically at runtime, based on the generic function and the specific argument type associated with the type signature.
  • In step 405, the specialized (or generic) function is received and stored within a cache. In one example, the specialized function may then be retrieved and used when the function is called at runtime with the specific type signature.
  • Many of the above-described features and applications are implemented as software processes that are specified as a set of instructions recorded on a computer readable storage medium (also referred to as computer readable medium). When these instructions are executed by one or more processing unit(s) (e.g., one or more processors, cores of processors, or other processing units), they cause the processing unit(s) to perform the action indicated in the instructions. Examples of computer readable media include, but are not limited to, CD-ROMs, flash drives, RAM chips, hard drives, EPROMs, etc. The computer readable media does not include carrier waves and electronic signals passing wirelessly or over wired connections.
  • In this specification, the term “software” is meant to include firmware residing in read-only memory or applications stored in magnetic storage, which can be read into memory for processing by a processor. Also, in some implementations, multiple software aspects of the subject disclosure can be implemented as sub-parts of a larger program while remaining distinct software aspects of the subject disclosure. In some implementations, multiple software aspects can also be implemented as separate programs. Finally, any combination of separate programs that together implement a software aspect described her is within the scope of the subject disclosure. In some implementations, the software programs, when installed to operate on one or more electronic systems, define one or more specific machine implementations that execute and perform the operations of the software programs.
  • A computer program (also known as a program, software, software application, script, or code) can be written in any form of programming language, including compiled or interpreted languages, declarative or procedural languages, and it can be deployed in any form, including as a standalone program or as a module, component, subroutine, object, or other unit suitable for use in a computing environment. A computer program may, but need not, correspond to a file in a file system. A program can be stored in a portion of a file that holds other programs or data (e.g., one or more scripts stored in a markup language document), in a single file dedicated to the program in question, or in multiple coordinated files (e.g., files that store one or more modules, sub programs, or portions of code). A computer program can be deployed to be executed on one computer or on multiple computers that are located at one site or distributed across multiple sites and interconnected by a communication network.
  • FIG. 5 conceptually illustrates an electronic system with which some implementations of the subject technology are implemented. Electronic system 500 can be a server, computer, phone, PDA, laptop, tablet computer, television with one or more processors embedded therein or coupled thereto, or any other sort of electronic device. Such an electronic system includes various types of computer readable media and interfaces for various other types of computer readable media. Electronic system 500 includes a bus 508, processing unit(s) 512, a system memory 504, a read-only memory (ROM) 510, a permanent storage device 502, an input device interface 514, an output device interface 506, and a network interface 516.
  • Bus 508 collectively represents all system, peripheral, and chipset buses that communicatively connect the numerous internal devices of electronic system 500. For instance, bus 508 communicatively connects processing unit(s) 512 with ROM 510, system memory 504, and permanent storage device 502.
  • From these various memory units, processing unit(s) 512 retrieves instructions to execute and data to process in order to execute the processes of the subject disclosure. The processing unit(s) can be a single processor or a multi-core processor in different implementations.
  • ROM 510 stores static data and instructions that are needed by processing unit(s) 512 and other modules of the electronic system. Permanent storage device 502, on the other hand, is a read-and-write memory device. This device is a non-volatile memory unit that stores instructions and data even when electronic system 500 is off. Some implementations of the subject disclosure use a mass-storage device (such as a magnetic or optical disk and its corresponding disk drive) as permanent storage device 502.
  • Other implementations use a removable storage device (such us a floppy disk, flash drive, and its corresponding disk drive) as permanent storage device 502. Like permanent storage device 502, system memory 504 is a read-and-write memory device. However, unlike storage device 502, system memory 504 is a volatile read-and-write memory, such a random access memory. System memory 504 stores some of the instructions and data that the processor needs at runtime. In some implementations, the processes of the subject disclosure are stored in system memory 504, permanent storage device 502, and/or ROM 510. For example, the various memory units include instructions for generation of specialized intermediate representation (“IR”) and optimized generation of machine code at runtime according to various implementations. From these various memory units, processing unit(s) 512 retrieves instructions to execute and data to process in order to execute the processes of some implementations.
  • Bus 508 also connects to input and output device interfaces 514 and 506. Input device interface 514 enables the user to communicate information and select commands to the electronic system. Input devices used wit input device interface 514 include, for example, alphanumeric keyboards and pointing devices (also called “cursor control devices”). Output device interfaces 506 enables, for example, the display of images generated by the electronic system 500. Output devices used with output device interface 506 include, for example, printers and display devices, such as cathode ray tubes (CRT) or liquid crystal displays (LCD). Some implementations include devices such as a touchscreen that functions as both input and output devices.
  • Finally, as shown in FIG. 5, bus 508 also couples electronic system 500 to a network (not shown) through a network interface 516. In this manner, the computer can be a part of a network of computers (such as a local area network (“LAN”), a wide area network (“WAN”), or an Intranet, or a network of networks, such as the Internet. Any or all components of electronic system 500 can be used in conjunction with the subject disclosure.
  • These functions described above can be implemented in digital electronic circuitry, in computer software, firmware or hardware. The techniques can be implemented using one or more computer program products. Programmable processors and computers can be included in or packaged as mobile devices. The processes and logic flows can be performed by one or more programmable processors and by one or more programmable logic circuitry. General and special purpose computing devices and storage devices can be interconnected through communication networks.
  • Some implementations include electronic components, such as mircoprocessors, storage and memory that store computer program instructions in a machine-readable or computer-readable medium (alternatively referred to as computer-readable storage media, machine-readable media, or machine-readable storage media). Some examples of such computer-readable media include RAM, ROM, read-only compact discs (CD-ROM), recordable compact discs (CD-R), rewritable compact discs (CD-RW), read-only digital versatile discs (e.g., DVD-ROM, dual-layer DVD-ROM), a variety of recordable/rewritable DVDs (e.g., DVD-RAM, DVD-RW, DVD+RW, etc.), flash memory (e.g., SD cards, mini-SD cards, micro-SD cards, etc.), magnetic and/or solid state hard drives, read-only and recordable Blu-Ray® discs, ultra density optical discs, any other optical or magnetic media, and floppy disks. The computer-readable media can store a computer program that is executable by at least one processing unit and includes sets of instructions for performing various operations. Examples of computer programs or computer code include machine code, such as is produced by a compiler, and files including higher-level code that are executed by a computer, an electronic component, or a microprocessor using an interpreter.
  • While the above discussion primarily refers to microprocessor or multi-core processors that execute software, some implementations are performed by one or more integrated circuits, such as application specific integrated circuits (ASICs) or field programmable gate arrays (FPGAs). In some implementations, such integrated circuits execute instructions that are stored on the circuit itself.
  • As used in this specification and any claims of this application, the terms “computer”, “server”, “processor”, and “memory” all refer to electronic or other technological devices. These terms exclude people or groups of people. For the purposes of the specification, the terms display or displaying means displaying on an electronic device. As used in this specification and any claims of this application, the terms “computer readable medium” and “computer readable media” are entirely restricted to tangible, physical objects that store information in a form that is readable by a computer. These terms exclude any wireless signals, wired download signals, and any other ephemeral signals.
  • To provide for interaction with a user, implementations of the subject matter described in this specification can be implemented on a computer having a display device, e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor, for displaying information to the user and a keyboard and a pointing device, e.g., a mouse or a trackball, by which the user can provide input to the computer. Other kinds of devices can be used to provide for interaction with a user as well; for example, feedback provided to the user can be any form of sensory feedback, e.g., visual feedback, auditory feedback, or tactile feedback; and input from the user can be received in any form, including acoustic, speech, or tactile input. In addition, a computer can interact with a user by sending documents to and receiving documents from a device that is used by the user, for example, by sending web pages to a web browser on a user's client device in response to requests received from the web browser.
  • Implementations of the subject matter described in this specification can be implemented in a computing system that includes a back end component, e.g., as a data server, or that includes a middleware component, e.g., an application server, or that includes a front end component, e.g., a client computer having a graphical user interface or a Web browser through which a user can interact with an implementation of the subject matter described in this specification, or any combination of one or more such back end, middleware, or front end components. The components of the system can be interconnected by any form or medium of digital data communication, e.g., a communication network. Examples of communication networks include a local area network (“LAN”) and a wide area network (“WAN”), an inter-network (e.g., the Internet), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks).
  • The computing system can include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. In some implementations, a server transmits data (e.g., an HTML page) to a client device (e.g., for purposes of displaying data to and receiving user input from a user interacting with the client device). Data generated at the client device (e.g., a result of the user interaction) can be received from the client device at the server.
  • It is understood that any specific order or hierarchy of steps in the processes disclosed in an illustration of example approaches. Based upon design preferences, it is understood that the specific order or hierarchy of steps in the processes may be rearranged, or that some illustrated steps may not be performed. Some of the steps may be performed simultaneously. For example, in certain circumstances, multitasking and parallel processing may be advantageous. Moreover, the separation of various system components in the implementations described above should not be understood as requiring such separation in all implementations and it should be understood that the described program components and systems can generally be integrated together in a single software product or packaged into multiple software products.
  • The previous description is provided to enable any person skilled in the art to practice the various aspects described herein. Various modifications to these aspects will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other aspects. Thus, the claims are not intended to be limited to the aspects shown herein, but are to be accorded the full scope consistent with the language claims, where reference to an element in the singular is not intended to mean “one and only one” unless specifically so stated, but rather “one or more.” Unless specifically stated otherwise, the term “some” refers to one or more. Pronouns in the masculine (e.g., his) include the feminine and neuter gender (e.g., her and its) and vice versa. Headings and subheadings, if any, are used for convenience only and do not limit the subject disclosure.
  • A phrase such as an “aspect” does not imply that such aspect is essential to the subject technology or that such aspect applies to all configurations of the subject technology. A disclosure relating to an aspect may apply to all configurations, or one or more configurations. A phrase such as an aspect may refer to one or more aspects and vice versa. A phrase such as a “configuration” does not imply that such configuration is essential to the subject technology or that such configuration applies to all configurations of the subject technology. A disclosure relating to a configuration may apply to all configurations, or one or more configurations. A phrase such as a configuration may refer to one or more configurations and vice versa.
  • The word “exemplary” is used herein to mean “serving as an example or illustration.” Any aspect or design described herein as “exemplary” is not necessarily to be construed as preferred or advantageous over other aspects or designs.

Claims (20)

What is claimed is:
1. A method for optimizing execution of dynamic language code, the method comprising:
identifying a first dynamic language function call during runtime, the function call including argument values for one or more arguments of the function;
calculating a type signature for the one or more argument values of the function;
determining if a function associated with the type signature is stored in a cache;
looking up the function in the cache when the function associated with the type signature is stored in the cache; and
dynamically calling the function associated with the type signature when the function for the type signature is not stored in the cache.
2. The method of claim 1, further comprising:
receiving, in response to calling function, a function associated with the type signature.
3. The method of claim 2, further comprising:
storing the received function associated with the type signature, generated in response to the dynamically calling the function, in the cache.
4. The method of claim 1, wherein the type signature is one of a set of type signatures of the function associated with specialized functions and wherein the function associated with the type signature is a specialized function.
5. The method of claim 1, wherein the type signature is not one of a set of type signatures of the function associated with specialized functions and wherein the function associated with the type signature is a generic function.
6. The method of claim 1, wherein the type signature comprises a bit string with a specific number of bits assigned to each of the one or more arguments of the function.
7. The method of claim 6, wherein the bits assigned to each of the one or more arguments of the function indicates the type of the argument values.
8. The method of claim 1, wherein looking up the function further comprises:
determining if the type signature is one of a set of type signatures associated with specialized functions; and
looking up the specialized function from the cache where the type signature is one of the set of type signatures associated with specialized functions.
9. The method of claim 8, further comprising:
looking up a generic function from the cache where the type signature is not one of the set of type signatures associated with specialized functions.
10. The method of claim 1, wherein determining the type signature comprises:
determining if the one or more arguments of the function are associated with a pre-determined type set; and
determining the type signature based on the pre-determined type set for each of the one or more arguments associated with a pre-determined type set.
11. The method of claim 1, wherein the calculated type signature provides an indication of the type of each of the one or more argument values.
12. The method of claim 1, wherein the type signature includes a single bit string.
13. The method of claim 1, wherein the type signature includes a set of bit strings, each bit string indicating a type of at least one of the one or more argument values.
14. A system for optimizing execution of dynamic language code, the system comprising:
one or more processors; and
a machine-readable medium comprising instructions stored therein, which when executed by the processors, cause the processors to perform operations comprising:
identifying a first dynamic language function call during runtime, the function call including one or more argument values for the one or more arguments of the function;
determining a type for each of the one or more argument values;
generating a type signature for the function according to the type for each of the one or more argument values;
identifying a function associated with the type signature; and
generating code based on the identified function, in response to the function call.
15. The system of claim 14, wherein identifying a function associated with the type signature comprises:
determining if a function associated with the type signature is stored in a cache; and
looking up the function in the cache when the function associated with the type signature is stored in the cache.
16. The system of claim 15, the operations further comprising:
dynamically calling the function associated with the type signature when the function for the type signature is not stored in the cache.
17. The system of claim 14, wherein the function associated with the type signature is a specialized function generated in response to the specific type of the one or more argument values.
18. A machine-readable medium comprising instructions stored therein, which when executed by a machine, cause the machine to perform operations comprising:
identifying a first dynamic language function call during runtime, the function call including one or more argument values for the one or more arguments of the function;
determining a type for each of the one or more argument values;
generating a type signature for the function according to the type for each of the one or more argument values;
determining if a function associated with the type signature is stored in a cache;
looking up the function in the cache when the function associated with the type signature is stored in the cache; and
dynamically calling the function associated with the type signature when the function for the type signature is not stored in the cache.
19. The machine readable medium of claim 19, wherein the function associated wit the type signature is a specialized function generated in response to the specific type of the one or more argument values.
20. The machine-readable medium of claim 19, wherein the type signature includes a single bit string, including specific bits for each of the one or more arguments, each of the specific bits representing a value indicating the type of the argument value for an argument of the one or more arguments.
US15/863,797 2014-07-17 2018-01-05 Optimized execution of dynamic languages Abandoned US20180129488A1 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
US15/863,797 US20180129488A1 (en) 2014-07-17 2018-01-05 Optimized execution of dynamic languages

Applications Claiming Priority (3)

Application Number Priority Date Filing Date Title
US14/334,610 US9244665B1 (en) 2014-07-17 2014-07-17 Optimized execution of dynamic languages
US14/972,004 US20160179489A1 (en) 2014-07-17 2015-12-16 Optimized execution of dynamic languages
US15/863,797 US20180129488A1 (en) 2014-07-17 2018-01-05 Optimized execution of dynamic languages

Related Parent Applications (1)

Application Number Title Priority Date Filing Date
US14/972,004 Continuation US20160179489A1 (en) 2014-07-17 2015-12-16 Optimized execution of dynamic languages

Publications (1)

Publication Number Publication Date
US20180129488A1 true US20180129488A1 (en) 2018-05-10

Family

ID=53836816

Family Applications (3)

Application Number Title Priority Date Filing Date
US14/334,610 Active US9244665B1 (en) 2014-07-17 2014-07-17 Optimized execution of dynamic languages
US14/972,004 Abandoned US20160179489A1 (en) 2014-07-17 2015-12-16 Optimized execution of dynamic languages
US15/863,797 Abandoned US20180129488A1 (en) 2014-07-17 2018-01-05 Optimized execution of dynamic languages

Family Applications Before (2)

Application Number Title Priority Date Filing Date
US14/334,610 Active US9244665B1 (en) 2014-07-17 2014-07-17 Optimized execution of dynamic languages
US14/972,004 Abandoned US20160179489A1 (en) 2014-07-17 2015-12-16 Optimized execution of dynamic languages

Country Status (2)

Country Link
US (3) US9244665B1 (en)
WO (1) WO2016011417A1 (en)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9244665B1 (en) * 2014-07-17 2016-01-26 Google Inc. Optimized execution of dynamic languages
US10025571B1 (en) 2014-07-17 2018-07-17 Google Llc Optimized execution of dynamic languages
CN106126311B (en) * 2016-06-22 2019-06-14 华东师范大学 A kind of intermediate code optimization method based on algebra calculation
CN106126312B (en) * 2016-06-22 2019-05-14 华东师范大学 A kind of intermediate code optimization system based on algebra calculation
CN106775781B (en) * 2017-02-17 2021-04-27 北京金山安全软件有限公司 Method and device for reducing application installation packages and electronic equipment
FR3071642B1 (en) 2017-09-26 2019-11-22 Commissariat A L'energie Atomique Et Aux Energies Alternatives METHOD OF EXECUTING A PROGRAM BY AN ELECTRONIC APPARATUS
JP7433011B2 (en) * 2018-10-16 2024-02-19 テイラー メイド ゴルフ カンパニー, インコーポレーテッド golf club head

Family Cites Families (26)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5452457A (en) 1993-01-29 1995-09-19 International Business Machines Corporation Program construct and methods/systems for optimizing assembled code for execution
US5509129A (en) 1993-11-30 1996-04-16 Guttag; Karl M. Long instruction word controlling plural independent processor operations
US5999732A (en) * 1998-03-23 1999-12-07 Sun Microsystems, Inc. Techniques for reducing the cost of dynamic class initialization checks in compiled code
US6651248B1 (en) * 2000-09-01 2003-11-18 International Business Machines Corporation Method and apparatus for efficient interface method dispatch
US6964039B2 (en) * 2000-12-13 2005-11-08 Esmertec Ag Method to create optimized machine code through combined verification and translation of JAVA™ bytecode
US7437718B2 (en) * 2003-09-05 2008-10-14 Microsoft Corporation Reviewing the security of trusted software components
US7917898B2 (en) * 2004-02-02 2011-03-29 Intel Corporation Methods and apparatus to provide a modular native method invocation system
US7711740B2 (en) * 2004-10-19 2010-05-04 Microsoft Corporation Data access layer design and code generation
US20060242654A1 (en) * 2005-04-22 2006-10-26 Lund Kasper V Process and apparatus for sharing inline caches
US8244775B1 (en) * 2008-05-13 2012-08-14 Google Inc Using map objects to access object properties in a dynamic object-oriented programming language
US8392881B1 (en) * 2008-05-13 2013-03-05 Google Inc. Supporting efficient access to object properties in a dynamic object-oriented programming language
US8321850B2 (en) 2008-06-06 2012-11-27 Vmware, Inc. Sharing and persisting code caches
US8095507B2 (en) 2008-08-08 2012-01-10 Oracle International Corporation Automated topology-based statistics monitoring and performance analysis
US20100083219A1 (en) * 2008-10-01 2010-04-01 Microsoft Corporation Runtime Object Composition
US8707161B2 (en) 2009-09-30 2014-04-22 Facebook, Inc. Executing server side script code specified using PHP on a server to generate dynamic web pages
JP4912452B2 (en) * 2009-11-27 2012-04-11 インターナショナル・ビジネス・マシーンズ・コーポレーション Method of converting and executing source code described in dynamically typed language into target code described in statically typed language, and computer program and computer system thereof
US9043478B2 (en) * 2009-12-15 2015-05-26 Qualcomm Innovation Center, Inc. Methods and apparatus for using a distributed message bus for ad hoc peer-to-peer connectivity
US20110321010A1 (en) * 2010-06-24 2011-12-29 Yifei Wang Web application framework based on object oriented class mapping
JP5466601B2 (en) * 2010-08-31 2014-04-09 インターナショナル・ビジネス・マシーンズ・コーポレーション Code generation method, system and program
US9582275B2 (en) * 2011-05-31 2017-02-28 Intel Corporation Method and apparatus for obtaining a call stack to an event of interest and analyzing the same
US9047407B2 (en) 2011-12-16 2015-06-02 Microsoft Technology Licensing, Llc State capture after execution in dependent sequences
US9104449B2 (en) 2012-06-18 2015-08-11 Google Inc. Optimized execution of dynamic languages
US8924944B2 (en) 2012-06-29 2014-12-30 Microsoft Corporation Implementation of distributed methods that support generic functions
US8893098B2 (en) * 2012-12-14 2014-11-18 Oracle International Corporation Deferred type inference of generic type parameters in function calls to overloaded functions
US20140173556A1 (en) 2012-12-17 2014-06-19 Qualcomm Incorporated Systems and methods for selection of specialized functions in dynamically-typed languages
US9244665B1 (en) * 2014-07-17 2016-01-26 Google Inc. Optimized execution of dynamic languages

Also Published As

Publication number Publication date
US20160019035A1 (en) 2016-01-21
US20160179489A1 (en) 2016-06-23
US9244665B1 (en) 2016-01-26
WO2016011417A1 (en) 2016-01-21

Similar Documents

Publication Publication Date Title
US20180129488A1 (en) Optimized execution of dynamic languages
US9696974B2 (en) Graph-based model for type systems
US10025571B1 (en) Optimized execution of dynamic languages
CN110383238B (en) System and method for model-based software analysis
US8881293B1 (en) Static application security testing
US9928156B2 (en) Missing include suggestions for external files
US11489905B2 (en) Data-centric integration modeling
US8655913B1 (en) Method for locating web elements comprising of fuzzy matching on attributes and relative location/position of element
US10360004B2 (en) Using dynamic information to refine control flow graphs
US20160004858A1 (en) Security-Enhanced Web Application Module Translation
CN103164249A (en) Extension mechanism for scripting language compiler
US9619215B2 (en) Pre-compiler
US9189204B2 (en) Static analysis of computer software applications having a model-view-controller architecture
US10296313B2 (en) Safely consuming dynamically-typed code from a statically-typed programming language
US20140372993A1 (en) Overloading on constants
US9158923B2 (en) Mitigating security risks via code movement
US11586839B2 (en) Code completion of method parameters with machine learning
EP2856312B1 (en) Representation and conversion of dynamically-typed arrays
US20140282442A1 (en) Statically extensible types
US8677314B1 (en) Modifying a source code file to reduce dependencies included therein
US8924945B1 (en) Managing dependencies on multi-threaded environment
EP3301590A1 (en) Algebraic data types for database query languages
US9280361B2 (en) Methods and systems for a real time transformation of declarative model and layout into interactive, digital, multi device forms
US20140359258A1 (en) Declarative Configuration Elements
US20230419036A1 (en) Random token segmentation for training next token prediction models

Legal Events

Date Code Title Description
STCB Information on status: application discontinuation

Free format text: ABANDONED -- FAILURE TO RESPOND TO AN OFFICE ACTION