Introduction: : Introduction CLR CLR � What What is is a a virtual virtual machine machine? ? � A new new virtual virtual machine machine A � CLI CLI and and CLR CLR � � JIT JIT execution execution and and performance performance on on CLR CLR � João Ferreira João Ferreira � Unix Unix with with “.NET” “.NET” � joao.ferreira@progmat.com joao.ferreira@progmat.com (c) João Ferreira - - ICCA 2004 ICCA 2004 1 1 (c) João Ferreira - - ICCA 2004 ICCA 2004 2 2 (c) João Ferreira (c) João Ferreira Virtual Machines Virtual Machines Virtual Machines Machines Virtual � Problems Problems with with native native compilers compilers � • Machine Machine arquitecture arquitecture dependence dependence • � Why Why “virtual”? “virtual”? � • Operating • Operating system system conventions conventions • Emulation Emulation software software that that translates translates from from • • Compiler Compiler specific specific issues issues • one language one language to to another another HIGH LEVEL LANGUAGE C � To solve To solve this this... ... � • Develop • Develop a a language language that that executes as executes as Assembly LOW LEVEL LANGUAGE bytecode (UNCOL, bytecode (UNCOL, Lisp Lisp, , P P- -Code Code, , etc etc.) .) • Failure Failure � � not not running running at at native native speed speed! ! • (c) João Ferreira - - ICCA 2004 ICCA 2004 3 3 (c) João Ferreira - - ICCA 2004 ICCA 2004 4 4 (c) João Ferreira (c) João Ferreira
Virtual Machines Machines New era era of of VM VM Virtual New � JVM JVM and and CLR CLR � Source Code (High Level Language) • Use • Use JIT JIT ( (Just Just- -In In- -Time Time) to ) to produce produce well well- - optimized native optimized native machine machine code code • Bytecode Bytecode ( (portability portability) ) • Compiler produces bytecode + + • native • native code code generation generation ( (speed speed) ) VIRTUAL MACHINE + + • Bytecode • Bytecode verifier verifier MISC HARDWARE/SOFTWARE • Stack Stack based based – – doesn’t doesn’t now now the the mean mean of of • registers registers (c) João Ferreira - - ICCA 2004 ICCA 2004 5 5 (c) João Ferreira - - ICCA 2004 ICCA 2004 6 6 (c) João Ferreira (c) João Ferreira Common Language Language Runtime Runtime Common Common Language Language Infraestructure Infraestructure Common � Microsoft marketing Microsoft marketing � � .NET ( .NET (DotNet DotNet) ) � International International Standard (ECMA) Standard (ECMA) � � � Is Is nothing nothing more more than than a virtual a virtual � CLI CLI Specification Specification � � machine, , however however.. .. machine CTS (Common Type System) � Based Based on on CLI CLI � � a standard a standard designed designed � from the the scracth scracth to to support support multiple multiple from CLS (Common Language Specification) languages languages CIL (Common Intermediate Language) VES (Virtual Execution System) (c) João Ferreira - - ICCA 2004 ICCA 2004 7 7 (c) João Ferreira - - ICCA 2004 ICCA 2004 8 8 (c) João Ferreira (c) João Ferreira
CTS (Common CTS ( Common Type Type Specification Specification) ) CLS (Common Common Language Language Specification Specification) ) CLS ( � A A rich rich type type system system that that supports supports the the � � A A subset subset of of CTS CTS types and and operations operations found found in in many many types � programming languages languages programming � Defines Defines the the rules rules for for each each individual individual � � To To support support a a wide wide range range of of programming programming language interop interop with with each each other other language � languages languages � Defines a Defines a set set of of rules rules for for types types � � Designed Designed for for object object oriented oriented, , procedural procedural � and functional functional languages languages and � More More than than 15 15 languages languages implemented implemented � CTS CTS (c) João Ferreira - - ICCA 2004 ICCA 2004 9 9 (c) João Ferreira - - ICCA 2004 ICCA 2004 10 10 (c) João Ferreira (c) João Ferreira CIL Example CIL Example CIL (Common Common Intermediate Intermediate Language Language) ) CIL ( public static void TestMethod (int a, int b) // arguments { int c; int d; int e; // locals � Also Also known known as as IL IL or or MSIL (Microsoft) MSIL (Microsoft) � c = a + b; d = 10; � A A language language more “ more “higher higher” ” than than native native � e = c + d; instruction set set instruction } ldarg num load argument no. num onto the stack � Based Based on on metadata metadata – – self self describing describing � … � …, value � An An assembly assembly oriented oriented language language � ldarg.1 • • Can Can create create instances instances of of objects objects • Call Call virtual virtual methods methods • ldloc indx load local variable no. indx onto the stack • Work Work with with arrays arrays • … � …, value • Throw Throw and and catch catch exceptions exceptions! ! • ldloc.1 (c) João Ferreira - - ICCA 2004 ICCA 2004 11 11 (c) João Ferreira - - ICCA 2004 ICCA 2004 12 12 (c) João Ferreira (c) João Ferreira
public static void TestMethod (int a, int b) { evaluation stack int c; int d; int e; CIL Example Example CIL c = a + b; d = 10; e = c + d; ldc num load numeric constant } … � …, num .method public hidebysig static void TestMethod(int32 a,int32 b) cil managed { ldc.i4 10 // Code size 12 (0xc) .maxstack 2 .locals init ([0] int32 c, [1] int32 d, stloc indx pop value from stack to local [2] int32 e) variable IL_0000: ldarg.0 …, value � … IL_0001: ldarg.1 IL_0002: add stloc.0 IL_0003: stloc.0 IL_0004: ldc.i4.s 10 IL_0006: stloc.1 IL_0007: ldloc.0 starg num store a value in an argument IL_0008: ldloc.1 slot IL_0009: add …, value � … IL_000a: stloc.2 IL_000b: ret starg.1 } // end of method Class1::TestMethod (c) João Ferreira - - ICCA 2004 ICCA 2004 13 13 (c) João Ferreira - - ICCA 2004 ICCA 2004 14 14 (c) João Ferreira (c) João Ferreira CLR CLR VES (Virtual Execution Execution System System) ) VES (Virtual � Is Is the the Microsoft VES (Virtual Microsoft VES (Virtual Execution Execution � System) for CLI ) for CLI � Implements Implements and and enforces enforces CTS CTS System � � CLR CLR will will use: use: � Will Will load load and and run run programs programs written written � � • Managed Managed modules modules for the for the CLI CLI ( (with with IL IL code code) ) • • Assemblies Assemblies • � Handles Handles all all the the major major overheads overheads of of � • JIT • JIT compilers compilers traditional programming programming models models traditional � How How it it will will load load? ? � To run To run CLI CLI- -compliant compliant programms programms into into Win32 Win32 • JIT • JIT and Intel and Intel x86 x86 architectures architectures. . • Install Install time time compilers compilers • (c) João Ferreira - - ICCA 2004 ICCA 2004 15 15 (c) João Ferreira - - ICCA 2004 ICCA 2004 16 16 (c) João Ferreira (c) João Ferreira
Recommend
More recommend