mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 02:55:47 +01:00
c97ce029e9
PaperMC believes that 1.16.2 is now ready for general release as we fixed the main issue plagueing the 1.16.x release, the MapLike data conversion issues. Until now, it was not safe for a server to convert a world to 1.16.2 without data conversion issues around villages and potentially other things. If you did, those MapLike errors meant something went wrong. This is now resolved. Big thanks to all those that helped, notably @BillyGalbreath and @Proximyst who did large parts of the update process with me. Please as always, backup your worlds and test before updating to 1.16.2! If you update to 1.16.2, there is no going back to an older build than this. --------------------------------- Co-authored-by: William Blake Galbreath <Blake.Galbreath@GMail.com> Co-authored-by: Mariell Hoversholm <proximyst@proximyst.com> Co-authored-by: krolik-exe <69214078+krolik-exe@users.noreply.github.com> Co-authored-by: BillyGalbreath <BillyGalbreath@users.noreply.github.com> Co-authored-by: stonar96 <minecraft.stonar96@gmail.com> Co-authored-by: Shane Freeder <theboyetronic@gmail.com> Co-authored-by: Jason <jasonpenilla2@me.com> Co-authored-by: kashike <kashike@vq.lc> Co-authored-by: Aurora <21148213+aurorasmiles@users.noreply.github.com> Co-authored-by: KennyTV <kennytv@t-online.de> Co-authored-by: commandblockguy <commandblockguy1@gmail.com> Co-authored-by: DigitalRegent <misterwener@gmail.com> Co-authored-by: ishland <ishlandmc@yeah.net>
60 lines
2.7 KiB
Diff
60 lines
2.7 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Trigary <trigary0@gmail.com>
|
|
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 de44d850d7b3ab3e528eb6f2de375a6c3e0e5cf9..9d1f7cdf12029c8198792fd299f92be476040222 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 {
|
|
final Server server;
|
|
private final Pattern[] fileFilters = new Pattern[]{Pattern.compile("\\.jar$")};
|
|
private final Map<String, Class<?>> classes = new ConcurrentHashMap<String, Class<?>>();
|
|
+ private final Map<String, java.util.concurrent.locks.ReentrantReadWriteLock> classLoadLock = new java.util.HashMap<String, java.util.concurrent.locks.ReentrantReadWriteLock>(); // Paper
|
|
+ private final Map<String, Integer> classLoadLockCount = new java.util.HashMap<String, Integer>(); // Paper
|
|
private final List<PluginClassLoader> loaders = new CopyOnWriteArrayList<PluginClassLoader>();
|
|
|
|
/**
|
|
@@ -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
|
|
|
|
if (cachedClass != null) {
|
|
return cachedClass;
|
|
@@ -205,6 +219,19 @@ public final class JavaPluginLoader implements PluginLoader {
|
|
}
|
|
}
|
|
}
|
|
+ // Paper start - make MT safe
|
|
+ } finally {
|
|
+ synchronized (classLoadLock) {
|
|
+ lock.writeLock().unlock();
|
|
+ if (classLoadLockCount.get(name) == 1) {
|
|
+ classLoadLock.remove(name);
|
|
+ classLoadLockCount.remove(name);
|
|
+ } else {
|
|
+ classLoadLockCount.compute(name, (x, prev) -> prev - 1);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ // Paper end
|
|
return null;
|
|
}
|
|
|