View
49
Download
1
Category
Preview:
DESCRIPTION
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 - PowerPoint PPT Presentation
Citation preview
JVM And CLRJVM And CLRDan AgarDan Agar
April 16, 2004April 16, 2004
OutlineOutline
• Java and .NET Design Philosophies
• Overview of Virtual Machines
• Technical Look at JVM and CLR
• Comparison of Environments
• Conclusions
Java DesignJava 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.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 MachinesVirtual 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?Why Use Virtual Machines?
Advantages:• Fewer Numbers of Compilers to Write• Compact Code• Safety
Disadvantage:• Slower Execution Times
JVMJVM
• Approximately 250 InstructionsApproximately 250 Instructions
• 32 bit Word Size32 bit Word Size
• Two Forms of Data RepresentationTwo Forms of Data Representation• ScalarsScalars• Object ReferencesObject References
JVMJVM
Program ExecutionProgram Execution• Java Programs Compiled to Class FilesJava Programs Compiled to Class Files• JVM Loads Classes as Needed- Performs JVM Loads Classes as Needed- Performs
Safety ChecksSafety Checks• During Execution JVM Performs Runtime During Execution JVM Performs Runtime
ChecksChecks
JVMJVM
Many JVM Instructions are Type-SpecificMany 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
JVMJVM
Four Different Method Call InstructionsFour Different Method Call Instructions• Virtual MethodsVirtual Methods• Static MethodsStatic Methods• Interface MethodsInterface Methods• Virtual Methods Invoked StaticallyVirtual Methods Invoked Statically
JVMJVM
SummarySummary• Target for JavaTarget for Java• Supports Primarily Safe, Object-Oriented Supports Primarily Safe, Object-Oriented
TechniquesTechniques• Not Necessarily Desirable as a Target for Not Necessarily Desirable as a Target for
Other LanguagesOther Languages
CLRCLR
• Approximately 220 InstructionsApproximately 220 Instructions
• No Fixed Word SizeNo Fixed Word Size
• Three Types of Data at RuntimeThree Types of Data at Runtime• ScalarsScalars• ReferencesReferences• Instances of Value ClassesInstances of Value Classes
CLRCLR
Program ExecutionProgram Execution• Assembly Files are the Main UnitsAssembly Files are the Main Units• Loaded DynamicallyLoaded Dynamically• Checks Performed Both During Load Time Checks Performed Both During Load Time
and During Runtimeand During Runtime
CLRCLR
CLR Instructions Not Type-SpecificCLR 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
CLRCLR
Three Different Method Call InstructionsThree Different Method Call Instructions callcall for standard method calls for standard method calls callvirtcallvirt for virtual and static method calls for virtual and static method calls callicalli for calls to function pointers for calls to function pointers
CLRCLR
Reference and Value TypesReference and Value Types• Value Types: Collections of FieldsValue Types: Collections of Fields• Analogous to C structs or Pascal recordsAnalogous to C structs or Pascal records
• Reference Types: Classes and ArraysReference Types: Classes and Arrays• Only One Instruction Needed to Instantiate a ClassOnly One Instruction Needed to Instantiate a Class
ComparisonsComparisons
Safety:Safety:• The CLR allows for unsafe programming The CLR allows for unsafe programming
practices- JVM does not.practices- JVM does not.
Parameter Passing:Parameter Passing:• The CLR allows for the passing of reference The CLR allows for the passing of reference
parametersparameters
Language Support:Language Support:• The CLR is designed to support non object-The CLR is designed to support non object-
oriented languages.oriented languages.
Case Study: “C Support”Case Study: “C Support”
The JVM:The JVM:• ecgs-jvmecgs-jvm• University of QueenslandUniversity of Queensland• gcc Backend Targeting the JVMgcc Backend Targeting the JVM
• WorkaroundsWorkarounds• C’s view of memoryC’s view of memory• Global Static DataGlobal Static Data• Signed and Unsigned NumbersSigned and Unsigned Numbers
• ResultsResults• JVM and C Do Not MixJVM and C Do Not Mix
Case Study: “C Support”Case Study: “C Support”
The CLRThe CLR• gcc .NETgcc .NET• Implemented at CambridgeImplemented at Cambridge
• gcc Backend Targeting the CLRgcc Backend Targeting the CLR
• No workarounds requiredNo workarounds required• ResultsResults• Flawless compilation and execution on CLRFlawless compilation and execution on CLR
PerformancePerformance
Java Grande Benchmarks Java Grande Benchmarks • Java and C# Tested Java and C# Tested • 1.4Ghz x86, Windows 2000 Professional1.4Ghz x86, Windows 2000 Professional
QuickTime™ and aTIFF (LZW) decompressor
are needed to see this picture.
ConclusionsConclusions
Neither Machine is Definitively “Better”:Neither Machine is Definitively “Better”:• JVM is a Platform-Neutral RuntimeJVM is a Platform-Neutral Runtime• CLR is a Language-Neutral RuntimeCLR is a Language-Neutral Runtime
CLR is More ExtensibleCLR is More Extensible• Languages of Varying Types SupportedLanguages of Varying Types Supported• Could be Ported to Other PlatformsCould be Ported to Other Platforms
Recommended