mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-10-22 08:07:42 +00:00
Release runtime statics
- Null Iris.instance, the console sender, the Multiverse link, the compat set and the chunk tickets at the end of teardownRuntime - Bind the host bridge suppliers to the constructing plugin instead of reading the instance static on every call - State that Iris is disabled when service, getTemp or getSender is reached after teardown instead of raising a bare NullPointerException - Add IrisRuntimeStatics so a disable drops the service registry, both capability singletons, the loaded datapack runtime and the localization roots - Add WorldLifecycleService.reset and WorldRuntimeControlService.reset so the next boot snapshots the server it is running on - Add ServerConfigurator.resetLoadedDatapackRuntime so an enable revalidates instead of trusting the previous boot's fingerprint - Clear the localization data folder and plain-text memo on shutdown - Add BukkitPlatform.releaseHost and call it last in terminal cleanup so the disabled plugin, console sender and log bridge stop being reachable from a static
This commit is contained in:
1 parent
f83cf71b11
commit
6c6dba0232
10 files changed
+197
-13
No files matched your search
@@ -158,6 +158,20 @@ public class ServerConfigurator {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forgets what the previous boot loaded, so an enable in the same JVM recompiles and revalidates rather
|
||||
* than trusting a fingerprint taken against a server that is gone.
|
||||
*/
|
||||
public static void resetLoadedDatapackRuntime() {
|
||||
synchronized (DATAPACK_INSTALL_LOCK) {
|
||||
loadedDatapackRuntimeReady = false;
|
||||
loadedDatapackCompilerInputFingerprint = "";
|
||||
loadedDatapackRegistryRequirements = Map.of();
|
||||
loadedDatapackRuntimeGeneration++;
|
||||
loadedDatapackRestartRequired = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static LoadedDatapackRuntimeInvalidation invalidateLoadedDatapackRuntime() {
|
||||
synchronized (DATAPACK_INSTALL_LOCK) {
|
||||
boolean wasReady = loadedDatapackRuntimeReady;
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package art.arcane.iris.core.lifecycle;
|
||||
|
||||
import art.arcane.iris.core.ServerConfigurator;
|
||||
import art.arcane.iris.core.localization.IrisLanguage;
|
||||
import art.arcane.iris.core.runtime.WorldRuntimeControlService;
|
||||
import art.arcane.iris.spi.IrisServices;
|
||||
|
||||
/**
|
||||
* Drops every process-wide cache core keeps about the running server, so a disable leaves nothing an
|
||||
* enable in the same JVM could answer from.
|
||||
* <p>
|
||||
* The capability singletons are the reason this exists: each holds reflective handles onto the live
|
||||
* CraftServer and MinecraftServer, and a boot that reused them would be talking to the previous server's
|
||||
* objects. The platform binding itself is not cleared here - core still logs through it while the adapter
|
||||
* finishes its own teardown - and is unbound last by the adapter.
|
||||
*/
|
||||
public final class IrisRuntimeStatics {
|
||||
private IrisRuntimeStatics() {
|
||||
}
|
||||
|
||||
public static void reset() {
|
||||
IrisServices.clear();
|
||||
WorldLifecycleService.reset();
|
||||
WorldRuntimeControlService.reset();
|
||||
ServerConfigurator.resetLoadedDatapackRuntime();
|
||||
IrisLanguage.shutdown();
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,15 @@ public final class WorldLifecycleService {
|
||||
this.worldBackendByKey = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops the cached snapshot so the next boot in this JVM builds one against the server it is running on.
|
||||
*/
|
||||
public static void reset() {
|
||||
synchronized (WorldLifecycleService.class) {
|
||||
instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static WorldLifecycleService get() {
|
||||
WorldLifecycleService current = instance;
|
||||
if (current != null) {
|
||||
|
||||
@@ -429,6 +429,8 @@ public final class IrisLanguage {
|
||||
}
|
||||
|
||||
public static synchronized void shutdown() {
|
||||
dataFolder = null;
|
||||
PLAIN_MEMO.set(null);
|
||||
PluginLanguageService current = selections;
|
||||
selections = null;
|
||||
if (current != null) {
|
||||
|
||||
@@ -76,6 +76,15 @@ public final class WorldRuntimeControlService {
|
||||
+ ", " + backend.describeCapabilities();
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops the cached snapshot so the next boot in this JVM builds one against the server it is running on.
|
||||
*/
|
||||
public static void reset() {
|
||||
synchronized (WorldRuntimeControlService.class) {
|
||||
instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static WorldRuntimeControlService get() {
|
||||
WorldRuntimeControlService current = instance;
|
||||
if (current != null) {
|
||||
|
||||
@@ -50,6 +50,7 @@ final class DecoratorCore {
|
||||
|
||||
static final ThreadLocal<PlaceOpts> SCRATCH_OPTS = ThreadLocal.withInitial(PlaceOpts::new);
|
||||
|
||||
|
||||
static final class PlaceOpts {
|
||||
boolean caveSkipFluid;
|
||||
boolean underwater;
|
||||
|
||||
@@ -103,6 +103,19 @@ public final class BukkitPlatform implements IrisPlatform {
|
||||
PLUGIN = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops every reference this class holds to the disabled plugin. Called last in the adapter's teardown,
|
||||
* after core has stopped logging through the host bridge, so a disabled plugin instance is not reachable
|
||||
* from a static for the life of the JVM.
|
||||
*/
|
||||
public static void releaseHost() {
|
||||
PLUGIN = null;
|
||||
HUD_BAR = null;
|
||||
HUD_LANES = null;
|
||||
CONSOLE = null;
|
||||
BRIDGE = null;
|
||||
}
|
||||
|
||||
public static Plugin plugin() {
|
||||
Plugin plugin = PLUGIN;
|
||||
if (plugin == null) {
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package art.arcane.iris.core.lifecycle;
|
||||
|
||||
import art.arcane.iris.core.runtime.WorldRuntimeControlService;
|
||||
import art.arcane.iris.spi.IrisServices;
|
||||
import art.arcane.iris.testsupport.BukkitTestServer;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* Iris keeps process-wide caches that describe the running server: the service registry, and the lifecycle
|
||||
* and runtime-control singletons that each hold a capability snapshot of reflective handles onto the live
|
||||
* server. Nothing cleared them on disable, so a re-enable in the same JVM kept answering from the previous
|
||||
* boot's snapshot.
|
||||
*/
|
||||
public class IrisRuntimeStaticsTest {
|
||||
@Before
|
||||
public void installServer() {
|
||||
BukkitTestServer.install();
|
||||
}
|
||||
|
||||
@After
|
||||
public void clearStatics() {
|
||||
IrisRuntimeStatics.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resetUnbindsEveryRegisteredService() {
|
||||
Runnable service = () -> {
|
||||
};
|
||||
IrisServices.register(Runnable.class, service);
|
||||
|
||||
IrisRuntimeStatics.reset();
|
||||
|
||||
assertNull(IrisServices.getOrNull(Runnable.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resetDropsTheCachedCapabilitySingletons() {
|
||||
WorldLifecycleService lifecycle = WorldLifecycleService.get();
|
||||
WorldRuntimeControlService control = WorldRuntimeControlService.get();
|
||||
|
||||
IrisRuntimeStatics.reset();
|
||||
|
||||
assertNotSame(lifecycle, WorldLifecycleService.get());
|
||||
assertNotSame(control, WorldRuntimeControlService.get());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package art.arcane.iris.platform.bukkit;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* The host statics are how core reaches the plugin. Nothing cleared them on disable, so the disabled
|
||||
* plugin instance, its console sender and its log bridge stayed reachable from a static for the life of
|
||||
* the JVM.
|
||||
*/
|
||||
public class BukkitPlatformHostReleaseTest {
|
||||
@After
|
||||
public void clearHost() {
|
||||
BukkitPlatform.releaseHost();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void releasingTheHostDropsThePluginAndTheHud() {
|
||||
BukkitPlatform.hostPlugin(mock(Plugin.class));
|
||||
|
||||
BukkitPlatform.releaseHost();
|
||||
|
||||
assertFalse(BukkitPlatform.hasPlugin());
|
||||
assertFalse(BukkitPlatform.hasHud());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user