Nigel Daniels | Waratek Ltd.Want to do the impossiblewith Java? Let„s do it!
Waratek Ltd © 2013Nigel Daniels• Wide range of tech roles including robotics,process control, network management, 3Dvisual...
Waratek Ltd © 2013Java Virtualization Interface• A pure-Java hypervisor inside the JVM.• Makes JVM multitenant, creates Ja...
Waratek Ltd © 2013What will we cover?• Java virtualization, an introduction• Key concepts• Object != Object• Exchanging ob...
Waratek Ltd © 2013Java virtualization,an introduction
Waratek Ltd © 2013Java virtualization, an introductionHost HardwareHypervisorGuest OSType 1 virtualizationHardwareHost OSH...
Waratek Ltd © 2013Java virtualization, an introductionHypervisorHost HardwareHypervisor(Virtual Machine Monitor)Is itsensi...
Waratek Ltd © 2013Java virtualization, an introductionTrap-and-emulating x86 instructions doesn‟t work forJava, all JVM in...
Waratek Ltd © 2013Java virtualization, an introductionHost JVMGuest Application (JVC)HypervisorJVM Hypervisor(Java Virtual...
Waratek Ltd © 2013Key concepts
Waratek Ltd © 2013Object != Object
Waratek Ltd © 2013Key concepts, Object != ObjectHost JVMHypervisorDOM-0JVC-1 JVC-2 JVC-3
Waratek Ltd © 2013Key concepts, Object != ObjectHost JVMHypervisorDOM-0JVC-1 JVC-2 JVC-3java.util.HashMap java.util.HashMa...
Waratek Ltd © 2013Key concepts, Object != ObjectHost JVMHypervisorDOM-0JVC-1 JVC-2 JVC-3Real BCLVirtual BCL-A Virtual BCL-...
Waratek Ltd © 2013Key concepts, Object != ObjectHost JVMHypervisorDOM-0JVC-1 JVC-2 JVC-3Real BCLVirtual BCL-A Virtual BCL-...
Waratek Ltd © 2013Exchanging objects
Waratek Ltd © 2013HypervisorJVMM-1 JVMM-2 JVMM-3JVMM-0Key concepts, exchanging objectsHost JVMDOM-0JVC-1 JVC-2 JVC-3RBCLVB...
Waratek Ltd © 2013HypervisorJVMM-1 JVMM-2 JVMM-3JVMM-0Key concepts, exchanging objectsHost JVMDOM-0JVC-1 JVC-2 JVC-3exit()...
Waratek Ltd © 2013HypervisorJVMM-1 JVMM-2 JVMM-3JVMM-0Key concepts, exchanging objectsHost JVMDOM-0JVC-1 JVC-2 JVC-3entry(...
Waratek Ltd © 2013HypervisorJVMM-1 JVMM-2 JVMM-3JVMM-0Key concepts, exchanging objectsHost JVMDOM-0JVC-1 JVC-2 JVC-3entry(...
Waratek Ltd © 2013DOM-0Key concepts, exchanging objectsJVC-1 JVC-2
Waratek Ltd © 2013Creating virtualenvironments
Waratek Ltd © 2013HypervisorJVMM-1 JVMM-2 JVMM-3JVMM-0Key concepts, creating virtual environmentsHost JVMDOM-0JVC-1 JVC-2 ...
Waratek Ltd © 2013JVMM-1Key concepts, creating virtual environmentsJVC-1GuestEnv-1MonitorEnvRuntimeSystemEnvFileSystemEnvN...
Waratek Ltd © 2013Java Virtualization InterfaceAPI
Waratek Ltd © 2013Java Virtualization Interface API
Waratek Ltd © 2013Java Virtualization Interface APIEntryPoint
Waratek Ltd © 2013package org.apache.catalina.startup;…public class BootstrapEnv extends HostEnvWhen the hypervisor starts...
Waratek Ltd © 2013public void start( String[] args, Class mainClass ){// Step 1) tell the world were loading……// Step 2) l...
Waratek Ltd © 2013public ClassLoaderEnv virtualize( final ClassLoader cl ){// Load our privileged types…// Is this class l...
Waratek Ltd © 2013DOM-0typespaceJVC-1typespaceVCLRCLStubClassJava Virtualization Interface API
Waratek Ltd © 2013Java Virtualization Interface APIJVC EntryPointNB. This may be renamedmarshalling on release
Waratek Ltd © 2013public ClassLoaderEnv startJVC(){// Load our managed exit transitions…// Start the JVCsuper.start();// S...
Waratek Ltd © 2013DOM-0typespaceJVC-1typespaceJava Virtualization Interface API
Waratek Ltd © 2013public ClassLoaderEnv virtualize( final ClassLoader cl ) {// Load our privileged typesif ( privTypes == ...
Waratek Ltd © 2013@MemberExit(type={ "javax/servlet/ServletRequest","javax/servlet/ServletRequestWrapper" },name="getLocal...
Waratek Ltd © 2013DEMO
Waratek Ltd © 2013What have we covered?• Java virtualization is type 1 virtualization, and ispure Java.• This requires typ...
Waratek Ltd © 2013References
Waratek Ltd © 2013Virtualisation references:https://en.wikipedia.org/wiki/Virtual_machine_monitorhttps://en.wikipedia.org/...
Waratek Ltd © 2013Thank Younigel.daniels@waratek.comQuestions?
Upcoming SlideShare
Loading in …5
×

Want to do the impossible with Java? Lets do it!

559
-1

Published on

Nigel Daniels presentation at JAXConf Santa Clara 2013

Want the impossible from Java? Lets do it!
Love Java but find the JVM doesn’t let you do what you want, or maybe you have never considered what could be done if you could change the machine itself? After all doing that means writing a custom JVM, right? That was true, until now!

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
559
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Mention the isolation in terms of memory, CPU, etc. This is how we get away from co-operative multi-tenancy.
  • Privileged types
  • Want to do the impossible with Java? Lets do it!

    1. 1. Nigel Daniels | Waratek Ltd.Want to do the impossiblewith Java? Let„s do it!
    2. 2. Waratek Ltd © 2013Nigel Daniels• Wide range of tech roles including robotics,process control, network management, 3Dvisualization, media and enterprise software.• 8 years with IBM developing, delivering andmanaging WebSphere related products.• Now freelance consulting on software productmanagement and delivery.• Consulting Product Manager with Waratek for1½ years.Introduction
    3. 3. Waratek Ltd © 2013Java Virtualization Interface• A pure-Java hypervisor inside the JVM.• Makes JVM multitenant, creates Java VirtualContainers (JVCs).• Simple example:• chroot for a JVC, written in pure-Java.• Complex example:• Virtualise webapps running on Apache Tomcat et al.• Currently on Waratek‟s CloudVM for Java.• V 1.0 – OSS License, includes the virtualizationdriver for Apache Tomcat.Introduction
    4. 4. Waratek Ltd © 2013What will we cover?• Java virtualization, an introduction• Key concepts• Object != Object• Exchanging objects• Creating virtual environments• API overview• DemoIntroduction
    5. 5. Waratek Ltd © 2013Java virtualization,an introduction
    6. 6. Waratek Ltd © 2013Java virtualization, an introductionHost HardwareHypervisorGuest OSType 1 virtualizationHardwareHost OSHypervisorGuest OSType 2 virtualization
    7. 7. Waratek Ltd © 2013Java virtualization, an introductionHypervisorHost HardwareHypervisor(Virtual Machine Monitor)Is itsensitive?No EmulateinstructionYesTrap x86instructionCallGuest OS
    8. 8. Waratek Ltd © 2013Java virtualization, an introductionTrap-and-emulating x86 instructions doesn‟t work forJava, all JVM instructions are non-sensitive.But what about a call like:java.lang.System.exit(int)JavaEE and every other Java application frameworkuses co-operative multi-tenancy…So how do we provide fully isolated virtualization forJava?but the last time co-operative multi-tenancy was usedwas in Windows 3.1 and Mac OS 9 in the 1990‟s!
    9. 9. Waratek Ltd © 2013Java virtualization, an introductionHost JVMGuest Application (JVC)HypervisorJVM Hypervisor(Java Virtual Machine Monitor)Is typevirtualized?NoEmulatetypeaccessYesExittransitionCallWith a type-1 virtual machine monitor for the JVMAll in pure Java!
    10. 10. Waratek Ltd © 2013Key concepts
    11. 11. Waratek Ltd © 2013Object != Object
    12. 12. Waratek Ltd © 2013Key concepts, Object != ObjectHost JVMHypervisorDOM-0JVC-1 JVC-2 JVC-3
    13. 13. Waratek Ltd © 2013Key concepts, Object != ObjectHost JVMHypervisorDOM-0JVC-1 JVC-2 JVC-3java.util.HashMap java.util.HashMap java.util.HashMapjava.util.HashMap
    14. 14. Waratek Ltd © 2013Key concepts, Object != ObjectHost JVMHypervisorDOM-0JVC-1 JVC-2 JVC-3Real BCLVirtual BCL-A Virtual BCL-B Virtual BCL-C
    15. 15. Waratek Ltd © 2013Key concepts, Object != ObjectHost JVMHypervisorDOM-0JVC-1 JVC-2 JVC-3Real BCLVirtual BCL-A Virtual BCL-B Virtual BCL-Cdefine()java.util.HashMapJIT emitted byte[]HashMapdefine()HashMap′define()HashMap′′define()HashMap′′′
    16. 16. Waratek Ltd © 2013Exchanging objects
    17. 17. Waratek Ltd © 2013HypervisorJVMM-1 JVMM-2 JVMM-3JVMM-0Key concepts, exchanging objectsHost JVMDOM-0JVC-1 JVC-2 JVC-3RBCLVBCL-A VBCL-B VBCL-C
    18. 18. Waratek Ltd © 2013HypervisorJVMM-1 JVMM-2 JVMM-3JVMM-0Key concepts, exchanging objectsHost JVMDOM-0JVC-1 JVC-2 JVC-3exit()ObjectAObjectB
    19. 19. Waratek Ltd © 2013HypervisorJVMM-1 JVMM-2 JVMM-3JVMM-0Key concepts, exchanging objectsHost JVMDOM-0JVC-1 JVC-2 JVC-3entry()ObjectCObjectB
    20. 20. Waratek Ltd © 2013HypervisorJVMM-1 JVMM-2 JVMM-3JVMM-0Key concepts, exchanging objectsHost JVMDOM-0JVC-1 JVC-2 JVC-3entry()ObjectCObjectAexit()
    21. 21. Waratek Ltd © 2013DOM-0Key concepts, exchanging objectsJVC-1 JVC-2
    22. 22. Waratek Ltd © 2013Creating virtualenvironments
    23. 23. Waratek Ltd © 2013HypervisorJVMM-1 JVMM-2 JVMM-3JVMM-0Key concepts, creating virtual environmentsHost JVMDOM-0JVC-1 JVC-2 JVC-3HostEnv-0GuestEnv-1 GuestEnv-2 GuestEnv-3
    24. 24. Waratek Ltd © 2013JVMM-1Key concepts, creating virtual environmentsJVC-1GuestEnv-1MonitorEnvRuntimeSystemEnvFileSystemEnvNetworkSystemEnv
    25. 25. Waratek Ltd © 2013Java Virtualization InterfaceAPI
    26. 26. Waratek Ltd © 2013Java Virtualization Interface API
    27. 27. Waratek Ltd © 2013Java Virtualization Interface APIEntryPoint
    28. 28. Waratek Ltd © 2013package org.apache.catalina.startup;…public class BootstrapEnv extends HostEnvWhen the hypervisor starts a particular sequence is used todetermine if a driver is to be loaded:1. Is the class provided an instance of HostEnv?2. Else append “Env” to the fully qualified class name. Is there amatching class?3. Else call the standard main entry point for the class.The JVI drivers entry point replaces the standard call to public staticvoid main (String[] args).JVI API – BootstrapEnv
    29. 29. Waratek Ltd © 2013public void start( String[] args, Class mainClass ){// Step 1) tell the world were loading……// Step 2) load our managed entry transitions.…// Step 3) start Tomcat propersuper.start( args, mainClass );}JVI API – BootstrapEnv
    30. 30. Waratek Ltd © 2013public ClassLoaderEnv virtualize( final ClassLoader cl ){// Load our privileged types…// Is this class loader a child of a virtualized// class loader?…else if( cl.getClass().getName().equals("org.apache.catalina.loader.WebappClassLoader")){// This is a webapp class loader, virtualise this!…tomcat_driver.ServletMonitorEnv me =new tomcat_driver.ServletMonitorEnv(this, name, cl);ClassLoaderEnv webappClassLoaderEnv = me.startJVC();…return webappClassLoaderEnv;}…}JVI API – BootstrapEnv
    31. 31. Waratek Ltd © 2013DOM-0typespaceJVC-1typespaceVCLRCLStubClassJava Virtualization Interface API
    32. 32. Waratek Ltd © 2013Java Virtualization Interface APIJVC EntryPointNB. This may be renamedmarshalling on release
    33. 33. Waratek Ltd © 2013public ClassLoaderEnv startJVC(){// Load our managed exit transitions…// Start the JVCsuper.start();// Setup the virtualized web app class loader environment…return webappClassLoaderEnv;}JVI API – MonitorEnv
    34. 34. Waratek Ltd © 2013DOM-0typespaceJVC-1typespaceJava Virtualization Interface API
    35. 35. Waratek Ltd © 2013public ClassLoaderEnv virtualize( final ClassLoader cl ) {// Load our privileged typesif ( privTypes == null &&cl.getClass().getName().equals("org.apache.catalina.loader.StandardClassLoader”)){privTypes = new TypeSet( cl );try {privTypes.loadPackages( new String[]{"javax.servlet.","javax.el." },true,new String[] {"javax.servlet.jsp.el.ImplicitObjectELResolver$Scope”},);privTypes.loadClass( "org.apache.tomcat.InstanceManager" );privTypes.loadClass( "java.io.Writer" );…// that’s all the classes, so seal it now.privTypes.seal();} catch( ClassNotFoundException e ) {throw new EnvironmentError( e );}}JVI API – BootstrapEnv
    36. 36. Waratek Ltd © 2013@MemberExit(type={ "javax/servlet/ServletRequest","javax/servlet/ServletRequestWrapper" },name="getLocale",descriptor="()Ljava/util/Locale;",conversion={ "java.util.Locale" } )public static Locale getLocaleX( ServletRequest req ) {return req.getLocale();}Java Virtualization Interface API – Exit/EntryAs the hypervisor loads the JVI driver the following sequence takesplace for each member:1. Is the member a privileged type (in the intersection)?2. Is there a matching description of the member as a MemberEntry or Exit?3. Failing ether of these throw an error while loading the driver.Here we can completely override the function without sub-classing,this gives us true polymorphism! We can make our Local anywhere.
    37. 37. Waratek Ltd © 2013DEMO
    38. 38. Waratek Ltd © 2013What have we covered?• Java virtualization is type 1 virtualization, and ispure Java.• This requires typespace virtualization.• Virtual machine monitors marshal the types andhandle the transitions (unless the type isprivileged).• The API allows us entry points into the VMMs.• We can now extend and control the entire JVMimage!Summary
    39. 39. Waratek Ltd © 2013References
    40. 40. Waratek Ltd © 2013Virtualisation references:https://en.wikipedia.org/wiki/Virtual_machine_monitorhttps://en.wikipedia.org/wiki/Popek_and_Goldberg_virtualization_requirementshttps://en.wikipedia.org/wiki/X86_virtualizationJVI an Introduction (Part I)http://www.waratek.com/blog/june-2013/open-source-api-for-java-virtualizationGeneral information about the Waratek CloudVM:http://www.waratek.comElasticat (JVI implemented for TomCat):http://www.waratek.com/product/elasticatJVI source code and Java doc (coming soon):https://github.com/waratek
    41. 41. Waratek Ltd © 2013Thank Younigel.daniels@waratek.comQuestions?

    ×