summaryrefslogtreecommitdiff
path: root/stubs/src/kotlin/proxy/KotlinProxyNoLog.java
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2026-11-16 22:36:22 +0100
committerJoel Klinghed <the_jk@spawned.biz>2026-11-16 22:36:22 +0100
commitf38efe3ea55ab83d0f0a13b9e52ea61daf880226 (patch)
tree40c20d3f40f2036c1c19f5ee7c7316edec80fb5d /stubs/src/kotlin/proxy/KotlinProxyNoLog.java
parent854788d8824fceaf0ce45045a56150e0bc92f2ee (diff)
Add --no-log stub flavor and a second jar
The --no-log flag in gen_class.py is now wired through the body generators: emitted stubs skip KotlinProxyLog.loaded()/call() and route reference returns through kotlin.proxy.KotlinProxyNoLog.returnValue instead, so the generated trio references only KotlinProxyNoLog (call/ loaded methodrefs are kept out of the constant pool; max_stack is recomputed for the logging-free bodies). Makefile builds two jars from the same kotlin.proxy.* sources: dist/kotlin-proxy-compiler-stubs.jar (logging) and dist/kotlin-proxy-compiler-stubs-nolog.jar (--no-log). Adds KotlinProxyNoLog (logging-free returnValue/newInstance) and ignores its build outputs like the log flavor's.
Diffstat (limited to 'stubs/src/kotlin/proxy/KotlinProxyNoLog.java')
-rw-r--r--stubs/src/kotlin/proxy/KotlinProxyNoLog.java51
1 files changed, 51 insertions, 0 deletions
diff --git a/stubs/src/kotlin/proxy/KotlinProxyNoLog.java b/stubs/src/kotlin/proxy/KotlinProxyNoLog.java
new file mode 100644
index 0000000..8b7e202
--- /dev/null
+++ b/stubs/src/kotlin/proxy/KotlinProxyNoLog.java
@@ -0,0 +1,51 @@
+package kotlin.proxy;
+
+public final class KotlinProxyNoLog {
+ private KotlinProxyNoLog() {
+ }
+
+ /**
+ * Return value for stub methods with a reference return type (other than
+ * String). Asks {@link KotlinProxyOverrides#invoke} first — per-method
+ * custom implementations, passed the full argument list and the receiver
+ * (the stub instance the method was called on, null for statics) — and
+ * falls back to materializing a real no-arg instance of the declared
+ * return type. The generated body checkcasts the result to the declared
+ * type.
+ *
+ * The generated bytecode pushes the args array FIRST (member, owner,
+ * return type and receiver last) so its stack stays shallow (peak 5) —
+ * keep this parameter order in sync with RETURN_VALUE_DESC in
+ * gen_class.py.
+ */
+ public static Object returnValue(Object[] args, String member,
+ String ownerDotName, String returnDotName,
+ Object instance) {
+ Object v = KotlinProxyOverrides.invoke(member, ownerDotName,
+ returnDotName, args, instance);
+ if (v == KotlinProxyOverrides.NO_VALUE) {
+ return newInstance(returnDotName);
+ }
+ return v;
+ }
+
+ /**
+ * Default return-value materialization (the fallback of
+ * {@link #returnValue}). Reflectively instantiates the real, un-stubbed
+ * class of the declared return type so the caller (the daemon) can keep
+ * going: e.g.
+ * K2JVMCompiler.createArguments() returns a genuine K2JVMCompilerArguments,
+ * which lets parseCommandLineArguments run and doExecute be reached with the
+ * fully-populated args (the boundary we want to log). Returns null when the
+ * type has no usable no-arg constructor (interfaces, enums, abstract, etc.).
+ */
+ private static Object newInstance(String dotName) {
+ try {
+ Class<?> c = Class.forName(dotName, false,
+ KotlinProxyNoLog.class.getClassLoader());
+ return c.getDeclaredConstructor().newInstance();
+ } catch (Throwable t) {
+ return null;
+ }
+ }
+}