diff --git a/tools/core/src/main/java/org/teavm/tooling/TeaVMTool.java b/tools/core/src/main/java/org/teavm/tooling/TeaVMTool.java index b30b994fe..ab613f8b3 100644 --- a/tools/core/src/main/java/org/teavm/tooling/TeaVMTool.java +++ b/tools/core/src/main/java/org/teavm/tooling/TeaVMTool.java @@ -119,6 +119,7 @@ public class TeaVMTool { private Set generatedFiles = new HashSet<>(); private int minHeapSize = 4 * (1 << 20); private int maxHeapSize = 128 * (1 << 20); + private boolean directMallocSupport = false; private ReferenceCache referenceCache; private boolean heapDump; private boolean shortFileNames; @@ -268,6 +269,10 @@ public class TeaVMTool { this.maxHeapSize = maxHeapSize; } + public void setDirectMallocSupport(boolean enableDirectMalloc) { + this.directMallocSupport = enableDirectMalloc; + } + public ClassLoader getClassLoader() { return classLoader; } @@ -411,6 +416,11 @@ public class TeaVMTool { target.setSourceMapBuilder(wasmSourceMapWriter); target.setSourceMapLocation(getResolvedTargetFileName() + ".map"); } + if(directMallocSupport) { + target.setEnableDirectMallocSupport(directMallocSupport); + target.setDirectMallocMinHeapSize(minHeapSize); + target.setDirectMallocMaxHeapSize(maxHeapSize); + } return target; } diff --git a/tools/core/src/main/java/org/teavm/tooling/builder/BuildStrategy.java b/tools/core/src/main/java/org/teavm/tooling/builder/BuildStrategy.java index 2fe510467..f391bb036 100644 --- a/tools/core/src/main/java/org/teavm/tooling/builder/BuildStrategy.java +++ b/tools/core/src/main/java/org/teavm/tooling/builder/BuildStrategy.java @@ -89,6 +89,8 @@ public interface BuildStrategy { void setWasmDebugInfoLocation(WasmDebugInfoLocation wasmDebugInfoLocation); + void setDirectMallocSupport(boolean enable); + void setMinHeapSize(int minHeapSize); void setMaxHeapSize(int maxHeapSize); diff --git a/tools/core/src/main/java/org/teavm/tooling/builder/InProcessBuildStrategy.java b/tools/core/src/main/java/org/teavm/tooling/builder/InProcessBuildStrategy.java index 9f790dfd1..ed94a59e8 100644 --- a/tools/core/src/main/java/org/teavm/tooling/builder/InProcessBuildStrategy.java +++ b/tools/core/src/main/java/org/teavm/tooling/builder/InProcessBuildStrategy.java @@ -75,6 +75,7 @@ public class InProcessBuildStrategy implements BuildStrategy { private TeaVMToolLog log = new EmptyTeaVMToolLog(); private boolean shortFileNames; private boolean assertionsRemoved; + private boolean directMallocSupport; @Override public void init() { @@ -258,6 +259,11 @@ public class InProcessBuildStrategy implements BuildStrategy { this.assertionsRemoved = assertionsRemoved; } + @Override + public void setDirectMallocSupport(boolean enable) { + this.directMallocSupport = enable; + } + @Override public BuildResult build() throws BuildException { TeaVMTool tool = new TeaVMTool(); @@ -289,6 +295,7 @@ public class InProcessBuildStrategy implements BuildStrategy { tool.setWasmExceptionsUsed(wasmExceptionsUsed); tool.setWasmDebugInfoLevel(wasmDebugInfoLevel); tool.setWasmDebugInfoLocation(wasmDebugInfoLocation); + tool.setDirectMallocSupport(directMallocSupport); tool.setMinHeapSize(minHeapSize); tool.setMaxHeapSize(maxHeapSize); tool.setHeapDump(heapDump); diff --git a/tools/core/src/main/java/org/teavm/tooling/builder/RemoteBuildStrategy.java b/tools/core/src/main/java/org/teavm/tooling/builder/RemoteBuildStrategy.java index bf71e65a6..106d10c0f 100644 --- a/tools/core/src/main/java/org/teavm/tooling/builder/RemoteBuildStrategy.java +++ b/tools/core/src/main/java/org/teavm/tooling/builder/RemoteBuildStrategy.java @@ -214,6 +214,11 @@ public class RemoteBuildStrategy implements BuildStrategy { request.maxHeapSize = maxHeapSize; } + @Override + public void setDirectMallocSupport(boolean enable) { + request.directMallocSupport = enable; + } + @Override public void setHeapDump(boolean heapDump) { request.heapDump = heapDump; diff --git a/tools/core/src/main/java/org/teavm/tooling/daemon/RemoteBuildRequest.java b/tools/core/src/main/java/org/teavm/tooling/daemon/RemoteBuildRequest.java index 78b40c20f..8fd6bbf3f 100644 --- a/tools/core/src/main/java/org/teavm/tooling/daemon/RemoteBuildRequest.java +++ b/tools/core/src/main/java/org/teavm/tooling/daemon/RemoteBuildRequest.java @@ -59,4 +59,5 @@ public class RemoteBuildRequest implements Serializable { public boolean heapDump; public boolean shortFileNames; public boolean assertionsRemoved; + public boolean directMallocSupport; } diff --git a/tools/gradle/src/main/java/org/teavm/gradle/TeaVMPlugin.java b/tools/gradle/src/main/java/org/teavm/gradle/TeaVMPlugin.java index c4f083fcc..5e8382f06 100644 --- a/tools/gradle/src/main/java/org/teavm/gradle/TeaVMPlugin.java +++ b/tools/gradle/src/main/java/org/teavm/gradle/TeaVMPlugin.java @@ -231,6 +231,9 @@ public class TeaVMPlugin implements Plugin { task.getStrict().convention(wasmGC.getStrict()); task.getSourceMap().convention(wasmGC.getSourceMap()); task.getSourceFilePolicy().convention(wasmGC.getSourceFilePolicy()); + task.getDirectMallocSupport().convention(wasmGC.getDirectMallocSupport()); + task.getMinHeapSize().convention(wasmGC.getMinHeapSize()); + task.getMaxHeapSize().convention(wasmGC.getMaxHeapSize()); setupSources(task.getSourceFiles(), project); buildTask.dependsOn(task); }); diff --git a/tools/gradle/src/main/java/org/teavm/gradle/api/TeaVMWasmGCConfiguration.java b/tools/gradle/src/main/java/org/teavm/gradle/api/TeaVMWasmGCConfiguration.java index 328d85643..356cd8d32 100644 --- a/tools/gradle/src/main/java/org/teavm/gradle/api/TeaVMWasmGCConfiguration.java +++ b/tools/gradle/src/main/java/org/teavm/gradle/api/TeaVMWasmGCConfiguration.java @@ -17,7 +17,7 @@ package org.teavm.gradle.api; import org.gradle.api.provider.Property; -public interface TeaVMWasmGCConfiguration extends TeaVMCommonConfiguration, TeaVMWebConfiguration { +public interface TeaVMWasmGCConfiguration extends TeaVMCommonConfiguration, TeaVMWebConfiguration, TeaVMNativeBaseConfiguration { Property getObfuscated(); Property getStrict(); @@ -37,4 +37,6 @@ public interface TeaVMWasmGCConfiguration extends TeaVMCommonConfiguration, TeaV Property getSourceFilePolicy(); Property getModularRuntime(); + + Property getDirectMallocSupport(); } diff --git a/tools/gradle/src/main/java/org/teavm/gradle/tasks/GenerateWasmGCTask.java b/tools/gradle/src/main/java/org/teavm/gradle/tasks/GenerateWasmGCTask.java index d91c3189b..7e244fdf2 100644 --- a/tools/gradle/src/main/java/org/teavm/gradle/tasks/GenerateWasmGCTask.java +++ b/tools/gradle/src/main/java/org/teavm/gradle/tasks/GenerateWasmGCTask.java @@ -27,6 +27,8 @@ import org.teavm.tooling.TeaVMTargetType; import org.teavm.tooling.builder.BuildStrategy; public abstract class GenerateWasmGCTask extends TeaVMTask { + private static final int MB = 1024 * 1024; + public GenerateWasmGCTask() { getStrict().convention(true); getObfuscated().convention(true); @@ -58,6 +60,18 @@ public abstract class GenerateWasmGCTask extends TeaVMTask { @Optional public abstract Property getSourceFilePolicy(); + @Input + @Optional + public abstract Property getDirectMallocSupport(); + + @Input + @Optional + public abstract Property getMinHeapSize(); + + @Input + @Optional + public abstract Property getMaxHeapSize(); + @Override protected void setupBuilder(BuildStrategy builder) { builder.setStrict(getStrict().get()); @@ -83,5 +97,8 @@ public abstract class GenerateWasmGCTask extends TeaVMTask { builder.setTargetType(TeaVMTargetType.WEBASSEMBLY_GC); TaskUtils.applySourceFiles(getSourceFiles(), builder); TaskUtils.applySourceFilePolicy(getSourceFilePolicy(), builder); + builder.setDirectMallocSupport(getDirectMallocSupport().getOrElse(false)); + builder.setMinHeapSize(getMinHeapSize().getOrElse(0) * MB); + builder.setMaxHeapSize(getMaxHeapSize().getOrElse(0) * MB); } }