Claims
- 1. A computer implemented method for converting a lightweight monitor into a heavy weight monitor when a first thread attempts to execute a synchronous operation on an object associated with the lightweight monitor, the object having an object header containing the lightweight monitor, comprising:
determining ownership of the object; creating a heavyweight monitor when it is determined that the object is owned by a second thread; setting ownership of the heavyweight monitor to the second thread; and entering the heavyweight monitor by the first thread.
- 2. A method as recited in claim 1, wherein the determining ownership further includes:
performing an atomic compare and swap operation between the first thread and the object header; and determining if the compare and swap operation was successful.
- 3. A method as recited in claim 2, wherein when it is determined that the operation was not successful, then determining the contents of the object header.
- 4. A method as recited in claim 3, wherein when it is determined that the object header contains a second thread ID corresponding to the second thread, then creating a new heavyweight monitor, and setting the new heavyweight monitor owner to the second thread.
- 5. A method as recited in claim 4, wherein the setting the new heavyweight monitor owner further includes:
performing an atomic compare and swap operation between the object header and a heavyweight monitor pointer associated with the new heavyweight monitor.
- 6. A method as recited in claim 3, wherein when it is determined that the object header contains a heavyweight monitor pointer, then the first thread entering the heavyweight monitor corresponds to heavyweight pointer contained in the object header.
- 7. A method as recited in claim 3, wherein when it is determined that the object header contains a first thread ID corresponding to the first thread, then determining if incrementing the recursion counter included in the lightweight monitor will cause an overflow condition.
- 8. A method as recited in claim 7, wherein when it is determined that incrementing the recursion counter will not cause the overflow condition, then re-entering the lightweight monitor by the first thread.
- 9. A method as recited in claim 7, wherein when it is determined that incrementing the recursion counter will cause an overflow condition, then converting the lightweight monitor to a corresponding heavyweight monitor.
- 10. A computer program product for converting a lightweight monitor into a heavy weight monitor when a first thread attempts to execute a synchronous operation on an object associated with the lightweight monitor, the object having an object header containing the lightweight monitor, comprising:
computer code that determines ownership of the object; computer code that creates a heavyweight monitor when it is determined that the object is owned by a second thread; computer code that sets ownership of the heavyweight monitor to the second thread; computer code that causes the first thread to enter the heavyweight monitor; and a computer readable medium that stores the computer codes.
- 11. A computer program product according to claim 10 wherein the computer readable medium is a data signal embodied in a carrier wave.
- 12. A computer program product according to claim 10 further including computer code that performs an atomic compare and swap operation between the first thread and the object header and determines if the compare and swap operation was successful.
- 13. A computer program product according to claim 12 wherein when the compare and swap operation was successful, computer code that determines the contents of the object header.
- 14. A computer program product according to claim 13, wherein when it is determined that the object header contains a second thread ID corresponding to the second thread, then computer code that creates a new heavyweight monitor, that sets the new heavyweight monitor owner to the second thread, and that performs an atomic compare and swap operation between the object header and a heavyweight monitor pointer associated with the new heavyweight monitor.
- 15. A computer system including a memory which includes a plurality of threads, each of the plurality of threads, the computer system comprising:
a processor coupled to the memory; and an object including an object header, the object header being arranged to contain a lightweight monitor which includes information relating to the ownership of object, a first thread selected from the plurality of threads that has locked the object as indicated by a first thread ID included in the lightweight monitor; and a second thread selected from the plurality of threads, the second thread being arranged to convert the lightweight monitor to a corresponding heavyweight monitor owned by the first thread when the object is not available to the second thread.
- 16. A computer system as recited in claim 15 wherein the lightweight monitor includes a recursion counter indicative of the number of times the object has been reentered.
- 17. A computer system as recited in claim 16, wherein the object header includes a heavyweight monitor pointer that points to the heavyweight monitor associated with the object.
CROSS-REFERENCE TO A RELATED APPLICATION
[0001] This application is takes priority under 35 U.S.C. §119(e) of U.S. patent application Ser. No 60/111,400 filed Dec. 8, 1998 (Attorney Docket No.: SUN1P206+) naming Hong Zhang et al. as inventor(s) and assigned to the assignee of the present application which is also incorporated herein by reference for all purposes.
Provisional Applications (1)
|
Number |
Date |
Country |
|
60111400 |
Dec 1998 |
US |