ReplBridge

object ReplBridge

Game-loader side of the REPL. Builds the MaskingClassLoader, crosses into the masking world with a single reflective bootstrap of ...repl.impl.MaskingBridgeImpl — reached type-safely thereafter through the shared MaskingBridge interface — and caches the result so every compile / execute after the first is a warm call. The same bridge also fronts the remap-cache builder (assembleMappings, buildSymbols), so ALL masking-only calls share this one hop.

Why reflection: MaskingBridgeImpl and its backends (ReplHost, RemapCacheBuilder) link the Kotlin scripting / remapper APIs, which live only on the masking loader's urls (see MaskingClassLoader for why they cannot sit on the game's module path). The game loader therefore cannot link them by name, and this one bootstrap hop is the whole cost of that isolation.

Only types the masking loader delegates to the parent may cross the boundary: java.*, Any, and the mod's own classes outside repl.impl — which is also why MaskingBridge itself must stay in ...repl; see MaskingClassLoader. Never a kotlin.* type, function types included: under SPLIT the two sides run different kotlins.

Properties

Link copied to clipboard
private var classpath: List<File>?
Link copied to clipboard

The one thread the compiler runs on. Its FIR caches are single-threaded and nothing locks them: every caller is a task here, run in submission order — warmup first (startBackgroundWarmup), then each eval's compile. One thread for the life of the process, too: every thread that looks a class up through the compiler leaves an entry, for good, in a cache nothing ever disposes (KotlinBinaryClassCache).

Link copied to clipboard

The thread COMPILER last made: what compile holds its callers to.

Link copied to clipboard
private lateinit var host: MaskingBridge
Link copied to clipboard

①: CommonClass.init trigger — the baseline the other three timestamps are relative to.

Link copied to clipboard
private val LOCK: Any
Link copied to clipboard
Link copied to clipboard

Gates buildClasspath on a host that has plugins — not on their jars, which are all loaded before any is enabled, but on the urls a plugin attaches to its own loader inside onEnable, which PluginJarCollector reads live. Opened by MixinDedicatedServer at initServer's RETURN, by paper's ServerLoadEvent listener, or here at warmup start where no plugins are expected (pluginsExpected). Untimed: no constant tells a slow startup from a signal that will never come, so mcp.plugins.gate=false is the way past one that never does.

Link copied to clipboard

③: compiler working set preloaded (~= initStartNanos on a training launch).

Link copied to clipboard

②: remap symbols ready (~= initStartNanos on a mojmap runtime, where no remap is needed).

Link copied to clipboard

True once warmup finishes; McpServer gates execute_code on this (set even on failure).

Link copied to clipboard

④: compiler built + one dummy snippet compiled and run — the first eval is now warm.

Link copied to clipboard

Counted down by the remap thread and the preload thread; the gate awaits both before building. Neither may run on COMPILER: the gate awaiting them heads its queue.

Functions

Link copied to clipboard
fun assembleMappings(clientTxt: String, secondSource: String, outMappings: String)

Cross into the masking loader (mapping-io + tiny-remapper live only there) to assemble the remap mappings: the half of the bundle that depends on the MC version alone. Called by RemapCache on a non-mojmap runtime with no mcp.remap.* flags, when no mappings are cached for this version yet.

Link copied to clipboard
private fun buildClasspath(): List<File>

The compile classpath, assembled once. Remap-DEPENDENT: see ReplJars.compileClasspath.

Link copied to clipboard
fun buildSymbols(mcUri: String, mappings: String, outSymbolsDir: String)

Reverse-remap the runtime jar through cached mappings into a mojmap symbol jar: the half of the bundle the loader's binpatches are baked into, and the only half a loader change rebuilds — locally, without the network.

Link copied to clipboard
private fun bukkitPresent(): Boolean

Whether the runtime carries a Bukkit layer at all. A false negative only costs the plugin wait; a false positive waits for a level load, which every server does.

Link copied to clipboard
fun compile(code: String, guardLane: GuardLane?, evalId: Int, abandoned: BooleanSupplier): Any

Compile code to an opaque handle, on COMPILER and nowhere else — pure computation, no game state. The handle is a masking-loaded type the game loader only ever passes back to execute.

Link copied to clipboard
private fun ensureMasking()

Build the masking loader + instantiate the MaskingBridge. Remap-independent, so the preload thread can run it while the remap download is still going. Idempotent.

Link copied to clipboard
fun execute(handle: Any?, code: String, out: Capture): Any

Run a handle from compile and return an exec.Outcome (result text + isError) or, if the snippet's value was a stdlib iterator { ... yield() ... }, an exec.IterEval for the lane to drive one step per tick.

Link copied to clipboard

The masking loader, built once and kept across a failed ensureMasking, its one caller, which holds LOCK.

Link copied to clipboard
internal fun pluginsExpected(): Boolean

Whether plugin jars can reach the compile classpath: a Bukkit layer, on a dedicated server. A client loads its plugins long after the classpath snapshot.

Link copied to clipboard

Called by the remap init (CommonClass) the moment mojmap symbols are ready — or immediately on a mojmap runtime where no remap is needed. Releases the warmup gate's remap half.

Link copied to clipboard

Start the warmup described above: the preload thread, and the gate that awaits both halves as COMPILER's first task. Called once from CommonClass.init. Both run below-normal priority to yield to the game's own startup work; the gate hands the compiler thread back at normal priority, which is what evals compile at.