Abstract:
A method of calling a method in a virtual machine environment is provided. The method includes reading a command of a first method; storing an address of the command code in predetermined memory space if the command is a command that calls a second method; changing an address of previously-compiled code of the second method and writing the address in the stored address; and directly branching to the address of newly-compiled code of the second method and calling the second method if the first method is performed.

Description:
CROSS-REFERENCE TO RELATED APPLICATION 
       [0001]    This application is based on and claims priority from Korean Patent Application No. 10-2006-0016216 filed on Feb. 20, 2006 in the Korean Intellectual Property Office, the disclosure of which is incorporated herein in its entirety by reference. 
       BACKGROUND OF THE INVENTION 
       [0002]    1. Field of the Invention 
         [0003]    Methods and apparatuses consistent with the present invention relate to calling a method in a virtual machine environment. More particularly, the present invention relates to an improved method of calling a method that uses a table including multiple slots in which the address of a method is written, and a system including a virtual machine processing the method. 
         [0004]    2. Description of the Related Art 
         [0005]    Because application programs are hardware dependent, separate versions of the same application must be designed for each hardware platform. In order to develop an application program which is platform independent, a virtual machine, which abstracts a hardware platform, has been developed. One representative virtual machine is the Java virtual machine. 
         [0006]    In order to realize platform independence, the Java language was developed by SUN Microsystems. Java can be used to produce software for electronics such as microwave ovens and remote controllers. 
         [0007]    In order to generate a platform-independent executable file, Java compiles source code into a unique bytecode format, and uses the Java virtual machine to execute the code. 
         [0008]    As shown in  FIG. 1 , a Java program  110  having the “java” extension is compiled by a compiler  120  such as “javac”, and the program file is converted into a Java executable file having the “.class” extension, i.e., a file written in Java bytecode. Then the class file is interpreted by the internal interpreter  130  of the Java Virtual Machine (JVM), and is executed. 
         [0009]      FIG. 2  illustrates a layer structure of a platform for executing a Java program. The layer structure includes a Java platform  240  written in Java that includes the JVM and the Java Application Program Interface (JAPI)  230 , and a hardware-dependent platform  210 . Under such a structure, because a Java executable file is a class file including bytecode, which is platform-neutral code, the file can be executed in the Java runtime environment regardless of which system the program has been developed on. 
         [0010]    The JVM is useful for executing platform-independent application programs, but its execution speed is very low compared with hardware-dependent application programs. In other words, when executing a Java application program, because an interpreter in the JVM sequentially executes the bytecode program, the execution speed is low. 
         [0011]    In order to overcome the execution speed, the Just-In-Time (JIT) compiler was developed. 
         [0012]    The JIT compiler compiles a called method at the point of time when the method is called while the JVM executes a Java application, and directly executes compiled machine code instead of bytecode. Here, because compiled machine code is stored in memory, the code does not have to be interpreted every time, the virtual machine can be optimized for the hardware platform, and the execution speed is higher than the interpretation method. 
         [0013]      FIG. 3  illustrates a state change of methods in the JVM including the JIT compiler. Referring to  FIG. 3 , bytecode  310  is converted into compiled code  320  by the JIT compiler for quick execution, and JIT-compiled code  320  is optimized for quicker execution. The JIT-compiled code  320 ,  330  is converted into bytecode  310  to secure memory. Here, the native code is platform-dependent machine code. 
         [0014]    Because the memory addresses of the methods are changed when the methods are changed, the address change of the methods should be considered when calling a method. 
         [0015]    The conventional method call is operated as follows. 
         [0016]    First, a load command that gets a method table from a class object is performed. Here, the method table indicates a multiple of data structures in which slots are constituted in an array form. Then, a load command that reads the address of the method to be called from a slot where the address of the method has been recorded is performed, and a command that branches to the address is performed. Hence, if the address of a called method is changed, content of a slot corresponding to the method should be updated in the method table. 
         [0017]    According to the conventional art mentioned above, whenever a method is called, the process of reading the address of the method from the method table should be performed. However, in this case, because the process should be performed in the case where the method is kept constant, unnecessary system overhead is generated. Moreover, in the case of a virtual machine installed in a system having few resources, such a system overhead can significantly affect the system performance. 
       SUMMARY OF THE INVENTION 
       [0018]    An object of the present invention is to provide a method-calling method, which minimizes overhead of a system by directly accessing the address of a method to be called when calling a method in a virtual machine environment, and a system having the virtual machine that performs the method. 
         [0019]    The present invention will not be limited to the technical objects described above. Other objects not described herein will be more definitely understood by those in the art from the following detailed description. 
         [0020]    According to an exemplary embodiment of the present invention, there is provided a method-calling method in a virtual machine environment, the method including reading a command of a first method; storing an address of the command code in predetermined memory space if the command is a command that calls a second method; changing an address of previously-compiled code of the second method and writing the address in the stored address; and directly branching to the address of newly-compiled code of the second method and calling the second method if the first method is performed. 
         [0021]    According to an exemplary embodiment of the present invention, there is provided a system including a direct-call-information management module, which stores an address of the command code in predetermined memory space, changes the address of the previously-compiled code to the address of the newly-compiled code, and records the address in the predetermined memory space, if a command of a first method is a command that calls a second method; and a virtual machine, which directly branches to the address of newly-compiled code of the second method and calls the second method if the first method is performed. 
     
     
       BRIEF DESCRIPTION OF THE DRAWINGS 
         [0022]    The above and other features and aspects of the present invention will become apparent by describing in detail exemplary embodiments thereof with reference to the attached drawings, in which: 
           [0023]      FIG. 1  illustrates a general process of executing a Java program. 
           [0024]      FIG. 2  illustrates a layer structure of a platform that executes a Java program. 
           [0025]      FIG. 3  illustrates a state change of methods in the Java Virtual Machine that includes the Just-In-Time compiler. 
           [0026]      FIG. 4  is a flow chart illustrating a process of compiling a method according to an exemplary embodiment of the present invention. 
           [0027]      FIG. 5  illustrates a structure of a method block according to an exemplary embodiment of the present invention. 
           [0028]      FIG. 6  illustrates an operation of a method call according an exemplary embodiment of the present invention. 
           [0029]      FIG. 7  is a block diagram illustrating a system in which a virtual machine is installed according to an exemplary embodiment of the present invention. 
       
    
    
     DETAILED DESCRIPTION OF THE INVENTION 
       [0030]    Exemplary embodiments of the present invention will be described in detail with reference to the accompanying drawings. 
         [0031]    Aspects and features of the present invention and methods of accomplishing the same may be understood more readily by reference to the following detailed description of the exemplary embodiments and the accompanying drawings. The present invention may, however, be embodied in many different forms and should not be construed as being limited to the exemplary embodiments set forth herein. Rather, these exemplary embodiments are provided so that this disclosure will be thorough and complete and will fully convey the concept of the invention to those skilled in the art, and the present invention will only be defined by the appended claims. 
         [0032]    The present invention is described hereinafter with reference to flowchart illustrations of user interfaces, methods, and computer program products according to exemplary embodiments of the invention. It will be understood that each block of the flowchart illustrations, and combinations of blocks in the flowchart illustrations, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart block or blocks. 
         [0033]    These computer program instructions may also be stored in a computer usable or computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer usable or computer-readable memory produce an article of manufacture including instruction means that implement the function specified in the flowchart block or blocks. 
         [0034]    The computer program instructions may also be loaded into a computer or other programmable data processing apparatus to cause a series of operational steps to be performed in the computer or other programmable apparatus to produce a computer implemented process such that the instructions that execute in the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart block or blocks. 
         [0035]    And each block of the flowchart illustrations may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that in some alternative implementations, the functions noted in the blocks may occur out of the order. For example, two blocks shown in succession may in fact be executed substantially concurrently or the blocks may sometimes be executed in reverse order depending upon the functionality involved. 
         [0036]    For explanatory convenience, it is assumed that a method “boo” includes code that calls a method “foo” of a class A-type object “obj”. 
         [0000]    
       
         
               
               
             
           
               
                   
                   
               
             
             
               
                   
                 void boo( ) 
               
               
                   
                 { 
               
               
                   
                   A obj = new A( ); 
               
               
                   
                   ... 
               
               
                   
                   obj.foo( ); 
               
               
                   
                   ... 
               
               
                   
                 } 
               
               
                   
                   
               
             
          
         
       
     
         [0037]    Here, an operation executed when a method “boo” is Just-In-Time-compiled is illustrated in  FIG. 4 . 
         [0038]    Referring to  FIG. 4 , when the JIT compiler starts to compile the method “boo”, the command of the method “boo” is read S 410 . Here, it is recognized whether the command is the last command of the method “boo” S 420 . 
         [0039]    If the command is the last command of the method “boo”, after step S 460  is performed, the compiling of the method is completed, otherwise steps S 430 , S 440  and S 450  are performed. The operation of step S 460  is described later. 
         [0040]    In step S 420 , if the current command is not the last command of the method “boo”, the JIT compiler compiles the current command S 430 . Here, it is examined whether the compiled command is a call for the method “foo” S 440 . 
         [0041]    Here, in the case where the compiled command is not a call for the method “foo”, the next command of the method “boo” is read by returning back to step S 410 , otherwise the JIT compiler stores an address of code that has called the method “foo” in memory space where direct-call information is stored S 450 . 
         [0042]    Here, the direct-call information can be stored in a method block  500  as illustrated in  FIG. 5 . 
         [0043]    The method block  500  stores information about the method “foo” such as interpreter code information that represents bytecode of the method “foo”, the code size of the method “foo”, and the start position of code of the method “foo”, and includes direct-call information that calls the method “foo”. The other information except the direct-call information  510  can be information stored in the conventional method block. 
         [0044]    The direct-call information can be managed by being connected via an address of code that calls the method “foo” (indicated as “position  1 ” and “position  2 ” in  FIG. 5 ) or a linked list. 
         [0045]    The management on the direct-call information can be performed by the JIT compiler, but can also be performed by a separate software module. 
         [0046]    Further, in step  420 , in the case where the currently-read command is the last command of the method “boo”, the position of code that calls the method “boo” should be traced, the previously-compiled address is updated to the address of newly-compiled code S 460 , and the compile of the method “boo” is terminated. 
         [0047]    In other words, if the compile of the method “boo” is completed, because the method “boo” can be called by another method, from now on, the method should be called to a newly-compiled position. 
         [0048]    When the compile of the method “boo” is completed according to the method illustrated in  FIG. 4 , operations corresponding to code of the compiled method “boo” are performed. Here, if the method “foo” is called in the method “boo”, the method “foo” is not indirectly called via a separate method table. Because the address for the code of the method “boo” that calls the method “foo” is stored in memory space where direct-call information is stored, the method “foo” can be directly called by recording the address of the compiled method “foo”. 
         [0049]      FIG. 6  illustrates an operation of a method call according to an exemplary embodiment of the present invention; it is assumed that the method “boo” and the method “zoo” include a command that calls the method “foo”, respectively. 
         [0050]    Referring to  FIG. 6 , a command to branch to the method “boo” resides in address 0x18 of the compiled code  610  of the method “boo”, and a command to branch to the method “foo” resides in address 0x4C of the compiled code  620  of the method “zoo”. 
         [0051]    Therefore, for example, when the method “boo” and the method “zoo” are compiled, the address 0x18 of the compiled code  610  of the method “boo” that calls each method “foo” and the address 0x4C of the compiled code  610  of the method “zoo” are stored in the linked list  520 ,  530  linked with the direct-call information. 
         [0052]    Further, in the case where the compiled code  610  of the method “boo” or the compiled code  620  of the method “zoo” are executed, when the method “foo” is called, the code branches to the address (here, 0x12345678) of the compiled code  630  of the direct method “foo”; the branch is expressed as “jump 0x12345678” in  FIG. 6 . 
         [0053]    According to the conventional art, in the case where the method “foo” is called within the method “boo”, the following process is performed. 
         [0000]      T=0x12341234  (step 1) 
         [0000]        T=LD ( T )  (step 2) 
         [0000]      JRT  (step 3) 
         [0054]    In step 1, a slot address of the method is acquired in a conventional method table; in step  2 , an address, in which the compiled code of the method “foo” has been recorded, is acquired from the slot address acquired in step 1; and in step 3, the code branches to the address acquired in step  2 . 
         [0055]    However, according to the present invention, in the case where the method “foo” is called within the method “boo”, only one step needs to be performed as follows. 
         [0000]      JR 0x12341234  (step 1) 
         [0056]    Further, in the case where a method to be called is defined as “private” or “final”, the method can be directly called according to the method mentioned above. 
         [0057]    Further, in the case where the compiled code needs to be corrected in a virtual machine to which the method-calling method according to the present invention is applied, when the execution of other threads has stopped, the correction can be handled collectively. 
         [0058]    Further, in the case of a virtual machine having a decompiler to which the method-calling method according to the present invention is applied, in order to overcome the lack of memory, the compiled code can be converted into code for an interpreter. Here, according to the conventional art, a thread-stop mechanism of the garbage collector can be used or the thread can be stopped in other ways so that the address on the method call can be promptly updated. 
         [0059]      FIG. 7  is a block diagram illustrating a system in which a virtual machine is installed according to an exemplary embodiment of the present invention. 
         [0060]    Referring to  FIG. 7 , a system  700  according to the present invention includes a virtual machine  710  having a direct-call-information management module  720 . 
         [0061]    The term “module”, as used herein, means, but is not limited to, a software or hardware component, such as a Field Programmable Gate Array (FPGA) or an Application Specific Integrated Circuit (ASIC), which performs certain tasks. A module may advantageously be configured to reside in the addressable storage medium and configured to execute on one or more processors. Thus, a module may include, by way of example, components, such as software components, object-oriented software components, class components and task components, processes, functions, attributes, procedures, subroutines, segments of program code, drivers, firmware, microcode, circuitry, data, databases, data structures, tables, arrays, and variables. The functionality provided for in the components and modules may be combined into fewer components and modules or further separated into additional components and modules. 
         [0062]    The direct-call-information management module  720  manages direct-call information described above, and the module can be operated when a method is changed from one using bytecode to one using compiled code or vice versa. 
         [0063]    Here, the direct-call-information management module  720  can store the address of code that calls a method in the form of the linked list in the method block of a called method, and the address of compiled code of the called method can be updated. Because such a process has been already described in  FIGS. 4 to 6 , the description is omitted here. 
         [0064]    Further, in  FIG. 7 , the direct-call-information management module  720  is separately illustrated with the JIT compiler in the virtual machine  710 , but the JIT compiler can be implemented to provide a function provided by the direct-call-information management module  720 . 
         [0065]    In  FIG. 7 , because the garbage collector, interpreter, decompiler, and class loader of the illustrated virtual machine  710  are the same as those of the conventional art, a detailed description is omitted here. 
         [0066]    It should be understood by those of ordinary skill in the art that various replacements, modifications and changes may be made in the form and details without departing from the spirit and scope of the present invention as defined by the following claims. Therefore, it is to be appreciated that the above described exemplary embodiments are for purposes of illustration only and are not to be construed as limitations of the invention. 
         [0067]    The method and apparatus of the present invention has an advantage that system performance is improved by minimizing system overhead by directly accessing the address of a method to be called when calling the method in virtual machine environment.