Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-15 11:00:06 +01:00
Improve synchronization on ExpiringMap
Dieser Commit ist enthalten in:
Ursprung
60b1ed9c76
Commit
1db10a30db
@ -1,4 +1,4 @@
|
||||
From e9f487b844501e35de9892cd88dfb2c85835b8f9 Mon Sep 17 00:00:00 2001
|
||||
From 8fc3810e70f40446333e8ff71983e7c238afcac3 Mon Sep 17 00:00:00 2001
|
||||
From: Aikar <aikar@aikar.co>
|
||||
Date: Sun, 16 Sep 2018 00:00:16 -0400
|
||||
Subject: [PATCH] Optimize and Fix ExpiringMap Issues
|
||||
@ -14,10 +14,10 @@ manipulation, and instead to run clean
|
||||
once per tick per active expiring map.
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/ExpiringMap.java b/src/main/java/net/minecraft/server/ExpiringMap.java
|
||||
index 4006f5a69c..9a3b35ea1a 100644
|
||||
index 4006f5a69c..127de5c8df 100644
|
||||
--- a/src/main/java/net/minecraft/server/ExpiringMap.java
|
||||
+++ b/src/main/java/net/minecraft/server/ExpiringMap.java
|
||||
@@ -2,29 +2,124 @@ package net.minecraft.server;
|
||||
@@ -2,38 +2,163 @@ package net.minecraft.server;
|
||||
|
||||
import it.unimi.dsi.fastutil.longs.Long2LongLinkedOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.longs.Long2LongMap;
|
||||
@ -42,21 +42,32 @@ index 4006f5a69c..9a3b35ea1a 100644
|
||||
this.a = j;
|
||||
}
|
||||
|
||||
- private void a(long i) {
|
||||
+ // Paper start
|
||||
+ private void setAccess(long i) { a(i); } // Paper - OBFHELPER
|
||||
private void a(long i) {
|
||||
- long j = SystemUtils.b();
|
||||
- this.b.put(i, j);
|
||||
- ObjectIterator objectiterator = this.b.long2LongEntrySet().iterator();
|
||||
+ // Paper start
|
||||
+ private synchronized void setAccess(long i) { a(i); } // Paper - OBFHELPER
|
||||
+ private synchronized void a(long i) {
|
||||
-
|
||||
- while(objectiterator.hasNext()) {
|
||||
- Entry entry = (Entry)objectiterator.next();
|
||||
- Object object = super.get(entry.getLongKey());
|
||||
- if (j - entry.getLongValue() <= (long)this.a) {
|
||||
- break;
|
||||
+ synchronized (this.sync) {
|
||||
+ long j = System.currentTimeMillis(); // Paper
|
||||
+ this.ttl.put(i, j);
|
||||
+ if (!registered) {
|
||||
+ registered = true;
|
||||
+ MinecraftServer.getServer().expiringMaps.add(this);
|
||||
}
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
|
||||
- if (object != null && this.a(object)) {
|
||||
- super.remove(entry.getLongKey());
|
||||
- objectiterator.remove();
|
||||
- }
|
||||
+ @Override
|
||||
+ public T compute(long l, BiFunction<? super Long, ? super T, ? extends T> biFunction) {
|
||||
+ setAccess(l);
|
||||
@ -130,34 +141,34 @@ index 4006f5a69c..9a3b35ea1a 100644
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public synchronized void clear() {
|
||||
+ public void clear() {
|
||||
+ synchronized (this.sync) {
|
||||
+ ttl.clear();
|
||||
+ super.clear();
|
||||
}
|
||||
+ }
|
||||
+
|
||||
|
||||
+ private boolean registered = false;
|
||||
+ private boolean hasLeaked = false;
|
||||
+
|
||||
+ // Break clean to its own method to be ticked
|
||||
+ synchronized boolean clean() {
|
||||
+ boolean clean() {
|
||||
+ synchronized (this.sync) {
|
||||
+ long now = System.currentTimeMillis();
|
||||
+ ObjectIterator<Long2LongMap.Entry> objectiterator = this.ttl.long2LongEntrySet().iterator(); // Paper
|
||||
|
||||
while(objectiterator.hasNext()) {
|
||||
- Entry entry = (Entry)objectiterator.next();
|
||||
- Object object = super.get(entry.getLongKey());
|
||||
- if (j - entry.getLongValue() <= (long)this.a) {
|
||||
+
|
||||
+ while (objectiterator.hasNext()) {
|
||||
+ Long2LongMap.Entry entry = objectiterator.next(); // Paper
|
||||
+ T object = super.get(entry.getLongKey()); // Paper
|
||||
+ if (now - entry.getLongValue() <= (long)this.a) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -33,7 +128,29 @@ public class ExpiringMap<T> extends Long2ObjectOpenHashMap<T> {
|
||||
objectiterator.remove();
|
||||
}
|
||||
}
|
||||
-
|
||||
+ if (now - entry.getLongValue() <= (long) this.a) {
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ if (object != null && this.a(object)) {
|
||||
+ super.remove(entry.getLongKey());
|
||||
+ objectiterator.remove();
|
||||
+ }
|
||||
+ }
|
||||
+ int ttlSize = this.ttl.size();
|
||||
+ int thisSize = this.size();
|
||||
+ if (ttlSize < thisSize) {
|
||||
@ -169,22 +180,25 @@ index 4006f5a69c..9a3b35ea1a 100644
|
||||
+ for (Entry<T> entry : this.long2ObjectEntrySet()) {
|
||||
+ ttl.putIfAbsent(entry.getLongKey(), now);
|
||||
+ }
|
||||
+ } catch (Exception e) { } // Ignore any como's
|
||||
+ } catch (Exception e) {
|
||||
+ } // Ignore any como's
|
||||
+ } else if (ttlSize > this.size()) {
|
||||
+ try {
|
||||
+ this.ttl.long2LongEntrySet().removeIf(entry -> !this.containsKey(entry.getLongKey()));
|
||||
+ } catch (Exception e) { } // Ignore any como's
|
||||
+ } catch (Exception e) {
|
||||
+ } // Ignore any como's
|
||||
+ }
|
||||
+ if (isEmpty()) {
|
||||
+ registered = false;
|
||||
+ return true;
|
||||
+ }
|
||||
+ return false;
|
||||
+ }
|
||||
+ // Paper end
|
||||
}
|
||||
|
||||
protected boolean a(T var1) {
|
||||
@@ -51,8 +168,13 @@ public class ExpiringMap<T> extends Long2ObjectOpenHashMap<T> {
|
||||
@@ -51,8 +176,13 @@ public class ExpiringMap<T> extends Long2ObjectOpenHashMap<T> {
|
||||
}
|
||||
|
||||
public T get(long i) {
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren