# Patent

## Title
Representation of objects in a Java programming environment

## Abstract

Improved techniques for representation of objects in a JavaTM programming environment are disclosed. The techniques are highly suitable for representation of JavaTM objects inside virtual machines, especially those that operate with limited resources (e.g., embedded systems). In accordance with one embodiment, a JavaTM object representation is disclosed. As will be appreciated, the JavaTM object representation provides a reference that can be used to directly access the internal class representation associated with the object. The internal class representation provides information regarding the JavaTM object (e.g., object size, object type, static fields, etc.) As a result, information regarding JavaTM objects can quickly be accessed. This means that the processing time conventionally needed to access information regarding JavaTM objects is reduced. Thus, performance of virtual machines, especially in systems with limited computing power and/or memory, can be enhanced.

## Background
BACKGROUND OF THE INVENTION
The present invention relates generally to object-based high level programming environments, and more particularly, to techniques suitable for representation of objects in a JavaTM programming environment.
One of the goals of high level languages is to provide a portable programming environment such that the computer programs may easily be ported to another computer platform. High level languages such as “C” provide a level of abstraction from the underlying computer architecture and their success is well evidenced from the fact that most computer applications are now written in a high level language.
Portability has been taken to new heights with the advent of the World Wide Web (“the Web”) which is an interface protocol for the Internet which allows communication between diverse computer platforms through a graphical interface. Computers communicating over the Web are able to download and execute small applications called applets. Given that applets may be executed on a diverse assortment of computer platforms, the applets are typically executed by a JavaTM virtual machine.
Recently, the JavaTM programming environment has become quite popular. The JavaTM programming language is a language that is designed to be portable enough to be executed on a wide range of computers ranging from small devices (e.g., pagers, cell phones and smart cards) up to supercomputers. Computer programs written in the JavaTM programming language (and other languages) may be compiled into JavaTM Bytecode instructions that are suitable for execution by a JavaTM virtual machine implementation. The JavaTM virtual machine is commonly implemented in software by means of an interpreter for the JavaTM virtual machine instruction set but, in general, may be software, hardware, or both. A particular JavaTM virtual machine implementation and corresponding support libraries together constitute a JavaTM runtime environment.
Computer programs in the JavaTM programming language are arranged in one or more classes or interfaces (referred to herein jointly as classes or class files). Such programs are generally platform, i.e., hardware and operating system, independent. As such, these computer programs may be executed without modification on any computer that is able to run an implementation of the JavaTM runtime environment.
Object-oriented classes written in the JavaTM programming language are compiled to a particular binary format called the “class file format.” The class file includes various components associated with a single class. These components can be, for example, methods and/or interfaces associated with the class. In addition, the class file format can include a significant amount of ancillary information that is associated with the class. The class file format (as well as the general operation of the JavaTM virtual machine) is described in some detail in The Java Virtual Machine Specification, Second Edition, by Tim Lindholm and Frank Yellin, which is hereby incorporated herein by reference.
FIG. 1A shows a progression of a simple piece of a JavaTM source code 101 through execution by an interpreter, the JavaTM virtual machine. The JavaTM source code 101 includes the classic Hello World program written in JavaTM. The source code is then input into a Bytecode compiler 103 that compiles the source code into Bytecodes. The Bytecodes are virtual machine instructions as they will be executed by a software emulated computer. Typically, virtual machine instructions are generic (i.e., not designed for any specific microprocessor or computer architecture) but this is not required. The Bytecode compiler outputs a JavaTM class file 105 that includes the Bytecodes for the JavaTM program. The JavaTM class file is input into a JavaTM virtual machine 107. The JavaTM virtual machine is an interpreter that decodes and executes the Bytecodes in the JavaTM class file. The JavaTM virtual machine is an interpreter, but is commonly referred to as a virtual machine as it emulates a microprocessor or computer architecture in software (e.g., the microprocessor or computer architecture may not exist in hardware).
FIG. 1B illustrates a simplified class file 100. As shown in FIG. 1B, the class file 100 includes a constant pool 102 portion, interfaces portion 104, fields portion 106, methods portion 108, and attributes portion 110. The attributes (or attributes table) 110 portion represents the attributes associated with the class file 100. This allows for one or more attributes to be defined, each of which can be associated with one or more components of the class file. As is known to those skilled in the art, the JavaTM virtual machine implementations are allowed to define and use various attributes. In addition, the virtual machine's implementations ignore attributes that they do not recognize. Thus, a class file may contain one or more attributes, all or none of which may be recognized by a particular virtual machine implementation.
Conventionally, JavaTM objects are represented in memory so that the methods associated with the objects can be referenced from the object representation. Typically, there is a reference from the JavaTM object representation directly to a method table that includes the methods associated with the object. Although the direct reference to the method table allows, method invocations to be performed, the conventional object representation in JavaTM requires some processing to find information about the object (e.g., object type, object size, static fields, etc.) Such information about the JavaTM object can be stored in the internal class representation of the object. In other words, the virtual machine typically internally represents and stores the information associated with the JavaTM object's class. However, accessing this information takes up valuable processing time. This can seriously hinder performance of virtual machines, especially in systems with limited computing power and/or memory.
In view of the foregoing, improved techniques for representation of objects in JavaTM programming environments are needed.
SUMMARY OF THE INVENTION
Broadly speaking, the present invention relates to techniques for representation of objects in a JavaTM programming environment. The techniques are highly suitable for representation of JavaTM objects inside virtual machines, especially those that operate with limited resources (e.g., embedded systems). In accordance with one aspect of the invention, a JavaTM object representation is disclosed. As will be appreciated, the JavaTM object representation provides a reference that can be used to directly access the internal class representation associated with the object. The internal class representation provides information regarding the JavaTM object (e.g., object size, object type, static fields, etc.) As a result, the invention allows quick access to information regarding JavaTM objects. This means that the processing time conventionally needed to access information regarding JavaTM objects is reduced. Thus, the invention can enhance performance of virtual machines, especially in systems with limited computing power and/or memory.
The invention can be implemented in numerous ways, including as a method, an apparatus, a computer readable medium, and a database system. Several embodiments of the invention are discussed below.
As a JavaTM object representation suitable for use by a JavaTM virtual machine, one embodiment of the invention includes a first reference to an internal class representation of the JavaTM object, a second reference to instance fields associated with the JavaTM object. The first reference is a direct reference to the internal class representation of the JavaTM object.
As a method for representing a JavaTM object in a virtual machine, one embodiment of the invention includes the acts of: allocating a first reference in a memory portion of the virtual machine, wherein the first reference is a reference to an internal class representation of the JavaTM object; and allocating a second reference in a memory portion of the virtual machine, wherein the second reference is a reference to instance fields associated with the JavaTM object; and wherein the first reference is a direct reference to the internal class representation of the JavaTM object.
As a method of accessing information regarding a JavaTM object, one embodiment of the invention includes the acts of identifying an object representation associated with the JavaTM object; using a first reference in the object representation to locate an appropriate internal class representation associated with the JavaTM object; accessing information regarding the JavaTM object from the internal class representation; and wherein the object is represented in a JavaTM virtual machine.
As a computer readable media including computer program code for a JavaTM object representation suitable for use by a JavaTM virtual machine, one embodiment of the invention includes computer program code for a first reference to an internal class representation of the JavaTM object; computer program code for a second reference to instance fields associated with the JavaTM object. The first reference is a direct reference to the internal class representation of the JavaTM object.
These and other aspects and advantages of the present invention will become more apparent when the detailed description below is read in conjunction with the accompanying drawings.



BRIEF DESCRIPTION OF THE DRAWINGS
The present invention will be readily understood by the following detailed description in conjunction with the accompanying drawings, wherein like reference numerals designate like structural elements, and in which:
FIG. 1A shows a progression of a simple piece of a JavaTM source code through execution by an interpreter, the JavaTM virtual machine.
FIG. 1B illustrates a simplified class file.
FIG. 2 represents a JavaTM computing environment including a JavaTM object representation in accordance with one embodiment of the invention.
FIG. 3 illustrates a method for representing JavaTM objects in a JavaTM computing environment.
FIG. 4 illustrates a method for accessing information regarding a JavaTM object using an object representation, in accordance with one embodiment of the invention.



DETAILED DESCRIPTION OF THE INVENTION
As noted in the background, typically, the virtual machines internally represent and store the information associated with the JavaTM object's class. However, accessing this information using conventional techniques takes up valuable processing time. This can seriously hinder performance of virtual machines, especially in systems with limited computing power and/or memory.
The present invention pertains to techniques for representation of objects in a JavaTM programming environment. The techniques are highly suitable for representation of JavaTM objects inside virtual machines, especially those that operate with limited resources (e.g., embedded systems). In accordance with one aspect of the invention, a JavaTM object representation is disclosed. As will be appreciated, the JavaTM object representation provides a reference that can be used to directly access the internal class representation associated with the object. The internal class representation provides information regarding the JavaTM object (e.g., object size, object type, static fields, etc.) As a result, the invention allows quick access to information regarding JavaTM objects. This means that the processing time conventionally needed to access information regarding JavaTM objects is reduced. Thus, the invention can enhance performance of virtual machines, especially in systems with limited computing power and/or memory.
Embodiments of the invention are discussed below with reference to FIGS. 2–4. However, those skilled in the art will readily appreciate that the detailed description given herein with respect to these figures is for explanatory purposes only as the invention extends beyond these limited embodiments.
FIG. 2 represents a JavaTM computing environment including a JavaTM object representation 200 in accordance with one embodiment of the invention. The object representation 200 is suitable for representation of a JavaTM object in a virtual machine. As shown in FIG. 2, the object representation 200 includes a first reference 202 to an internal class representation 204. The internal class representation 204 provides information regarding the JavaTM object. This information can include, for example, a method table 206 and a field descriptor table 208, as well as other information relating to the JavaTM object. In the described embodiment, the method table 210 immediately follows a header 209 which is of a predetermined size.
As will be appreciated, the first reference 202 can be used to directly access the internal class representation 204 so that information regarding the JavaTM object can be accessed quickly. As a result, information regarding objects can be accessed more quickly than conventional techniques which require more processing to find this information.
In addition, the object representation 200 includes a second reference 210 to instance fields associated with the JavaTM object. These instance fields can be unique for each object and can, for example, include instance variables associated with the JavaTM object. Instance fields in the context of the JavaTM programming language are well known to those skilled in the art.
It should be noted that the internal object representation 200 may include an identifier that uniquely identifies the JavaTM object. As will be appreciated by those skilled in the art, the identifier can be a hash key. In one embodiment, the address of the first reference 202 is used as the hash key. It should also be noted that the first and second references 202 and 210 represent two consecutive memory addresses. As such, each of the first and second references 202 and 210 can be four consecutive bytes (one word) in a memory portion of the virtual machine.
FIG. 3 illustrates a method 300 for representing JavaTM objects in a JavaTM computing environment. Method 300 can be used by a JavaTM virtual machine to represent JavaTM objects. Initially, at operation 302, two consecutive words is allocated in memory. Four consecutive bytes can be allocated for each word which can be used to represent a reference (e.g., a pointer to another memory location). Next, at operation 304, the first reference (i.e., first word) is set to the location of an internal class representation for the class which the JavaTM object belongs to. Thereafter, at operation 306, the second reference is set to the location of the instance fields associated with the JavaTM object. Finally, at operation 308, the address of the first reference is stored. As will be appreciated, this address can be used as a hash key to identify and/or locate the representation of the JavaTM object.
FIG. 4 illustrates a method 400 for accessing information regarding a JavaTM object using an object representation, in accordance with one embodiment of the invention. The method 400 can be used by a virtual machine to access information regarding the JavaTM object. Initially, at operation 402, the appropriate hash key is used to locate the representation of the JavaTM object. Next, at operation 404, the first reference of the JavaTM object representation is used to locate the appropriate internal class representation for the JavaTM object. Thereafter, at operation 406, a determination is made as to whether a method associated with the object needs to be invoked. If it is determined at operation 406 that a method associated with the object needs to be invoked, the method 400 proceeds to operation 408 where the header associated with the internal class representation is skipped. Accordingly, the method table that follows the header is accessed at operation 410 to invoke the appropriate method. The method 400 ends following operation 410. However, if it is determined at operation 406 that a method associated with the object does not need to be invoked, the method 400 proceeds to operation 412 where the information regarding the JavaTM object can be accessed from appropriate entries in the internal class representation.
The many features and advantages of the present invention are apparent from the written description, and thus, it is intended by the appended claims to cover all such features and advantages of the invention. Further, since numerous modifications and changes will readily occur to those skilled in the art, it is not desired to limit the invention to the exact construction and operation as illustrated and described. Hence, all suitable modifications and equivalents may be resorted to as falling within the scope of the invention.

## Claims

1. A computer readable medium stored in a computer system including computer program code for representing an object of an object-based programming environment as an object representation inside a virtual machine, wherein said object representation is suitable for use by said virtual machine, said object representation comprising a first reference, a second reference, and a hash key, and said computer readable medium comprising:
computer program code for allocating said first reference to an internal class representation inside said virtual machine, wherein said internal class representation is a representation inside said virtual machine for a class (or class file) of said object of said object-based programming environment, wherein said internal class representation describes one or more methods associated with said object and wherein said first reference is used to invoke said one or more methods;
computer program code for allocating said second reference to instance fields of said object which is represented by said object representation inside said virtual machine, wherein said second reference is used to access one or more instance fields of said object at runtime;
computer program code for storing a hash key that is used to identify the object, wherein said hash key is the memory address of said first reference;
wherein said second reference is a reference to an array of references that references each of said instance fields of said object, wherein each reference in said array of references is a reference to an instance field of said object, and wherein each of said instance fields is accessed by indexing said array of references; and
wherein said internal class representation includes a header of a predetermined size, and wherein a method table associated with said object is allocated immediately after said header.

2. A method for representing an object of an object-based programming environment in a virtual machine as an object representation that comprises a first and a second reference, said method comprising:
allocating said first reference in a memory portion of said virtual machine, wherein said first reference is a reference to an internal class representation of said object, wherein said internal class representation is a representation inside said virtual machine of a class (or class file) associated with said object of said object-based programming environment, wherein said internal class representation includes a method table that describes one or more methods associated with said object, wherein said first reference is a direct reference to said internal class representation, and wherein said first reference is used to invoke said one or more methods;
allocating said second reference in a memory portion of said virtual machine, wherein said second reference is a reference to instance fields of said object, and wherein said second reference is used to access one or more instance fields of said object at runtime, wherein said second reference is a reference to an array of references that references each of said instance fields of said object, wherein each reference in said array of references is a reference to an instance field associated with said object, and wherein each of said instance fields is accessed by indexing said array of references.

3. A method as recited in claim 2, wherein said first reference is allocated as four bytes.

4. A method as recited in claim 2, wherein said second reference is allocated as four bytes.

5. A method as recited in claim 2,
wherein said internal class representation includes a header of a predetermined size, and
wherein a method table associated with said object is allocated immediately after said header.

6. A method as recited in claim 2, wherein object representation further comprises:
storing a hash key that represents the object.

7. A method as recited in claim 2, wherein said hash key is the memory address of said first reference.

8. A method of accessing information associated with an object of an object-based programming environment which has been represented in an internal object representation inside a virtual machine, said method comprising:
identifying an internal object representation for said object inside said virtual machine, wherein said internal object representation includes a first reference and a second reference;
determining whether to invoke a method associated with said object or access an instance field associated with said object;
using said first reference in said internal object representation to locate an appropriate internal class representation inside said virtual machine when said determining determines to invoke said method, wherein said internal class representation is a representation inside said virtual machine of a class (or class file) associated with said object of said object-based computing environment, and wherein said internal class representation includes a method table which is used to invoke one or more methods associated with said object; and
using said second reference in said internal object representation to locate one or more instance fields of said object when said determining determines to access said instance field, wherein said second reference is used to directly access said one or more instance fields of said object, wherein said second reference is a reference to an array of references that references each of said instance fields of said object, wherein each reference In said array of references is a reference to an instance field associated with said object, and wherein each of said instance fields is accessed by indexing said array of references.

9. A method as recited in claim 8, wherein said method further comprises:
wherein said internal class representation includes a header of a predetermined size;
wherein a method table associated with said object is allocated immediately after said header; and
skipping said header of said internal class representation to access a method table associated with said object.

10. A method as recited in claim 8, wherein said information regarding said object further includes a field descriptor table.

11. An apparatus, comprising: at least one processor which can receives computer program code for a virtual machine, wherein said virtual machine is capable of:
identifying an internal object representation for an object of an object-based programming environment inside said virtual machine, wherein sad internal object representation includes a first reference and a second reference;
determining whether to invoke a method associated with said object or access an instance field associated with said object;
using said first reference in said internal object representation to locate an appropriate internal class representation inside said virtual machine when said determining determines to invoke said method, wherein said internal class representation is a representation inside said virtual machine of a class (or class file) associated with said object of said object-based programming environment, and wherein said internal class representation includes a method table which is used to locate one or more methods associated with said object; and
using said second reference in said internal object representation to locate one or more instance fields of said object when said determining determines to access said instance field, wherein said second reference is used to directly access said one or more instance fields of said object, wherein said second reference is a reference to an array of references that references each of said instance fields of said object, and wherein each of said instance fields is accessed by indexing said array of references.

12. A virtual machine as recited in claim 11,
wherein said internal class representation includes a header of a predetermined size, and
wherein a method table associated with said object is allocated immediately after said header.