This application is a National Phase application of, and claims priority to, International Application No. PCT/CN2005/002403, filed Dec. 30, 2005, entitled TYPE CHECKING FOR OBJECT-ORIENTED PROGRAMMING LANGUAGES.
Object-oriented programming languages may support inheritance, which may use an existing type to derive a new type. Derived types may inherit data and operations of super-type of the derived types; and they may overwrite existing operations or add new ones. Complex object-oriented programs may contain complex inheriting hierarchies. These hierarchies may often require that the program explicitly convert an object reference from one type to another type. This type of conversion may need run-time type checking that may be used to check whether the object is cast into an invalid target type. For most implementation of object-oriented programming languages, besides a memory to store fields of an object, each object may have an object header to provide basic services of object-oriented programming, such as class hierarchies with virtual methods, and other metadata that may be tapped into for different kinds of uses.
The invention described herein is illustrated by way of example and not by way of limitation in the accompanying figures. For simplicity and clarity of illustration, elements illustrated in the figures are not necessarily drawn to scale. For example, the dimensions of some elements may be exaggerated relative to other elements for clarity. Further, where considered appropriate, reference labels have been repeated among the figures to indicate corresponding or analogous elements.
The following description describes techniques to accelerate run-time type checking in Java virtual machine. The implementation of the techniques is not restricted in Java virtual machine; it may be used by any execution environments for similar purposes. In the following description, numerous specific details such as logic implementations, opcodes, means to specify operands, resource partitioning/sharing/duplication implementations, types and interrelationships of system components, and logic partitioning/integration choices are set forth in order to provide a more thorough understanding of the present invention. However, the invention may be practiced without such specific details. In other instances, control structures and full software instruction sequences have not been shown in detail in order not to obscure the invention.
References in the specification to “one embodiment”, “an embodiment”, “an example embodiment”, etc., indicate that the embodiment described may include a particular feature, structure, or characteristic, but every embodiment may not necessarily include the particular feature, structure, or characteristic. Moreover, such phrases are not necessarily referring to the same embodiment. Further, when a particular feature, structure, or characteristic is described in connection with an embodiment, it is submitted that it is within the knowledge of one skilled in the art to effect such feature, structure, or characteristic in connection with other embodiments whether or not explicitly described.
Embodiments of the invention may be implemented in hardware, firmware, software, or any combination thereof. Embodiments of the invention may also be implemented as instructions stored on a machine-readable medium, which may be read and executed by one or more processors. A machine-readable medium may include any mechanism for storing or transmitting information in a form readable by a machine (e.g., a computing device). For example, a machine-readable medium may include read only memory (ROM); random access memory (RAM); magnetic disk storage media; optical storage media; flash memory devices; electrical, optical, acoustical or other forms of propagated signals (e.g., carrier waves, infrared signals, digital signals, etc.), and others.
In one embodiment, processor 110 and memory 120 may be included on an integrated circuit board, and bus 115 may be implemented using traces on the circuit board. In another embodiment, processor 110 and memory 120 may be included within the same integrated circuit, and bus 115 may be implemented using interconnect within the integrated circuit.
As shown in
Referring to
For example, processor 110 may use dynamic profiling to find out one or more hotspots, e.g., during program running. For example, a hotspot may refer to a hot check point that may be a location in a program at which the type checking operation from objects to a given target class occurs one or more times, e.g., a lot of times, during program running. The processor 110 may deduce a target class from a type checking hotspot. In one embodiment, target class handle 222 may contain class identification of a first target class; target class handle 224 may contain class identification of a second target class; and target class handle 226 may contain class identification of the nth target class; however, other embodiments may identify target classes with different information. In one embodiment, the method of
In one embodiment, the first object header 205 may allocate one or more bits 210 that each may correspond to an entry in data structure 220. Similarly, the second object header 235 may allocate each of one or more bits 240 to a corresponding entry in data structure 220. For example, bit 212 may be allocated to the first entry 222; bit 214 may be assigned to the second entry 224; and bit 242 may be assigned to the nth entry 226; however, other embodiments may allocate a bit for an entry in a different order. In one embodiment, JVM 140 may assert the one or more bits 210 in the first object header 205 and/or one or more bits 240 in the second object header 235 as indicators that may each indicate whether a type checking associated with a corresponding entry is successful. For example, the one or more bit indicators 210 and/or 240 may have a first logic value (for example, “0”) in their initial states. Processor 110 may assert a bit indicator 210 and/or 240 corresponding to an entry to a second logic value (for example, “1”), in response to determining that a type checking associated with the entry is successful.
In block 304, during performing a checkcast type checking for an object at a hotspot, processor 110 may check whether a bit indicator 210 in object header 205 of the object is asserted. For example, processor 110 may determine whether the bit indicator 210 that is allocated to a target class of the hotspot is asserted to a second logic value (for example, “1”). In response to the bit indicator 210 being asserted, processor 110 may determine that the type checking between the object class and the target class associated with the hotspot is successful and may terminate the type checking at the hotspot.
On the contrary, in block 306, JVM 140 may call a function that may be stored in memory 120 to perform a type checking for the object class, in response to determining that the bit indicator 210 is deasserted. For example, processor 110 may call the function, in response to determining that the bit indicator 210 has a first logic value or the bit indicator 210 is in its initial state. In one embodiment, the function may comprise a special checkcast helper, for example, with reference to blocks 308, 310, 312, 314, 316 and 318. In one embodiment, processor 110 may determine whether the object class of the current object and the target class match a predetermined criterion/condition.
In one embodiment, processor 110 may traverse the super classes of the class of the current object to see whether one of the super classes could be the same as the target class. For example, the type checking for the class of the current object is successful, in response to the processor 110 determining that one of the super classes is the same as the target class. In another embodiment, processor 110 may traverse a class hierarchy associated with the class of the current object to determine whether the target class is represented in the class hierarchy based on one or more predetermined criteria or conditions. For example, the processor 110 may determine that the type checking between the class of the current object and the target class is successful, in response to determining that the target class is represented in the class hierarchy.
In one embodiment, the class hierarchy may be implemented as an array of class references or the like that may be used to perform type checking in Java computing environments. In one embodiment, the class hierarchy may represent all the parent classes of Java classes in a hierarchical relationship. In another embodiment, an example of a predetermined criterion/condition is described as follows, wherein S=class of an object; T=target class:
I) If S is a nonarray class, then:
II) If S is an interface type, then:
III) If S is a class representing the array type SC□, then:
In block 310, processor 110 may assert a bit indicator 210 in the object header of the current object to indicate that the type checking between the object class and the target class is successful. For example, processor 110 may assert the bit indicator 210 to a second logic value. In one embodiment, the bit indicator 210 may correspond to an entry in data structure 220 that represents a target class, for example, class handle, associated with a hotspot. Further, in block 312, processor 110 may return the result indicating that the type checking between the object class and the target class is successful or the object class and the target class matches a predetermined criterion/condition. For example, processor 110 may return “True”. In another embodiment, processor 110 may return a “True” result before asserting the bit indicator 210. Conversely, in response to determining that the class of the current object and the target class do not match the criterion/condition or the type checking fails, processor 110 may return a corresponding result, for example, “False” (block 314).
In block 316, processor 110 may determine whether the object has passed the type checking based upon the result returned in blocks 312 or 314. For example, in response to determining that the object has not passed the type checking based on a result “False” or a failure result, processor 110 may throw an exception (block 318). Conversely, in response to a pass result, e.g., “True”, the type checking flow of
Similar with 80-20 rule, the hot or hottest check points (using, e.g., either checkcast or instanceof bytecode), that consume most runtime on type checking may occur at several points (thus for several target classes). And, type checkings at one or more or most of the hot or hottest check points may be successful, e.g., in most cases. In one embodiment, the method as shown in
While the methods of
As shown in
In one embodiment, during the second time compilation, dynamic compiler 534 may deduce a target class for a hotspot of checkcast or instanceof helper. For example, dynamic compiler 534 may deduce a target class for hotspots 622 and 624 that relates to a normal checkcast helper and a normal instanceof helper, respectively. Dynamic compiler 534 may allocate an entry in data structure 220 to save the target class handle of the deduced target class and a corresponding bit indicator in an object for the entry. Referring to
In the following, an embodiment of a program that may need runtime type checking is described. For example, it may be assumed that there are two classes, Parent and Child. The program, e.g., Java program, may use the following statements to define the two classes.
In one embodiment, the program may use the following statement to create an instance of Child and assign to an reference (similar to a pointer) which has type Parent:
In another embodiment, the program may do type casting and call Child's bar as follows:
The first compiler 130 may output the bytecode checkcast, for example, before assigning the ref to ref2 to do runtime checking so as to make sure the casting is safe (e.g., the object is an instance of the target class or the target class's sub class).
In another embodiment, in the implementation 500, JVM 530 may be Implemented with dynamic compiler 534, such as a Just-In-Time (JIT) compiler. For example, the dynamic compiler 534 may translate the byte codes from the first compiler 510 to architecture native codes that may be recognized by processor 110. For checkcast & instanceof, dynamic compiler 534 may emit a call to a JVM 530's helper function, e.g., checkcast helper or instanceof helper. Processor 110 may use the function to do type checking and decide whether to throw an exception (for checkcast) or return the check status (for instanceof). An example of bytecodes and translated native instructions may be as follows:
In the example of a Java program, sometimes only several type checking may be hot. After dynamic compiler 534 completes the first time compilation, JVM 530 may use dynamic profiling to find hot places or hotspots, for example, in profiler 536. Another optimized procedure may be used for these hot places by saving the type checking results of the hot places into an object header 200. In one embodiment, dynamic compiler 534 may regenerate check codes for the hotspots. For example, if bit 0 in the object header is assigned for a hotspot, the following codes may be generated:
While certain features of the invention have been described with reference to embodiments, the description is not intended to be construed in a limiting sense. Various modifications of the embodiments, as well as other embodiments of the invention, which are apparent to persons skilled in the art to which the invention pertains are deemed to lie within the spirit and scope of the invention.
Filing Document | Filing Date | Country | Kind | 371c Date |
---|---|---|---|---|
PCT/CN2005/002403 | 12/30/2005 | WO | 00 | 6/20/2006 |
Publishing Document | Publishing Date | Country | Kind |
---|---|---|---|
WO2007/076629 | 7/12/2007 | WO | A |
Number | Name | Date | Kind |
---|---|---|---|
4788637 | Tamaru | Nov 1988 | A |
5847953 | Sojoodi et al. | Dec 1998 | A |
5930807 | Ebrahim et al. | Jul 1999 | A |
5978581 | Sadiq et al. | Nov 1999 | A |
6058396 | Birze et al. | May 2000 | A |
6064816 | Parthasarathy et al. | May 2000 | A |
6081665 | Nilsen et al. | Jun 2000 | A |
6138269 | Ball et al. | Oct 2000 | A |
6151703 | Crelier | Nov 2000 | A |
6212608 | Bak | Apr 2001 | B1 |
6289506 | Kwong et al. | Sep 2001 | B1 |
6317872 | Gee et al. | Nov 2001 | B1 |
6381734 | Golde et al. | Apr 2002 | B1 |
6453463 | Chaudhry et al. | Sep 2002 | B1 |
6484188 | Kwong et al. | Nov 2002 | B1 |
6510437 | Bak et al. | Jan 2003 | B1 |
6557023 | Taivalsaari | Apr 2003 | B1 |
6681381 | Soepenberg et al. | Jan 2004 | B1 |
6694507 | Arnold et al. | Feb 2004 | B2 |
6760907 | Shaylor | Jul 2004 | B2 |
6865730 | Burke et al. | Mar 2005 | B1 |
6886159 | Onodera | Apr 2005 | B2 |
6912542 | Li | Jun 2005 | B2 |
6948156 | Sokolov | Sep 2005 | B2 |
7058929 | Charnell et al. | Jun 2006 | B2 |
7080354 | Adl-Tabatabai et al. | Jul 2006 | B2 |
7200842 | Susser et al. | Apr 2007 | B1 |
7210122 | Shuf et al. | Apr 2007 | B2 |
7266813 | Nistler et al. | Sep 2007 | B2 |
7272828 | Wu et al. | Sep 2007 | B2 |
7356802 | de Sutter et al. | Apr 2008 | B2 |
7373639 | Halstead et al. | May 2008 | B2 |
7831640 | Stephens et al. | Nov 2010 | B2 |
7870170 | Achanta et al. | Jan 2011 | B2 |
8495427 | Arnold et al. | Jul 2013 | B2 |
20020037006 | Sampath et al. | Mar 2002 | A1 |
20020108107 | Darnell et al. | Aug 2002 | A1 |
20030079201 | Sokolov | Apr 2003 | A1 |
20040003380 | Fedorov | Jan 2004 | A1 |
20040015918 | Kawahito et al. | Jan 2004 | A1 |
20040103391 | Wu et al. | May 2004 | A1 |
20040205701 | Onodera | Oct 2004 | A1 |
20040205750 | Neuenhofen | Oct 2004 | A1 |
20050071810 | Sutter et al. | Mar 2005 | A1 |
20050071826 | Nistler et al. | Mar 2005 | A1 |
20060212847 | Tarditi et al. | Sep 2006 | A1 |
20060253503 | Barrs et al. | Nov 2006 | A1 |
20060253845 | Achanta et al. | Nov 2006 | A1 |
20070277021 | O'Connor et al. | Nov 2007 | A1 |
20090031292 | Fulton et al. | Jan 2009 | A1 |
20090064114 | Bottomley et al. | Mar 2009 | A1 |
20120054725 | Inglis et al. | Mar 2012 | A1 |
Number | Date | Country |
---|---|---|
1282914 | Feb 2001 | CN |
1310865 | May 2003 | EP |
1310865 | Apr 2006 | EP |
WO 0157656 | Aug 2001 | WO |
Entry |
---|
Alpern et al., Dynamic Type Checking in Jalapeno, Proceedings of the Java Virtual Machine Research and Technology Symposium, published 2001, pp. 1-11. |
Gosling et al., “The Java Language Specification”, Second Edition, Sun Microsystems, Inc. 901 San Antonio Road, Mountain View, California 94303, USA. Published 2005. |
PCT, International Search Report, Application No. PCT/CN2005/002403, mailed Nov. 11, 2006. |
Michal Cierniak, Guei-Yuan Lueh, James M. Stichnoth. Practicing JUDO: Java Under Dynamic Optimizations. In Proceedings of the ACM SIGPLAN 2000 conference on Programming language design and implementation. ACM Press, Vancouver, British Columbia, Canada, 2000, 13-26. |
Ellen Moyse, International Preliminary Report on Patentability, Patent Cooperation Treaty, Jul. 1, 2008, 4 pages, PCT/CN2005/002403, The International Bureau of WIPO, Geneva, Switzerland. |
Weihua Zhao, Written Opinion of the International Searching Authority, Patent Cooperation Treaty, Nov. 2, 2006, 3 pages, PCT/CN2005/002403, The State Intellectual Property Office, Beijing, China. |
Number | Date | Country | |
---|---|---|---|
20090150863 A1 | Jun 2009 | US |