summaryrefslogtreecommitdiff
path: root/tools
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 /tools
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 'tools')
-rwxr-xr-xtools/gen_class.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/tools/gen_class.py b/tools/gen_class.py
index 32f00c8..8e1e0f4 100755
--- a/tools/gen_class.py
+++ b/tools/gen_class.py
@@ -12,8 +12,9 @@ and access flags — and gives each concrete method a trivial body that
logs the call via kotlin.proxy.KotlinProxyLog and returns a default value.
Reference-return methods instead ask KotlinProxyLog.returnValue for their
value, which dispatches to kotlin.proxy.KotlinProxyOverrides.invoke (per-method
-custom implementations, passed the full argument list) before falling back to
-a real no-arg instance of the declared return type.
+custom implementations, passed the full argument list and the receiver —
+the stub instance the method was called on, null for statics) before falling
+back to a real no-arg instance of the declared return type.
The optional Signature attribute is OMITTED entirely, so there are no
generics in the emitted class files and therefore no generics clashes.
@@ -43,10 +44,11 @@ CALL_ARG_DESC = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;)V"
LOADED_DESC = "(Ljava/lang/String;)V"
# Arg order MUST match KotlinProxyLog.returnValue: the Object[] args array
# comes FIRST — the generated body builds it while the stack is shallowest
-# (peak 4 instead of 8 if it were pushed last).
+# (peak 5 instead of 9 if it were pushed last). The receiver (the stub
+# instance the method was called on; null for statics) comes last.
RETURN_VALUE_DESC = \
"([Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;" \
- "Ljava/lang/String;)Ljava/lang/Object;"
+ "Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;"
# access flags
A_PUBLIC, A_PRIVATE, A_PROTECTED = 0x1, 0x2, 0x4
@@ -435,9 +437,10 @@ def log_body(cp, member, dotname, desc, is_static, call_ref):
Reference-class returns ask KotlinProxyLog.returnValue, which dispatches
to KotlinProxyOverrides.invoke (per-method custom implementations, passed
- the full argument list) and falls back to materializing a real instance
- of the declared return type — so the daemon can proceed past e.g.
- createArguments() into doExecute() with a populated args object."""
+ the full argument list and the receiver — aload_0, or null for statics)
+ and falls back to materializing a real instance of the declared return
+ type — so the daemon can proceed past e.g. createArguments() into
+ doExecute() with a populated args object."""
slot, has_arg = first_param_ref_slot(desc, is_static)
if has_arg:
call_arg_ref = cp.methodref(KPL, "call", CALL_ARG_DESC)
@@ -450,17 +453,18 @@ def log_body(cp, member, dotname, desc, is_static, call_ref):
max_stack = 2
ti = new_instance_target(desc)
if ti is not None:
- # [argsArray, member, owner, returnType] -> returnValue(...) -> Object
+ # [argsArray, member, owner, returnType, instance] -> returnValue(...)
rv = cp.methodref(KPL, "returnValue", RETURN_VALUE_DESC)
b += args_array_body(cp, desc, is_static)
b += ldc(cp.string(member)) + ldc(cp.string(dotname)) \
+ ldc(cp.string(ti.replace("/", ".")))
+ b += b"\x2a" if not is_static else b"\x01" # receiver: aload_0 / null
b += bytes([0xb8]) + struct.pack(">H", rv)
# returnValue returns Object; checkcast to the declared return type so
# the verifier is happy (null passes checkcast, so un-instantiable
# types still just return null).
b += bytes([0xc0]) + struct.pack(">H", cp.cls(ti))
- max_stack = 4
+ max_stack = 5
else:
push, _ = ret_bytes(desc)
b += push