Method and apparatus for tracing memory accesses
Abstract
Apparatus, computer-readable storage medium and a method executed by a computer for tracing the memory accesses of an object-oriented program comprises assigning a unique identification to each class object created from at least one class in the object-oriented program by modifying a class definition of the at least one class. In response to an unloading of one of the class objects, obtaining class unloading related information from a runtime environment of the object-oriented program and obtaining the unique identification of the unloaded class object according to the returned information. Then releasing memory space assigned to the unloaded class object for storing the memory access information of the unloaded class object.
Claims
exact text as granted — not AI-modifiedThe invention claimed is:
1. A method executed by a computer for tracing the memory accesses of an object-oriented program, comprising:
assigning a unique identification to each class object created from at least one class in the object-oriented program by modifying a class definition of the at least one class;
in response to an unloading of one of the class objects, obtaining class unloading related information from a runtime environment of the object-oriented program and obtaining the unique identification of the unloaded class object according to the returned information; and
releasing memory space assigned to the unloaded class object for storing the memory access information of the unloaded class object.
2. The method of claim 1 , wherein the assigning a unique identification to each class object further comprises
adding an objectID data member to the definition of the at least one class, and
using an object method to assign a unique value of objectID to each object created from the at least one class.
3. The method of claim 2 , wherein said assigning a unique value of objectID further comprises one of the following methods:
setting the value of objectID as equal to a counter value in the program, wherein said counter value increases along with the class loading;
setting the value of objectID as equal to the loading time of the class;
setting the value of objectID as equal to UUID generated by the system.
4. The method of claim 1 , wherein said obtaining the unique identification of an unloaded class object comprises:
creating a weak reference object corresponding to the unloaded class object before it is unloaded;
setting an objectID of the weak reference object equal to the unique identification of said unloaded class object before it is unloaded;
adding the weak reference object to a reference queue;
calling a remove( )method in the reference queue to request the runtime environment to return the class unloading related information of the class object when the corresponding object class is unloaded and
obtaining the unique identification of the weak reference object returned from the runtime environment, to identify the unloaded class object.
5. The method of claim 1 , wherein said releasing the memory space for storing the memory access information of the unloaded class object further comprises removing the memory access information related to said unloaded class object.
6. An apparatus for tracing memory accesses of an object-oriented program, comprising:
a computer with at least one processor and memory;
a code modifying unit executing in the memory of the computer, the modifying unit being configured to assign a unique identification to each class object created from at least one class in the object-oriented program by modifying a class definition of the at least one class; and
a class unloading tracing unit executing in the memory of the computer, the tracing unit being configured to request class object unloading related information from the runtime environment when one of the class objects is unloaded, obtain the unique identification of the unloaded class object according to the returned information, and release memory space assigned for storing memory access information of the unloaded class object.
7. The apparatus of claim 6 , wherein said code modifying unit is configured to add a data member objectID to said class definition, and to set the objectID in each class object created from the class definition to a unique identification.
8. The apparatus of claim 7 , wherein said code modifying unit is configured to execute one of the following functions:
setting objectID in each class object created from the class definition as equal to a counter value, wherein the counter value is incremented with each creation of a class object;
setting objectID in each class object created from the class definition as equal to the loading time of the class;
setting the value of objectID in each class object created from the class definition as equal to UUID generated by the system.
9. The apparatus of claim 6 , wherein said class unloading tracing unit is configured to:
create a weak reference object corresponding to an unloaded class object before it is unloaded;
set an objectID of the weak reference object equal to the unique identification of said unloaded class object before it is unloaded;
call a remove( ) method in the reference queue to request the runtime environment to return the class unloading related information of the class object when the corresponding object class is unloaded and
obtain the unique identification of the weak reference object returned from the runtime environment to identify the unloaded class object.
10. The apparatus of claim 6 , wherein said class unloading tracing unit is configured to release the memory space for storing the memory access information of the unloaded class object.
11. A non-transitory computer-readable storage medium having program code executed by a computer for tracing the memory accesses of an object-oriented program, comprising:
program code for assigning a unique identification to each class object created from at least one class in the object-oriented program by modifying a class definition of the at least one class;
program code responsive to an unloading of one of the class objects, for obtaining class unloading related information from a runtime environment of the object-oriented program and obtaining the unique identification of the unloaded class object according to the returned information; and
program code for releasing memory space assigned to the unloaded class object for storing the memory access information of the unloaded class object.
12. The computer-readable storage medium of claim 11 , wherein the program code for assigning a unique identification to each class object further comprises
program code for adding an objectID data member to the definition of the at least one class, and
program code for using an object method to assign a unique value of objectID to each object created from the at least one class.
13. The computer-readable storage medium of claim 12 , wherein the program code for assigning a unique value of objectID further comprises one of the followings:
program code for setting the value of objectID as equal to a counter value in the program, wherein said counter value increases along with the class loading;
program code for setting the value of objectID as equal to the loading time of the class;
program code for setting the value of objectID as equal to UUID generated by the system.
14. The computer-readable storage medium of claim 11 , wherein said the program code for obtaining the unique identification of an unloaded class object further comprises:
program code for creating a weak reference object corresponding to the unloaded class object before it is unloaded;
program code for setting an objectID of the weak reference object equal to the unique identification of said unloaded class object before it is unloaded;
program code for adding the weak reference object to a reference queue;
program code for calling a remove( )method in the reference queue to request the runtime environment to return the class unloading related information of the class object when the corresponding object class is unloaded and
program code for obtaining the unique identification of the weak reference object returned from the runtime environment, to identify the unloaded class object.
15. The computer-readable storage medium of claim 11 , wherein the program code for releasing the memory space for storing the memory access information of the unloaded class object further comprises program code for removing the memory access information related to said unloaded class object.Cited by (0)
No later patents cite this yet.
References (0)
No backward citations on record.