US20020144243A1 - Process and system for java virtual method invocation - Google Patents

Process and system for java virtual method invocation Download PDF

Info

Publication number
US20020144243A1
US20020144243A1 US09/330,634 US33063499A US2002144243A1 US 20020144243 A1 US20020144243 A1 US 20020144243A1 US 33063499 A US33063499 A US 33063499A US 2002144243 A1 US2002144243 A1 US 2002144243A1
Authority
US
United States
Prior art keywords
methods
java
class
virtual
data processing
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.)
Granted
Application number
US09/330,634
Other versions
US6507946B2 (en
Inventor
William Preston Alexander Iii
Weiming Gu
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.)
International Business Machines Corp
Original Assignee
International Business Machines Corp
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 International Business Machines Corp filed Critical International Business Machines Corp
Priority to US09/330,634 priority Critical patent/US6507946B2/en
Assigned to INTERNATIONAL BUSINESS MACHINES CORPORATION reassignment INTERNATIONAL BUSINESS MACHINES CORPORATION ASSIGNMENT OF ASSIGNORS INTEREST (SEE DOCUMENT FOR DETAILS). Assignors: ALEXANDRER, III, WILLIAM P., GU, WEIMING
Publication of US20020144243A1 publication Critical patent/US20020144243A1/en
Application granted granted Critical
Publication of US6507946B2 publication Critical patent/US6507946B2/en
Anticipated expiration legal-status Critical
Expired - Lifetime legal-status Critical Current

Links

Images

Classifications

    • 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/4488Object-oriented
    • G06F9/449Object-oriented method invocation or resolution

Definitions

  • the present invention relates generally to an improved data processing system and, in particular, to a process and system for improved execution performance in a Java virtual machine.
  • Java is an interpreted language
  • any programs written in Java after being converted into Java class files, are interpreted by a Java virtual machine (JVM).
  • JVMs may compile Java classes into platform-specific binary code after they are loaded into the JVM. Then, instead of being interpreted, Java classes are executed in their compiled native code format, similar to programs written in other languages, such as C, C++, etc.
  • JIT just-in-time
  • a high performance JIT compiler is the key to a high performance Java implementation, and one of the most important actions of a high performance JIT compiler is optimizing method invocation.
  • Java is an object-oriented language, methods and method invocation are prevalent in typical Java programs.
  • An instance invocation can be a non-virtual method invocation (only for private methods and object instance initialization methods) or a virtual method invocation. While static method invocations and non-virtual instance method invocations are easier to optimize due to their static nature, interface method invocations and virtual instance method invocations are the most prevalent in Java. Therefore, improving virtual and interface method invocation is very important for the overall performance of a JIT compiler.
  • a virtual method can be declared final.
  • a final method can not be overridden by any subclass, which prevents malicious modification of trusted and verified code and ensures consistency.
  • invocations of final methods can be more easily optimized by the JIT compiler than those of regular virtual methods.
  • a method is inlined if its code is compiled into the calling method's context. Both static and non-virtual methods can be inlined. Final virtual methods, typically though not always, can be inlined. However, a disadvantage is that regular virtual methods cannot be directly inlined.
  • Inlining has important benefits. It dramatically reduces the frequency of method invocations, which saves the time needed to perform those method invocations. More importantly, inlining is synergistic with other code optimizations because it makes those optimizations more effective. Inlining produces much larger blocks of code for the optimizer to work on. This provides a situation that significantly increases the effectiveness of traditional compiler optimizations, thus overcoming a major obstacle to increased Java programming language performance.
  • the present invention provides a process and system for optimizing an invocation of a method.
  • a determination is made to compile a calling method, and a call to a callee method is detected within the first method.
  • the callee method may be a non-final, virtual method, and a determination may be made that the callee method has not been previously overridden.
  • the callee method is then inlined within the first method.
  • no conditional statements are inserted into the calling method along with the inlined method.
  • the determination to compile and optimize these methods may be made by a just-in-time compiler, and if the methods are Java methods, then a Java just-in-time compiler performs the optimization process. If a determination is made to load a class that contains a method that overrides the callee method, then the calling method is recompiled or patched.
  • FIG. 1 is a pictorial representation depicting a data processing system in which the present invention may be implemented in accordance with a preferred embodiment of the present invention
  • FIG. 2 is a block diagram illustrating internal components of a data processing system that may implement the present invention
  • FIG. 3 is a block diagram illustrating the relationship of software components operating within a computer system that may implement the present invention
  • FIG. 4 depicts a block diagram of a Java virtual machine in accordance with a preferred embodiment of the present invention
  • FIGS. 5 A- 5 B depict examples of Java source code and its effects on Java stack frames
  • FIGS. 6 A- 6 C depict a series of classes that explain virtual methods and final methods
  • FIGS. 7 A- 7 C depict a series of examples of virtual method invocations that explain the differences among virtual method invocations
  • FIGS. 8 A- 8 B depict a series of examples of pseudocode that explain the manner in which the present invention inlines virtual methods to improve method invocation performance
  • FIGS. 9 A- 9 D are a series of examples of Java code and assembly code that explain the manner in which the present invention inlines virtual methods to improve method invocation performance.
  • FIG. 1 a pictorial representation depicts a data processing system in which the present invention may be implemented in accordance with a preferred embodiment of the present invention.
  • a personal computer 100 is depicted, which includes a system unit 110 , a video display terminal 102 , a keyboard 104 , storage devices 108 , which may include floppy drives and other types of permanent and removable storage media, and mouse 106 . Additional input devices may be included with personal computer 100 .
  • Personal computer 100 can be implemented using any suitable computer, such as an IBM AptivaTM computer, a product of International Business Machines Corporation, located in Armonk, N.Y.
  • Computer 100 also preferably includes a graphical user interface that may be implemented by means of system software residing in computer readable media in operation within computer 100 .
  • Data processing system 200 is an example of a personal computer, such as computer 100 in FIG. 1.
  • Data processing system 200 employs a peripheral component interconnect (PCI) local bus architecture.
  • PCI peripheral component interconnect
  • Processor 202 and main memory 204 are connected to PCI local bus 206 through PCI bridge 208 .
  • PCI bridge 208 also may include an integrated memory controller and cache memory for processor 202 . Additional connections to PCI local bus 206 may be made through direct component interconnection or through add-in boards.
  • local area network (LAN) adapter 210 SCSI host bus adapter 212 , and expansion bus interface 214 are connected to PCI local bus 206 by direct component connection.
  • audio adapter 216 graphics adapter 218 , and audio/video adapter 219 are connected to PCI local bus 206 by add-in boards inserted into expansion slots.
  • Expansion bus interface 214 provides a connection for a keyboard and mouse adapter 220 , modem 222 , and additional memory 224 .
  • SCSI host bus adapter 212 provides a connection for hard disk drive 226 , tape drive 228 , and CD-ROM drive 230 .
  • Typical PCI local bus implementations will support three or four PCI expansion slots or add-in connectors.
  • An operating system runs on processor 202 and is used to coordinate and provide control of various components within data processing system 200 in FIG. 2.
  • the operating system may be a commercially available operating system such as OS/2, which is available from International Business Machines Corporation. “OS/2” is a trademark of International Business Machines Corporation.
  • An object oriented programming system such as Java may run in conjunction with the operating system and provides calls to the operating system from Java programs or applications executing on data processing system 200 .
  • Java is a trademark of Sun Microsystems, Inc. Instructions for the operating system, the object-oriented operating system, and applications or programs are located on storage devices, such as hard disk drive 226 , and may be loaded into main memory 204 for execution by processor 202 .
  • FIG. 2 may vary depending on the implementation.
  • Other internal hardware or peripheral devices such as flash ROM (or equivalent nonvolatile memory) or optical disk drives and the like, may be used in addition to or in place of the hardware depicted in FIG. 2.
  • the processes of the present invention may be applied to a multiprocessor data processing system.
  • data processing system 200 may not include SCSI host bus adapter 212 , hard disk drive 226 , tape drive 228 , and CD-ROM 230 .
  • the computer to be properly called a client computer, must include some type of network communication interface, such as LAN adapter 210 , modem 222 , or the like.
  • data processing system 200 may be a stand-alone system configured to be bootable without relying on some type of network communication interface, whether or not data processing system 200 comprises some type of network communication interface.
  • data processing system 200 may be a Personal Digital Assistant (PDA) device which is configured with ROM and/or flash ROM in order to provide nonvolatile memory for storing operating system files and/or user-generated data.
  • PDA Personal Digital Assistant
  • data processing system 200 examples include an Internet information appliance for surfing the Internet and the World Wide Web.
  • Internet information appliances may include Web-based interactive television set-top boxes.
  • FIG. 2 and above-described examples are not meant to imply architectural limitations.
  • Java-based system 300 contains platform specific operating system 302 that provides hardware and system support to software executing on a specific hardware platform.
  • Java Virtual Machine (JVM) 304 is one software application that may execute in conjunction with the operating system.
  • JVM 304 provides a Java run-time environment with the ability to execute Java application or applet 306 , which is a program, servlet, or software component written in the Java programming language.
  • the computer system in which JVM 304 operates may be similar to data processing system 200 or computer 100 described above. However, JVM 304 may be implemented in dedicated hardware on a so-called Java chip, Java-on-silicon, or Java processor with an embedded picoJava core.
  • the present invention provides a process and system for Java virtual method invocation. Hence, the present invention operates in conjunction with a Java virtual machine yet within the boundaries of a JVM as defined by Java standard specifications. In order to properly present the present invention, portions of the operation of a Java virtual machine according to Java specifications are herein described.
  • JVM Java run-time environment
  • the JVM is a virtual computer, i.e. a computer that is specified abstractly.
  • the specification defines certain features that every JVM must implement, with some range of design choices that may depend upon the platform on which the JVM is designed to execute. For example, all JVMs must execute Java bytecodes and may use a range of techniques to execute the instructions represented by the bytecodes.
  • a JVM may be implemented completely in software or somewhat in hardware. This flexibility allows different JVMs to be designed for mainframe computers and PDAs.
  • a JVM must load class files and execute the bytecodes within them.
  • the Java virtual machine contains a class loader, which loads class files from an application and the class files from the Java application programming interfaces (APIs) which are needed by the application.
  • the execution engine that executes the bytecodes may vary across platforms and implementations.
  • the simplest type of software-based execution engine is a just-in-time compiler. With this type of execution, the bytecodes of a method are compiled to native machine code upon the first invocation of the method. The native machine code for the method is then cached and reused upon the next invocation of the method.
  • the execution engine may also be implemented in hardware and embedded on a chip so that the Java bytecodes are executed natively. JVMs usually interpret bytecodes, but JVMs may also use other techniques, such as just-in-time compiling, to execute bytecodes.
  • Java application When an application is executed on a JVM that is implemented in software on a platform-specific operating system, a Java application may interact with the host operating system by invoking native methods.
  • a Java run-time environment may have two kinds of methods: Java and native.
  • Java method is written in the Java language, compiled to bytecodes, and stored in class files.
  • a native method is written in Java or some other language and compiled to the native machine code of a particular processor.
  • Native methods are stored in a dynamically linked library whose exact form is platform specific.
  • Java virtual machine (JVM) 400 includes a class loader subsystem 402 , which is a mechanism for loading types, such as classes and interfaces, given fully qualified names.
  • JVM 400 also contains runtime data areas 404 , execution engine 406 , native method interface 408 , and memory management 424 .
  • Execution engine 406 is a mechanism for executing instructions contained in the methods of classes loaded by class loader subsystem 402 .
  • Execution engine 406 may be, for example, Java interpreter 412 or just-in-time compiler 410 .
  • Native method interface 408 allows access to resources in the underlying operating system.
  • Native method interface 408 may be, for example, a Java native interface.
  • Runtime data areas 404 contain native method stacks 414 , Java stacks 416 , PC registers 418 , method area 420 , and heap 422 . These different data areas represent the organization of memory needed by JVM 400 to execute a program.
  • Java stacks 416 are used to store the state of Java method invocations.
  • the JVM creates a new Java stack for the thread.
  • the JVM performs only two operations directly on Java stacks: it pushes and pops frames.
  • a thread's Java stack stores the state of Java method invocations for the thread.
  • the state of a Java method invocation includes its local variables, the parameters with which it was invoked, its return value, if any, and intermediate calculations.
  • Java stacks are composed of stack frames.
  • a stack frame contains the state of a single Java method invocation.
  • the JVM pops the frame for that method and discards it.
  • a JVM does not have any registers for holding intermediate values; any Java instruction that requires or produces an intermediate value uses the stack for holding the intermediate values. In this manner, the Java instruction set is well-defined for a variety of platform architectures.
  • PC registers 418 are used to indicate the next instruction to be executed. Each instantiated thread gets its own pc register (program counter) and Java stack. If the thread is executing a JVM method, the value of the pc register indicates the next instruction to execute. If the thread is executing a native method, then the contents of the pc register are undefined.
  • Native method stacks 414 store the state of invocations of native methods. The state of native method invocations is stored in an implementation-dependent way in native method stacks, registers, or other implementation-dependent memory areas. In some Java virtual machine implementations, such as some IBM developed JVMs, native method stacks 414 and Java stacks 416 are combined.
  • Method area 420 contains class data while heap 422 contains all instantiated objects.
  • the JVM specification strictly defines data types and operations. Most JVM implementations choose to have one method area and one heap, each of which are shared by all threads running inside the JVM.
  • the JVM loads a class file, it parses information about a type from the binary data contained in the class file. It places this type information into the method area.
  • JVM 400 includes an instruction that allocates memory space within the memory for heap 422 but includes no instruction for freeing that space within the memory.
  • Memory management 424 in the depicted example manages memory space within the memory allocated to heap 420 . Memory management 424 may include a garbage collector which automatically reclaims memory used by objects that are no longer referenced by an application. Additionally, a garbage collector also may move objects to reduce heap fragmentation.
  • FIGS. 5 A- 5 B examples of Java source code and its effects on Java stack frames are provided.
  • FIG. 5A provides examples of Java programming language source code statements for an instance method, also known as a virtual method, and a class method, also known as a static method.
  • FIG. 5B depicts the state of a local variables section of a stack frame.
  • the local variables section contains a method's parameters and local variables. Compilers place the parameters into the local variable array first, in the order in which they are declared.
  • FIG. 5B shows the local variables section for the two methods shown in FIG. 5A.
  • FIG. 5B shows that the first parameter in the local variables section for an instance method “ Figure 5 method 1 ( )” is of type “reference” , even though no such parameter appears in the source code.
  • This reference is the hidden “this” passed to every instance method. Instance methods use this reference to access the instance data of the object upon which they were invoked.
  • class methods do not receive a hidden “this”. Class methods are not invoked on objects. A class's instance variables cannot be accessed from a class method because no instance is associated with the method invocation.
  • Data types “byte” , “short” , “char” , and “boolean” in the source code of FIG. 5A have data type “int” in the local variables and operand portions of the stack. Each is manipulated as an “int” while on the stack frame and then converted back into the proper type when stored in the heap or method area.
  • class (static) methods require an instance before they can be invoked, whereas class methods do not; and instance methods need to use dynamic (late) binding at actual method invocation time, whereas all class methods use static (early) binding at method name resolution time.
  • class method When a class method is invoked, its class name needs to be explicitly specified, which can be resolved and bound at JIT compile-time.
  • virtual instance method When a virtual instance method is invoked, the actual method is selected based on the actual class of the object, which may be known only at run-time.
  • references to methods are initially symbolic. All invoke instructions refer to a constant pool entry that initially contains a symbolic reference. When the JVM encounters an invoke instruction, if the symbolic reference has not yet been resolved, the JVM resolves it as part of the execution of the invoke instruction.
  • the JVM locates the method being referred to symbolically and replaces the symbolic reference with a direct reference.
  • a direct reference such as a pointer or offset, allows the JVM to invoke the method more quickly if the reference is ever used again in the future.
  • the JVM also performs several verification checks. These checks ensure that Java language rules are followed and that the invoke instruction can be safely executed.
  • the JVM ensures that the symbolically referenced method exists. If it exists, it ensures that the current class can legally access the method. For example, if the method is private, it must be a member of the current class. If any of these checks fail, the JVM throws an exception. After the method has been resolved, then the JVM is ready to invoke it. As can be seen, method invocation may incur significant overhead.
  • inlining methods in the caller's context is a JIT optimization technique for improving the performance of method invocation. Namely, bytecodes of the callee methods are copied into the caller's context at JIT compilation time. The bytecodes of the caller method and the inlined callee method are then compiled into native machine code. Therefore, when the caller method is executed, the callee method is also executed within the caller method when necessary, and the actual method invocation is avoided at runtime.
  • not all methods can be inlined.
  • the JIT compiler imposes a number of limitations, such as the restriction that inlined methods need to be static methods, non-virtual methods, or final virtual methods. It seems intuitive that non-final virtual methods cannot be inlined because the method actually invoked is determined at run-time by the actual class type of the instance reference involved in the method invocation.
  • the present invention improves upon prior art invocation processes by assuming that a virtual method, if not overridden by any class, is a final method until it is explicitly overridden. By doing so, the present invention can speculatively inline a regular virtual method.
  • FIG. 6A shows an example of class SuperA with a virtual method foo( ) defined in the class.
  • FIG. 6B shows an example of class SubB with a final virtual method foo( ). Since class SubB extends class SuperA, i.e. class SubB is a subclass of class SuperA or class SuperA is a super class of class SubB, method foo( ) of class SubB overrides method foo( ) of class SuperA.
  • FIG. 6C shows another example of class SubC with a virtual method foo( ). Since class SubC extends class SuperA, method foo( ) of class SubC overrides method foo( ) of class SuperA.
  • FIGS. 7 A- 7 C a series of examples of virtual method invocations explain the differences among these virtual method invocations.
  • FIG. 7A shows pseudocode of a method bar( ) which contains an invocation of a virtual method foo( ) of class SuperA. Since method foo( ) of class SuperA is explicitly overridden by method foo( ) of either class SubB or class SubC, the method invocation in bar( ) can not be optimized by the process of the present invention.
  • FIG. 7B shows pseudocode of another method moo( ) which contains an invocation of a final virtual method foo( ) of class SubB. Since method foo( ) of class SubB is a final method, the final method invocation s.foo( ) can be optimized by prior art JIT compilers.
  • FIG. 7C shows pseudocode of another method boo( ) which contains an invocation of a virtual method foo( ) of class SubC.
  • boo( ) which contains an invocation of a virtual method foo( ) of class SubC.
  • method foo( ) of class SubC is a virtual method and it is not overridden yet, the method invocation s.foo( ) can be assumed final, and it can be optimized by the process of the present invention.
  • FIGS. 8 A- 8 B a series of examples of pseudocode explain the manner in which the present invention inlines virtual methods to improve method invocation performance.
  • invocation of method s.foo( ) in FIG. 7C can not be directly inlined because it is not bound at JIT compilation time. Instead, it can be speculatively inlined, as illustrated by pseudocode statements in FIG. 8A.
  • the process By checking whether s.foo( ) is class SubC's foo( ) method, the process ensures that the method has not been previously overridden and that the inlining of the method will properly execute as expected.
  • the approach shown in FIG. 8A may not be particularly efficient for two reasons: (1) the overhead of checking for subclasses and overridden methods may be significant if foo( ) is a small method, i.e. the checking process may require more time than the method foo( ) takes to execute; and (2) the “if” statement prevents the optimization of the inlined code during optimization of method boo( ) because compiler optimization is typically based on basic blocks, and the additional branch statement breaks the original one block into three or four basic blocks.
  • the present invention treats virtual methods that have not yet been overridden as regular final methods.
  • Virtual methods in Java if not explicitly declared final, may potentially be overridden if subclassed.
  • many virtual methods are not overridden in the JVM. For such methods, their behavior is the same as those explicitly declared final.
  • FIG. 8B shows pseudocode statements that are optimized with the present invention for method boo( ) shown in FIG. 7C. If class SubC is not currently subclassed in the JVM and if SubC's foo( ) method satisfies the JIT compiler's inlining policies, then method s.foo( ) can be fully inlined into the context of method boo( ) when method boo( ) is compiled. Note that no branching is needed around SubC's foo( ), as is the case in FIG. 8A.
  • the JVM and the JIT keep track of dependencies among methods.
  • Each JIT compiled method stores a list of all the methods which are inlined because they are assumed final.
  • the depedency lists can be maintained by either JIT or JVM.
  • the JVM and JIT find all the methods overridden by newly loaded classes and invalidate or update JIT compiled code that inlines any newly overridden method. This can be achieved by simply searching the dependency lists maintained for the JIT compiled methods. For example, the JIT remembers that the compiled code of method boo( ) depends on SubC's foo( ) not having been overridden by any subclass.
  • the JIT compiled code of method boo( ) needs to be updated to reflect the new JVM state. In that case, the code may be patched, or it may be discarded and the method recompiled.
  • FIGS. 9 A- 9 D a series of examples of Java code and assembly code explain the manner in which the present invention inlines virtual methods to improve method invocation performance.
  • FIG. 9A shows an example of a Java language statement which is found in an industry standard benchmark.
  • the Java language statement creates a vector from an origin point consisting of a point with an x-coordinate, a y-coordinate, and a z-coordinate, where getorigin( ), getX( ), getY( ), and getZ( ) are simple methods, shown as statements in FIG. 9B. These types of small methods are encouraged by object-oriented languages, such as Java, to help encapsulate data structures. None of the four methods shown in FIG. 9B is overridden by any subclass in this benchmark.
  • FIG. 9C shows some of the pseudo-assembly language code for part of the Java statement “ray.getOrigin( ).getX( )”.
  • FIG. 9D shows some of the pseudo-assembly language code for part of the Java statement “ray.getOrigin( ).getX( )” after using the process of the present invention.
  • methods are assumed to be final methods until overridden.
  • the Java statement “ray.getOrigin( ).getX( )” both the methods getOrigin( ) and getX( ) are considered final methods. (In fact, these methods are not overridden in the actual implementation of the benchmark.) Instructions in FIG. 9D can be generated if both methods getorigin( ) and getX( ) are inlined and copied into the caller's context.
  • the present invention may reserve this kind of optimization for “hot” methods, i.e. those that are invoked very frequently and in which a lot of execution time is spent. Any recompilation cost can be reduced if only a small number of methods are highly optimized.
  • the advantages of the present invention should be apparent in light of the detailed description provided above.
  • the method may be inlined until overridden.
  • the processing overhead for invoking the method is then eliminated.
  • the JVM or JIT may recompile or patch the calling method once it is overridden, the overall performance of the code is increased. If the method is seldom overridden, then the performance decrease from recompiling the calling method is outweighed by the performance increase gained by repeatedly executing the code of the called method without invocation overhead.
  • a primary benefit of object-oriented programming is that it can increase development productivity by providing powerful language mechanisms for software reuse. In practice, such reusability is rarely attained. Extensive use of these mechanisms can significantly reduce performance, which leads programmers to use them sparingly. Many programmers using the Java programming language avoid using fully “virtual” methods and write larger methods, because they believe that every virtual method invocation entails a significant performance penalty. Fine-grain use of “virtual” methods (i.e. methods that are not “static” or “final” in the Java programming language) is extremely important to the construction of highly reusable classes, because each such method acts as a “hook” that allows new subclasses to modify the behavior of the superclass. However, because many methods are never overridden, the present invention treats a method as a final method until execution proves otherwise, resulting in a significant increase in performance.
  • a significant advantage of the approach of the present invention is that it should fit very well in a server environment where classes are loaded initially, and new classes are seldom loaded thereafter.
  • the JVM and the JIT compiler become “stable” after a period of execution, and they remain stable for the duration of their lifetimes.

Abstract

A process and system for optimizing an invocation of a method is provided. A determination is made to compile a calling method, and a call to a callee method is detected within the first method. The callee method may be a non-final, virtual method, and a determination may be made that the callee method has not been previously overridden. The callee method is then inlined within the first method. In addition, no conditional statements are inserted into the calling method along with the inlined method. The determination to compile and optimize these methods may be made by a just-in-time compiler, and if the methods are Java methods, then a Java just-in-time compiler performs the optimization process. If a determination is made to load a class that contains a method that overrides the callee method, then the calling method is recompiled or patched.

Description

    TECHNICAL FIELD
  • The present invention relates generally to an improved data processing system and, in particular, to a process and system for improved execution performance in a Java virtual machine. [0001]
  • DESCRIPTION OF RELATED ART
  • Since Java is an interpreted language, any programs written in Java, after being converted into Java class files, are interpreted by a Java virtual machine (JVM). In order to improve performance, many JVMs may compile Java classes into platform-specific binary code after they are loaded into the JVM. Then, instead of being interpreted, Java classes are executed in their compiled native code format, similar to programs written in other languages, such as C, C++, etc. Such just-in-time (JIT) compilation of Java programs can significantly improve the speed of execution of Java programs. [0002]
  • A high performance JIT compiler is the key to a high performance Java implementation, and one of the most important actions of a high performance JIT compiler is optimizing method invocation. Because Java is an object-oriented language, methods and method invocation are prevalent in typical Java programs. In Java, there are three kinds of method invocations: (1) static method invocation, also known as class method invocation; (2) interface method invocation; and (3) instance method invocation. An instance invocation can be a non-virtual method invocation (only for private methods and object instance initialization methods) or a virtual method invocation. While static method invocations and non-virtual instance method invocations are easier to optimize due to their static nature, interface method invocations and virtual instance method invocations are the most prevalent in Java. Therefore, improving virtual and interface method invocation is very important for the overall performance of a JIT compiler. [0003]
  • In Java, a virtual method can be declared final. A final method can not be overridden by any subclass, which prevents malicious modification of trusted and verified code and ensures consistency. Hence, invocations of final methods can be more easily optimized by the JIT compiler than those of regular virtual methods. [0004]
  • An important technique of method invocation optimization is called inlining. A method is inlined if its code is compiled into the calling method's context. Both static and non-virtual methods can be inlined. Final virtual methods, typically though not always, can be inlined. However, a disadvantage is that regular virtual methods cannot be directly inlined. [0005]
  • Inlining has important benefits. It dramatically reduces the frequency of method invocations, which saves the time needed to perform those method invocations. More importantly, inlining is synergistic with other code optimizations because it makes those optimizations more effective. Inlining produces much larger blocks of code for the optimizer to work on. This provides a situation that significantly increases the effectiveness of traditional compiler optimizations, thus overcoming a major obstacle to increased Java programming language performance. [0006]
  • Therefore, in order to improve the performance of certain Java programs, it would be advantageous to provide a JIT compiler with the ability to improve the performance of a program by improving the manner in which its methods are invoked. It would be particularly advantageous to provide a consistent process by which the invocation of virtual methods may be optimized. [0007]
  • SUMMARY OF THE INVENTION
  • The present invention provides a process and system for optimizing an invocation of a method. A determination is made to compile a calling method, and a call to a callee method is detected within the first method. The callee method may be a non-final, virtual method, and a determination may be made that the callee method has not been previously overridden. The callee method is then inlined within the first method. In addition, no conditional statements are inserted into the calling method along with the inlined method. The determination to compile and optimize these methods may be made by a just-in-time compiler, and if the methods are Java methods, then a Java just-in-time compiler performs the optimization process. If a determination is made to load a class that contains a method that overrides the callee method, then the calling method is recompiled or patched. [0008]
  • BRIEF DESCRIPTION OF THE DRAWINGS
  • The novel features believed characteristic of the invention are set forth in the appended claims. The invention itself, however, as well as a preferred mode of use, further objectives and advantages thereof, will best be understood by reference to the following detailed description of an illustrative embodiment when read in conjunction with the accompanying drawings, wherein: [0009]
  • FIG. 1 is a pictorial representation depicting a data processing system in which the present invention may be implemented in accordance with a preferred embodiment of the present invention; [0010]
  • FIG. 2 is a block diagram illustrating internal components of a data processing system that may implement the present invention; [0011]
  • FIG. 3 is a block diagram illustrating the relationship of software components operating within a computer system that may implement the present invention; [0012]
  • FIG. 4 depicts a block diagram of a Java virtual machine in accordance with a preferred embodiment of the present invention; [0013]
  • FIGS. [0014] 5A-5B depict examples of Java source code and its effects on Java stack frames;
  • FIGS. [0015] 6A-6C depict a series of classes that explain virtual methods and final methods;
  • FIGS. [0016] 7A-7C depict a series of examples of virtual method invocations that explain the differences among virtual method invocations;
  • FIGS. [0017] 8A-8B depict a series of examples of pseudocode that explain the manner in which the present invention inlines virtual methods to improve method invocation performance; and
  • FIGS. [0018] 9A-9D are a series of examples of Java code and assembly code that explain the manner in which the present invention inlines virtual methods to improve method invocation performance.
  • DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENT
  • With reference now to FIG. 1, a pictorial representation depicts a data processing system in which the present invention may be implemented in accordance with a preferred embodiment of the present invention. A [0019] personal computer 100 is depicted, which includes a system unit 110, a video display terminal 102, a keyboard 104, storage devices 108, which may include floppy drives and other types of permanent and removable storage media, and mouse 106. Additional input devices may be included with personal computer 100. Personal computer 100 can be implemented using any suitable computer, such as an IBM Aptiva™ computer, a product of International Business Machines Corporation, located in Armonk, N.Y. Although the depicted representation shows a personal computer, other embodiments of the present invention may be implemented in other types of data processing systems, such as network computers, Web based television set top boxes, Internet appliances, etc. Computer 100 also preferably includes a graphical user interface that may be implemented by means of system software residing in computer readable media in operation within computer 100.
  • With reference now to FIG. 2, a block diagram illustrates internal components of a data processing system that may implement the present invention. [0020] Data processing system 200 is an example of a personal computer, such as computer 100 in FIG. 1. Data processing system 200 employs a peripheral component interconnect (PCI) local bus architecture. Although the depicted example employs a PCI bus, other bus architectures, such as Micro Channel and ISA, may be used. Processor 202 and main memory 204 are connected to PCI local bus 206 through PCI bridge 208. PCI bridge 208 also may include an integrated memory controller and cache memory for processor 202. Additional connections to PCI local bus 206 may be made through direct component interconnection or through add-in boards. In the depicted example, local area network (LAN) adapter 210, SCSI host bus adapter 212, and expansion bus interface 214 are connected to PCI local bus 206 by direct component connection. In contrast, audio adapter 216, graphics adapter 218, and audio/video adapter 219 are connected to PCI local bus 206 by add-in boards inserted into expansion slots. Expansion bus interface 214 provides a connection for a keyboard and mouse adapter 220, modem 222, and additional memory 224. SCSI host bus adapter 212 provides a connection for hard disk drive 226, tape drive 228, and CD-ROM drive 230. Typical PCI local bus implementations will support three or four PCI expansion slots or add-in connectors.
  • An operating system runs on [0021] processor 202 and is used to coordinate and provide control of various components within data processing system 200 in FIG. 2. The operating system may be a commercially available operating system such as OS/2, which is available from International Business Machines Corporation. “OS/2” is a trademark of International Business Machines Corporation. An object oriented programming system such as Java may run in conjunction with the operating system and provides calls to the operating system from Java programs or applications executing on data processing system 200. “Java” is a trademark of Sun Microsystems, Inc. Instructions for the operating system, the object-oriented operating system, and applications or programs are located on storage devices, such as hard disk drive 226, and may be loaded into main memory 204 for execution by processor 202.
  • Those of ordinary skill in the art will appreciate that the hardware in FIG. 2 may vary depending on the implementation. Other internal hardware or peripheral devices, such as flash ROM (or equivalent nonvolatile memory) or optical disk drives and the like, may be used in addition to or in place of the hardware depicted in FIG. 2. Also, the processes of the present invention may be applied to a multiprocessor data processing system. [0022]
  • For example, [0023] data processing system 200, if optionally configured as a network computer, may not include SCSI host bus adapter 212, hard disk drive 226, tape drive 228, and CD-ROM 230. In that case, the computer, to be properly called a client computer, must include some type of network communication interface, such as LAN adapter 210, modem 222, or the like. As another example, data processing system 200 may be a stand-alone system configured to be bootable without relying on some type of network communication interface, whether or not data processing system 200 comprises some type of network communication interface. As a further example, data processing system 200 may be a Personal Digital Assistant (PDA) device which is configured with ROM and/or flash ROM in order to provide nonvolatile memory for storing operating system files and/or user-generated data.
  • Other examples for [0024] data processing system 200 include an Internet information appliance for surfing the Internet and the World Wide Web. Internet information appliances may include Web-based interactive television set-top boxes. The depicted example in FIG. 2 and above-described examples are not meant to imply architectural limitations.
  • With reference now to FIG. 3, a block diagram illustrates the relationship of software components operating within a computer system that may implement the present invention. Java-based [0025] system 300 contains platform specific operating system 302 that provides hardware and system support to software executing on a specific hardware platform. Java Virtual Machine (JVM) 304 is one software application that may execute in conjunction with the operating system. JVM 304 provides a Java run-time environment with the ability to execute Java application or applet 306, which is a program, servlet, or software component written in the Java programming language. The computer system in which JVM 304 operates may be similar to data processing system 200 or computer 100 described above. However, JVM 304 may be implemented in dedicated hardware on a so-called Java chip, Java-on-silicon, or Java processor with an embedded picoJava core.
  • The present invention provides a process and system for Java virtual method invocation. Hence, the present invention operates in conjunction with a Java virtual machine yet within the boundaries of a JVM as defined by Java standard specifications. In order to properly present the present invention, portions of the operation of a Java virtual machine according to Java specifications are herein described. [0026]
  • At the center of a Java run-time environment is the JVM, which supports all aspects of Java's environment, including its architecture, security features, mobility across networks, and platform independence. [0027]
  • The JVM is a virtual computer, i.e. a computer that is specified abstractly. The specification defines certain features that every JVM must implement, with some range of design choices that may depend upon the platform on which the JVM is designed to execute. For example, all JVMs must execute Java bytecodes and may use a range of techniques to execute the instructions represented by the bytecodes. A JVM may be implemented completely in software or somewhat in hardware. This flexibility allows different JVMs to be designed for mainframe computers and PDAs. [0028]
  • A JVM must load class files and execute the bytecodes within them. The Java virtual machine contains a class loader, which loads class files from an application and the class files from the Java application programming interfaces (APIs) which are needed by the application. The execution engine that executes the bytecodes may vary across platforms and implementations. [0029]
  • The simplest type of software-based execution engine is a just-in-time compiler. With this type of execution, the bytecodes of a method are compiled to native machine code upon the first invocation of the method. The native machine code for the method is then cached and reused upon the next invocation of the method. The execution engine may also be implemented in hardware and embedded on a chip so that the Java bytecodes are executed natively. JVMs usually interpret bytecodes, but JVMs may also use other techniques, such as just-in-time compiling, to execute bytecodes. [0030]
  • When an application is executed on a JVM that is implemented in software on a platform-specific operating system, a Java application may interact with the host operating system by invoking native methods. A Java run-time environment may have two kinds of methods: Java and native. A Java method is written in the Java language, compiled to bytecodes, and stored in class files. A native method is written in Java or some other language and compiled to the native machine code of a particular processor. Native methods are stored in a dynamically linked library whose exact form is platform specific. [0031]
  • With reference now to FIG. 4, a block diagram of a Java virtual machine is depicted in accordance with a preferred embodiment of the present invention. Java virtual machine (JVM) [0032] 400 includes a class loader subsystem 402, which is a mechanism for loading types, such as classes and interfaces, given fully qualified names. JVM 400 also contains runtime data areas 404, execution engine 406, native method interface 408, and memory management 424. Execution engine 406 is a mechanism for executing instructions contained in the methods of classes loaded by class loader subsystem 402. Execution engine 406 may be, for example, Java interpreter 412 or just-in-time compiler 410. Native method interface 408 allows access to resources in the underlying operating system. Native method interface 408 may be, for example, a Java native interface.
  • [0033] Runtime data areas 404 contain native method stacks 414, Java stacks 416, PC registers 418, method area 420, and heap 422. These different data areas represent the organization of memory needed by JVM 400 to execute a program.
  • Java stacks [0034] 416 are used to store the state of Java method invocations. When a new thread is launched, the JVM creates a new Java stack for the thread. The JVM performs only two operations directly on Java stacks: it pushes and pops frames. A thread's Java stack stores the state of Java method invocations for the thread. The state of a Java method invocation includes its local variables, the parameters with which it was invoked, its return value, if any, and intermediate calculations. Java stacks are composed of stack frames. A stack frame contains the state of a single Java method invocation. When a thread invokes a method, the JVM pushes a new frame onto the Java stack of the thread. When the method completes, the JVM pops the frame for that method and discards it. A JVM does not have any registers for holding intermediate values; any Java instruction that requires or produces an intermediate value uses the stack for holding the intermediate values. In this manner, the Java instruction set is well-defined for a variety of platform architectures.
  • PC registers [0035] 418 are used to indicate the next instruction to be executed. Each instantiated thread gets its own pc register (program counter) and Java stack. If the thread is executing a JVM method, the value of the pc register indicates the next instruction to execute. If the thread is executing a native method, then the contents of the pc register are undefined.
  • Native method stacks [0036] 414 store the state of invocations of native methods. The state of native method invocations is stored in an implementation-dependent way in native method stacks, registers, or other implementation-dependent memory areas. In some Java virtual machine implementations, such as some IBM developed JVMs, native method stacks 414 and Java stacks 416 are combined.
  • [0037] Method area 420 contains class data while heap 422 contains all instantiated objects. The JVM specification strictly defines data types and operations. Most JVM implementations choose to have one method area and one heap, each of which are shared by all threads running inside the JVM. When the JVM loads a class file, it parses information about a type from the binary data contained in the class file. It places this type information into the method area. Each time a class instance or array is created, the memory for the new object is allocated from heap 422. JVM 400 includes an instruction that allocates memory space within the memory for heap 422 but includes no instruction for freeing that space within the memory. Memory management 424 in the depicted example manages memory space within the memory allocated to heap 420. Memory management 424 may include a garbage collector which automatically reclaims memory used by objects that are no longer referenced by an application. Additionally, a garbage collector also may move objects to reduce heap fragmentation.
  • With reference now to FIGS. [0038] 5A-5B, examples of Java source code and its effects on Java stack frames are provided. FIG. 5A provides examples of Java programming language source code statements for an instance method, also known as a virtual method, and a class method, also known as a static method. FIG. 5B depicts the state of a local variables section of a stack frame.
  • The local variables section contains a method's parameters and local variables. Compilers place the parameters into the local variable array first, in the order in which they are declared. FIG. 5B shows the local variables section for the two methods shown in FIG. 5A. [0039]
  • FIG. 5B shows that the first parameter in the local variables section for an instance method “Figure[0040] 5method1( )” is of type “reference” , even though no such parameter appears in the source code. This reference is the hidden “this” passed to every instance method. Instance methods use this reference to access the instance data of the object upon which they were invoked. As shown for the local variables for a class method “Figure5method2( )”, class methods do not receive a hidden “this”. Class methods are not invoked on objects. A class's instance variables cannot be accessed from a class method because no instance is associated with the method invocation.
  • Data types “byte” , “short” , “char” , and “boolean” in the source code of FIG. 5A have data type “int” in the local variables and operand portions of the stack. Each is manipulated as an “int” while on the stack frame and then converted back into the proper type when stored in the heap or method area. [0041]
  • All objects are passed by reference, such as “Object Object[0042] 2” that is passed as a reference to “Figure5method2( )”. In Java, all objects are passed by reference. Therefore, only object references appear on the stack.
  • During method invocation, the difference between class (static) methods and instance (virtual or non-virtual) methods is as follows: instance methods require an instance before they can be invoked, whereas class methods do not; and instance methods need to use dynamic (late) binding at actual method invocation time, whereas all class methods use static (early) binding at method name resolution time. When a class method is invoked, its class name needs to be explicitly specified, which can be resolved and bound at JIT compile-time. When a virtual instance method is invoked, the actual method is selected based on the actual class of the object, which may be known only at run-time. [0043]
  • References to methods are initially symbolic. All invoke instructions refer to a constant pool entry that initially contains a symbolic reference. When the JVM encounters an invoke instruction, if the symbolic reference has not yet been resolved, the JVM resolves it as part of the execution of the invoke instruction. [0044]
  • To resolve a symbolic reference, the JVM locates the method being referred to symbolically and replaces the symbolic reference with a direct reference. A direct reference, such as a pointer or offset, allows the JVM to invoke the method more quickly if the reference is ever used again in the future. [0045]
  • During resolution, the JVM also performs several verification checks. These checks ensure that Java language rules are followed and that the invoke instruction can be safely executed. First, the JVM ensures that the symbolically referenced method exists. If it exists, it ensures that the current class can legally access the method. For example, if the method is private, it must be a member of the current class. If any of these checks fail, the JVM throws an exception. After the method has been resolved, then the JVM is ready to invoke it. As can be seen, method invocation may incur significant overhead. [0046]
  • In the prior art, inlining methods in the caller's context (method inlining) is a JIT optimization technique for improving the performance of method invocation. Namely, bytecodes of the callee methods are copied into the caller's context at JIT compilation time. The bytecodes of the caller method and the inlined callee method are then compiled into native machine code. Therefore, when the caller method is executed, the callee method is also executed within the caller method when necessary, and the actual method invocation is avoided at runtime. However, not all methods can be inlined. The JIT compiler imposes a number of limitations, such as the restriction that inlined methods need to be static methods, non-virtual methods, or final virtual methods. It seems intuitive that non-final virtual methods cannot be inlined because the method actually invoked is determined at run-time by the actual class type of the instance reference involved in the method invocation. [0047]
  • Methods that have been explicitly declared final cannot be overridden by any subclass. At JIT compilation time, the JIT compiler can determine the actual methods involved in the method invocations. Therefore, the JIT compiler can inline these methods. [0048]
  • The present invention improves upon prior art invocation processes by assuming that a virtual method, if not overridden by any class, is a final method until it is explicitly overridden. By doing so, the present invention can speculatively inline a regular virtual method. [0049]
  • With reference now to FIGS. [0050] 6A-6C, a series of classes explain virtual methods and final methods. FIG. 6A shows an example of class SuperA with a virtual method foo( ) defined in the class. FIG. 6B shows an example of class SubB with a final virtual method foo( ). Since class SubB extends class SuperA, i.e. class SubB is a subclass of class SuperA or class SuperA is a super class of class SubB, method foo( ) of class SubB overrides method foo( ) of class SuperA.
  • FIG. 6C shows another example of class SubC with a virtual method foo( ). Since class SubC extends class SuperA, method foo( ) of class SubC overrides method foo( ) of class SuperA. [0051]
  • With reference now to FIGS. [0052] 7A-7C, a series of examples of virtual method invocations explain the differences among these virtual method invocations.
  • FIG. 7A shows pseudocode of a method bar( ) which contains an invocation of a virtual method foo( ) of class SuperA. Since method foo( ) of class SuperA is explicitly overridden by method foo( ) of either class SubB or class SubC, the method invocation in bar( ) can not be optimized by the process of the present invention. [0053]
  • FIG. 7B shows pseudocode of another method moo( ) which contains an invocation of a final virtual method foo( ) of class SubB. Since method foo( ) of class SubB is a final method, the final method invocation s.foo( ) can be optimized by prior art JIT compilers. [0054]
  • FIG. 7C shows pseudocode of another method boo( ) which contains an invocation of a virtual method foo( ) of class SubC. Assume at JIT compilation time, there is no subclass of class SubC which overrides method foo( ). Since method foo( ) of class SubC is a virtual method and it is not overridden yet, the method invocation s.foo( ) can be assumed final, and it can be optimized by the process of the present invention. [0055]
  • With reference now to FIGS. [0056] 8A-8B, a series of examples of pseudocode explain the manner in which the present invention inlines virtual methods to improve method invocation performance. In prior art JIT compilers, invocation of method s.foo( ) in FIG. 7C can not be directly inlined because it is not bound at JIT compilation time. Instead, it can be speculatively inlined, as illustrated by pseudocode statements in FIG. 8A. By checking whether s.foo( ) is class SubC's foo( ) method, the process ensures that the method has not been previously overridden and that the inlining of the method will properly execute as expected.
  • Note that the approach shown in FIG. 8A may not be particularly efficient for two reasons: (1) the overhead of checking for subclasses and overridden methods may be significant if foo( ) is a small method, i.e. the checking process may require more time than the method foo( ) takes to execute; and (2) the “if” statement prevents the optimization of the inlined code during optimization of method boo( ) because compiler optimization is typically based on basic blocks, and the additional branch statement breaks the original one block into three or four basic blocks. [0057]
  • To improve on the speculative inlining shown in FIG. 8A, the present invention treats virtual methods that have not yet been overridden as regular final methods. Virtual methods in Java, if not explicitly declared final, may potentially be overridden if subclassed. However, at a given point of time, many virtual methods are not overridden in the JVM. For such methods, their behavior is the same as those explicitly declared final. [0058]
  • Virtual methods that are treated as final methods may participate in many optimizations available to the JIT compiler. In particular, aggressive inlining can be applied to these methods. FIG. 8B shows pseudocode statements that are optimized with the present invention for method boo( ) shown in FIG. 7C. If class SubC is not currently subclassed in the JVM and if SubC's foo( ) method satisfies the JIT compiler's inlining policies, then method s.foo( ) can be fully inlined into the context of method boo( ) when method boo( ) is compiled. Note that no branching is needed around SubC's foo( ), as is the case in FIG. 8A. [0059]
  • However, the JVM and the JIT keep track of dependencies among methods. Each JIT compiled method stores a list of all the methods which are inlined because they are assumed final. The depedency lists can be maintained by either JIT or JVM. When a class is loaded into the JVM at run-time, the JVM and JIT find all the methods overridden by newly loaded classes and invalidate or update JIT compiled code that inlines any newly overridden method. This can be achieved by simply searching the dependency lists maintained for the JIT compiled methods. For example, the JIT remembers that the compiled code of method boo( ) depends on SubC's foo( ) not having been overridden by any subclass. If a subclass of SubC is later loaded into the JVM and if foo( ) is redefined in the new class, then the JIT compiled code of method boo( ) needs to be updated to reflect the new JVM state. In that case, the code may be patched, or it may be discarded and the method recompiled. [0060]
  • With reference now to FIGS. [0061] 9A-9D, a series of examples of Java code and assembly code explain the manner in which the present invention inlines virtual methods to improve method invocation performance.
  • FIG. 9A shows an example of a Java language statement which is found in an industry standard benchmark. The Java language statement creates a vector from an origin point consisting of a point with an x-coordinate, a y-coordinate, and a z-coordinate, where getorigin( ), getX( ), getY( ), and getZ( ) are simple methods, shown as statements in FIG. 9B. These types of small methods are encouraged by object-oriented languages, such as Java, to help encapsulate data structures. None of the four methods shown in FIG. 9B is overridden by any subclass in this benchmark. [0062]
  • In order to understand the cost of executing this code pattern, FIG. 9C shows some of the pseudo-assembly language code for part of the Java statement “ray.getOrigin( ).getX( )”. [0063]
  • In the example shown in FIG. 9C, 12 instructions are needed if both methods are speculatively inlined, i.e. neither the path between label [0064] 1_10 and 1_20 or the path between label 1_30 and 1_40 is taken. Many of these instructions are computationally expensive because of the data dependencies among the instructions.
  • FIG. 9D shows some of the pseudo-assembly language code for part of the Java statement “ray.getOrigin( ).getX( )” after using the process of the present invention. In the process of the present invention, methods are assumed to be final methods until overridden. In the example discussed above, i.e. the Java statement “ray.getOrigin( ).getX( )”, both the methods getOrigin( ) and getX( ) are considered final methods. (In fact, these methods are not overridden in the actual implementation of the benchmark.) Instructions in FIG. 9D can be generated if both methods getorigin( ) and getX( ) are inlined and copied into the caller's context. [0065]
  • It should be noted that only two instructions are necessary to complete the same task as in FIG. 9C and that further optimization of the caller side is possible because of the simple code pattern. Also note that as a result of the process of the present invention being applied on the benchmark code, the time to run the benchmark test was significantly reduced. [0066]
  • Alternatively, the present invention may reserve this kind of optimization for “hot” methods, i.e. those that are invoked very frequently and in which a lot of execution time is spent. Any recompilation cost can be reduced if only a small number of methods are highly optimized. [0067]
  • The advantages of the present invention should be apparent in light of the detailed description provided above. By considering a non-final, virtual method as a final virtual method, the method may be inlined until overridden. The processing overhead for invoking the method is then eliminated. Although the JVM or JIT may recompile or patch the calling method once it is overridden, the overall performance of the code is increased. If the method is seldom overridden, then the performance decrease from recompiling the calling method is outweighed by the performance increase gained by repeatedly executing the code of the called method without invocation overhead. [0068]
  • A primary benefit of object-oriented programming is that it can increase development productivity by providing powerful language mechanisms for software reuse. In practice, such reusability is rarely attained. Extensive use of these mechanisms can significantly reduce performance, which leads programmers to use them sparingly. Many programmers using the Java programming language avoid using fully “virtual” methods and write larger methods, because they believe that every virtual method invocation entails a significant performance penalty. Fine-grain use of “virtual” methods (i.e. methods that are not “static” or “final” in the Java programming language) is extremely important to the construction of highly reusable classes, because each such method acts as a “hook” that allows new subclasses to modify the behavior of the superclass. However, because many methods are never overridden, the present invention treats a method as a final method until execution proves otherwise, resulting in a significant increase in performance. [0069]
  • A significant advantage of the approach of the present invention is that it should fit very well in a server environment where classes are loaded initially, and new classes are seldom loaded thereafter. In this case, the JVM and the JIT compiler become “stable” after a period of execution, and they remain stable for the duration of their lifetimes. [0070]
  • It is important to note that while the present invention has been described in the context of a fully functioning data processing system, those of ordinary skill in the art will appreciate that the processes of the present invention are capable of being distributed in the form of a computer readable medium of instructions and a variety of forms, and that the present invention applies equally regardless of the particular type of signal bearing media actually used to carry out the distribution. Examples of computer readable media include recordable-type media such as floppy disks, a hard disk drive, RAM, CD-ROMs, and transmission-type media such as digital and analog communications links. [0071]
  • The description of the present invention has been presented for purposes of illustration and description but is not intended to be exhaustive or limited to the invention in the form disclosed. Many modifications and variations will be apparent to those of ordinary skill in the art. The embodiment was chosen and described in order to best explain the principles of the invention and the practical application, and to enable others of ordinary skill in the art to understand the invention for various embodiments with various modifications as are suited to the particular use contemplated. [0072]

Claims (22)

What is claimed is:
1. A process for optimizing an invocation of a method, the process comprising the computer-implemented steps of:
in response to a determination to compile a first method, detecting an invocation of a second method by the first method; and
inlining the second method in the first method without a conditional statement in the first method for conditional execution of the inlined second method.
2. The process of claim 1 wherein the second method is a non-final, virtual method.
3. The process of claim 1 further comprising:
in response to a determination to load a class comprising a third method that overrides the second method, recompiling or patching the first method.
4. The process of claim 1 further comprising:
determining that the second method has not been previously overridden.
5. A process for optimizing an invocation of a method, the process comprising the computer-implemented steps of:
in response to a determination to compile a first method, detecting a call to a second method within the first method, wherein the second method is a non-final, virtual method; and
inlining the second method within the first method.
6. The process of claim 5 wherein the second method is unconditionally inlined within the first method.
7. The process of claim 5, further comprising:
just-in-time compiling the first method with the inlined second method.
8. The process of claim 5 wherein the first method and the second method are Java methods.
9. The process of claim 5 further comprising:
in response to a determination to load a class comprising a third method that overrides the second method, recompiling or patching the first method.
10. The process of claim 5 further comprising:
determining that the second method has not been previously overridden.
11. The process of claim 5 further comprising:
maintaining a list of dependencies among methods for updating compiled methods that contain inlined methods that may be overridden.
12. A data processing system for optimizing an invocation of a method, the data processing system comprising:
detecting means for detecting, in response to a determination to compile a first method, a call to a second method within the first method, wherein the second method is a non-final, virtual method; and
inlining means for inlining the second method within the first method.
13. The data processing system of claim 12 wherein the second method is unconditionally inlined within the first method.
14. The data processing system of claim 12 further comprising:
compiling means for just-in-time compiling the first method with the inlined second method.
15. The data processing system of claim 12 wherein the first method and the second method are Java methods.
16. The data processing system of claim 12 further comprising:
recompiling means for recompiling, in response to a determination to load a class comprising a third method that overrides the second method, the first method.
17. The data processing system of claim 12 further comprising:
patching means for patching, in response to a determination to load a class comprising a third method that overrides the second method, the first method.
18. The data processing system of claim 12 further comprising:
determining means for determining that the second method has not been previously overridden.
19. The data processing system of claim 12 further comprising:
maintaining means for maintaining a list of dependencies among methods for updating compiled methods that contain inlined methods that may be overridden.
20. A computer program product in a computer-readable medium for use in a data processing system for optimizing an invocation of a method, the computer program product comprising:
instructions for detecting, in response to a determination to compile a first method, a call to a second method within the first method, wherein the second method is a non-final, virtual method; and
instructions for inlining the second method within the first method.
21. The computer program product of claim 20 further comprising:
instructions for updating the first method in response to a determination to load a class comprising a third method that overrides the second method.
22. The computer program product of claim 20 further comprising:
instructions for determining that the second method has not been previously overridden.
US09/330,634 1999-06-11 1999-06-11 Process and system for Java virtual method invocation Expired - Lifetime US6507946B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
US09/330,634 US6507946B2 (en) 1999-06-11 1999-06-11 Process and system for Java virtual method invocation

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
US09/330,634 US6507946B2 (en) 1999-06-11 1999-06-11 Process and system for Java virtual method invocation

Publications (2)

Publication Number Publication Date
US20020144243A1 true US20020144243A1 (en) 2002-10-03
US6507946B2 US6507946B2 (en) 2003-01-14

Family

ID=23290614

Family Applications (1)

Application Number Title Priority Date Filing Date
US09/330,634 Expired - Lifetime US6507946B2 (en) 1999-06-11 1999-06-11 Process and system for Java virtual method invocation

Country Status (1)

Country Link
US (1) US6507946B2 (en)

Cited By (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030018909A1 (en) * 2001-07-17 2003-01-23 International Business Machines Corporation Method and apparatus for enforcing security policies in Java applications
US20040143820A1 (en) * 2003-01-16 2004-07-22 Sun Microsystems, Inc., A Delaware Corporation Optimized representation of data type information in program verification
US20040143641A1 (en) * 2003-01-16 2004-07-22 Sun Microsystems, Inc., A Delaware Corporation System for communicating program data between a first device and a second device
US20040143831A1 (en) * 2003-01-16 2004-07-22 Sun Microsystems, Inc., A Delaware Corporation Ordering program data for loading on a device
US20040143551A1 (en) * 2003-01-16 2004-07-22 Sun Microsystems, Inc., A Delaware Corporation Signing program data payload sequence in program loading
WO2004066147A2 (en) * 2003-01-16 2004-08-05 Sun Microsystems, Inc. Linking of virtual methods
US20040154013A1 (en) * 2003-01-16 2004-08-05 Sun Microsystems, Inc., A Delaware Corporation Using a digital fingerprint to commit loaded data in a device
US20060259054A1 (en) * 2004-06-15 2006-11-16 Shinya Masuda Energy accessory
EP1821210A2 (en) * 2006-02-20 2007-08-22 Samsung Electronics Co., Ltd. Method of calling a method in virtual machine environment and system including a virtual machine processing the method
US20070204258A1 (en) * 2006-02-24 2007-08-30 Samsung Electronics Co., Ltd. Method of invoking inlined method and java virtual machine using the method
US20070234325A1 (en) * 2006-03-31 2007-10-04 Bobrovsky Konstantin S Methods and apparatus to tune intermediate representations in a managed runtime environment
US20070294679A1 (en) * 2006-06-20 2007-12-20 Konstantin Bobrovsky Methods and apparatus to call native code from a managed code application
US8042103B2 (en) * 2005-11-29 2011-10-18 International Business Machines Corporation Pre-translated files used in a virtual machine
US8578352B1 (en) * 2011-03-31 2013-11-05 Google, Inc. Optimizing object oriented programs using limited customization
US20140325492A1 (en) * 2013-04-24 2014-10-30 International Business Machines Corporation Selective speculative class-based optimization

Families Citing this family (32)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5933635A (en) * 1997-10-06 1999-08-03 Sun Microsystems, Inc. Method and apparatus for dynamically deoptimizing compiled activations
JP3807860B2 (en) * 1999-01-29 2006-08-09 インターナショナル・ビジネス・マシーンズ・コーポレーション Compiling method and apparatus, and method activity calculating method and apparatus
US7150005B2 (en) * 1999-07-02 2006-12-12 Beryl Technical Assays, Llc Method and system for global constant management for memory
US6968549B1 (en) 1999-07-02 2005-11-22 Beryl Technical Assays Llc Method and system for dynamically loading data structures into memory with global constant pool
US6874145B1 (en) 1999-07-13 2005-03-29 Sun Microsystems, Inc. Methods and apparatus for implementing an application lifecycle design for applications
US7257812B1 (en) 1999-12-16 2007-08-14 Sun Microsystems, Inc. Methods and apparatus for managing an application
US6701334B1 (en) * 1999-07-13 2004-03-02 Sun Microsystems, Inc. Methods and apparatus for implementing individual class loaders
CA2386658A1 (en) * 1999-08-16 2001-06-28 Z-Force Corporation System of reusable software parts for implementing concurrency and hardware access, and methods of use
US6754887B1 (en) * 1999-10-22 2004-06-22 International Business Machines Corporation Methods for implementing virtual bases with fixed offsets in object oriented applications
JP3986721B2 (en) * 2000-01-20 2007-10-03 三菱電機株式会社 Software module dynamic exchange method and software module dynamic exchange program recording medium
US6981249B1 (en) * 2000-05-02 2005-12-27 Microsoft Corporation Methods for enhancing type reconstruction
AU2001265028A1 (en) * 2000-05-25 2001-12-03 Sun Microsystems, Inc. Method and apparatus for creating efficient native methods that extend a bytecode interpreter
US6766460B1 (en) * 2000-08-23 2004-07-20 Koninklijke Philips Electronics N.V. System and method for power management in a Java accelerator environment
US6799262B1 (en) 2000-09-28 2004-09-28 International Business Machines Corporation Apparatus and method for creating instruction groups for explicity parallel architectures
US6779106B1 (en) 2000-09-28 2004-08-17 International Business Machines Corporation Apparatus and method for an enhanced integer divide in an IA64 architecture
US6883165B1 (en) * 2000-09-28 2005-04-19 International Business Machines Corporation Apparatus and method for avoiding deadlocks in a multithreaded environment
US6886094B1 (en) 2000-09-28 2005-04-26 International Business Machines Corporation Apparatus and method for detecting and handling exceptions
US6912647B1 (en) 2000-09-28 2005-06-28 International Business Machines Corportion Apparatus and method for creating instruction bundles in an explicitly parallel architecture
US7007270B2 (en) * 2001-03-05 2006-02-28 Cadence Design Systems, Inc. Statistically based estimate of embedded software execution time
US7350200B2 (en) * 2001-03-29 2008-03-25 Intel Corporation Method and system of controlling dynamically compiled native code size
EP1253514A1 (en) * 2001-04-24 2002-10-30 Sun Microsystems, Inc. Protected resource access
US6976254B2 (en) * 2001-11-28 2005-12-13 Esmertec Ag Inter-method control transfer for execution engines with memory constraints
US20040003018A1 (en) * 2002-06-26 2004-01-01 Pentkovski Vladimir M. Method and system for efficient handlings of serial and parallel java operations
US7080368B2 (en) * 2002-10-31 2006-07-18 International Business Machines Corporation Object oriented apparatus and method for preserving stack frame identity during inlined method calls
US7089340B2 (en) * 2002-12-31 2006-08-08 Intel Corporation Hardware management of java threads utilizing a thread processor to manage a plurality of active threads with synchronization primitives
US7458070B2 (en) * 2004-03-05 2008-11-25 International Business Machines Corporation Reducing the run-time cost of invoking a server page
US7395530B2 (en) * 2004-08-30 2008-07-01 International Business Machines Corporation Method for implementing single threaded optimizations in a potentially multi-threaded environment
US8789021B2 (en) * 2005-06-30 2014-07-22 International Business Machines Corporation Method and apparatus for object-oriented load testing of computing systems
US8581912B2 (en) 2008-06-27 2013-11-12 Microsoft Corporation Dynamic subroutine linkage optimizing shader performance
CA2719653A1 (en) * 2010-11-05 2011-01-18 Ibm Canada Limited - Ibm Canada Limitee Partial inlining with software based restart
US8543991B2 (en) 2011-03-10 2013-09-24 Microsoft Corporation Profile driven multicore background compilation
US10564943B2 (en) 2015-06-08 2020-02-18 Oracle International Corporation Special calling sequence for caller-sensitive methods

Family Cites Families (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US4989132A (en) * 1988-10-24 1991-01-29 Eastman Kodak Company Object-oriented, logic, and database programming tool with garbage collection
JP2834171B2 (en) * 1989-02-06 1998-12-09 株式会社日立製作所 Compilation method
US5613120A (en) * 1994-10-20 1997-03-18 Silicon Graphics, Inc. System and method for enabling, without recompilation, modification of class definitions and implementations in an object-oriented computer program
JP3290567B2 (en) * 1995-08-24 2002-06-10 富士通株式会社 Profile instrumentation method
EP0976030B1 (en) * 1996-01-24 2008-07-02 Sun Microsystems, Inc. Instruction folding for a stack-based machine
US6041179A (en) * 1996-10-03 2000-03-21 International Business Machines Corporation Object oriented dispatch optimization
US6101326A (en) * 1997-05-29 2000-08-08 Hewlett-Packard Company Method and apparatus for frame elimination for simple procedures with tail calls
US5995754A (en) * 1997-10-06 1999-11-30 Sun Microsystems, Inc. Method and apparatus for dynamically optimizing byte-coded programs
US5970249A (en) * 1997-10-06 1999-10-19 Sun Microsystems, Inc. Method and apparatus for performing byte-code optimization during pauses
US6072951A (en) * 1997-10-15 2000-06-06 International Business Machines Corporation Profile driven optimization of frequently executed paths with inlining of code fragment (one or more lines of code from a child procedure to a parent procedure)
US6401137B1 (en) * 1998-06-30 2002-06-04 Sun Microsystems, Inc. Method, apparatus, and article of manufacture for processing a virtual call in a multi-threaded program
US6195793B1 (en) * 1998-07-22 2001-02-27 International Business Machines Corporation Method and computer program product for adaptive inlining in a computer system
US6199201B1 (en) * 1998-08-03 2001-03-06 Xerox Corporation Software constructs that facilitate partial evaluation of source code
US6161217A (en) * 1998-09-14 2000-12-12 Sun Microsystems, Inc. Accurate method for inlining virtual calls
US6223340B1 (en) * 1998-10-09 2001-04-24 Sun Microsystems, Inc. Method for directly inlining virtual calls without on-stack replacement

Cited By (30)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030018909A1 (en) * 2001-07-17 2003-01-23 International Business Machines Corporation Method and apparatus for enforcing security policies in Java applications
US8121955B2 (en) 2003-01-16 2012-02-21 Oracle America, Inc. Signing program data payload sequence in program loading
US7165246B2 (en) 2003-01-16 2007-01-16 Sun Microsystems, Inc. Optimized representation of data type information in program verification
US20040143831A1 (en) * 2003-01-16 2004-07-22 Sun Microsystems, Inc., A Delaware Corporation Ordering program data for loading on a device
US20040143551A1 (en) * 2003-01-16 2004-07-22 Sun Microsystems, Inc., A Delaware Corporation Signing program data payload sequence in program loading
WO2004066147A2 (en) * 2003-01-16 2004-08-05 Sun Microsystems, Inc. Linking of virtual methods
US20040154013A1 (en) * 2003-01-16 2004-08-05 Sun Microsystems, Inc., A Delaware Corporation Using a digital fingerprint to commit loaded data in a device
US20040143641A1 (en) * 2003-01-16 2004-07-22 Sun Microsystems, Inc., A Delaware Corporation System for communicating program data between a first device and a second device
US7281244B2 (en) 2003-01-16 2007-10-09 Sun Microsystems, Inc. Using a digital fingerprint to commit loaded data in a device
WO2004066147A3 (en) * 2003-01-16 2005-09-09 Sun Microsystems Inc Linking of virtual methods
US7222331B2 (en) 2003-01-16 2007-05-22 Sun Microsystems, Inc. Linking of virtual methods
US8473417B2 (en) 2003-01-16 2013-06-25 Oracle America, Inc. Signing program data payload sequence in program loading
US7484095B2 (en) 2003-01-16 2009-01-27 Sun Microsystems, Inc. System for communicating program data between a first device and a second device
US7272830B2 (en) 2003-01-16 2007-09-18 Sun Microsystems, Inc. Ordering program data for loading on a device
US20040143820A1 (en) * 2003-01-16 2004-07-22 Sun Microsystems, Inc., A Delaware Corporation Optimized representation of data type information in program verification
US20060259054A1 (en) * 2004-06-15 2006-11-16 Shinya Masuda Energy accessory
US8042103B2 (en) * 2005-11-29 2011-10-18 International Business Machines Corporation Pre-translated files used in a virtual machine
US20070245328A1 (en) * 2006-02-20 2007-10-18 Samsung Electronics Co., Ltd. Method of calling a method in virtual machine environment and system including a virtual machine processing the method
EP1821210A3 (en) * 2006-02-20 2009-06-10 Samsung Electronics Co., Ltd. Method of calling a method in virtual machine environment
EP1821210A2 (en) * 2006-02-20 2007-08-22 Samsung Electronics Co., Ltd. Method of calling a method in virtual machine environment and system including a virtual machine processing the method
US20070204258A1 (en) * 2006-02-24 2007-08-30 Samsung Electronics Co., Ltd. Method of invoking inlined method and java virtual machine using the method
US8341606B2 (en) * 2006-02-24 2012-12-25 Samsung Electronics Co., Ltd. Method of invoking inlined method and java virtual machine using the method
US7793275B2 (en) 2006-03-31 2010-09-07 Intel Corporation Methods and apparatus to tune intermediate representations in a managed runtime environment
US20070234325A1 (en) * 2006-03-31 2007-10-04 Bobrovsky Konstantin S Methods and apparatus to tune intermediate representations in a managed runtime environment
US20070294679A1 (en) * 2006-06-20 2007-12-20 Konstantin Bobrovsky Methods and apparatus to call native code from a managed code application
US8578352B1 (en) * 2011-03-31 2013-11-05 Google, Inc. Optimizing object oriented programs using limited customization
US20140325492A1 (en) * 2013-04-24 2014-10-30 International Business Machines Corporation Selective speculative class-based optimization
US20140325493A1 (en) * 2013-04-24 2014-10-30 International Business Machines Corporation Selective speculative class-based optimization
US9239706B2 (en) * 2013-04-24 2016-01-19 International Business Machines Corporation Selective speculative class-based optimization
US9250865B2 (en) * 2013-04-24 2016-02-02 International Business Machines Corporation Selective speculative class-based optimization

Also Published As

Publication number Publication date
US6507946B2 (en) 2003-01-14

Similar Documents

Publication Publication Date Title
US6507946B2 (en) Process and system for Java virtual method invocation
US7434215B2 (en) Mechanism for loading plugin classes at an appropriate location in the class loader hierarchy
US9891900B2 (en) Generation of specialized methods based on generic methods and type parameterizations
US7913240B2 (en) Method and apparatus for transforming java native interface function calls into simpler operations during just-in-time compilation
US6851109B1 (en) Process and system for dynamically compiling a partially interpreted method
US8312439B2 (en) Inlining native functions into compiled java code
US8156482B2 (en) System and method for efficiently generating native code calls from byte code in virtual machines
US6704926B1 (en) Bimodal Java just-in-time complier
US9639329B2 (en) System and method for automatic invocation of constructor code for superclasses
CA2191411C (en) System and method for runtime optimization of private variable function calls in a secure interpreter
US5983021A (en) Dynamically switching statically bound function calls to dynamically bound function calls without recompilation
US7114152B2 (en) Method, apparatus, and program to determine the mutability of an object at loading time
JPH11327916A (en) Cost reduction technique for dynamic class initialization check in already compiled code
US20040154008A1 (en) Static binding of dynamically-dispatched calls in the presence of dynamic linking and loading
US6834391B2 (en) Method and apparatus for automated native code isolation
US20060248523A1 (en) Annotation management
US20050050528A1 (en) Method and apparatus to guarantee type and initialization safety in multithreaded programs
US20040083467A1 (en) System and method for executing intermediate code
US6604167B1 (en) Method and apparatus traversing stacks for just-in-time compilers for Java virtual machines
US6779188B1 (en) Apparatus and method for improved devirtualization of method calls
Krylov et al. Ahead-of-time compilation in OMR: overview and first steps
US7194736B2 (en) Dynamic division optimization for a just-in-time compiler
Stadler et al. Lazy continuations for Java virtual machines
Hong et al. Java client ahead-of-time compiler for embedded systems
Binder et al. Extending standard Java runtime systems for resource management

Legal Events

Date Code Title Description
AS Assignment

Owner name: INTERNATIONAL BUSINESS MACHINES CORPORATION, NEW Y

Free format text: ASSIGNMENT OF ASSIGNORS INTEREST;ASSIGNORS:ALEXANDRER, III, WILLIAM P.;GU, WEIMING;REEL/FRAME:010035/0281

Effective date: 19990611

FEPP Fee payment procedure

Free format text: PAYOR NUMBER ASSIGNED (ORIGINAL EVENT CODE: ASPN); ENTITY STATUS OF PATENT OWNER: LARGE ENTITY

STCF Information on status: patent grant

Free format text: PATENTED CASE

FPAY Fee payment

Year of fee payment: 4

FPAY Fee payment

Year of fee payment: 8

REMI Maintenance fee reminder mailed
FPAY Fee payment

Year of fee payment: 12

SULP Surcharge for late payment

Year of fee payment: 11