mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-01 17:01:56 +01:00
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.
This commit is contained in:
parent
eb71c5fa3b
commit
24d93aafa2
2 changed files with 14 additions and 9 deletions
|
@ -1,11 +1,11 @@
|
|||
From eae57c232e30ee963d3ca6f69a5dc10179be5858 Mon Sep 17 00:00:00 2001
|
||||
From 8ee6c03819b3128a206f5a5a73002bd719baf25b 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 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<PluginClassLoader> loaders = new CopyOnWriteArrayList<PluginClassLoader>();
|
||||
|
||||
/**
|
||||
@@ -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 {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
From e5ba87668be36b649b80633170a33e7ad3fae019 Mon Sep 17 00:00:00 2001
|
||||
From f05a44606eb3f3467c092da8ade51d8de1220561 Mon Sep 17 00:00:00 2001
|
||||
From: Spottedleaf <spottedleaf@spottedleaf.dev>
|
||||
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<L, R> implements App<Either.Mu<R>, 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
|
||||
|
|
Loading…
Reference in a new issue