WearBlackAllDay / DimensionalThreading

An attempt to optimize the fabric server, by assigning each dimension their own thread.
MIT License
256 stars 22 forks source link

Carpet profiler probably contains code that is not thread-safe #84

Open CaveNightingale opened 1 year ago

CaveNightingale commented 1 year ago

Carpet profiler seem to access Object2LongOpenHashMapasynchronously Crash report:

---- Minecraft Crash Report ----
// Don't be sad. I'll do better next time, I promise!

Time: 2023/1/22 上午8:17
Description: Exception ticking world

java.lang.ArrayIndexOutOfBoundsException: Index 51 out of bounds for length 33
    at it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap.find(Object2LongOpenHashMap.java:259)
    at it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap.put(Object2LongOpenHashMap.java:283)
    at carpet.utils.CarpetProfiler.end_current_entity_section(CarpetProfiler.java:148)
    at net.minecraft.class_2818$class_5563.handler$zib000$endTileEntitySection(class_2818.java:789)
    at net.minecraft.class_2818$class_5563.method_31703(class_2818.java:677)
    at net.minecraft.class_2818$class_5564.method_31703(class_2818.java:713)
    at net.minecraft.class_1937.method_18471(class_1937.java:475)
    at net.minecraft.class_3218.method_18765(class_3218.java:368)
    at net.minecraft.server.MinecraftServer.mdfda228$lambda$tickWorlds$0$4(MinecraftServer.java:6828)
    at wearblackallday.dimthread.DimThread.swapThreadsAndRun(DimThread.java:42)
    at net.minecraft.server.MinecraftServer.mdfda228$lambda$tickWorlds$1$3(MinecraftServer.java:6826)
    at wearblackallday.dimthread.util.ThreadPool.lambda$execute$1(ThreadPool.java:49)
    at wearblackallday.dimthread.util.ThreadPool.lambda$execute$0(ThreadPool.java:43)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:833)

A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Server thread
Stacktrace:
    at it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap.find(Object2LongOpenHashMap.java:259)
    at it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap.put(Object2LongOpenHashMap.java:283)
    at carpet.utils.CarpetProfiler.end_current_entity_section(CarpetProfiler.java:148)
    at net.minecraft.class_2818$class_5563.handler$zib000$endTileEntitySection(class_2818.java:789)
    at net.minecraft.class_2818$class_5563.method_31703(class_2818.java:677)
    at net.minecraft.class_2818$class_5564.method_31703(class_2818.java:713)
    at net.minecraft.class_1937.method_18471(class_1937.java:475)
Mixins in Stacktrace:
    carpet.utils.CarpetProfiler:
        carpettisaddition.mixins.rule.synchronizedLightThread.CarpetProfilerMixin (carpet-tis-addition.mixins.json)
    net.minecraft.class_2818$class_5563:
        carpet.mixins.BoundTickingBlockEntity_tickMixin (carpet.mixins.json)
        carpettisaddition.mixins.logger.microtiming.tickstages.tileentity.DirectBlockEntityTickInvokerMixin (carpet-tis-addition.mixins.json)
        carpettisaddition.mixins.utils.DirectBlockEntityTickInvokerAccessor (carpet-tis-addition.mixins.json)
    net.minecraft.class_2818$class_5564:
        carpettisaddition.mixins.utils.WrappedBlockEntityTickInvokerAccessor (carpet-tis-addition.mixins.json)
    net.minecraft.class_1937:
        com.ishland.c2me.notickvd.mixin.MixinWorld (c2me-notickvd.mixins.json)
        carpettisaddition.mixins.logger.microtiming.tickstages.entity.WorldMixin (carpet-tis-addition.mixins.json)
        ca.spottedleaf.starlight.mixin.common.world.LevelMixin (starlight.mixins.json)
        carpet.mixins.Level_getOtherEntitiesLimited (carpet.mixins.json)
        me.jellysquid.mods.lithium.mixin.world.inline_block_access.WorldMixin (lithium.mixins.json)
        me.jellysquid.mods.lithium.mixin.world.inline_height.WorldMixin (lithium.mixins.json)
        carpettisaddition.mixins.logger.microtiming.tickstages.tileentity.WorldMixin (carpet-tis-addition.mixins.json)
        wearblackallday.dimthread.mixin.WorldMixin (dimthread.mixins.json)
        carpet.mixins.Level_updateSuppressionCrashFixMixin (carpet.mixins.json)
        carpettisaddition.mixins.carpet.tweaks.rule.tntRandomRange.WorldAccessor (carpet-tis-addition.mixins.json)
        carpet.mixins.Level_movableBEMixin (carpet.mixins.json)
        dev.architectury.mixin.fabric.ExplosionPreInvoker (architectury.mixins.json)
        carpet.mixins.Level_scarpetPlopMixin (carpet.mixins.json)
        me.jellysquid.mods.lithium.mixin.world.block_entity_retrieval.WorldMixin (lithium.mixins.json)
        carpet.mixins.Level_fillUpdatesMixin (carpet.mixins.json)
        carpettisaddition.mixins.command.manipulate.container.WorldAccessor (carpet-tis-addition.mixins.json)
        me.jellysquid.mods.lithium.mixin.alloc.chunk_random.WorldMixin (lithium.mixins.json)
        me.jellysquid.mods.lithium.mixin.world.chunk_access.WorldMixin (lithium.mixins.json)
        carpettisaddition.mixins.rule.totallyNoBlockUpdate.WorldMixin (carpet-tis-addition.mixins.json)
        carpet.mixins.Level_tickMixin (carpet.mixins.json)
        carpettisaddition.mixins.logger.microtiming.events.WorldMixin (carpet-tis-addition.mixins.json)
        net.fabricmc.fabric.mixin.event.lifecycle.WorldMixin (fabric-lifecycle-events-v1.mixins.json)

-- Affected level --
Details:
    All players: 1 total; [EntityPlayerMPFake['Zhi_Yin_NbTiMg'/1079698, l='ServerLevel[world]', x=-563.54, y=100.00, z=-462.56]]
    Chunk stats: 2401
    Level dimension: minecraft:the_end
    Derived: true
    Level spawn location: World: (0,96,0), Section: (at 0,0,0 in 0,6,0; chunk contains blocks 0,0,0 to 15,255,15), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
    Level time: 2073354 game time, 2022747 day time
    Level name: world
    Level game mode: Game mode: survival (ID 0). Hardcore: false. Cheats: false
    Level weather: Rain time: 137611 (now: false), thunder time: 54020 (now: false)
    Known server brands: fabric
    Level was modded: true
    Level storage version: 0x04ABD - Anvil
Stacktrace:
    at wearblackallday.dimthread.util.CrashInfo.crash(CrashInfo.java:11)
    at net.minecraft.server.MinecraftServer.handler$cbe000$tickWorlds(MinecraftServer.java:6839)
    at net.minecraft.server.MinecraftServer.method_3813(MinecraftServer.java:896)
    at net.minecraft.class_3176.method_3813(class_3176.java:322)
    at net.minecraft.server.MinecraftServer.method_3748(MinecraftServer.java:851)
    at net.minecraft.server.MinecraftServer.handler$zho000$modifiedRunLoop(MinecraftServer.java:2896)
    at net.minecraft.server.MinecraftServer.method_29741(MinecraftServer.java:676)
    at net.minecraft.server.MinecraftServer.method_29739(MinecraftServer.java:273)
    at java.base/java.lang.Thread.run(Thread.java:833)
Mixins in Stacktrace:
    net.minecraft.server.MinecraftServer:
        carpet.mixins.MinecraftServer_coreMixin (carpet.mixins.json)
        carpettisaddition.mixins.logger.microtiming.messageflush.MinecraftServerMixin (carpet-tis-addition.mixins.json)
        net.fabricmc.fabric.mixin.biome.modification.MinecraftServerMixin (fabric-biome-api-v1.mixins.json)
        carpet.mixins.MinecraftServer_updateSuppressionCrashFixMixin (carpet.mixins.json)
        carpettisaddition.mixins.carpet.events.onServerLoadedWorlds.MinecraftServerMixin (carpet-tis-addition.mixins.json)
        carpet.mixins.MinecraftServer_scarpetMixin (carpet.mixins.json)
        com.ishland.c2me.opts.scheduling.mixin.shutdown.MixinMinecraftServer (c2me-opts-scheduling.mixins.json)
        net.szum123321.textile_backup.mixin.MinecraftServerMixin (textile_backup.mixins.json)
        net.szum123321.textile_backup.mixin.MinecraftServerSessionAccessor (textile_backup.mixins.json)
        carpet.mixins.MinecraftServer_tickspeedMixin (carpet.mixins.json)
        ch.endte.syncmatica.mixin.MixinMinecraftServer (syncmatica.mixin.json)
        wearblackallday.dimthread.mixin.MinecraftServerMixin (dimthread.mixins.json)
        net.fabricmc.fabric.mixin.biome.MixinMinecraftServer (fabric-biome-api-v1.mixins.json)
        fi.dy.masa.servux.mixin.MixinMinecraftServer (mixins.servux.json)
        com.ishland.c2me.opts.scheduling.mixin.idle_tasks.autosave.enhanced_autosave.MixinMinecraftServer (c2me-opts-scheduling.mixins.json)
        net.fabricmc.fabric.mixin.event.lifecycle.MinecraftServerMixin (fabric-lifecycle-events-v1.mixins.json)
        carpet.mixins.MinecraftServer_pingPlayerSampleLimit (carpet.mixins.json)
        com.sk89q.worldedit.fabric.mixin.MixinMinecraftServer (worldedit-fabric.mixins.json)
        carpettisaddition.mixins.logger.microtiming.tickstages.autosave.MinecraftServerMixin (carpet-tis-addition.mixins.json)
        net.fabricmc.fabric.mixin.resource.loader.MinecraftServerMixin (fabric-resource-loader-v0.mixins.json)
        net.fabricmc.fabric.mixin.registry.sync.MixinMinecraftServer (fabric-registry-sync-v0.mixins.json)
        carpettisaddition.mixins.logger.microtiming.api.MinecraftServerMixin (carpet-tis-addition.mixins.json)
        carpettisaddition.mixins.logger.microtiming.tickstages.asynctask.MinecraftServerMixin (carpet-tis-addition.mixins.json)
    net.minecraft.class_3176:
        carpettisaddition.mixins.logger.microtiming.tickstages.console.MinecraftDedicatedServerMixin (carpet-tis-addition.mixins.json)
        dev.architectury.mixin.fabric.MixinDedicatedServer (architectury.mixins.json)
        com.ishland.c2me.base.mixin.util.log4j2shutdownhookisnomore.MixinMinecraftDedicatedServer (c2me-base.mixins.json)

-- System Details --
Details:
    Minecraft Version: 1.18.2
    Minecraft Version ID: 1.18.2
    Operating System: Linux (amd64) version 3.10.0-1160.76.1.el7.x86_64
    Java Version: 17.0.5, Oracle Corporation
    Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode, sharing), Oracle Corporation
        [DELETED DEVICE INFORMATION]
    Fabric Mods: 
        architectury: Architectury 4.9.83
        c2me: Concurrent Chunk Management Engine 0.2.0+alpha.7.34
            c2me-base: Concurrent Chunk Management Engine (Base) 0.2.0+alpha.7.34
            c2me-fixes-chunkio-threading-issues: Concurrent Chunk Management Engine (Fixes/Chunk IO/Threading Issues) 0.2.0+alpha.7.34
            c2me-fixes-general-threading-issues: Concurrent Chunk Management Engine (Fixes/General/Threading Issues) 0.2.0+alpha.7.34
            c2me-fixes-worldgen-threading-issues: Concurrent Chunk Management Engine (Fixes/WorldGen/Threading Issues) 0.2.0+alpha.7.34
            c2me-fixes-worldgen-vanilla-bugs: Concurrent Chunk Management Engine (Fixes/WorldGen/Vanilla Bugs) 0.2.0+alpha.7.34
            c2me-notickvd: Concurrent Chunk Management Engine (No Tick View Distance) 0.2.0+alpha.7.34
            c2me-opts-allocs: Concurrent Chunk Management Engine (Optimizations/Memory Allocations) 0.2.0+alpha.7.34
            c2me-opts-chunk-access: Concurrent Chunk Management Engine (Optimizations/Chunk Access) 0.2.0+alpha.7.34
            c2me-opts-chunkio: Concurrent Chunk Management Engine (Optimizations/Chunk IO) 0.2.0+alpha.7.34
            c2me-opts-math: Concurrent Chunk Management Engine (Optimizations/Math) 0.2.0+alpha.7.34
            c2me-opts-scheduling: Concurrent Chunk Management Engine (Optimizations/Scheduling) 0.2.0+alpha.7.34
            c2me-opts-worldgen-general: Concurrent Chunk Management Engine (Optimizations/General WorldGen) 0.2.0+alpha.7.34
            c2me-opts-worldgen-vanilla: Concurrent Chunk Management Engine (Optimizations/Vanilla WorldGen) 0.2.0+alpha.7.34
            c2me-rewrites-chunkio: Concurrent Chunk Management Engine (Rewrites/Chunk IO) 0.2.0+alpha.7.34
            c2me-server-utils: Concurrent Chunk Management Engine (Server Utils) 0.2.0+alpha.7.34
            c2me-threading-chunkio: Concurrent Chunk Management Engine (Threading/WorldGen) 0.2.0+alpha.7.34
            c2me-threading-lighting: Concurrent Chunk Management Engine (Threading/Lighting) 0.2.0+alpha.7.34
            c2me-threading-scheduling: Concurrent Chunk Management Engine (Threading/Scheduling) 0.2.0+alpha.7.34
            c2me-threading-worldgen: Concurrent Chunk Management Engine (Threading/WorldGen) 0.2.0+alpha.7.34
            com_electronwill_night-config_core: core 3.6.5
            com_electronwill_night-config_toml: toml 3.6.5
            com_ibm_async_asyncutil: asyncutil 0.1.0
            org_threadly_threadly: threadly 6.6
        carpet: Carpet Mod 1.4.69
        carpet-extra: Carpet Extra 1.4.72
        carpet-tis-addition: Carpet TIS Addition 1.38.0
            conditional-mixin: conditional mixin 0.3.1
            org_yaml_snakeyaml: snakeyaml 1.30
        chunky: Chunky 1.2.194
        cloth-config: Cloth Config v6 6.2.62
            cloth-basic-math: cloth-basic-math 0.6.1
        crawl: Crawl 0.10.6
            mm: Manningham Mills 2.3
        dimthread: DimensionalThreading 1.2.6-1.18.2-sand-duper-fix.3
        fabric-api: Fabric API 0.59.1+1.18.2
            fabric-api-base: Fabric API Base 0.4.4+d7c144a860
            fabric-api-lookup-api-v1: Fabric API Lookup API (v1) 1.6.2+2373a54560
            fabric-biome-api-v1: Fabric Biome API (v1) 8.0.6+651bcc5960
            fabric-command-api-v1: Fabric Command API (v1) 1.1.9+d7c144a860
            fabric-commands-v0: Fabric Commands (v0) 0.2.8+b4f4f6cd60
            fabric-containers-v0: Fabric Containers (v0) 0.1.23+d7c144a860
            fabric-content-registries-v0: Fabric Content Registries (v0) 3.1.1+c85f2e3860
            fabric-convention-tags-v1: Fabric Convention Tags 1.0.1+474e4f7960
            fabric-crash-report-info-v1: Fabric Crash Report Info (v1) 0.2.1+ee261a3e60
            fabric-data-generation-api-v1: Fabric Data Generation API (v1) 3.0.2+9fcb91d260
            fabric-dimensions-v1: Fabric Dimensions API (v1) 2.1.20+489d6f8260
            fabric-entity-events-v1: Fabric Entity Events (v1) 1.4.8+d7c144a860
            fabric-events-interaction-v0: Fabric Events Interaction (v0) 0.4.19+d7c144a860
            fabric-events-lifecycle-v0: Fabric Events Lifecycle (v0) 0.2.19+d7c144a860
            fabric-game-rule-api-v1: Fabric Game Rule API (v1) 1.0.13+d7c144a860
            fabric-item-api-v1: Fabric Item API (v1) 1.5.2+17cbbd4360
            fabric-item-groups-v0: Fabric Item Groups (v0) 0.3.14+91896a4960
            fabric-lifecycle-events-v1: Fabric Lifecycle Events (v1) 2.1.0+cc71601c60
            fabric-loot-api-v2: Fabric Loot API (v2) 1.1.0+1997ad1260
            fabric-loot-tables-v1: Fabric Loot Tables (v1) 1.1.2+e747827960
            fabric-mining-level-api-v1: Fabric Mining Level API (v1) 2.1.4+cc71601c60
            fabric-networking-api-v1: Fabric Networking API (v1) 1.0.23+2d30af4b60
            fabric-networking-v0: Fabric Networking (v0) 0.3.10+b4f4f6cd60
            fabric-object-builder-api-v1: Fabric Object Builder API (v1) 2.1.3+032c981d60
            fabric-particles-v1: Fabric Particles (v1) 0.2.12+526dc1ac60
            fabric-registry-sync-v0: Fabric Registry Sync (v0) 0.9.11+bb2e047760
            fabric-rendering-data-attachment-v1: Fabric Rendering Data Attachment (v1) 0.3.7+d7c144a860
            fabric-rendering-fluids-v1: Fabric Rendering Fluids (v1) 2.0.2+54e5b2ec60
            fabric-resource-conditions-api-v1: Fabric Resource Conditions API (v1) 2.0.3+91b7aa6660
            fabric-resource-loader-v0: Fabric Resource Loader (v0) 0.5.2+446e059560
            fabric-screen-handler-api-v1: Fabric Screen Handler API (v1) 1.2.2+1f6558e860
            fabric-transfer-api-v1: Fabric Transfer API (v1) 1.6.3+f4563ac860
            fabric-transitive-access-wideners-v1: Fabric Transitive Access Wideners (v1) 1.1.0+e747827960
        fabric-language-kotlin: Fabric Language Kotlin 1.8.4+kotlin.1.7.20
            org_jetbrains_kotlin_kotlin-reflect: kotlin-reflect 1.7.20
            org_jetbrains_kotlin_kotlin-stdlib: kotlin-stdlib 1.7.20
            org_jetbrains_kotlin_kotlin-stdlib-jdk7: kotlin-stdlib-jdk7 1.7.20
            org_jetbrains_kotlin_kotlin-stdlib-jdk8: kotlin-stdlib-jdk8 1.7.20
            org_jetbrains_kotlinx_atomicfu-jvm: atomicfu-jvm 0.18.3
            org_jetbrains_kotlinx_kotlinx-coroutines-core-jvm: kotlinx-coroutines-core-jvm 1.6.4
            org_jetbrains_kotlinx_kotlinx-coroutines-jdk8: kotlinx-coroutines-jdk8 1.6.4
            org_jetbrains_kotlinx_kotlinx-datetime-jvm: kotlinx-datetime-jvm 0.4.0
            org_jetbrains_kotlinx_kotlinx-serialization-cbor-jvm: kotlinx-serialization-cbor-jvm 1.4.0
            org_jetbrains_kotlinx_kotlinx-serialization-core-jvm: kotlinx-serialization-core-jvm 1.4.0
            org_jetbrains_kotlinx_kotlinx-serialization-json-jvm: kotlinx-serialization-json-jvm 1.4.0
        fabricloader: Fabric Loader 0.14.9
        fabricproxy-lite: FabricProxy Lite 1.1.6
            com_moandjiezana_toml_toml4j: toml4j 0.7.2
        farmersdelight: Farmer's Delight 1.18.2-1.2.0
        ferritecore: FerriteCore 4.2.1
        java: Java HotSpot(TM) 64-Bit Server VM 17
        krypton: Krypton 0.1.9
            com_velocitypowered_velocity-native: velocity-native 1.1.0-SNAPSHOT
        ledger: Ledger 1.2.4
            server_translations_api: Server Translations API 1.4.9+1.18.2-rc1
                packet_tweaker: Packet Tweaker 0.2.0+1.18-pre1
        lithium: Lithium 0.7.10
        luckperms: LuckPerms 5.4.25
            fabric-permissions-api-v0: fabric-permissions-api 0.1-SNAPSHOT
        minecraft: Minecraft 1.18.2
        mixintrace: MixinTrace 1.1.1+1.17
        pca: Plusls carpet addition mod 0.2.5
        quickshulker: Quick Shulker 1.3.9-1.18
            kyrptconfig: Kyrpt Config 1.4.6-1.18
                blue_endless_jankson: jankson 1.2.1
            shulkerutils: shulkerutils 1.0.4-1.18
        roughlyenoughitems: Roughly Enough Items 8.3.529
            error_notifier: Error Notifier 1.0.9
        serveressentials: ServerEssentials 1.0
        servux: Servux 0.1.0
        simplerauth: Simpler Auth 1.5.2
        skinrestorer: Skin Restorer 1.1.0
        spark: spark 1.9.11
        starlight: Starlight 1.0.2+fabric.89b8d9f
        syncmatica: Syncmatica 1.18.2-0.3.2
        textile_backup: Textile Backup 2.4.0-1.18
            com_github_shevek_parallelgzip: parallelgzip af5f5c297e735f3f2df7aa4eb0e19a5810b8aff6
            org_apache_commons_commons-compress: commons-compress 1.21
            org_tukaani_xz: xz 1.9
        worldedit: WorldEdit 7.2.10+1742f98
    Server Running: true
    Player Count: 5 / 30; [DELETED PRIVACY]
    Data Packs: vanilla, Fabric Mods
    World Generation: Experimental
    Is Modded: Definitely; Server brand changed to 'fabric'
    Type: Dedicated Server (map_server.txt)