Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,11 @@ private static synchronized void main(String args, final Instrumentation inst) {
agentArgs = args;
}

File arthasCoreJarFile = new File(arthasCoreJar);
if (!arthasCoreJarFile.exists()) {
ps.println("Can not find arthas-core jar file from args: " + arthasCoreJarFile);
File arthasCoreJarFile = arthasCoreJar.trim().isEmpty() ? null : new File(arthasCoreJar);
if (arthasCoreJarFile == null || !arthasCoreJarFile.exists()) {
if (arthasCoreJarFile != null) {
ps.println("Can not find arthas-core jar file from args: " + arthasCoreJarFile);
}
// try to find from arthas-agent.jar directory
CodeSource codeSource = AgentBootstrap.class.getProtectionDomain().getCodeSource();
if (codeSource != null) {
Expand All @@ -136,7 +138,7 @@ private static synchronized void main(String args, final Instrumentation inst) {
}
}
}
if (!arthasCoreJarFile.exists()) {
if (arthasCoreJarFile == null || !arthasCoreJarFile.exists()) {
return;
}

Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/arthas.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ arthas.localConnectionNonAuth=true

#arthas.outputPath=arthas-output

# UTF-8 script with one startup command per line
#arthas.startupScript=/opt/arthas/startup.as

# MCP (Model Context Protocol) configuration
arthas.mcpEndpoint=/mcp
arthas.mcpProtocol=STREAMABLE
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ public boolean isLazy() {
return lazy;
}

boolean isLazy(Session session) {
return lazy || session != null && Boolean.TRUE.equals(session.get(Session.STARTUP_COMMAND));
}

/**
* 类名匹配
*
Expand Down Expand Up @@ -201,6 +205,7 @@ protected void enhance(CommandProcess process) {
EnhancerAffect effect = null;
int lock = session.getLock();
try {
boolean lazyEnhance = isLazy(session);
Instrumentation inst = session.getInstrumentation();
AdviceListener listener = getAdviceListenerWithId(process);
if (listener == null) {
Expand All @@ -216,7 +221,7 @@ protected void enhance(CommandProcess process) {
}

Enhancer enhancer = new Enhancer(listener, listener instanceof InvokeTraceable, skipJDKTrace,
getClassNameMatcher(), getClassNameExcludeMatcher(), getMethodNameMatcher(), this.lazy, this.hashCode);
getClassNameMatcher(), getClassNameExcludeMatcher(), getMethodNameMatcher(), lazyEnhance, this.hashCode);
enhancer.setLineEnhanceOptions(getLineEnhanceOptions());
// 注册通知监听器
process.register(listener, enhancer);
Expand All @@ -238,7 +243,7 @@ protected void enhance(CommandProcess process) {
}

// 懒加载模式:即使没有匹配的类也不立即结束,等待类加载
if (this.lazy) {
if (lazyEnhance) {
String lazyMsg = "Lazy mode is enabled, waiting for class to be loaded. Press Q or Ctrl+C to abort.\n"
+ "When the target class is loaded, it will be automatically enhanced.";
process.write(lazyMsg + "\n");
Expand Down
Loading
Loading