work on adding direct malloc support option to tooling

This commit is contained in:
lax1dude 2024-11-02 17:10:33 -07:00
parent 26df995f7c
commit c630fae269
8 changed files with 48 additions and 1 deletions

View File

@ -119,6 +119,7 @@ public class TeaVMTool {
private Set<File> generatedFiles = new HashSet<>(); private Set<File> generatedFiles = new HashSet<>();
private int minHeapSize = 4 * (1 << 20); private int minHeapSize = 4 * (1 << 20);
private int maxHeapSize = 128 * (1 << 20); private int maxHeapSize = 128 * (1 << 20);
private boolean directMallocSupport = false;
private ReferenceCache referenceCache; private ReferenceCache referenceCache;
private boolean heapDump; private boolean heapDump;
private boolean shortFileNames; private boolean shortFileNames;
@ -268,6 +269,10 @@ public class TeaVMTool {
this.maxHeapSize = maxHeapSize; this.maxHeapSize = maxHeapSize;
} }
public void setDirectMallocSupport(boolean enableDirectMalloc) {
this.directMallocSupport = enableDirectMalloc;
}
public ClassLoader getClassLoader() { public ClassLoader getClassLoader() {
return classLoader; return classLoader;
} }
@ -411,6 +416,11 @@ public class TeaVMTool {
target.setSourceMapBuilder(wasmSourceMapWriter); target.setSourceMapBuilder(wasmSourceMapWriter);
target.setSourceMapLocation(getResolvedTargetFileName() + ".map"); target.setSourceMapLocation(getResolvedTargetFileName() + ".map");
} }
if(directMallocSupport) {
target.setEnableDirectMallocSupport(directMallocSupport);
target.setDirectMallocMinHeapSize(minHeapSize);
target.setDirectMallocMaxHeapSize(maxHeapSize);
}
return target; return target;
} }

View File

@ -89,6 +89,8 @@ public interface BuildStrategy {
void setWasmDebugInfoLocation(WasmDebugInfoLocation wasmDebugInfoLocation); void setWasmDebugInfoLocation(WasmDebugInfoLocation wasmDebugInfoLocation);
void setDirectMallocSupport(boolean enable);
void setMinHeapSize(int minHeapSize); void setMinHeapSize(int minHeapSize);
void setMaxHeapSize(int maxHeapSize); void setMaxHeapSize(int maxHeapSize);

View File

@ -75,6 +75,7 @@ public class InProcessBuildStrategy implements BuildStrategy {
private TeaVMToolLog log = new EmptyTeaVMToolLog(); private TeaVMToolLog log = new EmptyTeaVMToolLog();
private boolean shortFileNames; private boolean shortFileNames;
private boolean assertionsRemoved; private boolean assertionsRemoved;
private boolean directMallocSupport;
@Override @Override
public void init() { public void init() {
@ -258,6 +259,11 @@ public class InProcessBuildStrategy implements BuildStrategy {
this.assertionsRemoved = assertionsRemoved; this.assertionsRemoved = assertionsRemoved;
} }
@Override
public void setDirectMallocSupport(boolean enable) {
this.directMallocSupport = enable;
}
@Override @Override
public BuildResult build() throws BuildException { public BuildResult build() throws BuildException {
TeaVMTool tool = new TeaVMTool(); TeaVMTool tool = new TeaVMTool();
@ -289,6 +295,7 @@ public class InProcessBuildStrategy implements BuildStrategy {
tool.setWasmExceptionsUsed(wasmExceptionsUsed); tool.setWasmExceptionsUsed(wasmExceptionsUsed);
tool.setWasmDebugInfoLevel(wasmDebugInfoLevel); tool.setWasmDebugInfoLevel(wasmDebugInfoLevel);
tool.setWasmDebugInfoLocation(wasmDebugInfoLocation); tool.setWasmDebugInfoLocation(wasmDebugInfoLocation);
tool.setDirectMallocSupport(directMallocSupport);
tool.setMinHeapSize(minHeapSize); tool.setMinHeapSize(minHeapSize);
tool.setMaxHeapSize(maxHeapSize); tool.setMaxHeapSize(maxHeapSize);
tool.setHeapDump(heapDump); tool.setHeapDump(heapDump);

View File

@ -214,6 +214,11 @@ public class RemoteBuildStrategy implements BuildStrategy {
request.maxHeapSize = maxHeapSize; request.maxHeapSize = maxHeapSize;
} }
@Override
public void setDirectMallocSupport(boolean enable) {
request.directMallocSupport = enable;
}
@Override @Override
public void setHeapDump(boolean heapDump) { public void setHeapDump(boolean heapDump) {
request.heapDump = heapDump; request.heapDump = heapDump;

View File

@ -59,4 +59,5 @@ public class RemoteBuildRequest implements Serializable {
public boolean heapDump; public boolean heapDump;
public boolean shortFileNames; public boolean shortFileNames;
public boolean assertionsRemoved; public boolean assertionsRemoved;
public boolean directMallocSupport;
} }

View File

@ -231,6 +231,9 @@ public class TeaVMPlugin implements Plugin<Project> {
task.getStrict().convention(wasmGC.getStrict()); task.getStrict().convention(wasmGC.getStrict());
task.getSourceMap().convention(wasmGC.getSourceMap()); task.getSourceMap().convention(wasmGC.getSourceMap());
task.getSourceFilePolicy().convention(wasmGC.getSourceFilePolicy()); task.getSourceFilePolicy().convention(wasmGC.getSourceFilePolicy());
task.getDirectMallocSupport().convention(wasmGC.getDirectMallocSupport());
task.getMinHeapSize().convention(wasmGC.getMinHeapSize());
task.getMaxHeapSize().convention(wasmGC.getMaxHeapSize());
setupSources(task.getSourceFiles(), project); setupSources(task.getSourceFiles(), project);
buildTask.dependsOn(task); buildTask.dependsOn(task);
}); });

View File

@ -17,7 +17,7 @@ package org.teavm.gradle.api;
import org.gradle.api.provider.Property; import org.gradle.api.provider.Property;
public interface TeaVMWasmGCConfiguration extends TeaVMCommonConfiguration, TeaVMWebConfiguration { public interface TeaVMWasmGCConfiguration extends TeaVMCommonConfiguration, TeaVMWebConfiguration, TeaVMNativeBaseConfiguration {
Property<Boolean> getObfuscated(); Property<Boolean> getObfuscated();
Property<Boolean> getStrict(); Property<Boolean> getStrict();
@ -37,4 +37,6 @@ public interface TeaVMWasmGCConfiguration extends TeaVMCommonConfiguration, TeaV
Property<SourceFilePolicy> getSourceFilePolicy(); Property<SourceFilePolicy> getSourceFilePolicy();
Property<Boolean> getModularRuntime(); Property<Boolean> getModularRuntime();
Property<Boolean> getDirectMallocSupport();
} }

View File

@ -27,6 +27,8 @@ import org.teavm.tooling.TeaVMTargetType;
import org.teavm.tooling.builder.BuildStrategy; import org.teavm.tooling.builder.BuildStrategy;
public abstract class GenerateWasmGCTask extends TeaVMTask { public abstract class GenerateWasmGCTask extends TeaVMTask {
private static final int MB = 1024 * 1024;
public GenerateWasmGCTask() { public GenerateWasmGCTask() {
getStrict().convention(true); getStrict().convention(true);
getObfuscated().convention(true); getObfuscated().convention(true);
@ -58,6 +60,18 @@ public abstract class GenerateWasmGCTask extends TeaVMTask {
@Optional @Optional
public abstract Property<SourceFilePolicy> getSourceFilePolicy(); public abstract Property<SourceFilePolicy> getSourceFilePolicy();
@Input
@Optional
public abstract Property<Boolean> getDirectMallocSupport();
@Input
@Optional
public abstract Property<Integer> getMinHeapSize();
@Input
@Optional
public abstract Property<Integer> getMaxHeapSize();
@Override @Override
protected void setupBuilder(BuildStrategy builder) { protected void setupBuilder(BuildStrategy builder) {
builder.setStrict(getStrict().get()); builder.setStrict(getStrict().get());
@ -83,5 +97,8 @@ public abstract class GenerateWasmGCTask extends TeaVMTask {
builder.setTargetType(TeaVMTargetType.WEBASSEMBLY_GC); builder.setTargetType(TeaVMTargetType.WEBASSEMBLY_GC);
TaskUtils.applySourceFiles(getSourceFiles(), builder); TaskUtils.applySourceFiles(getSourceFiles(), builder);
TaskUtils.applySourceFilePolicy(getSourceFilePolicy(), builder); TaskUtils.applySourceFilePolicy(getSourceFilePolicy(), builder);
builder.setDirectMallocSupport(getDirectMallocSupport().getOrElse(false));
builder.setMinHeapSize(getMinHeapSize().getOrElse(0) * MB);
builder.setMaxHeapSize(getMaxHeapSize().getOrElse(0) * MB);
} }
} }