A portion of the disclosure of this patent document contains material which is subject to copyright protection. The copyright owner has no objection to the facsimile reproduction by anyone of the patent document or the patent disclosure, as it appears in the Patent and Trademark Office patent file or records, but otherwise reserves all copyright rights whatsoever.
The invention is generally related to virtual machine environments and other runtime environments, and in particular to a system and method for improving performance by removing redundant array copying within such an environment.
Virtual machines are abstract computers that allow for portability of software, typically for running virtual applications between different underlying computer architectures. A virtual machine (VM) is a complex software product that is implemented upon a particular computer hardware platform and/or operating system. The VM then provides a uniform layer of abstraction between the hardware platform and any compiled software applications that will run thereon. Virtual machines are considered essential for the portability of certain technologies, such as Java. The Java Virtual Machine (JVM) allows compiled Java programs to be run on the JVM, independently of whatever hardware or operating system may be used underneath. Examples of available JVMs include the Sun Java Virtual Machine from Sun Microsystems, Inc., and the JRockit Virtual Machine from BEA Systems, Inc.
A real CPU understands and executes instructions native to that CPU (commonly called native code). In comparison, a virtual machine understands and executes virtual machine instructions (commonly called bytecode).
A virtual machine such as the JRockit Virtual Machine from BEA Systems, Inc. compiles the bytecode into native machine code tailored for the particular OS/CPU combination on which JRockit is running. It does so using compiler optimization techniques. Examples of such compiler techniques are described in “Advanced Compiler Design and Implementation” by Steven S. Muchnik; “Crafting a Compiler with C” by Charles N. Fischer and Richard J. LeBlanc, Jr.; and “Compilers” by Alfred V. Aho, Ravi Sethi, Jeffrey D. Ullman, each of which are incorporated herein by reference.
One feature that is commonly used to increase performance in a VM and in pointer free languages such as Java is the array copy operation, in which an array can be optimized by allocating a new larger array, and copying the contents into the new array. However, array copying is a time expensive operation on modern hardware with its memory bandwidth limitations. This is the area the present invention is designed to address.
Disclosed herein is a system and method for redundant array copy removal in a virtual machine (VM), or other runtime environment, and particularly for use in a system that includes a Java Virtual Machine (JVM). Array copying is a time expensive operation on modern hardware with its memory bandwidth limitations. Unfortunately array copying is also common in pointer free languages like Java.
An embodiment of the present invention addresses this problem by providing a system and method for redundant array copy removal where the compiled bytecode uses the source as the destination. In accordance with an embodiment, the invention provides a system for redundant array copy removal in a virtual machine environment, comprising: a virtual machine for executing a software application; a memory space for storing the application bytecode; a bytecode compiler, comprising an escape analyzer, or an escape analyzer process or logic, and functionality to add array equivalence guards to the compiled bytecode; a memory space for the compiled bytecode; and a memory space for use by the virtual machine in storing software objects and pointers as part of the software application.
Disclosed herein is a system and method for redundant array copy removal in a virtual machine (VM), or other runtime environment, and particularly for use in a system that includes a Java Virtual Machine (JVM).
Escape analysis is an optimization technique that can be used to determine if objects allocated within a certain scope (most often a method) are never used anywhere outside the scope. Given that it is possible to detect this, a number of optimizations can be applied. For example:
Stack allocation: An object can be allocated on the stack instead of on the heap if the scope of the object is within the function. Using the stack instead of the heap saves resources (both at allocation time and later at garbage collect time) and requires no synchronized allocation; and
Object explosion: “Exploding” the object into its members (fields), turning all loads and stores of these into local variable accesses, thus not needing to allocate the object at all. Sometimes object explosion can be performed within a limited scope, even if the object potentially escapes out into a super-scope, by materializing the object on its way out of the sub-scope.
One way of performing an escape analysis is to use a feedback-driven process, where one starts out with an allocation operator in a given scope, and tracks the uses of the newly allocated object. Given that the object is moved or joined (in SSA-form) into different variables (aliases), these are also tracked. Whenever the object or its aliases “escape” (for example, are stored in memory outside the scope or passed as parameters to calls) the analysis is ended. If the analysis is finished without detecting that the object escapes the scope, then the object is said to be “local”, and optimizations such as those described above can be applied.
In a pointer free language, only object references are used. A reference may never be changed; once instantiated it always points to the same object. This is very convenient for some things (for example, no pointer aliasing issues can appear when optimizing). However, it is inconvenient for other things (for example, expanding the capacity of an array, which has to be done by allocating a new larger array and copying the contents into the new array). In a pointer based language, the same memory space that represents the array can be enlarged if the heap permits. Java is a pointer free language, although it is important not to confuse resetting references to other instances with pointers that can be modified. (Furthermore, some implementations of the JVM use pointers internally). Therefore array copy operations are common in Java, and a type usage is buffer expansion:
Array copying is a time expensive operation on modern hardware with its memory bandwidth limitations. Unfortunately array copying is also common in pointer free languages like Java. Since memory copying is time expensive because of the limited memory bandwidth in modern hardware, any reduction in the number of arrays copied will immediately translate into a performance improvement.
An embodiment of the present invention addresses this problem by providing a system and method for redundant array copy removal, wherein the compiled bytecode uses the source as the destination. In accordance with an embodiment, the system allows for redundant array copy removal in a virtual machine environment, comprising: a virtual machine for executing a software application; a memory space for storing the application bytecode; a bytecode compiler, comprising an escape analyzer, or an escape analyzer process or logic, and functionality to add array equivalence guards to the compiled bytecode; a memory space for the compiled bytecode; and a memory space for use by the virtual machine in storing software objects and pointers as part of the software application.
The Java heap 111 is used for storing software objects and pointers (or more specifically the arrays) as part of the software application.
In accordance with an embodiment, the StringCollection class is configured to create one single long string as a response to the toString method call. The string constructor used in StringCollection uses the constructor, which takes a char array as an argument:
Since the constructor does not know anything about the context it is called from, it has to assume that it cannot safely use the char array argument as its string content. Since string objects are immutable, it is not safe to allow anyone else to keep pointers to the char array representing the value of the string. To be safe, the string constructor makes a copy of the char array. However, in accordance with an embodiment the system is configured to detect that value was allocated locally in StringCollection.toString and does not otherwise escape. It will also detect that the entire array is copied. This means that it is safe to use the argument value as the internal_value without any array copying.
To do this, in accordance with an embodiment, the system requires the string constructor to be inlined (which is a common optimization and in this instance is a reasonable optimization since the constructor is short).
As shown in Listing 3, the relevant code of the constructor has been inlined. In accordance with an embodiment, when the system applies escape analysis (for example, to the code in Listing 3), it detects that value does not escape the local scope, whereas v does escape, since it is stored within a field in an object that does itself escape. In accordance with an embodiment, the system can therefore replace the allocation of the char array and the call to arraycopy with a single move, in this instance the_string.internal_value=value.
If all of the requirements are met, then, in step 204, the array copy can be replaced with a guarded array copy. For example, if the array copy before replacement is:
then, after replacement, the guarded array copy will be:
The length guard, which verifies that the whole array is about to be copied, can be efficiently implemented as follows:
As shown above, the variable tmp will be 0 if and only if the whole array is to be copied. Standard compiler optimizations will improve the performance of this guard if any of the parameters are constants. For example, if the indexes from and to are zero, then the two or operations involving these parameters will be considered no-ops and will be optimized away.
The compiler can also predict that the else case will happen rarely, and optimize the control flow for the first case. In accordance with an embodiment, the system can improve performance by reducing the number of CPU cycles spent on array copy operations. It can also improve performance by delaying the next garbage collect because of the lower allocation rate.
The present invention may be conveniently implemented using a conventional general purpose or a specialized digital computer or microprocessor programmed according to the teachings of the present disclosure. Appropriate software coding can readily be prepared by skilled programmers based on the teachings of the present disclosure, as will be apparent to those skilled in the software art.
In some embodiments, the present invention includes a computer program product which is a storage medium (media) having instructions stored thereon/in which can be used to program a computer to perform any of the processes of the present invention. The storage medium can include, but is not limited to, any type of disk including floppy disks, optical discs, DVD, CD-ROMs, microdrive, and magneto-optical disks, ROMs, RAMs, EPROMs, EEPROMs, DRAMs, VRAMs, flash memory devices, magnetic or optical cards, nanosystems (including molecular memory ICs), or any type of media or device suitable for storing instructions and/or data.
The foregoing description of the present invention has been provided for the purposes of illustration and description. It is not intended to be exhaustive or to limit the invention to the precise forms disclosed. Many modifications and variations will be apparent to the practitioner skilled in the art. Particularly, it will be evident that while the examples described herein illustrate how the features may be used in a WebLogic or JRockit environment, other application servers, virtual machines, JVMs, computing environments and software development systems may use and benefit from the invention. The code examples given are presented for purposes of illustration. It will be evident that the techniques described herein may be applied using other code languages, and with different code.
The embodiments were chosen and described in order to best explain the principles of the invention and its practical application, thereby enabling others skilled in the art to understand the invention for various embodiments and with various modifications that are suited to the particular use contemplated. It is intended that the scope of the invention be defined by the following claims and their equivalence.
This application is a continuation of U.S. patent application Ser. No. 11/954,103, titled “SYSTEM AND METHOD FOR REDUNDANT ARRAY COPY REMOVAL IN A POINTER-FREE LANGUAGE”, filed Dec. 11, 2007, now U.S. Pat. No. 8,713,546, issued on Apr. 29, 2014; which claims the benefit of U.S. Provisional Application No. 60/870,600, titled “SYSTEM AND METHOD FOR REDUNDANT ARRAY COPY REMOVAL IN A POINTER-FREE LANGUAGE”, filed Dec. 18, 2006; which applications are incorporated herein by reference.
Number | Name | Date | Kind |
---|---|---|---|
4012725 | Spangler | Mar 1977 | A |
4180854 | Walden | Dec 1979 | A |
5790867 | Schmidt et al. | Aug 1998 | A |
6505344 | Blais et al. | Jan 2003 | B1 |
6675378 | Schmidt | Jan 2004 | B1 |
6684393 | Loen et al. | Jan 2004 | B1 |
6760905 | Hostetter et al. | Jul 2004 | B1 |
7076773 | Schmidt | Jul 2006 | B2 |
7168071 | Wu et al. | Jan 2007 | B2 |
7257685 | Tene et al. | Aug 2007 | B2 |
20020166116 | Eidt | Nov 2002 | A1 |
20040267804 | Fesko | Dec 2004 | A1 |
20060136875 | Thorpe | Jun 2006 | A1 |
20070074228 | Suzumura et al. | Mar 2007 | A1 |
20070100967 | Smith et al. | May 2007 | A1 |
20070150509 | Lev et al. | Jun 2007 | A1 |
20080091697 | Cui et al. | Apr 2008 | A1 |
20080148246 | Lagergren | Jun 2008 | A1 |
20140201742 | Lagergren | Jul 2014 | A1 |
Entry |
---|
Javacard, javacard.framework Class Util, Sun Microsystems, Inc. (2005) retrieved from http://www.win.tue.nl/pinpasjc/docs/apis/jc222/javacard/framework/Util.html on Oct. 29, 2014. |
Allen, Array.Copy Method Usage in C#, Jun. 13, 2009, 4 pages. |
Troll Tech, QT Shared Classes, May 1, 2001, 1 page. |
Blanchet, Escape Analysis for Object Oriented Languages, Application to Java, 1999, pp. 20-34. |
Friesen, Study Guide: Java's Character and Assorted String Classes Support Text Processing, Oct. 4, 2002, 7 pages. |
Choi, Escape Analysis for Java, 1999, 1-20 pages. |
Number | Date | Country | |
---|---|---|---|
20140201742 A1 | Jul 2014 | US |
Number | Date | Country | |
---|---|---|---|
60870600 | Dec 2006 | US |
Number | Date | Country | |
---|---|---|---|
Parent | 11954103 | Dec 2007 | US |
Child | 14222414 | US |