Space- and time-efficient enumerations
Systems, computer instructions and computer-implemented methods are disclosed for implementing space- and time-efficient enumerations. An instance of an enumeration class may be created with a constant, plurality of enumerations. A plurality of objects corresponding to the respective enumerations may be stored in memory along with a lookup table indexed by respective ordinal values of the plurality of enumerations, the lookup table including respective references to the stored objects of the instantiated enumeration class. A reference to an enumeration may be stored in a memory location by storing an ordinal value of the enumeration. A determination may then be made to convert a stored ordinal value to a reference to an object, and responsive to the determination, the ordinal value may be loaded and used as an index into the lookup table to obtain the reference to the object corresponding to the enumeration.
1 . A computer-implemented method of accessing an object by reference, comprising:
obtaining an ordinal value of the object of a plurality of objects of an instantiated class, wherein individual objects, including the object, of the instantiated class respectively comprise a plurality of immutable items, and wherein the instantiated class comprises a plurality of different ordinal values including the ordinal value;
loading a memory address of the object from a location in a lookup table, the location identified using the obtained ordinal value as an index, wherein the memory address is different from the location in the lookup table, and wherein the lookup table comprises a plurality of memory addresses, including the memory address, respectively identified by individual ones of the plurality of different ordinal values; and
accessing one or more of the plurality of immutable items of the object using the loaded memory address.
2 . The computer-implemented method of claim 1 , further comprising storing the reference to the object in a memory location containing a reference to an object type.
3 . The computer-implemented method of claim 1 , wherein accessing the object comprises performing a method lookup for the instantiated class.
4 . The computer-implemented method of claim 1 , wherein accessing the object is performed by one or more external methods via a native interface.
5 . The computer-implemented method of claim 1 , wherein a number of the plurality of different ordinal values is constant, and wherein a size of a memory location storing the ordinal value is less than a size of a memory location storing a reference to the object.
6 . The computer-implemented method of claim 1 , wherein the instantiated class is an enumeration class, wherein individual ones of the plurality of different ordinal values are enumeration values of the enumeration class, and wherein obtaining the ordinal value comprises loading, from a memory location, an enumeration of the enumeration class.
7 . The computer-implemented method of claim 1 , wherein the obtaining and loading are performed by a Java Virtual Machine.
8 . One or more non-transitory computer-accessible storage media storing program instructions that when executed on or across one or more processors cause the one or more processors to perform:
obtaining an ordinal value of the object of a plurality of objects of an instantiated class, wherein individual objects, including the object, of the instantiated class respectively comprise a plurality of immutable items, and wherein the instantiated class comprises a plurality of different ordinal values including the ordinal value
loading a memory address of the object from a location in a lookup table, the location identified using the obtained ordinal value as an index, wherein the memory address is different from the location in the lookup table, and wherein the lookup table comprises a plurality of memory addresses, including the memory address, respectively identified by individual ones of the plurality of different ordinal values; and
accessing one or more of the plurality of immutable data items of the object using the loaded memory address.
9 . The one or more non-transitory computer-accessible storage media of claim 8 , storing additional program instructions that when executed on or across the one or more processors cause the one or more processors to perform:
storing the reference to the object in a memory location containing a reference to an object type.
10 . The one or more non-transitory computer-accessible storage media of claim 8 , wherein accessing the object comprises performing a method lookup for the instantiated class.
11 . The one or more non-transitory computer-accessible storage media of claim 8 , wherein accessing the object is performed by one or more external methods via a native interface.
12 . The one or more non-transitory computer-accessible storage media of claim 8 , wherein a number of the plurality of different ordinal values is constant, and wherein a size of a memory location storing the ordinal value is less than a size of a memory location storing a reference to the object.
13 . The one or more non-transitory computer-accessible storage media of claim 8 , wherein the instantiated class is an enumeration class, wherein individual ones of the plurality of different ordinal values are enumeration values of the enumeration class, and wherein obtaining the ordinal value comprises loading, from a memory location, an enumeration of the enumeration class.
14 . The one or more non-transitory computer-accessible storage media of claim 8 , wherein the obtaining and loading are performed by a Java Virtual Machine.
15 . A system, comprising:
one or more processors and a memory comprising program instructions executable by the one or more processors to implement an application configured to:
obtain an ordinal value of the object of a plurality of objects of an instantiated class, wherein individual objects, including the object, of the instantiated class respectively comprise a plurality of immutable items, and wherein the instantiated class comprises a plurality of different ordinal values including the ordinal value;
load a memory address of the object from a location in a lookup table, the location identified using the obtained ordinal value as an index, wherein the memory address is different from the location in the lookup table, and wherein the lookup table comprises a plurality of memory addresses, including the memory address, respectively identified by individual ones of the plurality of different ordinal values; and
access one or more of the plurality of immutable data items of the object using the loaded memory address.
16 . The system of claim 15 , wherein the application is further configured to store the reference to the object in a memory location containing a reference to an object type.
17 . The system of claim 15 , wherein accessing the object comprises performing a method lookup for the instantiated class.
18 . The system of claim 15 , wherein accessing the object is performed by one or more external methods via a native interface.
19 . The system of claim 15 , wherein the instantiated class is an enumeration class, wherein individual ones of the plurality of different ordinal values are enumeration values of the enumeration class, and wherein obtaining the ordinal value comprises loading, from a memory location, an enumeration of the enumeration class.
20 . The system of claim 15 , wherein the obtaining and loading are performed by a Java Virtual Machine.