210 likes | 417 Views
JVM And CLR. Dan Agar April 16, 2004. Outline. Java and .NET Design Philosophies Overview of Virtual Machines Technical Look at JVM and CLR Comparison of Environments Conclusions. Java Design. Developed by Sun Microsystems in the Early 1990s
E N D
JVM And CLR Dan Agar April 16, 2004
Outline • Java and .NET Design Philosophies • Overview of Virtual Machines • Technical Look at JVM and CLR • Comparison of Environments • Conclusions
Java Design • Developed by Sun Microsystems in the Early 1990s • Designed Primarily With the World Wide Web in Mind • Portability • Safety • Simplicity • Platform-neutral Virtual Machine
.NET Design • First Announced by Microsoft in mid-2000 • New Platform for Development of Windows Applications • Intended to Make Greater Use of the WWW • Language-Neutral Virtual Machine
Virtual Machines • Definition: self-contained environment that behaves like a separate computer • Used by Languages Before Java and .NET • Abstract Stack-Based Machines
Why Use Virtual Machines? Advantages: • Fewer Numbers of Compilers to Write • Compact Code • Safety Disadvantage: • Slower Execution Times
JVM • Approximately 250 Instructions • 32 bit Word Size • Two Forms of Data Representation • Scalars • Object References
JVM Program Execution • Java Programs Compiled to Class Files • JVM Loads Classes as Needed- Performs Safety Checks • During Execution JVM Performs Runtime Checks
JVM Many JVM Instructions are Type-Specific iload_1 ; push local int variable 1 iload_2 ; push local int variable 2 iadd ; add the two top elements istore_3 ; pop result into variable 3
JVM Four Different Method Call Instructions • Virtual Methods • Static Methods • Interface Methods • Virtual Methods Invoked Statically
JVM Summary • Target for Java • Supports Primarily Safe, Object-Oriented Techniques • Not Necessarily Desirable as a Target for Other Languages
CLR • Approximately 220 Instructions • No Fixed Word Size • Three Types of Data at Runtime • Scalars • References • Instances of Value Classes
CLR Program Execution • Assembly Files are the Main Units • Loaded Dynamically • Checks Performed Both During Load Time and During Runtime
CLR CLR Instructions Not Type-Specific ldloc.1 ; push local variable 1 ldloc.2 ; push local variable 2 add ; add the two top elements stloc.3 ; pop result into variable 3
CLR Three Different Method Call Instructions • call for standard method calls • callvirt for virtual and static method calls • calli for calls to function pointers
CLR Reference and Value Types • Value Types: Collections of Fields • Analogous to C structs or Pascal records • Reference Types: Classes and Arrays • Only One Instruction Needed to Instantiate a Class
Comparisons Safety: • The CLR allows for unsafe programming practices- JVM does not. Parameter Passing: • The CLR allows for the passing of reference parameters Language Support: • The CLR is designed to support non object-oriented languages.
Case Study: “C Support” The JVM: • ecgs-jvm • University of Queensland • gcc Backend Targeting the JVM • Workarounds • C’s view of memory • Global Static Data • Signed and Unsigned Numbers • Results • JVM and C Do Not Mix
Case Study: “C Support” The CLR • gcc .NET • Implemented at Cambridge • gcc Backend Targeting the CLR • No workarounds required • Results • Flawless compilation and execution on CLR
Performance Java Grande Benchmarks • Java and C# Tested • 1.4Ghz x86, Windows 2000 Professional
Conclusions Neither Machine is Definitively “Better”: • JVM is a Platform-Neutral Runtime • CLR is a Language-Neutral Runtime CLR is More Extensible • Languages of Varying Types Supported • Could be Ported to Other Platforms