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
e7f799903e
commit
902942d9e4
2 changed files with 10 additions and 5 deletions
|
@ -5,7 +5,7 @@ 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
|
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
|
--- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
||||||
+++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
+++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
||||||
@@ -0,0 +0,0 @@ public final class JavaPluginLoader implements PluginLoader {
|
@@ -0,0 +0,0 @@ public final class JavaPluginLoader implements PluginLoader {
|
||||||
|
@ -22,16 +22,21 @@ index 8ff228ce..c0884f27 100644
|
||||||
@Nullable
|
@Nullable
|
||||||
Class<?> getClassByName(final String name) {
|
Class<?> getClassByName(final String name) {
|
||||||
+ // Paper start - make MT safe
|
+ // Paper start - make MT safe
|
||||||
|
Class<?> cachedClass = classes.get(name);
|
||||||
|
+ if (cachedClass != null) {
|
||||||
|
+ return cachedClass;
|
||||||
|
+ }
|
||||||
+ java.util.concurrent.locks.ReentrantReadWriteLock lock;
|
+ java.util.concurrent.locks.ReentrantReadWriteLock lock;
|
||||||
+ synchronized (classLoadLock) {
|
+ synchronized (classLoadLock) {
|
||||||
+ lock = classLoadLock.computeIfAbsent(name, (x) -> new java.util.concurrent.locks.ReentrantReadWriteLock());
|
+ lock = classLoadLock.computeIfAbsent(name, (x) -> new java.util.concurrent.locks.ReentrantReadWriteLock());
|
||||||
+ classLoadLockCount.compute(name, (x, prev) -> prev != null ? prev + 1 : 1);
|
+ classLoadLockCount.compute(name, (x, prev) -> prev != null ? prev + 1 : 1);
|
||||||
+ }
|
+ }
|
||||||
+ lock.writeLock().lock();try {
|
+ lock.writeLock().lock();try {
|
||||||
|
+ cachedClass = classes.get(name);
|
||||||
+ // Paper end
|
+ // Paper end
|
||||||
Class<?> cachedClass = classes.get(name);
|
|
||||||
|
|
||||||
if (cachedClass != null) {
|
if (cachedClass != null) {
|
||||||
|
return cachedClass;
|
||||||
@@ -0,0 +0,0 @@ public final class JavaPluginLoader implements PluginLoader {
|
@@ -0,0 +0,0 @@ public final class JavaPluginLoader implements PluginLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ In order to get chunk values, we shouldn't need to create
|
||||||
an optional each time.
|
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
|
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
|
--- a/src/main/java/com/mojang/datafixers/util/Either.java
|
||||||
+++ b/src/main/java/com/mojang/datafixers/util/Either.java
|
+++ b/src/main/java/com/mojang/datafixers/util/Either.java
|
||||||
@@ -0,0 +0,0 @@ public abstract class Either<L, R> implements App<Either.Mu<R>, L> {
|
@@ -0,0 +0,0 @@ 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) {
|
public Left(final L value) {
|
||||||
- this.value = 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
|
@Override
|
||||||
|
@ -41,7 +41,7 @@ index a90adac7b..efae74b71 100644
|
||||||
|
|
||||||
public Right(final R value) {
|
public Right(final R value) {
|
||||||
- this.value = 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
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue