21
JVM And CLR JVM And CLR Dan Agar Dan Agar April 16, 2004 April 16, 2004

JVM And CLR

  • Upload
    dai

  • View
    49

  • Download
    1

Embed Size (px)

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

Page 1: JVM And CLR

JVM And CLRJVM And CLRDan AgarDan Agar

April 16, 2004April 16, 2004

Page 2: JVM And CLR

OutlineOutline

• Java and .NET Design Philosophies

• Overview of Virtual Machines

• Technical Look at JVM and CLR

• Comparison of Environments

• Conclusions

Page 3: JVM And CLR

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

Page 4: JVM And CLR

.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

Page 5: JVM And CLR

Virtual MachinesVirtual Machines

• Definition: self-contained environment that behaves like a separate computer

• Used by Languages Before Java and .NET

• Abstract Stack-Based Machines

Page 6: JVM And CLR

Why Use Virtual Machines?Why Use Virtual Machines?

Advantages:• Fewer Numbers of Compilers to Write• Compact Code• Safety

Disadvantage:• Slower Execution Times

Page 7: JVM And CLR

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

Page 8: JVM And CLR

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

Page 9: JVM And CLR

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

Page 10: JVM And CLR

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

Page 11: JVM And CLR

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

Page 12: JVM And CLR

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

Page 13: JVM And CLR

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

Page 14: JVM And CLR

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

Page 15: JVM And CLR

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

Page 16: JVM And CLR

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

Page 17: JVM And CLR

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.

Page 18: JVM And CLR

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

Page 19: JVM And CLR

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

Page 20: JVM And 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.

Page 21: JVM And CLR

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