Skip to content

Instantly share code, notes, and snippets.

View shelajev's full-sized avatar

Oleg Šelajev shelajev

View GitHub Profile
Value mainFunction = context.getBindings("wasm").getMember("main");
Object result = mainFunction.execute();
import org.junit.Test;
import static org.junit.Assert.*;
import org.graalvm.polyglot.*;
import org.graalvm.polyglot.io.ByteSequence;
import java.io.IOException;
public class WasmPolyglotTest {
@Test
public void test() throws IOException {
Context.Builder contextBuilder = Context.newBuilder("wasm");
long fact(long n) {
if (n == 0)
return 1L;
else
return n * fact(n - 1);
}
public static void main(String[] args) throws Exception {
int cnt = Integer.parseInt(args[0]);
long seed = Long.parseLong(args[1]);
int repeat = Integer.parseInt(args[2]);
Shape[] samples = generate(3, args, cnt, seed);
double expected = computeArea(samples);
long prev = System.currentTimeMillis();
for (int i = 0; i < repeat * 1000; i++) {
double sum = computeArea(samples);
if (sum  != expected) {
static double computeArea(Shape[] all) {
double sum = 0;
for (Shape shape : all) {
sum += shape.area();
}
return sum;
}
abstract class Shape {
public abstract double area();
public static Shape cicle(double radius) {
return new Circle(radius);
}
public static Shape square(double side) {
return new Square(side);
}
public static Shape rectangle(double a, double b) {
return new Rectangle(a, b);
package example
object Hello extends App {
println(System.getProperty("java.home"))
}
@shelajev
shelajev / test-container.rb
Created March 25, 2019 18:56
Using test-containers-java from Python (GraalVM)
generic = Java.type('org.testcontainers.containers.GenericContainer')
container = generic.new('nginx')
container.setExposedPorts([80])
container.start();
puts "#{container.getContainerIpAddress()}:#{container.getMappedPort(80)}"
@shelajev
shelajev / test-containers.py
Created March 25, 2019 18:16
Using test-containers-java from Python (GraalVM)
import java
generic = java.type('org.testcontainers.containers.GenericContainer')
container = generic('nginx')
container.setExposedPorts([80])
container.start();
print('%s:%s' % (container.getContainerIpAddress(), container.getMappedPort(80)));
ImageName = netty-plot
Args = --features=com.oracle.svm.nettyplot.PlotterSingletonFeature -H:+SpawnIsolates