JavaAgent:版本对比 v4 → v5
v4(2026-10-04 02:09,mcst12345)→ v5(2026-10-04 02:25,mcst12345)
共 25 行变更 · 新增 17 行 · 删除 3 行(左右分栏:左为旧版本,右为新版本)
| 1 | Java自帶的調試接口,常用於運行時字節碼注入。 | 1 | Java自帶的調試接口,常用於運行時字節碼注入。 |
| 2 | Java's debug interface, commonly used for runtime class bytecode injection. | ||
| 2 | javaagent為一至少聲明有Premain-Class或Agent-Class屬性的jar,Premain-Class與Agent-Class為agent主類,Premain-Class類需定義public static void premain(String args, Instrumentation inst) 方法,Agent-Class類需定義public static void agentmain(String args, Instrumentation inst) 方法。 | ||
| 3 | 其他可選屬性為 | ||
| 4 | * Can-Redefine-Classes 允許重定義類 | ||
| 5 | * Can-Retransform-Classes 允許重轉換類 | ||
| 6 | * Can-Set-Native-Method-Prefix 允許設置[[native method prefix]] | ||
| 3 | 7 | ||
| 4 | == 相关/Related == | ||
| 8 | == 相关 == | ||
| 5 | * 核心接口及获取方式见 [[Instrumentation]],JDK 内部实现见 [[InstrumentationImpl]],底层依赖 [[JVMTI]]。 | 9 | * 核心接口及获取方式见 [[Instrumentation]],JDK 内部实现见 [[InstrumentationImpl]],底层依赖 [[JVMTI]]。 |
| 6 | * See [[Instrumentation]] for provided methods and how to load a javaagent, see [[InstrumentationImpl]] for default implementation at runtime, see [[JVMTI]] for underlying mechanism. | ||
| 7 | * 目前最常用的加载方式是'''运行时外部进程附加''',不需要任何启动参数,详见 [[Instrumentation]] 的“运行时外部进程附加”一节。 | 10 | * 目前最常用的加载方式是'''运行时外部进程附加''',不需要任何启动参数,详见 [[Instrumentation]] 的“运行时外部进程附加”一节。 |
| 11 | |||
| 12 | |||
| 13 | Java's debug interface, commonly used for runtime class bytecode injection. | ||
| 14 | javaagent is a jar file with manifest attribute Premain-Class or Agent-Class, Premain-Class attribute and Agent-Class attribute declares the agent main class of a javaagent, the class speficied by Premain-Class should declare method public static void premain(String args, Instrumentation inst) , the class specified by Agent-Class should declare method public static void agentmain(String args, Instrumentation inst) . | ||
| 15 | Other optional attribute for a javaagent can be | ||
| 16 | * Can-Redefine-Classes | ||
| 17 | * Can-Retransform-Classes | ||
| 18 | * Can-Set-Native-Method-Prefix | ||
| 19 | |||
| 20 | == Related == | ||
| 21 | * See [[Instrumentation]] for provided methods and how to load a javaagent, see [[InstrumentationImpl]] for default implementation at runtime, see [[JVMTI]] for underlying mechanism. | ||
| 8 | * "runtime attach" is the most commonly used method to load a javaagent at present, it doesn't require any commandline arguments, see [[Instrumentation]] for more details. | 22 | * "runtime attach" is the most commonly used method to load a javaagent at present, it doesn't require any commandline arguments, see [[Instrumentation]] for more details. |