MaskingClassLoader

Classloader for the REPL's Kotlin scripting stack.

It hosts the entire Kotlin scripting stack (kotlin-compiler-embeddable + scripting + stdlib + reflect + script-runtime) plus the REPL impl's own Kotlin classes, on a self-managed URLClassLoader that lives OFF the FML/securejarhandler module path. That is mandatory on NeoForge: putting kotlin-compiler-embeddable on the module path makes securejarhandler throw "Invalid package name: 'native' is not a Java identifier" at boot (the compiler ships a package org.jetbrains.kotlin.native.interop, and native is a Java keyword).

The compiler (org.jetbrains.kotlin.*), the shaded intellij/etc. inside compiler-embeddable, and the REPL impl classes under ...repl.impl.* are ALWAYS child-first (masking-owned). The JDK, MC, and the mod's own non-impl classes are ALWAYS parent-first so they keep a single shared identity with the game loader.

The kotlin RUNTIME (kotlin.* stdlib/reflect) is version-regime dependent

A REPL snippet must exchange kotlin objects (lambdas = Function0, Pair, Sequence, …) with the game's mods, which use the GAME loader's kotlin. If the masking loader defines its OWN copy of those classes, a snippet value is a DIFFERENT class from the mod's parameter type → LinkageError. One shared kotlin identity is the only fully-safe unification, and it needs the versions to line up — hence Regime, overridable with mcp.kotlin.regime=auto|share|split.

A feature that would otherwise need a JVM agent

Because every masking-owned class is defined right here in findClass, this loader is the single door those classes' bytes come through — which makes java.lang.instrument unnecessary for anything scoped to them. So the preload working-set capture works on a JVM launched WITHOUT -Djdk.attach.allowAttachSelf / -XX:+EnableDynamicAgentLoading: definedClassNames answers "what did this loader define?" from its own bookkeeping.

The live-patch engine (Patches.onEnter/onExit) still needs the agent and still dies without those flags: it retransforms already-loaded net.minecraft.* classes on the GAME loader and injects a jar into the bootstrap loader — neither is something a classloader can do for itself.

Parameters

urls

the masking classpath (our extracted kotlin stack + repl.impl + mod jar)

parent

the game loader

Constructors

Link copied to clipboard
internal constructor(urls: Array<URL>, parent: ClassLoader)

Types

Link copied to clipboard
object Companion
Link copied to clipboard

Kotlin-identity regime, decided once from (our bundled kotlin C, the parent/game kotlin P).

Link copied to clipboard
private class SnippetLoader(masking: MaskingClassLoader, val game: ClassLoader, val redirectKotlin: Boolean) : ClassLoader

The whole snippet chain in ONE hop: game-identity names to the game loader, the rest to masking, and only a miss in both retries a hybrid server's plugins (PluginBridge). One loader, not one per concern: every snippet class load walks this, and each level costs a lock + findLoadedClass.

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
private val classes: ArrayList<Class<*>?>?
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
private val defined: MutableSet<String>
Link copied to clipboard
Link copied to clipboard
private val libraries: NativeLibraries?
Link copied to clipboard
open val name: String?
Link copied to clipboard
private val nameAndId: String?
Link copied to clipboard

C packed; -1 if our own urls have no kotlin.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
protected open val packages: Array<out Package?>?
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
private val parentKotlin: Int
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
private val ucp: URLClassPath?
Link copied to clipboard
Link copied to clipboard
open val urLs: Array<out URL?>?

Functions

Link copied to clipboard
open fun addClass(c: Class<*>?)
Link copied to clipboard
protected open fun addURL(url: URL?)
Link copied to clipboard
private open fun checkCerts(name: String?, cs: CodeSource?)
Link copied to clipboard
private fun childFirst(name: String): Class<*>

Our own urls first: the compiler and our own kotlin.

Link copied to clipboard
Link copied to clipboard
open fun close()
Link copied to clipboard
private open fun compareCerts(pcerts: Array<out Certificate?>?, certs: Array<out Certificate?>?): Boolean
Link copied to clipboard
protected fun defineClass(b: ByteArray?, off: Int, len: Int): Class<*>?
protected fun defineClass(name: String?, b: ByteBuffer?, protectionDomain: ProtectionDomain?): Class<*>?
protected fun defineClass(name: String?, b: ByteArray?, off: Int, len: Int): Class<*>?
protected fun defineClass(name: String?, b: ByteArray?, off: Int, len: Int, protectionDomain: ProtectionDomain?): Class<*>?
private open fun defineClass(name: String?, res: Resource?): Class<*>?
protected fun defineClass(name: String?, b: ByteBuffer?, cs: CodeSource?): Class<*>?
protected fun defineClass(name: String?, b: ByteArray?, off: Int, len: Int, cs: CodeSource?): Class<*>?
Link copied to clipboard
Link copied to clipboard

Every binary name this loader has DEFINED (not merely delegated), for the preload working-set capture. findClass is this loader's only definition site.

Link copied to clipboard
open fun definePackage(c: Class<*>?): Package?
open fun definePackage(name: String?, m: Module?): Package?
protected open fun definePackage(name: String?, specTitle: String?, specVersion: String?, specVendor: String?, implTitle: String?, implVersion: String?, implVendor: String?, sealBase: URL?): Package?
protected open fun definePackage(name: String?, man: Manifest?, url: URL?): Package?
Link copied to clipboard
open fun desiredAssertionStatus(className: String?): Boolean
Link copied to clipboard
protected open fun findClass(moduleName: String?, name: String?): Class<*>?

protected open override fun findClass(name: String): Class<*>

Every masking-owned class is defined HERE (see the class doc for what that buys), which is also what makes every successfully defined name recordable for definedClassNames.

Link copied to clipboard
protected open fun findLibrary(libname: String?): String?
Link copied to clipboard
protected fun findLoadedClass(name: String?): Class<*>?
Link copied to clipboard
private external fun findLoadedClass0(p0: String?): Class<*>?
Link copied to clipboard
protected open fun findResource(moduleName: String?, name: String?): URL?
open fun findResource(name: String?): URL?
Link copied to clipboard
open fun findResources(name: String?): Enumeration<URL?>?
Link copied to clipboard
protected fun findSystemClass(name: String?): Class<*>?
Link copied to clipboard
private open fun getAndVerifyPackage(pkgname: String?, man: Manifest?, url: URL?): Package?
Link copied to clipboard
protected open fun getClassLoadingLock(className: String?): Any?
Link copied to clipboard
Link copied to clipboard
private open fun getNamedPackage(pn: String?, m: Module?): NamedPackage?
Link copied to clipboard
protected open fun getPackage(name: String?): Package?
Link copied to clipboard
protected open fun getPermissions(codesource: CodeSource?): PermissionCollection?
Link copied to clipboard
Link copied to clipboard
open override fun getResource(name: String): URL?

Unconditionally child-first, unlike ClassLoader.getResource's parent-first default — and unlike loadClass, which stays parent-first for whole namespaces. KotlinJars locates kotlin-stdlib / -script-runtime / -reflect via Class.getResource("<marker>.class") (JvmStatic / ScriptTemplateWithArgs / KClasses), which routes through THIS loader. Parent-first hands back Forge's copy of the marker, whose class lives under a securejarhandler union: URI that KotlinJars cannot turn into a File → "Unable to find kotlin stdlib". Our urls hold only the kotlin stack + repl.impl (+ the mod jar), so MC/JDK resources still fall through to the parent.

Link copied to clipboard
private open fun getResourceAsByteArray(name: String?): ByteArray?
Link copied to clipboard
Link copied to clipboard
open fun getResources(name: String?): Enumeration<URL?>?
Link copied to clipboard
private open fun initializeJavaAssertionMaps()
Link copied to clipboard
private open fun isSealed(name: String?, man: Manifest?): Boolean
Link copied to clipboard
open fun loadClass(name: String?): Class<*>?
fun loadClass(module: Module?, name: String?): Class<*>?
protected open override fun loadClass(name: String, resolve: Boolean): Class<*>
Link copied to clipboard
private fun locate(name: String): Class<*>
Link copied to clipboard
fun name(): String?
Link copied to clipboard
open fun nameAndId(): String?
Link copied to clipboard
open fun packages(): Stream<Package?>?
Link copied to clipboard

P as "major.minor" for the snippet compiler's -api-version/-language-version in SPLIT; null in SHARE_ALL, where the two kotlins are one and no pin is needed.

Link copied to clipboard
private fun parentFirst(name: String): Class<*>

One kotlin identity with the mods; falls back to our own copy for anything the parent lacks — or can no longer answer for, its loader being closed (see SnippetLoader.load).

Link copied to clipboard
private open fun postDefineClass(c: Class<*>?, pd: ProtectionDomain?)
Link copied to clipboard
private open fun preDefineClass(name: String?, pd: ProtectionDomain?): ProtectionDomain?
Link copied to clipboard
Link copied to clipboard
private open fun reinitObjectField(name: String?, obj: Any?)
Link copied to clipboard
private open fun resetArchivedStates()
private open fun resetArchivedStates()
Link copied to clipboard
protected fun resolveClass(c: Class<*>?)
Link copied to clipboard
open fun resources(name: String?): Stream<URL?>?
Link copied to clipboard
open fun setClassAssertionStatus(className: String?, enabled: Boolean)
Link copied to clipboard
Link copied to clipboard
open fun setPackageAssertionStatus(packageName: String?, enabled: Boolean)
Link copied to clipboard
protected fun setSigners(c: Class<*>?, signers: Array<out Any?>?)
Link copied to clipboard

Parent loader for a compiled snippet: a single SnippetLoader over masking. ReplHost passes this as the eval baseClassLoader.

Link copied to clipboard
private open fun toPackage(name: String?, p: NamedPackage?, m: Module?): Package?
Link copied to clipboard
private open fun trySetObjectField(name: String?, obj: Any?): Boolean