diff --git a/patches/server/Add-setting-for-proxy-online-mode-status.patch b/patches/server/Add-setting-for-proxy-online-mode-status.patch index b11699521a..3215842db8 100644 --- a/patches/server/Add-setting-for-proxy-online-mode-status.patch +++ b/patches/server/Add-setting-for-proxy-online-mode-status.patch @@ -51,7 +51,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + return com.destroystokyo.paper.PaperConfig.isProxyOnlineMode(); // Paper } - public synchronized void add(GameProfile profile) { // Paper - synchronize + public void add(GameProfile profile) { diff --git a/src/main/java/net/minecraft/server/players/OldUsersConverter.java b/src/main/java/net/minecraft/server/players/OldUsersConverter.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/players/OldUsersConverter.java diff --git a/patches/server/Optimize-UserCache-Thread-Safe.patch b/patches/server/Async-GameProfileCache-saving.patch similarity index 75% rename from patches/server/Optimize-UserCache-Thread-Safe.patch rename to patches/server/Async-GameProfileCache-saving.patch index ff1f5e3945..b8e18acaf8 100644 --- a/patches/server/Optimize-UserCache-Thread-Safe.patch +++ b/patches/server/Async-GameProfileCache-saving.patch @@ -1,15 +1,8 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Aikar Date: Mon, 16 May 2016 20:47:41 -0400 -Subject: [PATCH] Optimize UserCache / Thread Safe +Subject: [PATCH] Async GameProfileCache saving -Because Techable keeps complaining about how this isn't thread safe, -easier to do this than replace the entire thing. - -Additionally, move Saving of the User cache to be done async, incase -the user never changed the default setting for Spigot's save on stop only. - -1.17: TODO does this need the synchronized blocks anymore? diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 @@ -41,15 +34,6 @@ diff --git a/src/main/java/net/minecraft/server/players/GameProfileCache.java b/ index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/players/GameProfileCache.java +++ b/src/main/java/net/minecraft/server/players/GameProfileCache.java -@@ -0,0 +0,0 @@ public class GameProfileCache { - return GameProfileCache.usesAuthentication; - } - -- public void add(GameProfile profile) { -+ public synchronized void add(GameProfile profile) { // Paper - synchronize - Calendar calendar = Calendar.getInstance(); - - calendar.setTime(new Date()); @@ -0,0 +0,0 @@ public class GameProfileCache { GameProfileCache.GameProfileInfo usercache_usercacheentry = new GameProfileCache.GameProfileInfo(profile, date); @@ -59,14 +43,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } private long getNextOperation() { - return this.operationCount.incrementAndGet(); - } - -- public Optional get(String name) { -+ public synchronized Optional get(String name) { // Paper - synchronize - String s1 = name.toLowerCase(Locale.ROOT); - GameProfileCache.GameProfileInfo usercache_usercacheentry = (GameProfileCache.GameProfileInfo) this.profilesByName.get(s1); - boolean flag = false; @@ -0,0 +0,0 @@ public class GameProfileCache { } @@ -97,7 +73,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } catch (IOException ioexception) { ; } -- + // Paper start + }; + if (asyncSave) { @@ -106,6 +81,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + save.run(); + } + // Paper end + } - private Stream getTopMRUProfiles(int limit) { diff --git a/patches/server/Basic-PlayerProfile-API.patch b/patches/server/Basic-PlayerProfile-API.patch index e1cfabc408..aeb760dfde 100644 --- a/patches/server/Basic-PlayerProfile-API.patch +++ b/patches/server/Basic-PlayerProfile-API.patch @@ -607,7 +607,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } + // Paper start -+ @Nullable public GameProfile getProfileIfCached(String name) { ++ public @Nullable GameProfile getProfileIfCached(String name) { + GameProfileCache.GameProfileInfo entry = this.profilesByName.get(name.toLowerCase(Locale.ROOT)); + if (entry == null) { + return null; @@ -617,7 +617,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + // Paper end + - public synchronized Optional get(String name) { // Paper - synchronize + public Optional get(String name) { String s1 = name.toLowerCase(Locale.ROOT); GameProfileCache.GameProfileInfo usercache_usercacheentry = (GameProfileCache.GameProfileInfo) this.profilesByName.get(s1); diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java diff --git a/patches/server/Separate-lookup-locking-from-state-access-in-UserCac.patch b/patches/server/Fix-GameProfileCache-concurrency.patch similarity index 87% rename from patches/server/Separate-lookup-locking-from-state-access-in-UserCac.patch rename to patches/server/Fix-GameProfileCache-concurrency.patch index 6faef29e7e..18b800af69 100644 --- a/patches/server/Separate-lookup-locking-from-state-access-in-UserCac.patch +++ b/patches/server/Fix-GameProfileCache-concurrency.patch @@ -1,9 +1,10 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Sat, 11 Jul 2020 05:09:28 -0700 -Subject: [PATCH] Separate lookup locking from state access in UserCache +Subject: [PATCH] Fix GameProfileCache concurrency -Prevent lookups from stalling simple state access/write calls +Separate lookup and state access locks prevent lookups +from stalling simple state access/write calls diff --git a/src/main/java/net/minecraft/server/players/GameProfileCache.java b/src/main/java/net/minecraft/server/players/GameProfileCache.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 @@ -37,19 +38,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } -@@ -0,0 +0,0 @@ public class GameProfileCache { - return com.destroystokyo.paper.PaperConfig.isProxyOnlineMode(); // Paper - } - -- public synchronized void add(GameProfile profile) { // Paper - synchronize -+ public void add(GameProfile profile) { // Paper - synchronize // Paper - allow better concurrency - Calendar calendar = Calendar.getInstance(); - - calendar.setTime(new Date()); @@ -0,0 +0,0 @@ public class GameProfileCache { // Paper start - @Nullable public GameProfile getProfileIfCached(String name) { + public @Nullable GameProfile getProfileIfCached(String name) { + try { this.stateLock.lock(); // Paper - allow better concurrency GameProfileCache.GameProfileInfo entry = this.profilesByName.get(name.toLowerCase(Locale.ROOT)); if (entry == null) { @@ -61,8 +53,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } // Paper end -- public synchronized Optional get(String name) { // Paper - synchronize -+ public Optional get(String name) { // Paper - synchronize // Paper start - allow better concurrency + public Optional get(String name) { String s1 = name.toLowerCase(Locale.ROOT); + boolean stateLocked = true; try { this.stateLock.lock(); // Paper - allow better concurrency GameProfileCache.GameProfileInfo usercache_usercacheentry = (GameProfileCache.GameProfileInfo) this.profilesByName.get(s1);