1. Field of Invention
The invention preferably relates to optimized execution of object oriented languages which use the ‘interface’ abstraction, and in particular JAVA. In a preferred embodiment, the invention relates to Dispatch Mechanism for Interface Methods.
2. Description of Related Art
In recent years, there have been developments in programming languages towards what is known as an object-oriented language. In these developments, concepts are regarded as ‘objects’, each carrying with it a set of data, or attributes, pertinent to that object, as well as information relating to so-called ‘methods’, that is functions or sub-routines, that can be performed on that object and its data. This is well known to those skilled in the art of computing and/or programming.
The advent and rapid advancement in the spread and availability of computers has led to the independent development of different types of systems, such as the IBM and IBM-compatible PC running IBM-DOS or MS-DOS or MS-Windows applications, the Apple Macintosh machines running their own Apple System operating system, or various Unix machines running their own Unix operating systems. This proliferation of independent systems has led to useful applications being available only in one format and not being capable of running on a machine for which the application was not designed.
Under such circumstances, programmers have devised software which ‘emulates’ the host computer's operating system so that a ‘foreign’ application can be made to run successfully in such a way that, as far as the user is concerned, the emulation is invisible. In other words, the user can perform all of the normal functions of say a Windows-based application on a Unix machine using a Unix-based operating system without noticing that he is doing so.
A particularly notable product of this type is that developed by Insignia Solutions of High Wycombe, GB and Santa Clara, Calif., USA and known under the name ‘SoftWindows 2.0 for Powermac’. This software enables a physical Macintosh computer to emulate a PC having an Intel 80486DX processor and 80487 maths co-processor plus memory, two hard disks, IBM-style keyboard, colour display and other features normally found on recent versions of the PC-type of computer.
Furthermore, there is an ever-increasing demand by the consumer for electronics gadgetry, communications and control systems which, like computers, have developed independently of one another and have led to incompatibility between operating systems and protocols. For example, remote-control devices for video players, tape players and CD players have similar functions, analogous to ‘play,’ ‘forward,’ ‘reverse,’ ‘pause,’ etc., but the codes for transmission between the remote control, or commander, operated by the user may not be compatible either between different types of equipment made by the same manufacturer or between the same types of equipment made by different manufacturers. There would be clear benefits of having software within the equipment which can produce for example the correct ‘play’ code based upon a ‘play’ command regardless of the specific hardware used in the equipment. Such software is commonly known as a ‘Virtual Machine.’
Other uses and applications are legion: for example, set-top boxes for decoding television transmissions, remote diagnostic equipment, in-car navigation systems and so-called ‘Personal Digital Assistants.’ Mobile telephones, for instance, can have a system upgrade downloaded to them from any service provider.
Emulation software packages lend to have certain features in common, notably that they are not general purpose but are dedicated. They are of most benefit in rapid development areas and have a distinct advantage in enabling manufacturers to cut costs. In particular, they can divorce software from the physical machine, i.e., the effect of the software in the physical machine can be altered by the emulating software without having to go into the machine's native software to implement those changes.
The specific object-oriented language used in some of the implementations described later is that known as JAVA (registered trade mark to Sun Microsystems Corporation). Some of the following implementations will enable JAVA to be used in smaller devices than is currently possible because of the improved performance and/or reduced memory footprint. Future uses projected for embedded software (virtual machines) include computers worn on the body, office equipment, household appliances, and intelligent houses and cars.
While it is recognised that there are clear advantages in the use of virtual machines, especially those using object-oriented languages, there are naturally areas where it is important and/or beneficial for some of the operations that are carried out within the system to be optimised. These may include reducing the memory requirement, increasing the speed of operation, and improving the ‘transparency’ of the system when embedded in another system. One of the principal aims of the inventions described herein is to provide a Virtual Machine which is optimised to work as quickly as possible within a memory constraint of, for example, less than 10, 5, 2 or even 1 Mbyte. Such a constraint is likely to be applicable, for example, to electronics gadgetry and other equipment where cost (or size) is a major constraint.
JAVA supports single inheritance of class types, with interfaces. Interfaces themselves can be multiply inherited from other interfaces. When a concrete class claims to implement a set of interfaces, it must provide or inherit implementations of every method directly or indirectly defined by those interfaces. (See Reference [2] listed under Other Information at the end of this specification).
In object oriented programming, objects are classified in a hierarchical stricture with each object associated with attributes (data about its features or properties) and methods (functions it may perform). Typical such functions might be ‘ring’ in the context of a mobile or other telephone, or ‘play’ in the context of audio and/or video reproduction equipment. As one of the features in object-oriented languages, such as JAVA, the attributes and methods of a super class of objects are ‘inherited’ by its subclasses.
For example, as shown in
In another context, the user of a mobile or other telephone may wish to arrange for his handset to emit a different ring depending on whether the call was business or social. In this context, ‘ring’ would be termed an ‘interface.’ Its significance is that ‘ring’ is a function that a variety of objects in the hierarchy would perform (like ‘turn on lights’ in the car example above) but the actual implementation would differ from object to object. Interfaces therefore cut across hierarchies. An interface is thus a list of functions that the object can perform (such as ‘ring’ or ‘play’ or ‘record’ and so on).
Single inheritance is usually implemented using dispatch tables (otherwise known as virtual function tables). A subclass inherits the dispatch table of its superclass, extending it with any new methods, and replacing entries which have been overridden.
Multiple inheritance in languages such as C++ is normally implemented using multiple dispatch tables and offsets ((See Reference [1] listed under Other Information at the end of this specification).
The relevant data is stored in slots in a dispatch table illustrated schematically in FIG. 1B. The attributes of an object in a table 410 are always located at the same distance from the start of the object. The object includes a pointer 412 to a dispatch table of methods 414 which are always at the same distance from the start for the same function. However, when interface methods are used, as explained above, there is no longer any certainty of knowing in which slot of the dispatch table the particular function appears. This is a problem peculiar to the multiple inheritance and particularly interfaces found in JAVA language.
Up to now, the whole of the dispatch table had to be interrogated to check that the method accessed was the proper method. It had been realised that, ideally, a unique identifier would be needed for the interfaces, but in practice the table cannot be of such a size that everything within it has a unique identifier.
Reverting to the ‘play’ function analogy, there would be one dispatch table for video recorder and one for tape recorder. Each would have different interface references, so ‘play’ might be at position 2 for video recorder and position 22 for tape recorder.
The logical definition of invoking an interface method is to search the list of methods implemented directly or indirectly by the given class of object. This is clearly slow. This can be improved by searching a ‘flat’ structure which mirrors the dispatch table.
Reference [3] listed under Other Information at the end of this specification describes an optimization where the last offset at which the interface method was found is remembered, and tried as a first guess next time the invoke interface is encountered. If the guess turns out to be wrong, a fuller search is performed. This approach is based on the assumption that a given call site will tend to operate on the same type of objects.
Even if the guess is right, the destination method has to be checked to confirm that it is. In the cases where the guess is wrong, a fairly slow search is needed.
Another approach would be to use an analog of the way C++ multiple inheritance is supported.
The invention solves this problem by a method for reducing dispatch times during the execution of a program in object-oriented language, which program has a number of interface methods, the method including the steps of:
(i) creating dispatch tables;
(ii) creating an interface hash table for one or more of the dispatch tables, the interface hash table having a pointer either as an index into a specific location in the corresponding dispatch table, or to a method stored on a computer executing the program;
(iii) when the program executes a step requiring a particular interface method, using the interface hash table to look up the latter interface method, either via the dispatch table, or directly.
Whereas the latter method applies in the case where the invention is applied to the program, the invention can also be applied in the form of a “virtual machine” wherein software emulates a “virtual” computer system in order to run a “foreign application. However, steps (ii) and (iii) above are still similarly applied.
More particularly, the invention also provides a method for reducing dispatch times wherein a virtual machine, and a set of programs executed by the virtual machine are stored on a computer readable medium (such as a CD); the virtual machine being operative to reduce dispatch times in the course of program execution by:
(i) creating dispatch tables;
(ii) creating an interface hash table for one or more of the dispatch tables, the interface hash table having a pointer either as an index into a specific location in the corresponding dispatch table, or to a method stored on a computer executing the program;
(iii) when the program executes a step requiring a particular interface method, using the interface hash table to look up the latter interface method, either via the dispatch table, or directly.
These methods of reducing dispatch time can clearly be specifically applied to JAVA.
In one embodiment of the invention, there is one interface hash per dispatch table. In another embodiment of the invention, there is a single interface hash table for all the dispatch tables.
In one form of the invention, the dispatch table points to the interface hash table. In another form of the invention, the hash table is part of the dispatch table at the start. This later form of the invention thereby eliminates one level of indirection.
The interface hash table can contain, for example, slot numbers of the dispatch table. Alternatively, the interface hash table can contain function points, thereby eliminating one level of indirection.
Chief advantages of at least preferred embodiments of the invention are that it is fast in the majority of situations. It uses no support routines in the common case, and does not need checks on the caller. This makes the common case fast, and makes the generated code smaller. It also has very little memory overhead, since a small hash table is needed only in the case where a class implements an interface. Small and fast are important qualities for uses such as Mobile Telephones where memory is limited on account of size or cost.
The method of the invention preferably includes the step of calling a special recovery method, in the event of a collision occurring when looking up the same interface method in the interface hash table. In this case, the hash table can either point to a method stored in the computer, or to a fallback slot in the dispatch table, which will redirect the call to an appropriate stored method, which is designed to “sort out” the class and direct the call to the appropriate location.
According to the invention in its broadest aspect, the solution to this problem is to use an extra level of indirection through a hash table.
For the majority of cases where there is no clash in the hash table, invoking an interface is only slightly slower than a standard virtual dispatch, and faster than the known techniques for invoking interface methods. It is also expected to be more compact than the C++ multiple inheritance approach, especially when dispatch table slots contain more than one word of information.
Where there is a clash in the interface hash table, a fallback slot in the dispatch table performs the slow but sure search.
According to other aspects of the invention, the problem of fast access to the required information is solved or alleviated by the use of an interface hash table as well as a dispatch table for each of the various devices.
The following considerations apply to any and all of the inventions and aspects of the inventions described above.
Preferred embodiments of the invention will now be described, purely by way of example having reference to the accompanying figures of the drawings (which represent schematically the improvements) in which:
A specific example of a preferred embodiment of virtual machine is now described with reference to FIG. 1.
The virtual machine 20 is an executable code installed in the particular item of equipment 22. It can provide a degree of independence from the hardware and operating system. The virtual machine may typically include any, some, or all of the following features: an operating engine, a library of routines, one or more interpreters, one or more compilers, storage means for storing a plurality of instruction sequences, queue management means, and buffer management means.
The virtual machine is coupled to one or more applications 24 on one side (the “high level” side), and, on the other side (the “low level” side), perhaps via various intermediate logical units, to the hardware 26 of the item of equipment. The hardware can be regarded as including various ports or interfaces 28 (perhaps an interface for accepting user input); the virtual machine receives events from those ports or interfaces. The hardware also includes one or more processors/control means 30 and memory 32.
An embodiment of the invention will now be described by way of example only, to illustrate how a “virtual machine” can be applied in practice. It will be appreciated that this is just an illustrative example, because the “virtual machine” can be applied to very many different systems. Examples of these include Mobile Telephones (which incorporate hand-held computers); Set Top Boxes for digital television; Video Equipment which is intended for use with MPEG digital systems; and intelligent Disc Drives. The invention is particularly useful where, due to physical size (e.g., Mobile Telephones) memory is limited and more efficient modes of executing programs, using an object-oriented language such as JAVA, can be used. The memory onboard a Mobile Telephone may be limited, for example, to less than 500 kB, and it is in environments with limited memory that the invention works well. However, it can also run well for memories above this.
Referring now to
It is clear from
Preferably, choose a starting hash value which does not collide with any related interface classes, and then allocate hash numbers for each member method of the interface sequentially from this. Hash values should be chosen so that methods of the same interface or related interfaces have unique hash values and do not conflict or clash. Clearly an object which implements many interfaces or interfaces with many methods may not be able to avoid clashes. A larger hash table usually reduces the number of clashes.
In the event of a clash in the hash table, because the same location is needed for two interface methods, the hash table will point to a method stored in the computer designed to ‘sort out’ the clash and direct the caller to the appropriate location. This can also be done by first pointing to a slot (e.g., the first) in the dispatch table 422 which then points to the “sort out” method stored in the computer.
More generally speaking, each dispatch table is created after defining each concrete class and when the set of methods it implements is known. (The dispatch table will take into account method implementations inherited from its superclass). A fixed size hash table is created for each class which maps the interface method hash value described above to a dispatch table index of the corresponding implementation. Where a class implements two or more interface methods which have the same interface hash value, the hash table is set to contain the dispatch table index of the fallback routine for “sorting out” a clash.
This hash table is either included at the beginning of the dispatch table, or referenced from the dispatch table.
To invoke an interface method on a given object (in a register),
The pseudo assembler sequence for the above steps is:
In the form of the invention where the hash table is part of the dispatch table, one level of indirection is eliminated.
In the form of the invention where the interface hash table contains method pointers, another level of indirection is eliminated:
Where there is a clash between interface method hash entries for a particular class, the interface hash table contains the dispatch table index of a fallback method. The fallback method has access (in registers) to the destination object, and a unique identifier for the interface method. It performs the standard search for that object's implementation of the interface method.
It will be known to those of skill in the computing art that a hash table is a means of reducing lo manageable proportions a data set where information is sparsely populated and there is otherwise a high degree of redundancy within the data set. A hash table thus can reduce the scale of a whole application and thereby reduce the footprint of the device, one of the important features of JAVA.
In summary, the inventions of this patent application include
1. Using a Hash for Interface Methods
Each interface method is allocated a small hash value. This interface hash value can be derived in many ways, but must not exceed the size of the hash table used below.
It is best if the hash values are chosen to reduce conflicts between interface methods, therefore hash values should be chosen so that methods of the same interface or related interfaces have unique hash values. Clearly an object which implements many interfaces or interfaces with many methods may not be able to avoid clashes.
Naturally, a larger hash table usually reduces the number of clashes.
2. Indirect Through a Hash Table when Invoking Interface Methods
When each concrete class is defined, the set of methods it implements is known, and a dispatch table is created. The dispatch table takes into account methods implementations inherited from its superclass.
A fixed size hash table is created for each class which maps the interface method hash value described above to a dispatch table index of the corresponding implementation. Where a class implements two or more interface methods which have the same interface hash value, the hash table is set to contain the dispatch table index of the fallback routine described below.
This hash table is either included at the beginning of the dispatch table, or referenced from the dispatch table.
To invoke an interface method on a given object (in a register),
a. Load the address of the interface hash table for the given object.
b. Get the slot number for the specified interface method using its hash as an index into the interface hash table.
c. Load a unique identifier for the destination interface method into a register.
d. Given the dispatch table slot number, perform a normal virtual invoke.
3. Fallback Dispatch Table Entry
Where there is a clash between interface method hash entries for a particular class, the interface hash table contains the dispatch table index of a fallback method. The fallback method has access (in registers) to the destination object, and a unique identifier for the interface method.
It performs the standard search for that object's implementation of the interface method.
It will be known to those of skill in the computing an that a hash table is a means of reducing to manageable proportions a data set where information is sparsely populated and there is otherwise a high degree of redundancy within the data set. A hash table thus can reduce the scale of a whole application and thereby reduce the footprint of the device, one of the important features of JAVA. Overflows are taken into account in a way which is already known in the utilisation of hash tables.
Also according to the invention, therefore, a computer system includes one or more dispatch tables for storing data containing methods appropriate to objects in a class hierarchy and an interface hash table pointing to the location in the dispatch table where a method of interest is located.
The invention also provides a method of operating a computer system which uses dispatch tables containing methods appropriate to objects in a class hierarchy, including the steps of: directing a call for a method to the dispatch table; passing on the call to a hash table containing information as to the location of methods in the dispatch table; and redirecting the call from the hash table to that location in the dispatch table where the method is stored.
The invention also provides a computer system including means for storing data relating to an object, means for calling data relating to a method appropriate to the object, a dispatch table adapted to contain data relating to at least one the method, means for passing the call on to a hash table containing information as to the location of method(s) in the dispatch table and means for redirecting the call from the hash table to the dispatch table to access the location of the called method.
In one form of the invention, there is one interface hash per dispatch table. In another form of the invention, there is a single interface hash table for all the dispatch tables.
Alternatively, the invention provides both a method of improving the performance of interface dispatching by using a hash table and a computer system including a hash table to improve the performance of interface dispatching.
In another aspect, the invention provides a method or a computer system in which the interface reference for a particular method is found by means of a hash table.
It will be understood that ‘interface dispatching’ is the method by which the slot location for a particular method, e.g., the slot location number (2) for the ‘play’ function of a video recorder, is located and then the relevant data is called.
Chief advantages of the invention may include faster interface dispatching and/or a reduction in the size of footprint.
In each case, the method or computer system of the invention as specified in the preceding paragraphs may be applied specifically to JAVA.
The operation of the system can be looked at in another way. Thus, in
In the event of a clash in the hash table, perhaps because the same location is needed for two interface methods, or perhaps due to being called by two different threads in a multi-threaded environment, the hash table will point to a method designed to ‘sort out’ the clash and direct the caller to the appropriate location or locations.
In any or all of the aforementioned, certain features of the present invention have been implemented using computer software. However, it will of course be clear to the skilled person that any of these features may be implemented using hardware or a combination of hardware and software. Furthermore, it will be readily understood that the functions performed by the hardware, the computer software, and such like are performed on or using electrical and like signals.
Features which relate to the storage of information may be implemented by suitable memory locations or stores. Features which relate to the processing of information may be implemented by a suitable processor or control means, either in software or in hardware or in a combination of the two.
In any or all of the aforementioned, the invention may be embodied in any, some or all of the following forms: it may be embodied in a method of operating a computer system; it may be embodied in the computer system itself; it may be embodied in a computer system when programmed with or adapted or arranged to execute the method of operating that system; and/or it may be embodied in a computer-readable storage medium having a program recorded thereon which is adapted to operate according to the method of operating the system.
As used herein throughout the term “computer system” may be interchanged for “computer”, “system”, “equipment”, “apparatus”, “machine” and like terms. The computer system may be or may include a virtual machine.
In any or all of the aforementioned, different features and aspects described above, including method and apparatus features and aspects, may be combined in any appropriate fashion.
It will be understood that the present invention(s) has been described above purely by way of example, and modifications of detail can be made within the scope of the invention.
Each feature disclosed in the description, and (where appropriate) the claims and drawings may be proved independently or in any appropriate combination.
Number | Date | Country | Kind |
---|---|---|---|
9825102 | Nov 1998 | GB | national |
This is a continuation of International Application PCT/GB99/00788, Filed on Mar. 16, 1999, which claims priority to U.K. Patent Application GB9825102.8, filed on Nov. 16, 1998, now abandoned and all of whose entire disclosures are incorporated by reference herein.
Number | Name | Date | Kind |
---|---|---|---|
4525780 | Bratt et al. | Jun 1985 | A |
4675829 | Clemenson | Jun 1987 | A |
4924408 | Highland | May 1990 | A |
5210876 | Uchida | May 1993 | A |
5301260 | Miyashita | Apr 1994 | A |
5301325 | Benson | Apr 1994 | A |
5339436 | Tairaku et al. | Aug 1994 | A |
5367685 | Gosling | Nov 1994 | A |
5442792 | Chun | Aug 1995 | A |
5450575 | Sites | Sep 1995 | A |
5452457 | Alpert et al. | Sep 1995 | A |
5469574 | Chang et al. | Nov 1995 | A |
5511190 | Sharma et al. | Apr 1996 | A |
5530964 | Alpert et al. | Jun 1996 | A |
5551040 | Blewett | Aug 1996 | A |
5590332 | Baker | Dec 1996 | A |
5598561 | Funaki | Jan 1997 | A |
5603030 | Gray et al. | Feb 1997 | A |
5613120 | Palay et al. | Mar 1997 | A |
5655122 | Wu | Aug 1997 | A |
5675804 | Sidik et al. | Oct 1997 | A |
5721854 | Ebcioglu et al. | Feb 1998 | A |
5761513 | Yellin et al. | Jun 1998 | A |
5764989 | Gustafsson et al. | Jun 1998 | A |
5815720 | Buzbee | Sep 1998 | A |
5835771 | Veldhuizen | Nov 1998 | A |
5848274 | Hamby et al. | Dec 1998 | A |
5857104 | Natarjan et al. | Jan 1999 | A |
5872978 | Hoskins | Feb 1999 | A |
5873104 | Tremblay et al. | Feb 1999 | A |
6041179 | Bacon et al. | Mar 2000 | A |
6079018 | Hardy et al. | Jun 2000 | A |
6189048 | Lim et al. | Feb 2001 | B1 |
6205465 | Schoening et al. | Mar 2001 | B1 |
6301652 | Prosser et al. | Oct 2001 | B1 |
6338133 | Schroter | Jan 2002 | B1 |
6366876 | Looney | Apr 2002 | B1 |
6412105 | Maslennikov et al. | Jun 2002 | B1 |
6513156 | Bak et al. | Jan 2003 | B2 |
6529909 | Bowman-Amuah | Mar 2003 | B1 |
6529948 | Bowman-Amuah | Mar 2003 | B1 |
6539396 | Bowman-Amuah | Mar 2003 | B1 |
6615253 | Bowman-Amuah | Sep 2003 | B1 |
6651248 | Alpern | Nov 2003 | B1 |
6664978 | Kekic et al. | Dec 2003 | B1 |
6704927 | Bak et al. | Mar 2004 | B1 |
Number | Date | Country | |
---|---|---|---|
20020108107 A1 | Aug 2002 | US |
Number | Date | Country | |
---|---|---|---|
Parent | PCTGB99/00788 | Mar 1999 | US |
Child | 09859133 | US |