Method and system provide concurrent access to a software object
A method and system to provide concurrent access to a software object. At least some of the illustrative embodiments may be a method comprising creating an object having a read-write field and read-only field, accessing the read-write field by a first thread, duplicating the read-write field to the read-only field, and then concurrently accessing the read-write field by the first thread and the read-only field by the second thread.
Latest Texas Instruments Incorporated Patents:
This application claims the benefit of European Patent Application No. 04291918.3, filed Jul. 27, 2004, incorporated by reference herein as if reproduced in full below.
BACKGROUND OF THE INVENTION1. Technical Field of the Invention
The present invention relates to processors, and more particularly to processors executing software streams that each accesses a common object.
2. Background Information
Java™ is a programming language that, at the source code level, is similar to object oriented programming languages such as C++. Java™ language source code is compiled into an intermediate representation based on a plurality “bytecodes” that define specific tasks. In some implementations, the bytecodes are further compiled to machine language for a particular processor.
Many high level languages such as Java allow the programmer to dynamically allocate and deallocate memory. Dynamically allocated memory may, however, become unreachable when there is no chain of references to the memory in question from the root object. Unreachable objects that the programmer fails to deallocate may be referred to as “garbage.” To address unreachable memory, some systems implement a automatic reclamation of unreachable memory known as “garbage collection” The garbage collection software runs periodically and traces through the various software objects created by application programs looking for objects that are garbage. The garbage collection program “collects” the garbage objects and returns their memory to the heap for further allocation.
The garbage collection software thus traces through each object, even objects that are in active use by the application programs. Contention as to memory locations is possible as between the application programs and the garbage collection software, thus slowing the application programs. In some cases, the application programs are stopped while garbage collection takes place.
SUMMARYThe problems noted above are solved in large part by a method and system to provide concurrent access to a software object. At least some of the illustrative embodiments may be a method comprising creating an object having a read-write field and read-only field, accessing the read-write field by a first thread, duplicating the read-write field to the read-only field, and then concurrently accessing the read-write field by the first thread and the read-only field by a second thread.
NOTATION AND NOMENCLATURECertain terms are used throughout the following description and claims to refer to particular system components. As one skilled in the art will appreciate, semiconductor companies may refer to a component by different names. This document does not intend to distinguish between components that differ in name but not function. In the following discussion and in the claims, the terms “including” and “comprising” are used in an open-ended fashion, and thus should be interpreted to mean “including, but not limited to . . . ”. Also, the term “couple” or “couples” is intended to mean either an indirect or direct connection. Thus, if a first device couples to a second device, that connection may be through a direct connection, or through an indirect connection via other devices and connections.
BRIEF DESCRIPTION OF THE DRAWINGSFor a more detailed description of the preferred embodiments of the present invention, reference will now be made to the accompanying drawings, wherein:
The following discussion is directed to various embodiments of the invention. Although one or more of these embodiments may be preferred, the embodiments disclosed should not be interpreted, or otherwise used, as limiting the scope of the disclosure, unless otherwise specified. In addition, one skilled in the art will understand that the following description has broad application, and the discussion of any embodiments is meant only to be illustrative of those embodiments, and not intended to intimate that the scope of the disclosure is limited to those embodiments.
Moreover, the various embodiments of the invention were developed in the context of Java programs and their associated garbage collection programs, and so the description is related to that developmental context; however, the methods and systems find applicability outside the Java environment, and so the description should not be construed as a limitation to the breadth of the claims.
Java language source code is converted or compiled to a series of bytecodes 112, with each individual one of the bytecodes referred to as an “opcode.” Bytecodes 112 may be provided to the JVM 108, possibly compiled by compiler 110, and provided to the JSM 102 and/or MPU 104 for execution. In accordance with some embodiments of the invention, the JSM 102 may execute at least some Java bytecodes directly. When appropriate, however, the JVM 108 may also request the MPU 104 to execute one or more Java bytecodes not executed or executable by the JSM 102. In addition to executing compiled Java bytecodes, the MPU 104 also may execute Java garbage collection as well as non-Java instructions. The MPU 104 may thus also host an operating system (“O/S”) (not specifically shown) which performs various functions such as system memory management, system task management that schedules the software aspects of the JVM 108 and most or all other native tasks running on the system, management of the display 114, and receiving input from input devices (not specifically shown). Java code, whether executed on the JSM 102 or MPU 104, may be used to perform any one of a variety of applications such as multimedia, games or web based applications in the system 100, while non-Java code, which may comprise the O/S and other native applications, may still run on the system on the MPU 104.
In accordance with embodiments of the invention, Java or other programs executing on one or both of the JSM 102 and MPU 104 allocate memory, and within the allocated memory create objects. Each object has one or more internal components known as fields.
Still referring to
Although the additional fields may be updated at any suitable frequency, in accordance with at least some embodiments the updating of the additional fields may take place just prior to running programs that need access to the data, such as the garbage collection programs. Thus, the application programs may continue to access the primary fields in a read-write fashion, and the illustrative garbage collection program may perform its task with respect to the additional fields. It is again noted that garbage collection programs are merely illustrative of a family of programs that may need access to shared data, but for which strong consistency of the data is not required. Copying the data from the primary fields the additional fields may also be referred to as fixing a memory view at a particular point in time.
Now further consider that a second memory fix is applied, as illustrated by vertical line 420, and thus the read-write field of each object is copied to the read-only field, as illustrated by lines 422, 424 and 426 for each of the objects 402, 408 and 412 respectively. Also, after the memory fix illustrated by line 420 read-write field of object 402 is modified to have a NULL reference (which as we shall see acts to make objects 408 and 412 unreachable, and therefore garbage). Finally consider that yet another memory fix is run as illustrated by vertical line 428, where again the contents of each objects' read-write field is copied to its read-only field. After each memory fix, a second thread, such as a garbage collection program, may operate on the read-only fields of the objects without interference with a first thread operating on the read-write fields of those same objects, and the fact there is not a strong consistency is immaterial, especially for the illustrative garbage collection process as the second thread
Analyzing
While the various embodiments of the invention have been shown and described, modifications thereof can be made by one skilled in the art without departing from the spirit and teachings of the invention. The embodiments described herein are illustrative only, and are not intended to be limiting. Many variations and modifications of the invention disclosed herein are possible and are within the scope of the invention. Each and every claim is incorporated into the specification as an embodiment of the present invention.
Claims
1. A method comprising:
- creating an object having a read-write field and read-only field;
- accessing the read-write field by a first thread;
- duplicating the read-write field to the read-only field; and then concurrently accessing the read-write field by the first thread and the read-only field by a second thread.
2. The method as defined in claim 1 wherein concurrently accessing further comprises accessing the read-write field of the object by the first thread executed on a first processor, and accessing the read-only field by the second thread executed on a second processor.
3. The method as defined in claim 2 wherein concurrently accessing further comprises accessing the read-write field by an application program, and accessing the read-only field by a garbage collection program.
4. A computer readable medium storing a first program that, when executed by a processor, performs a method comprising:
- creating a software object having a first field and a second field, the first field accessed by a second program;
- periodically stopping execution of the second program and duplicating the first field to the second field; and then
- accessing the second field by the first program simultaneously with accessing of the first field by the second program.
5. The computer readable medium as defined in claim 4 wherein accessing further comprises accessing the second field by the first program executing on a first processor, and accessing the second field by the second program executing on a second processor.
6. The computer readable medium as defined in claim 5 wherein creating further comprises creating the software object in a cache memory accessible to both the first and second processors.
7. The computer readable medium as defined in claim 4 wherein accessing further comprises accessing the second field by the first program being a user program, and accessing the second field by the second program being a program to identify and free unused software objects.
8. A system comprising:
- a first processor;
- a second processor; and
- a memory coupled to the first and second processor;
- wherein the memory is configurable to store a software object; and
- wherein a first process executing on the first processor writes to a first field of the object, and when a second process needs the access the object, the first field is copied to a second field, and thereafter the first and second processes have the capability to access the object simultaneously.
9. The system as defined in claim 9 wherein the first process executed on the first processor is an application program, and the second processes executed on the second processor is configured to identify unused software objects.
10. The system as defined in claim 9 where the memory is a cache memory.
11. The system as defined in claim 9 wherein the first process has read-write access to the first field, and wherein the second process has only read access to the second field.
12. A method comprising:
- operating an application program accessing a plurality of software objects, each software object having a read-write field;
- ceasing operation of the application program; and then
- copying, within each object, the read-write field to a read-only field; and
- accessing a read-write field of a first of the plurality of software objects by the application program, and simultaneously accessing the read-only field of the first of the plurality of software objects by a second program.
13. The method as defined in claim 12 wherein accessing further comprises accessing the read-only field of the first of the plurality of software objects by a program configured to identify unused software objects.
14. The method as defined in claim 12 wherein accessing further comprises accessing by the application program executed on a first processor, and the second program executed on a second processor.
15. The method as defined in claim 12 wherein accessing further comprises accessing by the application program executed as a first thread on a processor, and accessing by the second program as a second thread on the processor.
Type: Application
Filed: Jul 21, 2005
Publication Date: Feb 2, 2006
Applicant: Texas Instruments Incorporated (Dallas, TX)
Inventors: Gilbert Cabillic (Brece), Jean-Philippe Lesot (Etrelles)
Application Number: 11/186,063
International Classification: G06F 7/00 (20060101);