{"id":15135720,"url":"https://github.com/jetbrains/debugger-memory-agent","last_synced_at":"2025-10-19T15:32:13.671Z","repository":{"id":39381508,"uuid":"138988838","full_name":"JetBrains/debugger-memory-agent","owner":"JetBrains","description":null,"archived":false,"fork":false,"pushed_at":"2024-11-04T11:12:45.000Z","size":510,"stargazers_count":24,"open_issues_count":10,"forks_count":10,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-01-30T02:03:35.836Z","etag":null,"topics":["intellij","java-agent","jvm","memory","profiling"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JetBrains.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-28T08:23:52.000Z","updated_at":"2025-01-18T00:16:57.000Z","dependencies_parsed_at":"2024-07-16T21:19:14.827Z","dependency_job_id":"2cc4fbc2-9af4-4346-872b-da1afe50a016","html_url":"https://github.com/JetBrains/debugger-memory-agent","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JetBrains%2Fdebugger-memory-agent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JetBrains%2Fdebugger-memory-agent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JetBrains%2Fdebugger-memory-agent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JetBrains%2Fdebugger-memory-agent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JetBrains","download_url":"https://codeload.github.com/JetBrains/debugger-memory-agent/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237163036,"owners_count":19265201,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["intellij","java-agent","jvm","memory","profiling"],"created_at":"2024-09-26T06:01:16.512Z","updated_at":"2025-10-19T15:32:08.206Z","avatar_url":"https://github.com/JetBrains.png","language":"C++","readme":"[![JetBrains team project](http://jb.gg/badges/team.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub)\n[![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](https://www.apache.org/licenses/LICENSE-2.0)\n\n# Memory agent\nThis is a native [JVMTI](https://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html) agent for a JVM, which is currently used in the [IDEA debugger](https://www.jetbrains.com/help/idea/analyze-objects-in-the-jvm-heap.html#45c4d5cd) to perform basic heap diagnostic during the debug process. It can also be used in any project, that is running on a JVM, to attach allocation sampling listeners for [low-overhead heap profiling](https://openjdk.java.net/jeps/331) and to collect information about the heap, such as retained sizes, object reachability, and paths to closest GC roots.\n\n# Example usage\n## Allocation sampling\nUsing the memory agent, you can attach allocation listeners that will catch allocation sampling events and execute your code. In the example below a stack trace of each allocation is printed.\n```\nMemoryAgent agent = MemoryAgent.get();\nagent.addAllocationListener((info) -\u003e {\n   for (StackTraceElement element : info.getThread().getStackTrace()) {\n       System.out.println(element);\n   }\n});\n```\nYou can also change the [heap sampling interval](https://openjdk.java.net/jeps/331) with\n```\nagent.setHeapSamplingInterval(512);\n```\nThe overhead for allocation sampling is [1-3%](https://openjdk.java.net/jeps/331) if the user-defined code is not taken into account.\n\n## Checking for object reachability\nThe example below shows how to check object reachability in the heap with weak/soft/phantom reference handling.\n```\nMemoryAgent agent = MemoryAgent.get();\n// Passing null here forces the agent to traverse heap from the GC roots\nSystem.out.println(agent.getFirstReachableObject(null, TestClass.class));\nfor (TestClass instance : agent.getAllReachableObjects(null, TestClass.class)) {\n    System.out.println(instance);\n}\n```\n\n# Using the agent in your projects\nThe library is published to the bintray [repository](https://bintray.com/jetbrains/intellij-third-party-dependencies/debugger-memory-agent).\n\n## Maven\nAdd the external repository url:\n```\n\u003crepositories\u003e\n  \u003crepository\u003e\n    \u003cid\u003ejetbrains.bintray\u003c/id\u003e\n    \u003curl\u003ehttps://jetbrains.bintray.com/intellij-third-party-dependencies\u003c/url\u003e\n  \u003c/repository\u003e\n\u003c/repositories\u003e\n```\nThen add the dependency:\n```\n\u003cdependencies\u003e\n  \u003cdependency\u003e\n    \u003cgroupId\u003eorg.jetbrains.intellij.deps\u003c/groupId\u003e\n    \u003cartifactId\u003edebugger-memory-agent\u003c/artifactId\u003e\n    \u003cversion\u003e1.0.32\u003c/version\u003e\n  \u003c/dependency\u003e\n\u003c/dependencies\u003e\n```\n##  Gradle\nAdd the external repository url:\n```\nrepositories {\n  maven {\n    url \"https://jetbrains.bintray.com/intellij-third-party-dependencies\"\n  }\n}\n```\nThen add the dependency:\n```\ndependencies {\n  implementation 'org.jetbrains.intellij.deps:debugger-memory-agent:1.0.32'\n}\n```\n\n## Gradle Kotlin DSL\nAdd the external repository url:\n```\nrepositories {\n  maven {\n    url = uri(\"https://jetbrains.bintray.com/intellij-third-party-dependencies\")\n  }\n}\n```\nThen add the dependency:\n```\ndependencies {\n  implementation(\"org.jetbrains.intellij.deps:debugger-memory-agent:1.0.32\")\n}\n```\n\n## Attaching the agent to a JVM\nIf the agent library doesn't meet your needs, you can still attach the agent to a JVM separately. To do so, you should compile the agent library following the steps in [CONTRIBUTING.md](CONTRIBUTING.md). Then run a JVM with the parameter: \n\n`-agentpath:/path/to/agent/library`. \n\nAfter that, you can call the memory agent's methods using the [IdeaNativeAgentProxy](test_data/proxy/src/com/intellij/memory/agent/IdeaNativeAgentProxy.java) class.\n\n# Building and contributing\nSee [CONTRIBUTING.md](CONTRIBUTING.md) for building and development tips before submitting a pull request. File an issue if you find any bug or have an idea for a new feature.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjetbrains%2Fdebugger-memory-agent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjetbrains%2Fdebugger-memory-agent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjetbrains%2Fdebugger-memory-agent/lists"}