From 24d93aafa2fd62b38c5c73ad31c117a7e2c730ef Mon Sep 17 00:00:00 2001 From: Aikar Date: Thu, 16 Apr 2020 03:57:02 -0400 Subject: [PATCH] Fix Optional null issue - Fixes #3155 Also check class loader cache before locking to speed up cached hits to avoid the lock wasn't gonna make a unique build just for that but can lump it in here. --- .../0196-Make-JavaPluginLoader-thread-safe.patch | 15 ++++++++++----- .../0472-Reduce-Either-Optional-allocation.patch | 8 ++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Spigot-API-Patches/0196-Make-JavaPluginLoader-thread-safe.patch b/Spigot-API-Patches/0196-Make-JavaPluginLoader-thread-safe.patch index a2a00d142..61f47853a 100644 --- a/Spigot-API-Patches/0196-Make-JavaPluginLoader-thread-safe.patch +++ b/Spigot-API-Patches/0196-Make-JavaPluginLoader-thread-safe.patch @@ -1,11 +1,11 @@ -From eae57c232e30ee963d3ca6f69a5dc10179be5858 Mon Sep 17 00:00:00 2001 +From 8ee6c03819b3128a206f5a5a73002bd719baf25b Mon Sep 17 00:00:00 2001 From: Trigary Date: Wed, 15 Apr 2020 01:24:55 -0400 Subject: [PATCH] Make JavaPluginLoader thread-safe diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java -index 8ff228ce..c0884f27 100644 +index 8ff228ce..ba2c5c6e 100644 --- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -52,6 +52,8 @@ public final class JavaPluginLoader implements PluginLoader { @@ -17,22 +17,27 @@ index 8ff228ce..c0884f27 100644 private final List loaders = new CopyOnWriteArrayList(); /** -@@ -191,6 +193,14 @@ public final class JavaPluginLoader implements PluginLoader { +@@ -191,7 +193,19 @@ public final class JavaPluginLoader implements PluginLoader { @Nullable Class getClassByName(final String name) { + // Paper start - make MT safe + Class cachedClass = classes.get(name); ++ if (cachedClass != null) { ++ return cachedClass; ++ } + java.util.concurrent.locks.ReentrantReadWriteLock lock; + synchronized (classLoadLock) { + lock = classLoadLock.computeIfAbsent(name, (x) -> new java.util.concurrent.locks.ReentrantReadWriteLock()); + classLoadLockCount.compute(name, (x, prev) -> prev != null ? prev + 1 : 1); + } + lock.writeLock().lock();try { ++ cachedClass = classes.get(name); + // Paper end - Class cachedClass = classes.get(name); if (cachedClass != null) { -@@ -205,6 +215,19 @@ public final class JavaPluginLoader implements PluginLoader { + return cachedClass; +@@ -205,6 +219,19 @@ public final class JavaPluginLoader implements PluginLoader { } } } diff --git a/Spigot-Server-Patches/0472-Reduce-Either-Optional-allocation.patch b/Spigot-Server-Patches/0472-Reduce-Either-Optional-allocation.patch index d99a4e2f8..b6c6837ec 100644 --- a/Spigot-Server-Patches/0472-Reduce-Either-Optional-allocation.patch +++ b/Spigot-Server-Patches/0472-Reduce-Either-Optional-allocation.patch @@ -1,4 +1,4 @@ -From e5ba87668be36b649b80633170a33e7ad3fae019 Mon Sep 17 00:00:00 2001 +From f05a44606eb3f3467c092da8ade51d8de1220561 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Mon, 6 Apr 2020 18:35:09 -0700 Subject: [PATCH] Reduce Either Optional allocation @@ -7,7 +7,7 @@ In order to get chunk values, we shouldn't need to create an optional each time. diff --git a/src/main/java/com/mojang/datafixers/util/Either.java b/src/main/java/com/mojang/datafixers/util/Either.java -index a90adac7b..efae74b71 100644 +index a90adac7b..4bb621d57 100644 --- a/src/main/java/com/mojang/datafixers/util/Either.java +++ b/src/main/java/com/mojang/datafixers/util/Either.java @@ -22,10 +22,10 @@ public abstract class Either implements App, L> { @@ -19,7 +19,7 @@ index a90adac7b..efae74b71 100644 public Left(final L value) { - this.value = value; -+ this.value = value; this.valueOptional = Optional.of(value); // Paper - reduce the optional allocation... ++ this.value = value; this.valueOptional = value != null ? Optional.of(value) : Optional.empty(); // Paper - reduce the optional allocation... } @Override @@ -41,7 +41,7 @@ index a90adac7b..efae74b71 100644 public Right(final R value) { - this.value = value; -+ this.value = value; this.valueOptional = Optional.of(value); // Paper - reduce the optional allocation... ++ this.value = value; this.valueOptional = value != null ? Optional.of(value) : Optional.empty(); // Paper - reduce the optional allocation... } @Override