-
Notifications
You must be signed in to change notification settings - Fork 59
Aot pre-compiled machine #556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
1df811d to
d1306d9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great!
runtime/src/test/java/com/dylibso/chicory/runtime/ModuleTest.java
Outdated
Show resolved
Hide resolved
machines-tests/src/test/java/com/dylibso/chicory/testing/MachinesTest.java
Outdated
Show resolved
Hide resolved
aot-maven-plugin/src/main/java/com/dylibso/chicory/maven/aot/AotGenMojo.java
Outdated
Show resolved
Hide resolved
aot-maven-plugin/src/main/java/com/dylibso/chicory/maven/aot/AotGenMojo.java
Show resolved
Hide resolved
aot-maven-plugin/src/main/java/com/dylibso/chicory/maven/aot/AotGenMojo.java
Outdated
Show resolved
Hide resolved
|
Let me see if I can change the generated module so that we don't need to generate the machine. |
|
It's mostly done, but I'll need to finish it tomorrow: https://github.com/electrum/chicory/commits/aot-machine |
That would be really cool, we still need to generate a wrapper(or something) usable by the user as directly referencing the generated |
0ece6c8 to
617d65e
Compare
|
Things are coming together pretty nicely! |
aot-maven-plugin/src/main/java/com/dylibso/chicory/maven/aot/AotGenMojo.java
Outdated
Show resolved
Hide resolved
| return this; | ||
| } | ||
|
|
||
| public Builder withSkipImportMapping(boolean s) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding this, we should refactor the AOT compiler so that it doesn't need Instance, as it actually only uses Module. The reason it takes Instance is because it implements the Machine interface. But the compilation itself doesn't use it.
I'll put up a PR to refactor it. I like that these changes push the code to have a better structure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this approach and I'll follow up, let me have a little more slack time 😅
|
|
||
| <name>Chicory - wabt</name> | ||
| <description>wabt tools running in pure Java with Chicory</description> | ||
| <description>wabt tools compiled to pure Java with Chicory</description> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technical "compiled to pure JVM bytecode" but that doesn't sound as nice 😆
wabt/pom.xml
Outdated
| <dependencies> | ||
| <dependency> | ||
| <groupId>com.dylibso.chicory</groupId> | ||
| <artifactId>aot-runtime</artifactId> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is why we need to add it to the BOM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding here is that we want to add to the bom only modules that are actually going to make the "supported" 1.0.
The aot is still out of this category imho(needs a bit more investment), I aim for it to be next, and I'm happy to help whenever possible, but I'm a bit on the fence of adding it to the bom now as it might create misaligned expectations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the latest changes in #565, aot-runtime is no longer needed at all!
machine-tests/src/test/java/com/dylibso/chicory/testing/MachinesTest.java
Outdated
Show resolved
Hide resolved
| private Instance.Builder quickJsInstanceBuilder() { | ||
| return Instance.builder( | ||
| Parser.parse( | ||
| MachinesTest.class.getResourceAsStream( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can use getclass()
| } | ||
|
|
||
| @Test | ||
| public void shouldUseMachineCallOnlyForExport() throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we move this test to the AOT module? It's not dependent on precompilation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good suggestion 👍 it's just a sanity check from the prev implementation of call_indirect at the end of the day.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out that is not dependent on precompilation, but it uses wabt and moving it to aot introduces a circular dependency.
Let's keep it as a follow up.
aot-maven-plugin/pom.xml
Outdated
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-plugin-plugin</artifactId> | ||
| <configuration> | ||
| <goalPrefix>prefix</goalPrefix> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be chicory?
| var instance = | ||
| Instance.builder(Parser.parse(wasmFile)) | ||
| .withMachineFactory(inst -> new AotMachine(name, inst)) | ||
| .withStart(false) | ||
| .withInitialize(false) | ||
| .withSkipImportMapping(true) | ||
| .build(); | ||
| var compiled = ((AotMachine) instance.getMachine()).compiledClass(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With #565, this can become
var module = Parser.parse(wasmFile);
var result = AotCompiler.compileModule(module, name);
var compiled = result.classBytes();It returns Map<String, byte[]> because we'll need to support multiple classes for method splitting and possibly other features. Any additional classes will be nested classes of the provided class name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like an ideal API, just give me a little to review 565 👍 thanks a lot for the support!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the API to allow returning multiple classes, which is needed for inlining AotMethods, method splitting, etc. With that change, this code can become something like
for (Entry<String, byte[]> entry : result.classBytes()) {
var binaryName = entry.getKey().replace('.', '/') + ".class"
var targetFile = targetClassFolder.toPath().resolve();
try {
Files.write(targetFile, entry.getValue());
} catch (IOException e) {
throw new MojoExecutionException("Failed to write " + targetFile, e);
}
}Note that the configured class name must not be a nested name like x.y.Foo.Bar as it's not possible to differentiate this from an uppercase Foo package, and more importantly, generating code into a nested class is not possible (see this and this for an idea of why).
617d65e to
7d6ba99
Compare
| var split = name.split("\\."); | ||
| var finalFolder = targetClassFolder.toPath(); | ||
| var finalSourceFolder = targetSourceFolder.toPath(); | ||
| for (int i = 0; i < (split.length - 1); i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this code is a little messy, but should be easy to improve over it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated everything on top of the great latest improvement done by @electrum .
I go ahead and merge this, we can fix on top any leftover.
This builds on top of #552 , so review only the second commit here.
Supersede and finalize the effort started in #494
Notes:
Machineimplementation to get the interoperability working