Method for implementing multiple type hierarchies

A system and method of unifying data structures is described. Equivalent data structures are combined so that multiple programming languages can recognize the data structure. One embodiment includes a data structure. The data structure includes a pointer to a vtable. The vtable includes at least one pointer. The pointer points to one or more classes and at least one of the classes includes a unified type hierarchy.

FIELD OF THE INVENTION

The present invention relates to computer software programming techniques and more specifically to a method of simplifying software.

BACKGROUND OF THE INVENTION

Many object-oriented computer programming languages share several similar structures and often share equivalent functions or methods. Each object-oriented computer programming language has a hierarchy of data types or objects. The hierarchy of data types includes every data type used in the language. Each data type in each language is a sub-class of the respective language. For example, both Java and C# (C-sharp) languages have similar hierarchical structures in that both have a top-level hierarchy called a class and the top-level class is referred to as an “Object” (i.e. in Java: java.lang.Object and in C#: System.Object).

FIGS. 1 and 1Ashow the similar hierarchical structures of Java and C# respectively. A graphical representation of the hierarchy of data types for a single object-oriented language can be presented as an inverted tree with a “root” object110,150at the top and each sub-class appearing as a branch extending downward from the language object. Additional layers of sub-classes can extend from each sub-class. Each class (and the sub classes that fall below the class) share common characteristics. The characteristics include the type of functions that can be performed in each class or sub-class or sub-sub-class. For examples: inFIG. 1a Java root class110is presented. The Java root class110includes several fields including a Java name111that identifies the object as a Java object. A field identifying the number of methods112and a field with links114to the actual Java methods120,130. Each Java method120,130also includes a Java name121,131and an implementation of the actual method123,133including the actual code of the respective Java method120,130.

Similarly,FIG. 1Ashows a C# root object150. The C# root object150includes several fields including a C# name151that identifies the object as a C# object. A field identifying the number of methods152and a field with links154to the actual C# methods160,170. Each C# method160,170also includes a C# name161,171and an implementation of the actual method163,173including the actual code of the respective C# method160,170.

As object-oriented programming languages all serve similar goals: i.e. modularized programming, then inevitably many similar and often identical data types, methods and sub-classes of objects are found in the various object-oriented programming languages. However, often certain languages include unique classes or methods that are not easily implemented in another language. For example, Java may more easily allow a function that C# does not allow easily.

DETAILED DESCRIPTION

A system and method of unifying data structures is described. Equivalent data structures are combined so that multiple programming languages can recognize the data structure. One embodiment includes a data structure. The data structure includes a pointer to a vtable. The vtable includes at least one pointer. The pointer points to one or more classes and at least one of the classes includes a unified type hierarchy.

Often several different hierarchical programming languages are used to develop a particular software application. Multiple languages are often used because an implementation of a particular class or method is more easily allowed or available in one programming language than in another programming language. For example a method may be available in Java that a C# programmer wishes to use. Conversely, a programmer may be updating a previously written Java program to include a new method that is implemented in C# or another hierarchical language.

As will be described in more detail below, Java and C# are used as merely examples to illustrate the various embodiments. Other object-oriented languages such as C++, Smalltalk, and Eiffel, and others could also be used similar to how Java and C# are described herein. In addition, while the various embodiments are described using only two object-oriented languages, more than two object-oriented languages could also be used and still be within the scope of the described embodiments.

FIG. 1Bshows one embodiment of a Java object185that has been added to a C# program. A C# object175is the root object which identifies the program as a C# program. The C# root object includes many fields such as a C# name176, a number of methods177, and links to or implementations of the methods178. Two methods179,181are linked to the C# root object175. Of course one skilled in the art would recognize that many more methods could also be linked to the C# root object175. The first method179is a C# method entitled ToString, or more properly “System.Object.ToString”, but truncated to “ToString” for ease of discussion. ToString is a C# method of converting input data to a string. The first method179also includes an implementation180(or a link thereto) of the actual software code for performing the ToString method.

The second method181is entitled GetHash and is a C# method of hashing input data. GetHash is a truncated reference to the C# method “System.Object.GetHash”. The GetHash method also includes an implementation182(or a link thereto) of the actual software code for performing the GetHash method.

A Java class object185includes a Java header “Java.lang.object” that identifies the class185as a Java class object. The Java class object185also includes a “super class”193which points to or links to the C# root object175. The Java class object185also includes a third and a fourth method189,191. The third method189entitled “toString”, is a Java method of converting the input data to a string. toString is a truncated reference to the Java method “java.lang.Object.toString”. The toString method189also includes an implementation190(or a link thereto) of the actual software code for performing the toString method. The fourth method191entitled “hashCode,” is a Java method of hashing the input data. hashCode is a truncated reference to the Java method “java.lang.Object.hashCode”. The hashCode method191also includes an implementation192(or a link thereto) of the actual software code for performing the hashCode method.

As often happens, the C# GetHash method181and the Java hashCode method191have exactly identical implementations in that the actual software codes182,192, respectively, for performing the GetHash181and hashCode191methods are identical. However, the implementations of the Java tostring method189and the C# ToString method179are similar but not identical. In the example shown inFIG. 1Bit is likely that the programmer desired to include the precise functionality of the Java toStringe method189into a C# program.

However, this embodiment also illustrates how duplicated software code for the Java hashCode method192and the C# GetHash method182can be included. Duplicate software code can cause excess complication and poor utilization of the memory of the computer that ultimately runs the software. Excess complication and poor utilization of the memory can cause the software to be less robust and more prone to causing a computer to crash. In addition, more complicated software is more difficult to maintain, i.e. update, modify, etc.

Another embodiment includes a shared or unified data structure system where the data type hierarchies from two or more languages are implemented in a a single, unified data type hierarchy. In one embodiment, all objects are subclasses of the same class, Unified Object. The Unified Object will appear to be of type java.lang.Object to Java code and System.Object to C# code.

FIG. 2illustrates one embodiment of a unified data structure or object202. The unified object202also includes a vtable203for virtual method dispatch and type identification. In one embodiment, a hidden field with a vtable pointer is included in every object. The vtable203contains a pointer to the structure representing the class204information and pointers to implementations of all instance methods261,262,263that may be invoked through the virtual dispatch mechanism. In an alternative embodiment, the structure representing the class204may also be directly included in the vtable203.

The class data structure220of one embodiment includes a pointer to the Java name of the class221, a pointer to the C# name of the class222, and a pointer to the array of method pointers224. A different name is needed for each language used. As shown, Java and C# names are included so that, from the point of view of Java programs, the same unified class is called java.lang.Object and from the point of view of the C# programs, the unified class is called System.Object. The class data structure can also include other fields.

Also as shown inFIG. 2, the array of method pointers224includes three methods230,240,250. A first pointer points to the data structure for the hashCode method230. This method is available from Java under the name of java.lang.Object.hashCode and from C# under the name System.Object.GetHash. Because both names are available for reflection the method is a Java-and-C# method and includes both Java (java.lang.Object.hashCode)231and C# (System.Object.GetHash)232names in the respective fields. The hashCode method230can also include a pointer to a hashCode method implementation261. A second method240is the toString. The toString method240is available from Java only (i.e. a Java-only method), so the toString method's Java name (java.lang.Object.toString) field241points to the name toString. Conversely, because there is no C# equivalent of the toString method, the C# field242is null (i.e. empty). Because the C# name field is null, then the reflection library will automatically recognize that the toString method should not be shown to C# methods. The toString method240can also include a pointer to a toString method implementation262. The third method250is ToString method. The ToString method is a C# method only i.e. a C#-only method, therefore the C# name (System.Object.ToString) field252points to the name ToString and the Java name field251is null. Because the Java name field251is null, the Java reflection library will not show this method. The ToString method250can also include a pointer to a ToString method implementation263. For efficiency, other methods of marking Java-only, C#-only and Java-and-C# methods can also be used.

In alternative embodiments, an approach similar to that described above for methods can also be used for fields such that the object can contain Java-only, C#-only and Java-and-C# fields. The characteristics of the fields, including the Java and C# names of the fields, are described in a field data structures. The class data structure contains a field that stores the number of fields defined in that the class and another field that points to an array of pointers to field structures.

FIG. 3shows a process300of identifying equivalent data structures. First, in block305, several data structures are received. Each one of the data structures is from a different programming language. Next, the data structures are compared in block310and at least two data structures that have identical implementations are identified in block315. In one embodiment, the data structures with identical implementations are unified to create a unified data structure in block320. The unified data structure includes one implementation of the identified data structures and the names of the identified data structures that correspond to the respective programming languages. The unified data structure can also include additional data structures that do not have equivalents such as the toString240and ToString250methods shown inFIG. 2above, in one embodiment, the data structures that do not have equivalents will include a name from each of the programming languages and those programming languages that do not include an equivalent, can have a null name as described above inFIG. 2.

FIG. 4illustrates a high-level block diagram of a computer system representative of any computer such as a personal computer (PC) or a server or other type of computer system. As shown, the computer system includes a processor402, ROM404, RAM406, and a mass storage device410each connected to a bus system408. The bus system408may include one or more buses connected to each other through various bridges, controllers and/or adapters, such as are well known in the art. For example, the bus system408may include a “system bus” that is connected through an adapter to one or more expansion buses, such as a Peripheral Component Interconnect (PCI) bus. Also coupled to the bus system408are a network interface412, and a number (N) of input/output (I/O) devices416-1through416-N.

I/O devices416-1through416-N may include, for example, a keyboard, a pointing device, a display device and/or other conventional I/O devices. Mass storage device410may include any suitable device for storing large volumes of data, such as a magnetic disk or tape, magneto-optical (MO) storage device, or any of various types of Digital Versatile Disk (DVD) or Compact Disk (CD) based storage.

Network interface412provides data communication between the computer system and other computer systems such as on a network. Hence, network interface412maybe any device suitable for or enabling the computer system400to communicate data with a remote processing system over a data communication link, such as a conventional telephone modem, an Integrated Services Digital Network (ISDN) adapter, a Digital Subscriber Line (DSL) adapter, a cable modem, a satellite transceiver, an Ethernet adapter, or the like.

Of course, many variations upon the architecture shown inFIG. 4can be made to suit the particular needs of a given system. Thus, certain components may be added to the components shown inFIG. 4for given system, or certain components shown inFIG. 4may be omitted from the given system.

It will be further appreciated that the instructions represented by the blocks inFIG. 3is not required to be performed in the order illustrated, and that all the processing represented by the blocks may not be necessary to practice the invention.

One skilled in the art will immediately appreciate that the invention can be practiced with other computer system configurations, including multiprocessor systems, minicomputers, mainframe computers, and the like. The invention can also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network.