From e1fbaaff592b87fcb651081f8c28b413d295634a Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Tue, 30 Oct 2018 18:39:51 -0700 Subject: [PATCH 1/6] Add tracing for unflushed EditSessions --- .../src/main/resources/defaults/config.yml | 3 ++ .../java/com/sk89q/worldedit/EditSession.java | 10 ++++ .../sk89q/worldedit/EditSessionFactory.java | 9 ++-- .../sk89q/worldedit/LocalConfiguration.java | 1 + .../sk89q/worldedit/TracedEditSession.java | 49 +++++++++++++++++++ .../extent/reorder/ChunkBatchingExtent.java | 4 ++ .../extent/reorder/MultiStageReorder.java | 4 ++ .../util/PropertiesConfiguration.java | 1 + .../worldedit/util/YAMLConfiguration.java | 1 + .../resources/defaults/worldedit.properties | 1 + .../config/ConfigurateConfiguration.java | 1 + 11 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/TracedEditSession.java diff --git a/worldedit-bukkit/src/main/resources/defaults/config.yml b/worldedit-bukkit/src/main/resources/defaults/config.yml index 794b69eda..a67dfb37c 100644 --- a/worldedit-bukkit/src/main/resources/defaults/config.yml +++ b/worldedit-bukkit/src/main/resources/defaults/config.yml @@ -139,6 +139,9 @@ history: calculation: timeout: 100 +debugging: + trace-unflushed-sessions: false + wand-item: minecraft:wooden_axe shell-save-type: no-double-slash: false diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index bc98a20e3..daf542958 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -234,6 +234,16 @@ public class EditSession implements Extent, AutoCloseable { return event.getExtent(); } + // pkg private for TracedEditSession only + + ChunkBatchingExtent getChunkBatchingExtent() { + return chunkBatchingExtent; + } + + MultiStageReorder getReorderExtent() { + return reorderExtent; + } + /** * Turns on specific features for a normal WorldEdit session, such as * {@link #enableQueue() queuing} and {@link #setBatchingChunks(boolean) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSessionFactory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSessionFactory.java index 094da742e..9b288271f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSessionFactory.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSessionFactory.java @@ -152,21 +152,24 @@ public class EditSessionFactory { @Override public EditSession getEditSession(World world, int maxBlocks) { - return new EditSession(eventBus, world, maxBlocks, null, new EditSessionEvent(world, null, maxBlocks, null)); + return getEditSession(world, maxBlocks, null, null); } @Override public EditSession getEditSession(World world, int maxBlocks, Player player) { - return new EditSession(eventBus, world, maxBlocks, null, new EditSessionEvent(world, player, maxBlocks, null)); + return getEditSession(world, maxBlocks, null, player); } @Override public EditSession getEditSession(World world, int maxBlocks, BlockBag blockBag) { - return new EditSession(eventBus, world, maxBlocks, blockBag, new EditSessionEvent(world, null, maxBlocks, null)); + return getEditSession(world, maxBlocks, blockBag, null); } @Override public EditSession getEditSession(World world, int maxBlocks, BlockBag blockBag, Player player) { + if (WorldEdit.getInstance().getConfiguration().traceUnflushedSessions) { + return new TracedEditSession(eventBus, world, maxBlocks, blockBag, new EditSessionEvent(world, player, maxBlocks, null)); + } return new EditSession(eventBus, world, maxBlocks, blockBag, new EditSessionEvent(world, player, maxBlocks, null)); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalConfiguration.java b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalConfiguration.java index 3ef39d94b..a56e2f06e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalConfiguration.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalConfiguration.java @@ -100,6 +100,7 @@ public abstract class LocalConfiguration { }; public boolean profile = false; + public boolean traceUnflushedSessions = false; public Set disallowedBlocks = new HashSet<>(); public int defaultChangeLimit = -1; public int maxChangeLimit = -1; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/TracedEditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/TracedEditSession.java new file mode 100644 index 000000000..efa79a0fd --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/TracedEditSession.java @@ -0,0 +1,49 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit; + +import com.sk89q.worldedit.event.extent.EditSessionEvent; +import com.sk89q.worldedit.extent.inventory.BlockBag; +import com.sk89q.worldedit.util.eventbus.EventBus; +import com.sk89q.worldedit.world.World; + +import java.util.logging.Level; + +public class TracedEditSession extends EditSession { + + TracedEditSession(EventBus eventBus, World world, int maxBlocks, BlockBag blockBag, EditSessionEvent event) { + super(eventBus, world, maxBlocks, blockBag, event); + } + + private final Throwable stacktrace = new Throwable("Creation trace."); + + @Override + protected void finalize() throws Throwable { + if (!isQueueEnabled() && !isBatchingChunks()) { + return; + } + + if (getChunkBatchingExtent().commitRequired() || getReorderExtent().commitRequired()) { + WorldEdit.logger.warning("####### LEFTOVER BUFFER BLOCKS DETECTED #######"); + WorldEdit.logger.warning("This means that some code did not flush their EditSession."); + WorldEdit.logger.log(Level.WARNING, "Here is a stacktrace from the creation of this EditSession:", stacktrace); + } + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/ChunkBatchingExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/ChunkBatchingExtent.java index b819bcac4..b5cd68572 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/ChunkBatchingExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/ChunkBatchingExtent.java @@ -73,6 +73,10 @@ public class ChunkBatchingExtent extends AbstractDelegateExtent { this.enabled = enabled; } + public boolean commitRequired() { + return batches.size() > 0; + } + @Override public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { if (!enabled) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java index 3ef74dd7a..af9a5e437 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java @@ -94,6 +94,10 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder this.enabled = enabled; } + public boolean commitRequired() { + return stage1.size() > 0 || stage2.size() > 0 || stage3.size() > 0; + } + @Override public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { BlockState existing = getBlock(location); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java index fee1917aa..67b23b608 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java @@ -75,6 +75,7 @@ public class PropertiesConfiguration extends LocalConfiguration { loadExtra(); profile = getBool("profile", profile); + traceUnflushedSessions = getBool("traceUnflushedSessions", traceUnflushedSessions); disallowedBlocks = getStringSet("disallowed-blocks", defaultDisallowedBlocks); defaultChangeLimit = getInt("default-max-changed-blocks", defaultChangeLimit); maxChangeLimit = getInt("max-changed-blocks", maxChangeLimit); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java index 9fa16df5f..697e77e56 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java @@ -54,6 +54,7 @@ public class YAMLConfiguration extends LocalConfiguration { } profile = config.getBoolean("debug", profile); + traceUnflushedSessions = config.getBoolean("debugging.trace-unflushed-sessions", traceUnflushedSessions); wandItem = convertLegacyItem(config.getString("wand-item", wandItem)); defaultChangeLimit = Math.max(-1, config.getInt( diff --git a/worldedit-forge/src/main/resources/defaults/worldedit.properties b/worldedit-forge/src/main/resources/defaults/worldedit.properties index f14a7a7d3..567118f0f 100644 --- a/worldedit-forge/src/main/resources/defaults/worldedit.properties +++ b/worldedit-forge/src/main/resources/defaults/worldedit.properties @@ -5,6 +5,7 @@ super-pickaxe-many-drop-items=true register-help=true nav-wand-item=minecraft:compass profile=false +traceUnflushedSessions=false super-pickaxe-drop-items=true disallowed-blocks=minecraft:oak_sapling,minecraft:jungle_sapling,minecraft:dark_oak_sapling,minecraft:spruce_sapling,minecraft:birch_sapling,minecraft:acacia_sapling,minecraft:black_bed,minecraft:blue_bed,minecraft:brown_bed,minecraft:cyan_bed,minecraft:gray_bed,minecraft:green_bed,minecraft:light_blue_bed,minecraft:light_gray_bed,minecraft:lime_bed,minecraft:magenta_bed,minecraft:orange_bed,minecraft:pink_bed,minecraft:purple_bed,minecraft:red_bed,minecraft:white_bed,minecraft:yellow_bed,minecraft:powered_rail,minecraft:detector_rail,minecraft:grass,minecraft:dead_bush,minecraft:moving_piston,minecraft:piston_head,minecraft:sunflower,minecraft:rose_bush,minecraft:dandelion,minecraft:poppy,minecraft:brown_mushroom,minecraft:red_mushroom,minecraft:tnt,minecraft:torch,minecraft:fire,minecraft:redstone_wire,minecraft:wheat,minecraft:potatoes,minecraft:carrots,minecraft:melon_stem,minecraft:pumpkin_stem,minecraft:beetroots,minecraft:rail,minecraft:lever,minecraft:redstone_torch,minecraft:redstone_wall_torch,minecraft:repeater,minecraft:comparator,minecraft:stone_button,minecraft:birch_button,minecraft:acacia_button,minecraft:dark_oak_button,minecraft:jungle_button,minecraft:oak_button,minecraft:spruce_button,minecraft:cactus,minecraft:sugar_cane,minecraft:bedrock max-super-pickaxe-size=5 diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/config/ConfigurateConfiguration.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/config/ConfigurateConfiguration.java index d824e0a8f..29fe11b78 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/config/ConfigurateConfiguration.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/config/ConfigurateConfiguration.java @@ -58,6 +58,7 @@ public class ConfigurateConfiguration extends LocalConfiguration { } profile = node.getNode("debug").getBoolean(profile); + traceUnflushedSessions = node.getNode("debugging", "traceUnflushedSessions").getBoolean(traceUnflushedSessions); wandItem = node.getNode("wand-item").getString(wandItem); try { wandItem = LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(wandItem)).getId(); From b8ae611c7381c4b166489a9e7c34bb3f8d3d5261 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Tue, 30 Oct 2018 18:44:32 -0700 Subject: [PATCH 2/6] Checkstyle requires calling super.finalize --- .../src/main/java/com/sk89q/worldedit/TracedEditSession.java | 1 + 1 file changed, 1 insertion(+) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/TracedEditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/TracedEditSession.java index efa79a0fd..046046795 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/TracedEditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/TracedEditSession.java @@ -36,6 +36,7 @@ public class TracedEditSession extends EditSession { @Override protected void finalize() throws Throwable { + super.finalize(); if (!isQueueEnabled() && !isBatchingChunks()) { return; } From 351a8bbc6cbfffbfddc99444560c933885ebc0ef Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Tue, 30 Oct 2018 18:45:53 -0700 Subject: [PATCH 3/6] Align configurate with yaml config --- .../sk89q/worldedit/sponge/config/ConfigurateConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/config/ConfigurateConfiguration.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/config/ConfigurateConfiguration.java index 29fe11b78..ed9f76c5c 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/config/ConfigurateConfiguration.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/config/ConfigurateConfiguration.java @@ -58,7 +58,7 @@ public class ConfigurateConfiguration extends LocalConfiguration { } profile = node.getNode("debug").getBoolean(profile); - traceUnflushedSessions = node.getNode("debugging", "traceUnflushedSessions").getBoolean(traceUnflushedSessions); + traceUnflushedSessions = node.getNode("debugging", "trace-unflushed-sessions").getBoolean(traceUnflushedSessions); wandItem = node.getNode("wand-item").getString(wandItem); try { wandItem = LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(wandItem)).getId(); From e202348dac02449f14db7daac5a89f5be2b49aa6 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sat, 3 Nov 2018 22:22:43 -0700 Subject: [PATCH 4/6] Simplify commit-required detection --- .../java/com/sk89q/worldedit/EditSession.java | 20 +++++++++---------- .../sk89q/worldedit/TracedEditSession.java | 5 +---- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index daf542958..094d52327 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -104,7 +104,6 @@ import com.sk89q.worldedit.util.eventbus.EventBus; import com.sk89q.worldedit.world.NullWorld; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.biome.BaseBiome; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockCategories; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -113,8 +112,6 @@ import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.registry.LegacyMapper; import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; @@ -234,14 +231,15 @@ public class EditSession implements Extent, AutoCloseable { return event.getExtent(); } - // pkg private for TracedEditSession only - - ChunkBatchingExtent getChunkBatchingExtent() { - return chunkBatchingExtent; - } - - MultiStageReorder getReorderExtent() { - return reorderExtent; + // pkg private for TracedEditSession only, may later become public API + boolean commitRequired() { + if (isQueueEnabled() && reorderExtent.commitRequired()) { + return true; + } + if (isBatchingChunks() && chunkBatchingExtent.commitRequired()) { + return true; + } + return false; } /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/TracedEditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/TracedEditSession.java index 046046795..5793a4f04 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/TracedEditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/TracedEditSession.java @@ -37,11 +37,8 @@ public class TracedEditSession extends EditSession { @Override protected void finalize() throws Throwable { super.finalize(); - if (!isQueueEnabled() && !isBatchingChunks()) { - return; - } - if (getChunkBatchingExtent().commitRequired() || getReorderExtent().commitRequired()) { + if (commitRequired()) { WorldEdit.logger.warning("####### LEFTOVER BUFFER BLOCKS DETECTED #######"); WorldEdit.logger.warning("This means that some code did not flush their EditSession."); WorldEdit.logger.log(Level.WARNING, "Here is a stacktrace from the creation of this EditSession:", stacktrace); From b6f6f3dde6b5bfa0a2e1e2a6944f03ed7408e001 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sat, 3 Nov 2018 23:06:52 -0700 Subject: [PATCH 5/6] Correct trace property name --- .../java/com/sk89q/worldedit/util/PropertiesConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java index 67b23b608..2454581f1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java @@ -75,7 +75,7 @@ public class PropertiesConfiguration extends LocalConfiguration { loadExtra(); profile = getBool("profile", profile); - traceUnflushedSessions = getBool("traceUnflushedSessions", traceUnflushedSessions); + traceUnflushedSessions = getBool("trace-unflushed-sessions", traceUnflushedSessions); disallowedBlocks = getStringSet("disallowed-blocks", defaultDisallowedBlocks); defaultChangeLimit = getInt("default-max-changed-blocks", defaultChangeLimit); maxChangeLimit = getInt("max-changed-blocks", maxChangeLimit); From 1150256df17d974c0a29150cbbea077a3b7785df Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Sun, 4 Nov 2018 17:21:01 +1000 Subject: [PATCH 6/6] Update config --- .../src/main/resources/defaults/worldedit.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldedit-forge/src/main/resources/defaults/worldedit.properties b/worldedit-forge/src/main/resources/defaults/worldedit.properties index 567118f0f..d0296c15c 100644 --- a/worldedit-forge/src/main/resources/defaults/worldedit.properties +++ b/worldedit-forge/src/main/resources/defaults/worldedit.properties @@ -5,7 +5,7 @@ super-pickaxe-many-drop-items=true register-help=true nav-wand-item=minecraft:compass profile=false -traceUnflushedSessions=false +trace-unflushed-sessions=false super-pickaxe-drop-items=true disallowed-blocks=minecraft:oak_sapling,minecraft:jungle_sapling,minecraft:dark_oak_sapling,minecraft:spruce_sapling,minecraft:birch_sapling,minecraft:acacia_sapling,minecraft:black_bed,minecraft:blue_bed,minecraft:brown_bed,minecraft:cyan_bed,minecraft:gray_bed,minecraft:green_bed,minecraft:light_blue_bed,minecraft:light_gray_bed,minecraft:lime_bed,minecraft:magenta_bed,minecraft:orange_bed,minecraft:pink_bed,minecraft:purple_bed,minecraft:red_bed,minecraft:white_bed,minecraft:yellow_bed,minecraft:powered_rail,minecraft:detector_rail,minecraft:grass,minecraft:dead_bush,minecraft:moving_piston,minecraft:piston_head,minecraft:sunflower,minecraft:rose_bush,minecraft:dandelion,minecraft:poppy,minecraft:brown_mushroom,minecraft:red_mushroom,minecraft:tnt,minecraft:torch,minecraft:fire,minecraft:redstone_wire,minecraft:wheat,minecraft:potatoes,minecraft:carrots,minecraft:melon_stem,minecraft:pumpkin_stem,minecraft:beetroots,minecraft:rail,minecraft:lever,minecraft:redstone_torch,minecraft:redstone_wall_torch,minecraft:repeater,minecraft:comparator,minecraft:stone_button,minecraft:birch_button,minecraft:acacia_button,minecraft:dark_oak_button,minecraft:jungle_button,minecraft:oak_button,minecraft:spruce_button,minecraft:cactus,minecraft:sugar_cane,minecraft:bedrock max-super-pickaxe-size=5