multitasking jvms isolates and kaffeos presentation by james rose
Post on 21-Dec-2015
220 views
TRANSCRIPT
![Page 1: Multitasking JVMs Isolates and KaffeOS Presentation by James Rose](https://reader036.vdocuments.site/reader036/viewer/2022062516/56649d5d5503460f94a3b60f/html5/thumbnails/1.jpg)
Multitasking JVMs
Isolates and KaffeOS
Presentation by
James Rose
![Page 2: Multitasking JVMs Isolates and KaffeOS Presentation by James Rose](https://reader036.vdocuments.site/reader036/viewer/2022062516/56649d5d5503460f94a3b60f/html5/thumbnails/2.jpg)
Multitasking in Java
We want to share the virtual machineShare bytecodeShare JIT-compiled native codeStart JVM onceEfficient IPC
![Page 3: Multitasking JVMs Isolates and KaffeOS Presentation by James Rose](https://reader036.vdocuments.site/reader036/viewer/2022062516/56649d5d5503460f94a3b60f/html5/thumbnails/3.jpg)
Naïve approach
Create a thread for each task Hope for the best!
![Page 4: Multitasking JVMs Isolates and KaffeOS Presentation by James Rose](https://reader036.vdocuments.site/reader036/viewer/2022062516/56649d5d5503460f94a3b60f/html5/thumbnails/4.jpg)
Problems with Sharing
No way to enforce separationNo accounting for resourcesNo way to safely terminate
processes
![Page 5: Multitasking JVMs Isolates and KaffeOS Presentation by James Rose](https://reader036.vdocuments.site/reader036/viewer/2022062516/56649d5d5503460f94a3b60f/html5/thumbnails/5.jpg)
Approaches
Code-to-code translationModified JVM
Approach taken by Kaffe, MVM
![Page 6: Multitasking JVMs Isolates and KaffeOS Presentation by James Rose](https://reader036.vdocuments.site/reader036/viewer/2022062516/56649d5d5503460f94a3b60f/html5/thumbnails/6.jpg)
Sharing in KaffeOS
Per-process heap and namespace Shared heaps for communication
between processes Common shared.* namespace for all
shared objects
![Page 7: Multitasking JVMs Isolates and KaffeOS Presentation by James Rose](https://reader036.vdocuments.site/reader036/viewer/2022062516/56649d5d5503460f94a3b60f/html5/thumbnails/7.jpg)
KaffeOS Memory Structure
No pointers to user heaps except from kernel
![Page 8: Multitasking JVMs Isolates and KaffeOS Presentation by James Rose](https://reader036.vdocuments.site/reader036/viewer/2022062516/56649d5d5503460f94a3b60f/html5/thumbnails/8.jpg)
Separation in KaffeOS
Write barrier prevents illegal references Shared code can’t keep user objects alive All heaps have independent GC Cross-heap references tracked by
reference counting
![Page 9: Multitasking JVMs Isolates and KaffeOS Presentation by James Rose](https://reader036.vdocuments.site/reader036/viewer/2022062516/56649d5d5503460f94a3b60f/html5/thumbnails/9.jpg)
Termination in KaffeOS
User/kernel separation allows safe termination
Termination deferred inside kernel code Shared objects are always on top of call
stack: malicious code can be terminated without harm to system
![Page 10: Multitasking JVMs Isolates and KaffeOS Presentation by James Rose](https://reader036.vdocuments.site/reader036/viewer/2022062516/56649d5d5503460f94a3b60f/html5/thumbnails/10.jpg)
Accounting in KaffeOS
Memory accounting includes allocations within the VM for a process
Independent GC improves accuracy Shared heaps charged to all sharers Precise resource accounting prevents
denial-of-service attacks
![Page 11: Multitasking JVMs Isolates and KaffeOS Presentation by James Rose](https://reader036.vdocuments.site/reader036/viewer/2022062516/56649d5d5503460f94a3b60f/html5/thumbnails/11.jpg)
JSR-121: Isolates and MVM
Defines Isolate classDefines a simple mechanism for
passing messagesMVM: HotSpot + JSR-121
![Page 12: Multitasking JVMs Isolates and KaffeOS Presentation by James Rose](https://reader036.vdocuments.site/reader036/viewer/2022062516/56649d5d5503460f94a3b60f/html5/thumbnails/12.jpg)
MVM is not an OS
No resource accounting
![Page 13: Multitasking JVMs Isolates and KaffeOS Presentation by James Rose](https://reader036.vdocuments.site/reader036/viewer/2022062516/56649d5d5503460f94a3b60f/html5/thumbnails/13.jpg)
Cross-Isolate Method Invocation
Or XIMI, for short Stripped-down version of RMI Isolates can call methods on stubs of
objects in other Isolates Stubs are generated by the VM
dynamically (no rmic)
![Page 14: Multitasking JVMs Isolates and KaffeOS Presentation by James Rose](https://reader036.vdocuments.site/reader036/viewer/2022062516/56649d5d5503460f94a3b60f/html5/thumbnails/14.jpg)
Portals
XIMI equivalent of RMI’s RemoteObject Objects are wrapped in Portals and
passed to clientspublic abstract class Portal { static public Portal newPortal(
Class interface,Object target,boolean copyable);
//...}
![Page 15: Multitasking JVMs Isolates and KaffeOS Presentation by James Rose](https://reader036.vdocuments.site/reader036/viewer/2022062516/56649d5d5503460f94a3b60f/html5/thumbnails/15.jpg)
Invoking Methods on Portals
A method call spawns a new thread in the server…
Or blocks until the server calls accept() Arguments to the method are “serialized”
Not really, that’s slow Method calls may fail if server dies
What happens then?
![Page 16: Multitasking JVMs Isolates and KaffeOS Presentation by James Rose](https://reader036.vdocuments.site/reader036/viewer/2022062516/56649d5d5503460f94a3b60f/html5/thumbnails/16.jpg)
Heap Structure
Generational GC:
Shared old generation, per-isolate new generation
XIReference: weak reference held only by stubs
![Page 17: Multitasking JVMs Isolates and KaffeOS Presentation by James Rose](https://reader036.vdocuments.site/reader036/viewer/2022062516/56649d5d5503460f94a3b60f/html5/thumbnails/17.jpg)
Heap Structure
XIReference
XIMIStub$Map
Portal
HashMap
Isolate AIsolate B
old space
Map nameserv
new spaces
![Page 18: Multitasking JVMs Isolates and KaffeOS Presentation by James Rose](https://reader036.vdocuments.site/reader036/viewer/2022062516/56649d5d5503460f94a3b60f/html5/thumbnails/18.jpg)
KaffeOS MVM Write barriers enforce
isolation on shared objects
Methods invoked directly
Write barriers slow down all programs
Objects or stubs are copied between isolates
Methods execute in the owning isolate
Resource accounting tricky
![Page 19: Multitasking JVMs Isolates and KaffeOS Presentation by James Rose](https://reader036.vdocuments.site/reader036/viewer/2022062516/56649d5d5503460f94a3b60f/html5/thumbnails/19.jpg)
Applications
Java shell Java daemon Dynamic web server Web browser Which model fits these applications
better?
![Page 20: Multitasking JVMs Isolates and KaffeOS Presentation by James Rose](https://reader036.vdocuments.site/reader036/viewer/2022062516/56649d5d5503460f94a3b60f/html5/thumbnails/20.jpg)
Web Server
Natural way to code it:interface WebRequest {
String getPath(); String getHostname();String getHTTPVersion();void println (String out);
}
interface Servlet {void run (WebRequest w);
}
![Page 21: Multitasking JVMs Isolates and KaffeOS Presentation by James Rose](https://reader036.vdocuments.site/reader036/viewer/2022062516/56649d5d5503460f94a3b60f/html5/thumbnails/21.jpg)
WebServer in KaffeOS
WebRequest must be in shared.* But now WebRequest can’t do anything
with WebServer! The paper does not define a
communication mechanism, only a sharing mechanism
![Page 22: Multitasking JVMs Isolates and KaffeOS Presentation by James Rose](https://reader036.vdocuments.site/reader036/viewer/2022062516/56649d5d5503460f94a3b60f/html5/thumbnails/22.jpg)
WebServer in MVM/XIMI
class WebServer{ public void answerQuery(Socket s) {
// ..make WebRequest object..port = Portal.newPortal( WebRequest, curRequest, false);new Isolate(appletName).start (port);
}}
![Page 23: Multitasking JVMs Isolates and KaffeOS Presentation by James Rose](https://reader036.vdocuments.site/reader036/viewer/2022062516/56649d5d5503460f94a3b60f/html5/thumbnails/23.jpg)
XIMI WebServer Execution
applet
serverget print get print
![Page 24: Multitasking JVMs Isolates and KaffeOS Presentation by James Rose](https://reader036.vdocuments.site/reader036/viewer/2022062516/56649d5d5503460f94a3b60f/html5/thumbnails/24.jpg)
This is stupid…
Switching contexts like this is silly and slow
But a coarse-grained interface is inconvenient for many applications
RMI makes more sense between machines than within machines
![Page 25: Multitasking JVMs Isolates and KaffeOS Presentation by James Rose](https://reader036.vdocuments.site/reader036/viewer/2022062516/56649d5d5503460f94a3b60f/html5/thumbnails/25.jpg)
MVM Structure
SharedCode
HeapHeap
Isolate 1Isolate 2
XIMI