From 68a1b2efaedc2ad31f232fe89a5548536d6c455f Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Wed, 2 Oct 2024 20:18:04 +0200 Subject: [PATCH] wasm gc: fix issue with dependency initialization order --- .../java/org/teavm/dependency/DependencyAnalyzer.java | 10 ++++++---- core/src/main/java/org/teavm/vm/TeaVM.java | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/teavm/dependency/DependencyAnalyzer.java b/core/src/main/java/org/teavm/dependency/DependencyAnalyzer.java index 35397d61f..8a8b0b43e 100644 --- a/core/src/main/java/org/teavm/dependency/DependencyAnalyzer.java +++ b/core/src/main/java/org/teavm/dependency/DependencyAnalyzer.java @@ -410,10 +410,12 @@ public abstract class DependencyAnalyzer implements DependencyInfo { reachedMethods.add(dep.getReference()); dep.activated = true; if (!dep.isMissing()) { - for (DependencyListener listener : listeners) { - listener.methodReached(agent, dep); - } - activateDependencyPlugin(dep); + defer(() -> { + for (var listener : listeners) { + listener.methodReached(agent, dep); + } + activateDependencyPlugin(dep); + }); } } return dep; diff --git a/core/src/main/java/org/teavm/vm/TeaVM.java b/core/src/main/java/org/teavm/vm/TeaVM.java index b50e1c5b6..b3c07b482 100644 --- a/core/src/main/java/org/teavm/vm/TeaVM.java +++ b/core/src/main/java/org/teavm/vm/TeaVM.java @@ -388,8 +388,8 @@ public class TeaVM implements TeaVMHost, ServiceRepository { cancelled |= progressListener.progressReached(progress) != TeaVMProgressFeedback.CONTINUE; return !cancelled; }); - dependencyAnalyzer.initDependencies(); target.contributeDependencies(dependencyAnalyzer); + dependencyAnalyzer.initDependencies(); if (target.needsSystemArrayCopyOptimization()) { dependencyAnalyzer.addDependencyListener(new StdlibDependencyListener()); }