Share
Embed
TruffleReloader: A Low-Overhead Language-Neutral Reloader
ICOOOLPS Workshop
July 18, 2016
Transcript
49 slides
-
TruffleReloader: A Low-Overhead Language- Neutral Reloader Tõnis Pool Allan Raundahl
Gregersen Vesal Vojdani -
Reloading - seeing the effects of source code changes immediately
in a running application. -
> Reloading Java via bytecode rewriting > 100+ integrations >
Application servers > Frameworks > IDEs -
Motivation > Thesis! > Usefulness - nice to have >
Truffle seemed interesting -
Truffle > Oracle Labs & Johannes Kepler University Linz >
Reusing JVM runtime > Java API for AST interpreters > Language context > C, JavaScript, Ruby, Python, R, LLVM IR -
def add(first, second): return first + second add(1, 1) U
U U 1. read first 2. read second 3. add -
U U I 1. read first 2. read second 3.
add U I I 1. read first 2. read second 3. add -
I I L 1. read first 2. read second 3.
add I I I 1. read first 2. read second 3. add -
> Assume the tree is stable and compile AST (sub)tree
to machine code > Deoptimize when assumptions invalidated -
If and how the Truffle framework can help language implementers
in adding reloading to their languages -
Truffle Instrumentation API > Access to the execution state of
Truffle interpreters > Wrapper nodes > Delegate to wrapped nodes > Fire events -
TruffleReloader > Reusable reloading core > Low overhead > Java
agent > -javaagent:/path/to/truffle-reloader.jar -
Requirements for reloading 1. Detect source code changes 2. Source
code parsing 3. Updating the execution tree -
# math.py def cos(x): ... def sin(x): ... # human_behaviour.py
def socialize(x): ... def sin(x): ... -
public interface LanguageReloader { String mimeType(); Supplier<CallTargetIdentity> getIdentityFor( RootCallTarget callTarget);
ReplayController getReplayController(); default Predicate<String> acceptCodePath() { return (path) -> true; } } -
public interface LanguageReloader { String mimeType(); Supplier<CallTargetIdentity> getIdentityFor( RootCallTarget callTarget);
ReplayController getReplayController(); default Predicate<String> acceptCodePath() { return (path) -> true; } } -
public interface LanguageReloader { String mimeType(); Supplier<CallTargetIdentity> getIdentityFor( RootCallTarget callTarget);
ReplayController getReplayController(); default Predicate<String> acceptCodePath() { return (path) -> true; } } -
public interface LanguageReloader { String mimeType(); Supplier<CallTargetIdentity> getIdentityFor( RootCallTarget callTarget);
ReplayController getReplayController(); default Predicate<String> acceptCodePath() { return (path) -> true; } } -
public interface LanguageReloader { String mimeType(); Supplier<CallTargetIdentity> getIdentityFor( RootCallTarget callTarget);
ReplayController getReplayController(); default Predicate<String> acceptCodePath() { return (path) -> true; } } -
public interface ReplayController<T extends ExecutionContext> { default void beforeStart(T context,
Source source, Object[] currentArgs) {} default void afterStop(T context, Source source, Object[] currentArgs) {} boolean shouldStopAt( RootCallTarget executableCallTarget); } -
public interface ReplayController<T extends ExecutionContext> { default void beforeStart(T context,
Source source, Object[] currentArgs) {} default void afterStop(T context, Source source, Object[] currentArgs) {} boolean shouldStopAt( RootCallTarget executableCallTarget); } -
public interface ReplayController<T extends ExecutionContext> { default void beforeStart(T context,
Source source, Object[] currentArgs) {} default void afterStop(T context, Source source, Object[] currentArgs) {} boolean shouldStopAt( RootCallTarget executableCallTarget); } -
Proxy CallNodes 1. Has the Source changed? 2. Are we
running Partial AST Replay? -
Proxy CallNodes 1. Has the Source changed? 2. Are we
running Partial AST Replay? Guard the actions with Assumptions -
public class SourceFileChecker { private static void run() { while
(true) { wakeUp.await(CHECK_FREQUENCY, MILLISECONDS); sourceFiles.forEach((file, reloader) -> { long currentModified = file.lastModified(); if (map.get(file) != currentModified) { map.put(file, currentModified); reloader.invalidate(); } }); } } } -
public class SourceFileChecker { private static void run() { while
(true) { wakeUp.await(CHECK_FREQUENCY, MILLISECONDS); sourceFiles.forEach((file, reloader) -> { long currentModified = file.lastModified(); if (map.get(file) != currentModified) { map.put(file, currentModified); reloader.invalidate(); } }); } } } -
public class SourceFileChecker { private static void run() { while
(true) { wakeUp.await(CHECK_FREQUENCY, MILLISECONDS); sourceFiles.forEach((file, reloader) -> { long currentModified = file.lastModified(); if (map.get(file) != currentModified) { map.put(file, currentModified); reloader.invalidate(); } }); } } } -
Evaluation > Graal.js, ZipPy, JRuby+Truffle and Simple Language > Functionality
> Performance > https://github.com/poolik/bench9000 > Case Study -
Use case SL ZipPy JRuby+Truffle Graal.js Changing a function y
y y y Changing multiple functions y y y y Adding a new function y y y y Multiple consecutive reloads y y y y Changing global variable definition n/a y y y Adding a new global variable definition n/a y y y Reloading functions with same name n/a y y y Adding a new class n/a y y y Changing a static method n/a y y y Changing an instance method n/a y y y Adding a new instance method used from variable n/a y y y Adding a new instance method used from new object n/a y y y Adding a new instance method used from field n/a y y y Adding a new instance method used from global variable n/a y y y Multiple file reload, changing a method in dependency n/a y y n/a Multiple file reload, adding a new method in dependency n/a y y n/a Multiple file reload, changing an instance method in dependency on existing object n/a y y n/a Multiple file reload, changing an instance method in dependency on new object n/a y y n/a -
Case Study > Simple OSS Ruby web application > Fixed
bugs & added features > https://github.com/poolik/sinatra_todo -
> Changed method body > Added new method > Added
new handler -
TruffleReloader > Reusable reloading core > Ruby LanguageReloader ~ 80
LOC > Python LanguageReloader ~ 170 LOC > JS LanguageReloader ~ 160 LOC > Low overhead