Skip to content

Instantly share code, notes, and snippets.

@christianwimmer
Last active October 20, 2018 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christianwimmer/56f17b2d4658982f276501ac28617074 to your computer and use it in GitHub Desktop.
Save christianwimmer/56f17b2d4658982f276501ac28617074 to your computer and use it in GitHub Desktop.
static ByteBuffer plotAsSVGInNewIsolate(String function, double xmin, double xmax) {
/* Create a new isolate for the function evaluation and rendering. */
IsolateThread renderingContext = Isolates.createIsolate(CreateIsolateParameters.getDefault());
IsolateThread nettyContext = CurrentIsolate.getCurrentThread();
/* Copy the function String from the Netty isolate into the rendering isolate. */
ObjectHandle functionHandle = copyString(renderingContext, function);
/* Render the function. This call performs the transition from the Netty isolate to the rendering isolate, triggered by the annotations of plotAsSVG. */
ObjectHandle resultHandle = plotAsSVG(renderingContext, nettyContext, functionHandle, xmin, xmax);
/* Resolve and delete the resultHandle, now that execution is back in the Netty isolate. */
ByteBuffer result = ObjectHandles.getGlobal().get(resultHandle);
ObjectHandles.getGlobal().destroy(resultHandle);
/* Tear down the isolate, freeing all the temporary objects. */
Isolates.tearDownIsolate(renderingContext);
return result;
}
@CEntryPoint
private static ObjectHandle plotAsSVG(@CEntryPoint.IsolateThreadContext IsolateThread renderingContext, IsolateThread nettyContext, ObjectHandle functionHandle, double xmin, double xmax) {
/* Resolve and delete the functionHandle, now that execution is in the rendering isolate. */
String function = ObjectHandles.getGlobal().get(functionHandle);
ObjectHandles.getGlobal().destroy(functionHandle);
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment