spigot/CraftBukkit-Patches/0091-Remove-DataWatcher-Locking.patch

157 lines
5.8 KiB
Diff
Raw Normal View History

From 8aa5f51d925f4f934f1cf29d6883997c00b3ebc7 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Tue, 9 Jul 2019 02:18:54 -0700
Subject: [PATCH] Remove DataWatcher Locking
The lock in DataWatcher is used to prevent concurrent modifications,
however any modifications to this map only occur on initialization of
an Entity in its constructor.
Every other access is through a readlock, which allows the threads to
pass if there is no thread holding the writelock.
Since the writelock is only obtained in the constructor of the Entity,
the further readlocks are actually useless.
This patch also changes the entries map to be fastutil
int2objectopenhashmap for performance.
2021-03-16 09:00:00 +11:00
diff --git a/src/main/java/net/minecraft/network/syncher/DataWatcher.java b/src/main/java/net/minecraft/network/syncher/DataWatcher.java
2021-06-11 15:00:00 +10:00
index 67fd60179..60e3628fe 100644
2021-03-16 09:00:00 +11:00
--- a/src/main/java/net/minecraft/network/syncher/DataWatcher.java
+++ b/src/main/java/net/minecraft/network/syncher/DataWatcher.java
2021-06-11 15:00:00 +10:00
@@ -32,7 +32,7 @@ public class DataWatcher {
private static final int MAX_ID_VALUE = 254;
2019-07-20 09:00:00 +10:00
private final Entity entity;
2021-06-11 15:00:00 +10:00
private final Int2ObjectMap<DataWatcher.Item<?>> itemsById = new Int2ObjectOpenHashMap();
2019-07-20 09:00:00 +10:00
- private final ReadWriteLock lock = new ReentrantReadWriteLock();
+ // private final ReadWriteLock lock = new ReentrantReadWriteLock(); // Spigot - not required
2021-06-11 15:00:00 +10:00
private boolean isEmpty = true;
private boolean isDirty;
2021-06-11 15:00:00 +10:00
@@ -80,7 +80,9 @@ public class DataWatcher {
}
}
2021-03-16 09:00:00 +11:00
+ public boolean registrationLocked; // Spigot
public <T> void register(DataWatcherObject<T> datawatcherobject, T t0) {
+ if (this.registrationLocked) throw new IllegalStateException("Registering datawatcher object after entity initialization"); // Spigot
int i = datawatcherobject.a();
if (i > 254) {
2021-06-11 15:00:00 +10:00
@@ -99,13 +101,15 @@ public class DataWatcher {
private <T> void registerObject(DataWatcherObject<T> datawatcherobject, T t0) {
DataWatcher.Item<T> datawatcher_item = new DataWatcher.Item<>(datawatcherobject, t0);
2019-07-20 09:00:00 +10:00
- this.lock.writeLock().lock();
+ // this.lock.writeLock().lock(); // Spigot - not required
2021-06-11 15:00:00 +10:00
this.itemsById.put(datawatcherobject.a(), datawatcher_item);
this.isEmpty = false;
2019-07-20 09:00:00 +10:00
- this.lock.writeLock().unlock();
+ // this.lock.writeLock().unlock(); // Spigot - not required
}
private <T> DataWatcher.Item<T> b(DataWatcherObject<T> datawatcherobject) {
+ // Spigot start
+ /*
2019-07-20 09:00:00 +10:00
this.lock.readLock().lock();
DataWatcher.Item datawatcher_item;
2021-06-11 15:00:00 +10:00
@@ -123,6 +127,9 @@ public class DataWatcher {
}
return datawatcher_item;
+ */
2021-06-11 15:00:00 +10:00
+ return (DataWatcher.Item) this.itemsById.get(datawatcherobject.a());
+ // Spigot end
}
public <T> T get(DataWatcherObject<T> datawatcherobject) {
2021-06-11 15:00:00 +10:00
@@ -171,7 +178,7 @@ public class DataWatcher {
List<DataWatcher.Item<?>> list = null;
2021-06-11 15:00:00 +10:00
if (this.isDirty) {
2019-07-20 09:00:00 +10:00
- this.lock.readLock().lock();
+ // this.lock.readLock().lock(); // Spigot - not required
2021-06-11 15:00:00 +10:00
ObjectIterator objectiterator = this.itemsById.values().iterator();
2021-06-11 15:00:00 +10:00
while (objectiterator.hasNext()) {
@@ -187,7 +194,7 @@ public class DataWatcher {
}
}
2019-07-20 09:00:00 +10:00
- this.lock.readLock().unlock();
+ // this.lock.readLock().unlock(); // Spigot - not required
}
2021-06-11 15:00:00 +10:00
this.isDirty = false;
@@ -198,7 +205,7 @@ public class DataWatcher {
public List<DataWatcher.Item<?>> getAll() {
List<DataWatcher.Item<?>> list = null;
2019-07-20 09:00:00 +10:00
- this.lock.readLock().lock();
+ // this.lock.readLock().lock(); // Spigot - not required
DataWatcher.Item datawatcher_item;
2021-06-11 15:00:00 +10:00
@@ -209,7 +216,7 @@ public class DataWatcher {
}
}
2019-07-20 09:00:00 +10:00
- this.lock.readLock().unlock();
+ // this.lock.readLock().unlock(); // Spigot - not required
return list;
}
2021-06-11 15:00:00 +10:00
@@ -255,7 +262,7 @@ public class DataWatcher {
}
public void a(List<DataWatcher.Item<?>> list) {
- this.lock.writeLock().lock();
+ // this.lock.writeLock().lock(); // Spigot - not required
try {
Iterator iterator = list.iterator();
@@ -270,7 +277,7 @@ public class DataWatcher {
}
}
} finally {
- this.lock.writeLock().unlock();
+ // this.lock.writeLock().unlock(); // Spigot - not required
}
this.isDirty = true;
@@ -290,7 +297,7 @@ public class DataWatcher {
public void e() {
2021-06-11 15:00:00 +10:00
this.isDirty = false;
2019-07-20 09:00:00 +10:00
- this.lock.readLock().lock();
+ // this.lock.readLock().lock(); // Spigot - not required
2021-06-11 15:00:00 +10:00
ObjectIterator objectiterator = this.itemsById.values().iterator();
2021-06-11 15:00:00 +10:00
while (objectiterator.hasNext()) {
@@ -299,7 +306,7 @@ public class DataWatcher {
datawatcher_item.a(false);
}
2019-07-20 09:00:00 +10:00
- this.lock.readLock().unlock();
+ // this.lock.readLock().unlock(); // Spigot - not required
}
public static class Item<T> {
2021-03-16 09:00:00 +11:00
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
2021-08-15 08:08:25 +10:00
index e3a739448..c1d157293 100644
2021-03-16 09:00:00 +11:00
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
2021-08-15 08:08:25 +10:00
@@ -338,6 +338,7 @@ public abstract class Entity implements INamableTileEntity, EntityAccess, IComma
2021-06-11 15:00:00 +10:00
this.entityData.register(Entity.DATA_POSE, EntityPose.STANDING);
this.entityData.register(Entity.DATA_TICKS_FROZEN, 0);
this.initDatawatcher();
2021-03-16 09:00:00 +11:00
+ this.getDataWatcher().registrationLocked = true; // Spigot
2021-06-11 15:00:00 +10:00
this.setPosition(0.0D, 0.0D, 0.0D);
this.eyeHeight = this.getHeadHeight(EntityPose.STANDING, this.dimensions);
}
--
2.25.1