AccessBridge

Bootstrap methods for invokedynamic call sites emitted by the access-widening bytecode transform in ScriptWeave. Each bootstrap resolves a private/protected/package-private member via MethodHandles.privateLookupIn and returns a ConstantCallSite, which the JIT can inline.

This class lives on the game loader (not impl/), so script classes loaded by the masking loader can resolve it via parent delegation — same cross-loader pattern as ReplBridge and PatchEnterCallback.

The call-site MethodType is not the real signature. Widening a member's access is only half the job: a call site whose descriptor names an inaccessible class is rejected while the JVM resolves that descriptor, before any bootstrap here runs (e.g. a descriptor naming package-private kotlin.collections.EmptyMap is rejected). So the transform erases every inaccessible reference type in the call-site descriptor to Any and passes the real names through as string bootstrap arguments instead.

Two consequences for every bootstrap below:

  • type cannot be trusted for the member's real type — the field bootstraps read it reflectively via findField, the method bootstraps take it from the desc argument.

  • Every returned handle is MethodHandle.asType'd to type, which inserts the casts between the erased Any view and the real types.

ScriptWeave names each bootstrap by a descriptor it writes out itself, so all of them are @JvmStatic and spell their return type: one inferred as ConstantCallSite would link against nothing, at the first private access.

Properties

Link copied to clipboard

Functions

Link copied to clipboard
private fun backingField(cls: Class<*>, method: String, mt: MethodType, hasReceiver: Boolean, caller: MethodHandles.Lookup, cause: NoSuchMethodException): MethodHandle

A Kotlin private val has a backing field and no accessor, yet the metadata flip makes the frontend emit getXxx() against it — resolve such a call to the field instead. An object, companion or top-level property backs onto a STATIC field, so hasReceiver says whether the call site passes one that the handle has to swallow.

Link copied to clipboard
private fun capitalize(s: String): String

Kotlin capitalizes ASCII only, so URL and _options keep their head.

Link copied to clipboard
fun checkCast(caller: MethodHandles.Lookup, invokedName: String, type: MethodType, owner: String): CallSite

Bootstrap checkcast. The identity handle takes exactly that class, so asType from the call site's Object inserts checkcast's own check: null passes, anything else that is not an instance throws ClassCastException.

Link copied to clipboard
fun classConstant(caller: MethodHandles.Lookup, name: String, type: Class<*>, owner: String): Class<*>

Bootstrap a class literal, ::class, as a dynamic constant.

Link copied to clipboard
fun construct(caller: MethodHandles.Lookup, invokedName: String, type: MethodType, owner: String, desc: String): CallSite

Bootstrap a constructor call; desc is the constructor's own, and the instance comes back as the call's result. Resolved like every other member the bridge reaches, so a non-public constructor opens too.

Link copied to clipboard
private fun declaredField(c: Class<*>, field: String, wantStatic: Boolean): Field?

c's own field of the wanted kind, or null.

Link copied to clipboard
private fun declares(c: Class<*>, method: String, params: Array<out Class<*>>): Boolean

The spread is a copy per candidate class, once per call site: the JVM links each one only once.

Link copied to clipboard
fun fieldGet(caller: MethodHandles.Lookup, invokedName: String, type: MethodType, owner: String, field: String): CallSite

Bootstrap a GETFIELD call site.

Link copied to clipboard
private fun fieldHandle(f: Field, get: Boolean, hasReceiver: Boolean, caller: MethodHandles.Lookup): MethodHandle?

f as the accessor it backs, or null where it needs an instance a static call site does not have.

Link copied to clipboard
fun fieldSet(caller: MethodHandles.Lookup, invokedName: String, type: MethodType, owner: String, field: String): CallSite

Bootstrap a PUTFIELD call site.

Link copied to clipboard
private fun findAccessor(cls: Class<*>, method: String, get: Boolean, hasReceiver: Boolean, caller: MethodHandles.Lookup): MethodHandle?

The handle standing in for accessor method, or null when no field in cls's reach backs it.

Link copied to clipboard
private fun findField(ref: Class<*>, field: String, wantStatic: Boolean): Field

The field ref resolves field to. The transform emits the reference-site owner, but a private field can be declared on a superclass, where privateLookupIn(subclass) cannot reach it. Interfaces are searched last, transitively, for constants.

Link copied to clipboard
private fun findMethodOwner(ref: Class<*>, method: String, mt: MethodType): Class<*>

The class in ref's hierarchy that declares method with mt's parameter types — the method analogue of findField. Falls back to ref when nothing matches.

Link copied to clipboard
private fun getterName(prop: String): String

JvmAbi.getterName: an is-prefixed property is already its own getter.

Link copied to clipboard
fun instanceOf(caller: MethodHandles.Lookup, invokedName: String, type: MethodType, owner: String): CallSite

Bootstrap instanceof: Class.isInstance is the same test, null failing it.

Link copied to clipboard
private fun interfaceClosure(ref: Class<*>): Set<Class<*>>

Every interface reachable from ref, breadth-first.

Link copied to clipboard
private fun isCompanion(cls: Class<*>, host: Class<*>): Boolean

Whether cls is host's companion object, which the host holds in a static field.

Link copied to clipboard
private fun isPrefixed(name: String): Boolean

JvmAbi.startsWithIsPrefix: is followed by anything that is not a lower-case letter.

Link copied to clipboard

MethodHandles.privateLookupIn on cls, or caller where its module refuses to open — java.base being the one that does.

Link copied to clipboard
fun newArray(caller: MethodHandles.Lookup, invokedName: String, type: MethodType, owner: String): CallSite

Bootstrap anewarray: owner is the element class, and the array a real array of it, so storing anything else still throws ArrayStoreException.

Link copied to clipboard
private fun resolve(owner: String, caller: MethodHandles.Lookup): Class<*>
Link copied to clipboard
private fun setterName(prop: String): String

JvmAbi.setterName: the is is dropped rather than kept — isEmpty sets via setEmpty.

Link copied to clipboard
fun staticCall(caller: MethodHandles.Lookup, invokedName: String, type: MethodType, owner: String, method: String, desc: String): CallSite

Bootstrap an INVOKESTATIC call site; the real signature is in desc, the declaring class resolved via findMethodOwner.

Link copied to clipboard
fun staticFieldGet(caller: MethodHandles.Lookup, invokedName: String, type: MethodType, owner: String, field: String): CallSite

Bootstrap a GETSTATIC call site.

Link copied to clipboard
fun staticFieldSet(caller: MethodHandles.Lookup, invokedName: String, type: MethodType, owner: String, field: String): CallSite

Bootstrap a PUTSTATIC call site.

Link copied to clipboard
fun superCall(caller: MethodHandles.Lookup, invokedName: String, type: MethodType, owner: String, method: String, desc: String): CallSite

Bootstrap a super.method(...) call, opened like every other member: invokespecial from the declaring class findMethodOwner finds selects what the snippet's call would have — the first declaration up from the class the call names.

Link copied to clipboard
private fun superclasses(ref: Class<*>): Sequence<Class<*>>

ref and its superclasses, nearest first.

Link copied to clipboard
fun virtualCall(caller: MethodHandles.Lookup, invokedName: String, type: MethodType, owner: String, method: String, desc: String): CallSite

Bootstrap an INVOKEVIRTUAL/INVOKEINTERFACE call site; the real signature is in desc, the declaring class resolved via findMethodOwner.