Top Banner
Lecture 4: J# Execution Model
27

Lecture 4: J# Execution Model

Feb 09, 2016

Download

Documents

Okesola Okesola

Lecture 4: J# Execution Model. Objectives. “J# programs execute like any other .NET program --- based on a run-time execution engine and an extensive software library. The details of how this works is quite interesting, and exemplifies how program execution has evolved... ” - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lecture 4: J# Execution Model

Lecture 4:

J# Execution Model

Page 2: Lecture 4: J# Execution Model

2MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 4-2

Objectives

“J# programs execute like any other .NET program --- based on a run-time execution engine and an extensive software library. The details of how this works is quite interesting, and exemplifies how program execution has evolved... ”

• .NET execution model• J# execution model

Page 3: Lecture 4: J# Execution Model

3MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 4-3

Part 1

• .NET execution model…

Page 4: Lecture 4: J# Execution Model

4MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 4-4

Example

• Recall the Banking App we built…

transactions.txt

customers.txt Banking App

Page 5: Lecture 4: J# Execution Model

5MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 4-5

BankingApp.exe

• Visual Studio .NET produces .EXE:

Visual Studio .NET

App.jsl

Customer.jsl

CustomersIO.jsl

Transactions.jsl

BankingApp.exe

Page 6: Lecture 4: J# Execution Model

6MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 4-6

How does .EXE execute?

• Since you can double-click on .EXE, you might be mislead…• Recall the .NET architecture:

– run-time environment + large software library

HardwareHardware

Operating SystemOperating System

Common Language Runtime (CLR)Common Language Runtime (CLR)

BankingApp.exeBankingApp.exe .NET Framework.NET FrameworkClass Library (FxCL)Class Library (FxCL)

Page 7: Lecture 4: J# Execution Model

7MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 4-7

.NET execution model

• When you run .EXE, a process is created & a small main() run– main() loads CLR into process & starts CLR running– CLR then loads our .NET code & begins execution…

HardwareHardware

Operating SystemOperating System

BankingApp.exe processBankingApp.exe process

CLR FxCL

BankingApp code

Page 8: Lecture 4: J# Execution Model

8MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 4-8

Why do this?

• As noted in Lecture 1, two reasons:1. safer execution2. portable execution

• Safer?– because CLR can prevent BankingApp from doing things it

doesn't have permission to do• Portable?

– because BankingApp code can run anywhere CLR exists

Page 9: Lecture 4: J# Execution Model

9MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 4-9

Are .NET programs really portable?

• Yes!• Implementations exist on:

– FreeBSD (i.e. the OS underneath Mac OS X)

– Linux (Mono project)

– Unix (dotGNU project)

• Unfortunately, support for J# is lagging, mostly C# and VB at the moment…

Page 10: Lecture 4: J# Execution Model

10MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 4-10

What do compiled .NET programs look like?

• Java programs are compiled into bytecodes for portability• .NET programs are compiled into CIL for portability

– CIL = Common Intermediate Language– a portable, generic assembly language…

Page 11: Lecture 4: J# Execution Model

11MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 4-11

How does CLR execute CIL?

• CIL cannot be directly executed on the hardware• CIL is translated at run-time into hardware's object code

– this is know as Just-In-Time ("JIT") compilation

HardwareHardware

Operating SystemOperating System

BankingApp.exe processBankingApp.exe processCLR

FxCLJIT Compiler

object code

BankingApp code

Page 12: Lecture 4: J# Execution Model

12MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 4-12

Part 2

• J# execution model…

Page 13: Lecture 4: J# Execution Model

13MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 4-13

Where's the Java Class Library?

• J# enables the best of both worlds:– you can use Java to program the .NET platform (i.e. FxCL)– you can use Java to program the Java platform (i.e. JCL)

• So far, we've only shown the FxCL:– where is the Java Class Library?– how is it represented?– how is it found?

Page 14: Lecture 4: J# Execution Model

14MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 4-14

(1) Where is the JCL?

• The JCL is considered part of the .NET Framework Class Library– in other words, it has been rewritten by Microsoft for .NET

– compatible with Sun's JCL, but not a complete implementation:• most of v1.1, some of v1.2• full support for portion of JCL required by AP CS

BankingApp.exe processBankingApp.exe process

CLR

BankingApp code

FxCL

JCL

Page 15: Lecture 4: J# Execution Model

15MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 4-15

(2) How is the JCL represented?

• Java uses .class & .jar files• The .NET Framework Class Library is a set of .DLLs

– DLL = Dynamic Link Library file– DLL = compiled code in library form, loaded & linked at run-time– 1 DLL typically contains multiple classes– Windows OS itself is built from 100's of DLLs

• The JCL is a subset of the FxCL .DLLs:– vjscor.dll– vjslib.dll– VJSSupUILib.dll– …

FxCL

vjscor.dll

vjslib.dll

VJSSupUILib.dll...

Page 16: Lecture 4: J# Execution Model

16MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 4-16

(3) How is the JCL found?

• Java searches along a CLASSPATH (list) of directories

• J# searches exactly 2 places, in this order:1. GAC: Global Assembly Cache (a Windows OS

directory)

2. AppBase: directory containing .EXE file

Page 17: Lecture 4: J# Execution Model

17MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 4-17

The GAC

• The GAC is a global repository of .NET DLLs

– .NET DLLs are known as "assemblies", hence the term assembly cache

• GAC is a protected Windows OS directory– created when .NET is installed– any user can read from cache– requires administrative rights to modify

• Location?– Windows XP: C:\Windows\Assembly– Windows 2000: C:\WinNT\Assembly

Page 18: Lecture 4: J# Execution Model

18MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 4-18

Views of the GAC

• Explorer shows you conceptual view• For actual representation, open command prompt & cd to it:

C:\> cd WindowsC:\Windows\> cd AssemblyC:\Windows\Assembly> dir

04/20/2004 <DIR> GAC04/20/2004 <DIR> NativeImages1_v1.0.370504/20/2004 <DIR> NativeImages1_v1.1.432204/20/2004 <DIR> temp

C:\Windows\Assembly> cd GACC:\Windows\Assembly\GAC> cd vjscorC:\Windows\Assembly\GAC\vjscor> cd 1.0.5*C:\Windows\Assembly\GAC\vjscor\1.0.5…> dir

04/20/2004 8,704 vjscor.dll

Page 19: Lecture 4: J# Execution Model

19MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 4-19

One last piece of the puzzle...

• When you run .EXE file…• … how does CLR know exactly which DLLs to load?

BankingApp.exe processBankingApp.exe process

CLR

BankingApp code

FxCL

vjscor.dll

vjslib.dll

VJSSupUILib.dll

?

Page 20: Lecture 4: J# Execution Model

20MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 4-20

.DLL dependencies stored in .EXE

• .EXE contains a list of dependencies, as well as code…

Page 21: Lecture 4: J# Execution Model

21MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 4-21

How did dependencies end up in .EXE?

• Visual Studio .NET!• Visual Studio compiles dependency information into .EXE

– based on list of references maintained in project file…

• Every .DLL must be explicitly referenced– common references set for you

automatically by VS .NET

– additional references are addedvia Project menu, Add Reference…

Page 22: Lecture 4: J# Execution Model

22MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 4-22

ILDasm

• ILDasm = "IL Disassembler"• ILDasm allows you to reverse engineer .EXE / .DLL

– to see manifest, CIL, etc.• ILDasm is a command-line tool

– installed as part of Visual Studio .NET

– to run, use Visual Studio .NET2003 Command Prompt

C:\BankingApp\bin\Debug> ildasm BankingApp.exe

Page 23: Lecture 4: J# Execution Model

23MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 4-23

Overlap between JCL and FxCL

• There is some overlap between Java Class Library and the .NET Framework Class Library, which can cause confusion.

• Consider the different implementations of ArrayList, each with its own method for finding the size:

Library Class Name Size MethodJCL java.util.ArrayList size()

FxCL System.Collections.ArrayList get_Count()

Page 24: Lecture 4: J# Execution Model

24MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 4-24

ILDasm to see ArrayList size()

• For instance see the String methods using Intellisense. Both the JCL equals() and the FxCL Equals() are shown.

• Consider the implementation of ArrayList size()– Open a Visual Studio Command Prompt

(Start / Visual Studio / Tools / Command Prompt)– Navigate to the GAC:

C:/Windows / Assembly / GAC – Enter the vjslib directory, then into the version directory

cd vjslib cd 1.0.5*

– Look at the contents of vjslib.dll using ILDasm: ildasm vjslib.dll

Page 25: Lecture 4: J# Execution Model

25MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 4-25

ILDasm to see ArrayList size() (cont'd)

• Select java.util

• Drill down to locate java.util.ArrayList

• Note how the size() method is implemented

Page 26: Lecture 4: J# Execution Model

26MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 4-26

Summary

• J# is Java on the .NET platform– full support for .NET Framework Class Library

– partial support for Java Class Library

• J# has a different execution model than Java– Java uses JVM, searches for .class/.jar files along CLASSPATH

– J# uses CLR, searches for .DLL files in GAC & AppBase

Page 27: Lecture 4: J# Execution Model

27MicrosoftIntroducing CS using .NETJ# in Visual Studio .NET 4-27

What's next?

• Lab #2…