summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2026-11-05 21:18:56 +0100
committerJoel Klinghed <the_jk@spawned.biz>2026-11-05 21:18:56 +0100
commit64223f61fc8413ad69ba0e814fbbc552a6c57c33 (patch)
tree79f47335e71dfe6d702fbca520513b2b7eb90fae /README.md
parentaefb3dbf687b46775bca1b600317bc053648b211 (diff)
Pass the receiver instance to KotlinProxyOverrides.invoke
The generated returnValue call now carries the stub instance the method was called on (null for statics), so overrides can keep per-compiler state instead of statics: the performance manager is now stored in an IdentityHashMap keyed by receiver, and OVERRIDE log lines carry the receiver's identityHashCode as inst=0x… .
Diffstat (limited to 'README.md')
-rw-r--r--README.md41
1 files changed, 29 insertions, 12 deletions
diff --git a/README.md b/README.md
index ed6dc0d..2c14965 100644
--- a/README.md
+++ b/README.md
@@ -13,6 +13,7 @@ kotlin-proxy/
├── stubs/
│ ├── src/kotlin/proxy/KotlinProxyLog.java # the logger the stubs call
│ ├── src/kotlin/proxy/KotlinProxyOverrides.java # per-method custom return values
+│ ├── src/kotlin/proxy/ProxyPerformanceManager.java # override support class
│ └── classes_min/ # generated .class files (build output)
├── jars/
│ ├── defs.txt # 28 kotlin-2.2.10 jars (definition lookup)
@@ -55,12 +56,14 @@ output directory must not contain anything you need.
javac -nowarn -proc:none -d stubs/classes_min \
-cp "$(grep -v '^[[:space:]]*#' jars/defs.txt | tr '\n' ':')" \
stubs/src/kotlin/proxy/KotlinProxyLog.java \
- stubs/src/kotlin/proxy/KotlinProxyOverrides.java
+ stubs/src/kotlin/proxy/KotlinProxyOverrides.java \
+ stubs/src/kotlin/proxy/ProxyPerformanceManager.java
```
-`KotlinProxyLog` (the logger every stub calls) and `KotlinProxyOverrides`
-(the per-method return-value hook you implement against) are the only real
-classes in the jar. The `-cp` puts the real compiler jars on javac's
+`KotlinProxyLog` (the logger every stub calls), `KotlinProxyOverrides`
+(the per-method return-value hook you implement against), and
+`ProxyPerformanceManager` (an override support class the hook returns) are
+the only real classes in the jar. The `-cp` puts the real compiler jars on javac's
classpath so your overrides may import compiler types (`CommonCompilerArguments`,
`Services`, …). (Step 1 wiped the directory, so `javac` must run
**after** it.)
@@ -71,13 +74,14 @@ classpath so your overrides may import compiler types (`CommonCompilerArguments`
jar cf dist/kotlin-proxy-compiler-stubs.jar -C stubs/classes_min .
```
-Result: 5 class files + manifest
+Result: 6 class files + manifest
```
$ jar tf dist/kotlin-proxy-compiler-stubs.jar | grep -v '/$'
META-INF/MANIFEST.MF
kotlin/proxy/KotlinProxyLog.class
kotlin/proxy/KotlinProxyOverrides.class
+kotlin/proxy/ProxyPerformanceManager.class
org/jetbrains/kotlin/cli/jvm/K2JVMCompiler$Companion.class
org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.class
org/jetbrains/kotlin/cli/jvm/K2JVMCompilerKt.class
@@ -154,8 +158,10 @@ The list files contain one jar path per line; `#` starts a comment.
- reference-class returns (except `String`): build an `Object[]` of the
call's arguments (references as-is, primitives boxed — so position `i`
is parameter `i`; `null` for a param-less method), then ask
- `KotlinProxyLog.returnValue(member, owner, retType, args)` + `checkcast`.
- That first dispatches to `KotlinProxyOverrides.invoke` — your per-method
+ `KotlinProxyLog.returnValue(member, owner, retType, args, instance)` +
+ `checkcast`, where `instance` is the receiver — the stub instance the
+ method was called on (`this`), or `null` for statics. That first
+ dispatches to `KotlinProxyOverrides.invoke` — your per-method
custom implementation, see below — and falls back to
`KotlinProxyLog.newInstance(retType)`, which reflectively instantiates
the real (un-stubbed) return class so the daemon can proceed (e.g.
@@ -180,12 +186,14 @@ something for; return `NO_VALUE` for everything else.
```java
public static Object invoke(String member, String ownerDotName,
- String returnDotName, Object[] args) {
+ String returnDotName, Object[] args,
+ Object instance) {
if ("createPerformanceManager".equals(member)
&& "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler".equals(ownerDotName)) {
CommonCompilerArguments a = (CommonCompilerArguments) args[0];
Services services = (Services) args[1];
// build/return whatever this method should return, using the real args
+ // (and `instance`, to keep per-compiler-instance state)
return new MyPerformanceManager();
}
return NO_VALUE;
@@ -199,8 +207,15 @@ public static Object invoke(String member, String ownerDotName,
on the **real** arguments the daemon handed the compiler: reference types
as-is, primitives boxed (`Integer`, `Long`, `Boolean`, …). A param-less
method gets `args == null`.
+- `instance` is the receiver — the stub instance the method was called on
+ (the daemon's `K2JVMCompiler` object) — so you can keep per-compiler state
+ across calls (identity-keyed, e.g. in an `IdentityHashMap`). It is `null`
+ for static methods (e.g. everything on the `K2JVMCompilerKt` file facade).
- Returning `NO_VALUE` keeps the default (real no-arg instance, or null).
- An override is logged as `OVERRIDE <owner>.<member> -> <dump>`.
+ An override is logged as
+ `OVERRIDE <owner>.<member> [inst=0x…] -> <dump>` — the `inst` tag
+ (the receiver's `identityHashCode`, omitted for statics) lets you
+ correlate which compiler instance a method ran on.
Rebuild with steps **2–3** after editing (no need to re-run the generator).
Your overrides may reference the real compiler types — they resolve from the
@@ -275,9 +290,11 @@ RMI TCP Connection(2)-127.0.0.1 | CALL org.jetbrains.kotlin.cli.jvm.K2JVMCompil
- `CALL <name>.<member> arg=<dump>` — boundary argument: compiler-argument
objects are dumped via `toCommonList()`; other objects via their
non-null fields across the hierarchy.
-- `OVERRIDE <name>.<member> -> <dump>` — a `KotlinProxyOverrides.invoke`
- implementation supplied the return value (logged once, in
- `KotlinProxyLog.returnValue`).
+- `OVERRIDE <name>.<member> [inst=0x…] -> <dump>` — a
+ `KotlinProxyOverrides.invoke` implementation supplied the return value
+ (logged once, in `KotlinProxyLog.returnValue`); `inst` is the receiver
+ instance's `identityHashCode` (omitted for static calls), so you can see
+ which compiler instance the method ran on.
A `newInstance FAIL <type> : <exception>` line means a stub method's declared
return type has no usable no-arg constructor (e.g. `PerformanceManager`), so