From 52deb0f79b635b5184dbe759b12c6ef63497bf44 Mon Sep 17 00:00:00 2001 From: Maksim Zuev Date: Tue, 28 Apr 2026 12:07:32 +0200 Subject: [PATCH] [debugger] IJPL-240834 Class memory agent proxy class loading - agent in a separate module - caller module loads classses GitOrigin-RevId: b240eebaffd1558b253edddb63fc895e7d52478a --- .../debugger/memory/agent}/AgentExtractor.kt | 6 +++--- .../memory/agent/IdeaNativeAgentProxyMirror.java | 3 +-- .../debugger/memory/agent/MemoryAgentUtil.java | 1 - .../debugger/memory/agent/ProxyExtractor.kt | 14 ++++++++++++++ java/debugger/memory-agent/BUILD.bazel | 7 +++---- .../intellij.java.debugger.memory.agent.iml | 4 +--- .../memory/agent/extractor/ProxyExtractor.kt | 7 ------- .../com/intellij/memory/agent/package-info.java | 3 +++ java/java-backend/BUILD.bazel | 3 --- java/java-backend/intellij.java.backend.iml | 1 - .../resources/intellij.java.backend.xml | 1 - 11 files changed, 25 insertions(+), 25 deletions(-) rename java/debugger/{memory-agent/src/com/intellij/debugger/memory/agent/extractor => impl/src/com/intellij/debugger/memory/agent}/AgentExtractor.kt (82%) create mode 100644 java/debugger/impl/src/com/intellij/debugger/memory/agent/ProxyExtractor.kt delete mode 100644 java/debugger/memory-agent/src/com/intellij/debugger/memory/agent/extractor/ProxyExtractor.kt create mode 100644 java/debugger/memory-agent/src/com/intellij/memory/agent/package-info.java diff --git a/java/debugger/memory-agent/src/com/intellij/debugger/memory/agent/extractor/AgentExtractor.kt b/java/debugger/impl/src/com/intellij/debugger/memory/agent/AgentExtractor.kt similarity index 82% rename from java/debugger/memory-agent/src/com/intellij/debugger/memory/agent/extractor/AgentExtractor.kt rename to java/debugger/impl/src/com/intellij/debugger/memory/agent/AgentExtractor.kt index 43c3d70d727b..c362d2ed5e97 100644 --- a/java/debugger/memory-agent/src/com/intellij/debugger/memory/agent/extractor/AgentExtractor.kt +++ b/java/debugger/impl/src/com/intellij/debugger/memory/agent/AgentExtractor.kt @@ -1,5 +1,5 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package com.intellij.debugger.memory.agent.extractor +// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.debugger.memory.agent import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.io.FileUtilRt @@ -17,7 +17,7 @@ object AgentExtractor { if (!::extractedFile.isInitialized || !extractedFile.exists() || extractedFile.lastModified() != lastModified) { val agentFileName = "${agentType.prefix}memory_agent${agentType.suffix}" val file = FileUtilRt.createTempFile(directory.toFile(), "${agentType.prefix}memory_agent", agentType.suffix, true) - val inputStream = AgentExtractor::class.java.classLoader.getResourceAsStream("bin/$agentFileName") ?: throw FileNotFoundException(agentFileName) + val inputStream = classFromAgentJar().classLoader.getResourceAsStream("bin/$agentFileName") ?: throw FileNotFoundException(agentFileName) inputStream.use { input -> Files.newOutputStream(file.toPath()).use { output -> FileUtil.copy(input, output) diff --git a/java/debugger/impl/src/com/intellij/debugger/memory/agent/IdeaNativeAgentProxyMirror.java b/java/debugger/impl/src/com/intellij/debugger/memory/agent/IdeaNativeAgentProxyMirror.java index 5cf21995d203..6b767492affd 100644 --- a/java/debugger/impl/src/com/intellij/debugger/memory/agent/IdeaNativeAgentProxyMirror.java +++ b/java/debugger/impl/src/com/intellij/debugger/memory/agent/IdeaNativeAgentProxyMirror.java @@ -10,7 +10,6 @@ import com.intellij.debugger.engine.evaluation.EvaluateExceptionUtil; import com.intellij.debugger.engine.evaluation.EvaluationContextImpl; import com.intellij.debugger.impl.ClassLoadingUtils; import com.intellij.debugger.impl.DebuggerUtilsEx; -import com.intellij.debugger.memory.agent.extractor.ProxyExtractor; import com.intellij.debugger.memory.agent.parsers.BooleanParser; import com.intellij.debugger.memory.agent.parsers.ErrorCodeParser; import com.intellij.debugger.memory.agent.parsers.GcRootsPathsParser; @@ -408,7 +407,7 @@ public class IdeaNativeAgentProxyMirror { } private static byte @NotNull [] readUtilityClass() { - return new ProxyExtractor().extractProxy(); + return ProxyExtractorKt.extractProxy(); } private static @Nullable ReferenceType loadUtilityClass(@NotNull EvaluationContextImpl evaluationContext) throws EvaluateException { diff --git a/java/debugger/impl/src/com/intellij/debugger/memory/agent/MemoryAgentUtil.java b/java/debugger/impl/src/com/intellij/debugger/memory/agent/MemoryAgentUtil.java index b120e72a9680..335788a6cd36 100644 --- a/java/debugger/impl/src/com/intellij/debugger/memory/agent/MemoryAgentUtil.java +++ b/java/debugger/impl/src/com/intellij/debugger/memory/agent/MemoryAgentUtil.java @@ -3,7 +3,6 @@ package com.intellij.debugger.memory.agent; import com.intellij.debugger.engine.evaluation.EvaluateException; import com.intellij.debugger.engine.evaluation.EvaluationContextImpl; -import com.intellij.debugger.memory.agent.extractor.AgentExtractor; import com.intellij.debugger.memory.ui.JavaReferenceInfo; import com.intellij.debugger.memory.ui.SizedReferenceInfo; import com.intellij.execution.JavaExecutionUtil; diff --git a/java/debugger/impl/src/com/intellij/debugger/memory/agent/ProxyExtractor.kt b/java/debugger/impl/src/com/intellij/debugger/memory/agent/ProxyExtractor.kt new file mode 100644 index 000000000000..9348de0daf0e --- /dev/null +++ b/java/debugger/impl/src/com/intellij/debugger/memory/agent/ProxyExtractor.kt @@ -0,0 +1,14 @@ +// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.debugger.memory.agent + +internal fun classFromAgentJar(): Class<*> { + return com.intellij.memory.agent.MemoryAgent::class.java +} + +internal fun extractProxy(): ByteArray { + val resourcePath = "com/intellij/memory/agent/IdeaNativeAgentProxy.class" + val stream = classFromAgentJar().classLoader.getResourceAsStream(resourcePath) + ?: error("Cannot load memory agent proxy class $resourcePath") + return stream.use { it.readAllBytes() } +} + diff --git a/java/debugger/memory-agent/BUILD.bazel b/java/debugger/memory-agent/BUILD.bazel index 3c547eb5e817..8dda0de9a77a 100644 --- a/java/debugger/memory-agent/BUILD.bazel +++ b/java/debugger/memory-agent/BUILD.bazel @@ -14,11 +14,10 @@ jvm_library( srcs = glob(["src/**/*.kt", "src/**/*.java", "src/**/*.form"], allow_empty = True), resources = [":java-debugger-memory-agent_resources"], deps = [ - "//platform/util", "//platform/backend", "@lib//:java-debugger-memory-agent-debugger-memory-agent", - "@lib//:kotlin-stdlib", - ] + ], + exports = ["@lib//:java-debugger-memory-agent-debugger-memory-agent"] ) jvm_library( @@ -26,9 +25,9 @@ jvm_library( module_name = "intellij.java.debugger.memory.agent", visibility = ["//visibility:public"], srcs = glob([], allow_empty = True), + exports = ["@lib//:java-debugger-memory-agent-debugger-memory-agent"], runtime_deps = [ ":java-debugger-memory-agent", - "//platform/util:util_test_lib", "//platform/backend:backend_test_lib", ] ) diff --git a/java/debugger/memory-agent/intellij.java.debugger.memory.agent.iml b/java/debugger/memory-agent/intellij.java.debugger.memory.agent.iml index 466233667db4..323ef56404ac 100644 --- a/java/debugger/memory-agent/intellij.java.debugger.memory.agent.iml +++ b/java/debugger/memory-agent/intellij.java.debugger.memory.agent.iml @@ -8,9 +8,8 @@ - - + @@ -28,6 +27,5 @@ - \ No newline at end of file diff --git a/java/debugger/memory-agent/src/com/intellij/debugger/memory/agent/extractor/ProxyExtractor.kt b/java/debugger/memory-agent/src/com/intellij/debugger/memory/agent/extractor/ProxyExtractor.kt deleted file mode 100644 index e08b65c34090..000000000000 --- a/java/debugger/memory-agent/src/com/intellij/debugger/memory/agent/extractor/ProxyExtractor.kt +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package com.intellij.debugger.memory.agent.extractor - -class ProxyExtractor { - fun extractProxy(): ByteArray = - ProxyExtractor::class.java.classLoader.getResourceAsStream("com/intellij/memory/agent/IdeaNativeAgentProxy.class")!!.readAllBytes() -} diff --git a/java/debugger/memory-agent/src/com/intellij/memory/agent/package-info.java b/java/debugger/memory-agent/src/com/intellij/memory/agent/package-info.java new file mode 100644 index 000000000000..82c35d5bae0f --- /dev/null +++ b/java/debugger/memory-agent/src/com/intellij/memory/agent/package-info.java @@ -0,0 +1,3 @@ +package com.intellij.memory.agent; + +/* this file is added as a workaround for IJPL-103 */ diff --git a/java/java-backend/BUILD.bazel b/java/java-backend/BUILD.bazel index dec86b77b79c..72e009ca06d4 100644 --- a/java/java-backend/BUILD.bazel +++ b/java/java-backend/BUILD.bazel @@ -45,7 +45,6 @@ jvm_library( "//java/execution/impl", "//java/debugger/impl", "//java/debugger/backend", - "//java/debugger/memory-agent:java-debugger-memory-agent", "//uast/uast-java-ide:java-uast-ide", "@community//build:dependency-graph", ], @@ -85,7 +84,6 @@ jvm_library( "//java/execution/impl", "//java/debugger/impl", "//java/debugger/backend", - "//java/debugger/memory-agent:java-debugger-memory-agent", "//uast/uast-java-ide:java-uast-ide", "@community//build:dependency-graph", "//platform/backend", @@ -134,7 +132,6 @@ jvm_library( "//java/execution/impl:impl_test_lib", "//java/debugger/impl:impl_test_lib", "//java/debugger/backend:backend_test_lib", - "//java/debugger/memory-agent:java-debugger-memory-agent_test_lib", "//uast/uast-java-ide:java-uast-ide_test_lib", "@community//build:dependency-graph_test_lib", "//platform/backend:backend_test_lib", diff --git a/java/java-backend/intellij.java.backend.iml b/java/java-backend/intellij.java.backend.iml index 9b47ea4550d3..0a68772dfb48 100644 --- a/java/java-backend/intellij.java.backend.iml +++ b/java/java-backend/intellij.java.backend.iml @@ -43,7 +43,6 @@ - diff --git a/java/java-backend/resources/intellij.java.backend.xml b/java/java-backend/resources/intellij.java.backend.xml index c61a3cc92736..39d2c33a6af1 100644 --- a/java/java-backend/resources/intellij.java.backend.xml +++ b/java/java-backend/resources/intellij.java.backend.xml @@ -29,7 +29,6 @@ -