Fork of JauVM - JVM stack emulator in Java.
http://drxaos.github.io/jvmvm/
Target of this project is to create sandbox for user java code execution with control over instructions and save/load running program.
To run VM you just need to create and compile project:
Project project = new Project("Name")
.addFiles(mapWithFileNamesAsKeysAndTheirContentsAsValues)
.addSystemClasses(listOfSystemClassesThatYouAllowToUseInVm)
.compile()
.setupVM("pkg.ClassName", "methodName");
This will start execution of static method on given class.
JvmVM virtualizes jvm stack and instructions execution for given code. And then you can execute instructions:
while (project.isActive()) {
project.step();
}
Object result = project.getResult();
or to execute until return:
Object result = project.run();
You can manage breakpoints to stop execution at needed point:
project.setBreakpoint("pkg/ClassName.java", 15);
project.setBreakpoint("pkg.ClassName", "methodName");
project.removeBreakpoint("pkg/ClassName.java", 20);
try{
Object result = project.run();
} catch(ProjectBreakpointException e) {
// ...
}
project.clearBreakpoints();
VM has ability to mainpulate values of static objects and in stack:
int x = project.getLocalVariable("x");
project.setLocalVariable("x", x 1);
Object obj = project.getStaticField("pkg.ClassName", "fieldName");
project.setStaticField("pkg.ClassName", "fieldName", obj2);
Executed programs must use only serializable system classes for ability of VM serialization. User classes made serializable by classloader.
byte[] serializedProject = project.saveToBytes();
Project restoredProject = Project.fromBytes(serializedProject);
restoredProject.run();
You can continue running restored project as if it is a new separate project, stopped at same point as original.
Project is in alpha and contains bugs, undocumented features and documentation for unwritten features. See tests and source code.
Original project is JauVM - http://jauvm.blogspot.ru/. To achieve full functionality original classes were modified and additional utilities were added.
Contact me: [email protected].