Measuring the Memory Usage of Java Programs

Saved in:
Bibliographic Details
Title: Measuring the Memory Usage of Java Programs
Document Number: 20220107825
Publication Date: April 7, 2022
Appl. No: 16/482244
Application Filed: July 11, 2019
Abstract: Techniques for measuring the memory usage of Java programs are provided. In one set of embodiments, a Java agent can detect that a Java Virtual Machine (JVM) is loading a Java class used by a Java program. The Java agent can further determine a class name of the Java class and determine that the class name matches an entry in a first list included in a user-defined configuration file. The Java agent can then dynamically insert bytecode into a constructor of the Java class, where the inserted bytecode includes logic for registering a memory reference to an object created via the constructor.
Claim: 1. A method comprising: detecting, by a Java agent, that a Java Virtual Machine (JVM) is loading a Java class used by a Java program; determining, by, the Java agent, a class name of the Java class; determining, by the Java agent, that the class name matches an entry in a first list included in a user-defined configuration file, and in response to determining that the class name matches the entry, dynamically inserting, by the Java agent, bytecode into a constructor of the Java class, the inserted bytecode including logic for registering a memory reference to an object created via the constructor.
Claim: 2. The method of claim 1 wherein the first list is a list identifying Java classes of the Java program that are targets for memory measurement.
Claim: 3. The method of claim 1 wherein the entry in the first list identifies the class name and one or more fields of the Java class,
Claim: 4. The method of claim 1 further comprising, at a time memory measurement of the Java program is requested: executing a measurement function with the memory reference to the object as an input parameter; receiving a measured size of the object as output from the measurement function; and outputting the measured size to one or more predefined storage locations.
Claim: 5. The method of claim 4 wherein executing the measurement function comprises; initializing an object size variable to zero; determining, via the memory reference, whether the Java class of the object matches an entry in a second list included in the user-defined configuration file; and if the Java class of the object does match the entry in the second list, returning a value of the object size variable.
Claim: 6. The method of claim 5 wherein the second list is a list identifying Java classes of the Java program that should be excluded from memory measurement.
Claim: 7. The method of claim 5 wherein if the Java class of the object does not match the entry in the second list, executing the measurement function further comprises: for each field of the object: determining whether the field is a primitive data type or a reference to a sub-object of the object; if the field is a primitive data type, incrementing the object size variable by a size of the primitive data type; and if the field is a reference to a sub-object, recursively executing the measurement function with the reference to the sub-object as an input parameter.
Claim: 8. A non-transitory computer readable storage medium having stored thereon program code executable by a Java agent running on a computer system, the program code embodying a method comprising: detecting that a Java Virtual Machine (JVM) is loading a Java class used by a Java program; determining a class name of the Java class; determining that the class name matches an entry in a first list included in a user-defined configuration file; and in response to determining that the class name matches the entry, dynamically inserting bytecode into a constructor of the Java class, the inserted bytecode including logic for registering a memory reference to an object created via the constructor.
Claim: 9. The non-transitory computer readable storage medium of claim 8 wherein the first list is a list identifying Java classes of the Java program that are targets for memory measurement.
Claim: 10. The non-transitory computer readable storage medium of claim 8 wherein the entry in the first list identifies the class name and one or more fields of the Java class.
Claim: 11. The non-transitory computer readable storage medium of claim 8 wherein the method further comprises, at a time memory measurement of the Java program is requested: executing a measurement function with the memory reference to the object as an input parameter; receiving a measured size of the object as output from the measurement function; and outputting the measured size to one or more predefined storage locations.
Claim: 12. The non-transitory computer readable storage medium of claim 11 wherein executing the measurement function comprises; initializing an object size variable to zero; determining, via the memory reference, whether the Java class of the object matches an entry in a second list included in the user-defined configuration file; and if the Java class of the object does match the entry in the second list, returning a value of the object size variable.
Claim: 13. The non-transitory computer readable storage medium of claim 12 wherein the second list is a list identifying Java classes of the Java program that should be excluded from memory measurement.
Claim: 14. The non-transitory computer readable storage medium of claim 12 wherein if the Java class of the object does not match the entry in the second list, executing the measurement function further comprises: for each field of the object: determining whether the field is a primitive data type or a reference to a sub-object of the object; if the field is a primitive data type, incrementing the object size variable by a size of the primitive data type; and if the field is a reference to a sub-object, recursively executing the measurement function with the reference to the sub-object as an input parameter.
Claim: 15. A computer system comprising: a processor; and a non-transitory computer readable medium having stored thereon program code that, when run, causes the processor to: detect that a Java Virtual Machine (JVM) is loading a Java class used by a Java program; determine a class name of the Java class; determine that the class name matches an entry in a first list included in a user-defined configuration file; and in response to determining that the class name matches the entry, dynamically insert bytecode into a constructor of the Java class, the inserted bytecode including logic for registering a memory reference to an object created via the constructor.
Claim: 16. The computer system of claim 15 wherein the first list is a list identifying Java classes of the Java program that are targets for memory measurement.
Claim: 17. The computer system of claim 15 wherein the entry in the first list identifies the class name and one or more fields of the Java class.
Claim: 18. The computer system of claim 15 wherein the program code further causes the processor to, at a time memory measurement of the Java program is requested: execute a measurement function with the memory reference to the object as an input parameter; receive a measured size of the object as output from the measurement function; and output the measured size to one or more predefined storage locations.
Claim: 19. The computer system of claim 18 wherein executing the measurement function comprises: initializing an object size variable to zero; determining, via the memory reference, whether the Java class of the object matches an entry in a second list included in the user-defined configuration file; and if the Java class of the object does match the entry in the second list, returning a value of the object size variable.
Claim: 20. The computer system of claim 19 wherein the second list is a list identifying Java classes of the Java program that should be excluded from memory measurement.
Claim: 21. The computer system of claim 19 wherein if the Java class of the object does not match the entry in the second list, executing the measurement function further comprises: for each field of the object: determining whether the field is a primitive data type or a reference to a sub-object of the object; if the field is a primitive data type, incrementing the object size variable by a size of the primitive data type; and if the field is a reference to a sub-object, recursively executing the measurement function with the reference to the sub-object as an input parameter.
Current International Class: 06; 06
Accession Number: edspap.20220107825
Database: USPTO Patent Applications
Description
Abstract:Techniques for measuring the memory usage of Java programs are provided. In one set of embodiments, a Java agent can detect that a Java Virtual Machine (JVM) is loading a Java class used by a Java program. The Java agent can further determine a class name of the Java class and determine that the class name matches an entry in a first list included in a user-defined configuration file. The Java agent can then dynamically insert bytecode into a constructor of the Java class, where the inserted bytecode includes logic for registering a memory reference to an object created via the constructor.