Improve Timings stack protection more
Ensures in more places that exceptions will not corrupt the Timings stack. Timings will now better report stack corruption and auto repair itself too.
This commit is contained in:
@@ -475,7 +475,7 @@ index 000000000..a5d13a1e4
|
||||
+}
|
||||
diff --git a/src/main/java/co/aikar/timings/TimingHandler.java b/src/main/java/co/aikar/timings/TimingHandler.java
|
||||
new file mode 100644
|
||||
index 000000000..2a727994a
|
||||
index 000000000..bb46cb633
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/co/aikar/timings/TimingHandler.java
|
||||
@@ -0,0 +0,0 @@
|
||||
@@ -520,7 +520,7 @@ index 000000000..2a727994a
|
||||
+class TimingHandler implements Timing {
|
||||
+
|
||||
+ private static AtomicInteger idPool = new AtomicInteger(1);
|
||||
+ static Deque<TimingHandler> TIMING_STACK = new ArrayDeque<>();
|
||||
+ private static Deque<TimingHandler> TIMING_STACK = new ArrayDeque<>();
|
||||
+ final int id = idPool.getAndIncrement();
|
||||
+
|
||||
+ final TimingIdentifier identifier;
|
||||
@@ -587,10 +587,16 @@ index 000000000..2a727994a
|
||||
+
|
||||
+ public void stopTiming() {
|
||||
+ if (enabled && timingDepth > 0 && Bukkit.isPrimaryThread() && --timingDepth == 0 && start != 0) {
|
||||
+ TimingHandler last = TIMING_STACK.removeLast();
|
||||
+ if (last != this) {
|
||||
+ Logger.getGlobal().log(Level.SEVERE, "TIMING_STACK_CORRUPTION - Report this to Paper! ( " + this.identifier + ":" + last +")", new Throwable());
|
||||
+ TIMING_STACK.addLast(last); // Add it back
|
||||
+ TimingHandler last;
|
||||
+ while ((last = TIMING_STACK.removeLast()) != this) {
|
||||
+ last.timingDepth = 0;
|
||||
+ String reportTo;
|
||||
+ if ("minecraft".equals(last.identifier.group)) {
|
||||
+ reportTo = "Paper! This is a potential bug in Paper";
|
||||
+ } else {
|
||||
+ reportTo = "the plugin " + last.identifier.group + "(Look for errors above this in the logs)";
|
||||
+ }
|
||||
+ Logger.getGlobal().log(Level.SEVERE, "TIMING_STACK_CORRUPTION - Report this to " + reportTo + " (" + last.identifier +" did not stopTiming)", new Throwable());
|
||||
+ }
|
||||
+ addDiff(System.nanoTime() - start, TIMING_STACK.peekLast());
|
||||
+
|
||||
@@ -3356,7 +3362,7 @@ index 000000000..ca1893e9f
|
||||
+
|
||||
+}
|
||||
diff --git a/src/main/java/org/bukkit/command/SimpleCommandMap.java b/src/main/java/org/bukkit/command/SimpleCommandMap.java
|
||||
index 1586f6480..f7ec2e55f 100644
|
||||
index 1586f6480..6a786b8c5 100644
|
||||
--- a/src/main/java/org/bukkit/command/SimpleCommandMap.java
|
||||
+++ b/src/main/java/org/bukkit/command/SimpleCommandMap.java
|
||||
@@ -0,0 +0,0 @@ public class SimpleCommandMap implements CommandMap {
|
||||
@@ -3387,8 +3393,22 @@ index 1586f6480..f7ec2e55f 100644
|
||||
+ // Paper end
|
||||
+
|
||||
try {
|
||||
target.timings.startTiming(); // Spigot
|
||||
- target.timings.startTiming(); // Spigot
|
||||
+ try (co.aikar.timings.Timing ignored = target.timings.startTiming()) { // Paper - use try with resources
|
||||
// Note: we don't return the result of target.execute as thats success / failure, we return handled (true) or not handled (false)
|
||||
target.execute(sender, sentCommandLabel, Arrays.copyOfRange(args, 1, args.length));
|
||||
- target.timings.stopTiming(); // Spigot
|
||||
+ } // target.timings.stopTiming(); // Spigot // Paper
|
||||
} catch (CommandException ex) {
|
||||
- target.timings.stopTiming(); // Spigot
|
||||
+ //target.timings.stopTiming(); // Spigot // Paper
|
||||
throw ex;
|
||||
} catch (Throwable ex) {
|
||||
- target.timings.stopTiming(); // Spigot
|
||||
+ //target.timings.stopTiming(); // Spigot // Paper
|
||||
throw new CommandException("Unhandled exception executing '" + commandLine + "' in " + target, ex);
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/command/defaults/TimingsCommand.java b/src/main/java/org/bukkit/command/defaults/TimingsCommand.java
|
||||
deleted file mode 100644
|
||||
index 1e6e7033d..000000000
|
||||
|
||||
Reference in New Issue
Block a user