diff --git a/core/src/main/java/org/teavm/backend/wasm/WasmGCTarget.java b/core/src/main/java/org/teavm/backend/wasm/WasmGCTarget.java index e8e54d178..4c2ce9111 100644 --- a/core/src/main/java/org/teavm/backend/wasm/WasmGCTarget.java +++ b/core/src/main/java/org/teavm/backend/wasm/WasmGCTarget.java @@ -74,6 +74,8 @@ import org.teavm.model.ListableClassHolderSource; import org.teavm.model.MethodReader; import org.teavm.model.MethodReference; import org.teavm.model.Program; +import org.teavm.model.lowlevel.Characteristics; +import org.teavm.model.lowlevel.LowLevelNullCheckFilter; import org.teavm.model.transformation.BoundCheckInsertion; import org.teavm.model.transformation.NullCheckFilter; import org.teavm.model.transformation.NullCheckInsertion; @@ -86,7 +88,8 @@ import org.teavm.vm.spi.TeaVMHostExtension; public class WasmGCTarget implements TeaVMTarget, TeaVMWasmGCHost { private TeaVMTargetController controller; - private NullCheckInsertion nullCheckInsertion = new NullCheckInsertion(NullCheckFilter.EMPTY); + private Characteristics characteristics; + private NullCheckInsertion nullCheckInsertion; private BoundCheckInsertion boundCheckInsertion = new BoundCheckInsertion(); private boolean strict; private boolean obfuscated; @@ -179,6 +182,8 @@ public class WasmGCTarget implements TeaVMTarget, TeaVMWasmGCHost { @Override public void setController(TeaVMTargetController controller) { this.controller = controller; + characteristics = new Characteristics(controller.getUnprocessedClassSource()); + nullCheckInsertion = new NullCheckInsertion(new LowLevelNullCheckFilter(characteristics)); } @Override @@ -267,6 +272,7 @@ public class WasmGCTarget implements TeaVMTarget, TeaVMWasmGCHost { controller.getClassInitializerInfo(), controller.getDependencyInfo(), controller.getDiagnostics(), + characteristics, customGenerators, intrinsics, customTypeMapperFactories, diff --git a/core/src/main/java/org/teavm/backend/wasm/generate/gc/WasmGCDeclarationsGenerator.java b/core/src/main/java/org/teavm/backend/wasm/generate/gc/WasmGCDeclarationsGenerator.java index ca82f55f1..aa8e64428 100644 --- a/core/src/main/java/org/teavm/backend/wasm/generate/gc/WasmGCDeclarationsGenerator.java +++ b/core/src/main/java/org/teavm/backend/wasm/generate/gc/WasmGCDeclarationsGenerator.java @@ -44,6 +44,7 @@ import org.teavm.model.analysis.ClassInitializerInfo; import org.teavm.model.analysis.ClassMetadataRequirements; import org.teavm.model.classes.TagRegistry; import org.teavm.model.classes.VirtualTableBuilder; +import org.teavm.model.lowlevel.Characteristics; public class WasmGCDeclarationsGenerator { public final ClassHierarchy hierarchy; @@ -61,6 +62,7 @@ public class WasmGCDeclarationsGenerator { ClassInitializerInfo classInitializerInfo, DependencyInfo dependencyInfo, Diagnostics diagnostics, + Characteristics characteristics, WasmGCCustomGeneratorProvider customGenerators, WasmGCIntrinsicProvider intrinsics, List customTypeMapperFactories, @@ -83,6 +85,7 @@ public class WasmGCDeclarationsGenerator { functionTypes, names, diagnostics, + characteristics, customGenerators, intrinsics, strict, diff --git a/core/src/main/java/org/teavm/backend/wasm/generate/gc/methods/WasmGCGenerationContext.java b/core/src/main/java/org/teavm/backend/wasm/generate/gc/methods/WasmGCGenerationContext.java index 2a1c9395d..f3c5fa23e 100644 --- a/core/src/main/java/org/teavm/backend/wasm/generate/gc/methods/WasmGCGenerationContext.java +++ b/core/src/main/java/org/teavm/backend/wasm/generate/gc/methods/WasmGCGenerationContext.java @@ -43,6 +43,7 @@ import org.teavm.model.ClassReaderSource; import org.teavm.model.ElementModifier; import org.teavm.model.ListableClassReaderSource; import org.teavm.model.MethodReference; +import org.teavm.model.lowlevel.Characteristics; public class WasmGCGenerationContext implements BaseWasmGenerationContext { private WasmModule module; @@ -69,6 +70,7 @@ public class WasmGCGenerationContext implements BaseWasmGenerationContext { private String entryPoint; private Consumer initializerContributors; private Diagnostics diagnostics; + private Characteristics characteristics; public WasmGCGenerationContext(WasmModule module, WasmGCVirtualTableProvider virtualTables, WasmGCTypeMapper typeMapper, WasmFunctionTypes functionTypes, ListableClassReaderSource classes, @@ -78,7 +80,7 @@ public class WasmGCGenerationContext implements BaseWasmGenerationContext { WasmGCCustomGeneratorProvider customGenerators, WasmGCIntrinsicProvider intrinsics, WasmGCNameProvider names, boolean strict, String entryPoint, Consumer initializerContributors, - Diagnostics diagnostics) { + Diagnostics diagnostics, Characteristics characteristics) { this.module = module; this.virtualTables = virtualTables; this.typeMapper = typeMapper; @@ -98,6 +100,7 @@ public class WasmGCGenerationContext implements BaseWasmGenerationContext { this.entryPoint = entryPoint; this.initializerContributors = initializerContributors; this.diagnostics = diagnostics; + this.characteristics = characteristics; } public WasmGCClassInfoProvider classInfoProvider() { @@ -210,6 +213,10 @@ public class WasmGCGenerationContext implements BaseWasmGenerationContext { return diagnostics; } + public Characteristics characteristics() { + return characteristics; + } + public Collection getInterfaceImplementors(String className) { if (interfaceImplementors == null) { fillInterfaceImplementors(); diff --git a/core/src/main/java/org/teavm/backend/wasm/generate/gc/methods/WasmGCGenerationVisitor.java b/core/src/main/java/org/teavm/backend/wasm/generate/gc/methods/WasmGCGenerationVisitor.java index 64457d4e3..1bd528b1c 100644 --- a/core/src/main/java/org/teavm/backend/wasm/generate/gc/methods/WasmGCGenerationVisitor.java +++ b/core/src/main/java/org/teavm/backend/wasm/generate/gc/methods/WasmGCGenerationVisitor.java @@ -15,6 +15,8 @@ */ package org.teavm.backend.wasm.generate.gc.methods; +import static org.teavm.model.lowlevel.ExceptionHandlingUtil.isManagedMethodCall; + import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; @@ -97,6 +99,7 @@ public class WasmGCGenerationVisitor extends BaseWasmGenerationVisitor { private WasmGCGenerationUtil generationUtil; private WasmType expectedType; private PreciseTypeInference types; + private boolean managed; public WasmGCGenerationVisitor(WasmGCGenerationContext context, MethodReference currentMethod, WasmFunction function, int firstVariable, boolean async, PreciseTypeInference types) { @@ -104,6 +107,7 @@ public class WasmGCGenerationVisitor extends BaseWasmGenerationVisitor { this.context = context; generationUtil = new WasmGCGenerationUtil(context.classInfoProvider()); this.types = types; + managed = context.characteristics().isManaged(currentMethod); } @Override @@ -125,7 +129,7 @@ public class WasmGCGenerationVisitor extends BaseWasmGenerationVisitor { @Override protected boolean isManaged() { - return true; + return managed; } @Override @@ -135,7 +139,7 @@ public class WasmGCGenerationVisitor extends BaseWasmGenerationVisitor { @Override protected boolean isManagedCall(MethodReference method) { - return false; + return isManagedMethodCall(context.characteristics(), method); } @Override diff --git a/core/src/main/java/org/teavm/backend/wasm/generate/gc/methods/WasmGCMethodGenerator.java b/core/src/main/java/org/teavm/backend/wasm/generate/gc/methods/WasmGCMethodGenerator.java index 6365d7cd1..2d946ad32 100644 --- a/core/src/main/java/org/teavm/backend/wasm/generate/gc/methods/WasmGCMethodGenerator.java +++ b/core/src/main/java/org/teavm/backend/wasm/generate/gc/methods/WasmGCMethodGenerator.java @@ -61,6 +61,7 @@ import org.teavm.model.MethodReader; import org.teavm.model.MethodReference; import org.teavm.model.ValueType; import org.teavm.model.analysis.ClassInitializerInfo; +import org.teavm.model.lowlevel.Characteristics; import org.teavm.model.util.RegisterAllocator; public class WasmGCMethodGenerator implements BaseWasmFunctionRepository { @@ -74,6 +75,7 @@ public class WasmGCMethodGenerator implements BaseWasmFunctionRepository { private WasmGCSupertypeFunctionProvider supertypeFunctions; public final WasmGCNameProvider names; private Diagnostics diagnostics; + private Characteristics characteristics; private WasmGCTypeMapper typeMapper; private WasmGCCustomGeneratorProvider customGenerators; private WasmGCIntrinsicProvider intrinsics; @@ -101,6 +103,7 @@ public class WasmGCMethodGenerator implements BaseWasmFunctionRepository { WasmFunctionTypes functionTypes, WasmGCNameProvider names, Diagnostics diagnostics, + Characteristics characteristics, WasmGCCustomGeneratorProvider customGenerators, WasmGCIntrinsicProvider intrinsics, boolean strict, @@ -116,6 +119,7 @@ public class WasmGCMethodGenerator implements BaseWasmFunctionRepository { this.functionTypes = functionTypes; this.names = names; this.diagnostics = diagnostics; + this.characteristics = characteristics; this.customGenerators = customGenerators; this.intrinsics = intrinsics; this.strict = strict; @@ -367,7 +371,8 @@ public class WasmGCMethodGenerator implements BaseWasmFunctionRepository { strict, entryPoint, initializerContributors, - diagnostics + diagnostics, + characteristics ); } return context;