Post on 27-Dec-2015
1©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
Java Forum 2001
Clemens F. VastersCTO
clemensv@newtelligence.com
The Common Language Runtime
2©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
COM – The Good Things
Commercially most successful component model in history – for component vendors
COM concepts adopted throughout the industry• Influenced many environments on many platforms
Most complete component infrastructure•From Compound Documents to Enterprise Services
Microsoft Transaction Server (1996, now COM+)• Introduced component oriented transactions
•Component and role-based security
• If there wasn't MTS, there would be no J2EE or OTS
• J2EE steps on over 20 Microsoft MTS-related patents
3©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
COM – The Bad Things
Essentially "Windows Only"•Only a single port to other platforms (Software
AG)
•Mainsoft, Bristol, Microsoft use Software AG port Quite limited Type-System
•Only scalar types for most scenarios Relies on binary layout of C++
•Hard to implement with languages like SmallTalk DCOM wire-protocol is a closed model
•Not extensible and hard to configure Components must be registered
•Requires local code, system easily polluted
•Versioning difficult, "DLL Hell"
•Registration always has global scope
4©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
Java – The Good Things
"Write once, run anywhere" Single code-base runs on many platforms
•Executed on an isolated virtual machine
•Abstracts machine details Great, clean programming language Great features for server-side development
•Automatic memory management
•Remoting model, network support
• J2EE Enterprise Java Beans
5©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
Java – The Bad Things
"Write once, test anywhere"
•Many different JVMs, many different bug-sets
• JVMs are simply no picnic to build
JVM model is in jeopardy
•Applets and Java Desktop apps are essentially dead
•Server-side Java quickly fractioning (IBM,BEA,Sun)
J2EE betrays the "write once" model
•App-Server vendors enhance core spec
•Using essential features causes vendor lock-in
Real world apps need platform integration !
•Where is Sun 's platform support for SOAP, WSDL ?!?
•Real solutions run on one deployment platform
6©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
XML
Services .NET, OS and COM+ Services
.NET Framework
What Is Microsoft .NET ?
Runtime Layer
Operating System
Common Type
System
Common Language Runtime
Building Blocks"Hailstorm"
SQL Server BizTalk ...
LanguagesC#, Visual Basic, Python, Perl,... .NET Enterprise Servers
...YellowPages
...
Web Services
P/In
voke
COM/Interop
.NET Solutions
XML
IL
7©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
Microsoft .NET is ...
The Common Language Infrastructure (CLI)•Common Type System
•Common Language Runtime
• Intermediate Language
•CLI Class Framework (subset of .NET Framework) all of those are already submitted to ECMA TC39
The Development Languages and Tools• .NET Framework SDK
with C#, VB.NET, C++, JScript.NET
•C# also submitted to ECMA TC39
•Microsoft Visual Studio.NET Web Services ("Hailstorm") .NET Enterprise Servers
8©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
The Common Language Runtime
Jobs of the Common Language Runtime:•Code management, Loading and execution of
managed code (IL or native)
•Software memory isolation, memory management
•Conversion of IL to native code (JIT invocation), Verification of the type safety of IL
•Accessing metadata (enhanced type information), object layout
• Insertion and execution of security checks
•Handling exceptions, including cross-language exceptions
• Interoperation between .NET Framework objects, platform services and COM objects
•Supporting developer services (profiling, debugging)
9©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
CLR Diagram
Class Loader
IL to NativeCompilers (JIT)
CodeManager
GarbageCollector (GC)
Security Engine Debug Engine
Type Checker Exception Manager
Thread Support COM Marshaler
Base Class Library Support
10©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
The Intermediate Language (IL)
Simple, object-oriented Assembly language
•Stack based, no registers
•Automatic, method-level storage locations
•Each stack slot is System.Object typed
•Supports tail calls and other multi-language necessities
Type-safe without needing typed operators
•Allows "Generics" (Templates) in later CLR version Designed to be compiled into native code
•No "virtual machine" concept or restrictions
•Dissolves into 100% pure machine code at runtime
Comes with standardized canonical representation
•There is an actual assembler (ilasm) for IL
11©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
CLR Execution Model (1)
Common Language Runtime Execution Engine
IL &Metadata
ClassLib
Class Loader
ManagednativeCode
Execution
LanguageCompiler
JIT Compiler
SourceCode
12©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
CLR Execution Model (2)
All CLS-compliant languages compile into IL IL code is wrapped by metadata Host process hosts CLR, loads initial metadata CLR loader resolves external references All code is always JITted into native code
•PreJIT: JIT at installation time
•EconoJIT: JIT at runtime – fast JITting
•Standard JIT: JIT at runtime – balances speed/optimization
•OptJIT: JIT at runtime – fast, optimized code JITter optimized for machine (SMP,64Bit,etc.)
13©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
The Common Type System
A common type system for all .NET languages Rich, seamlessly shareable types and classes
•Enables cross-language (re)use
•Enables cross-language inheritance
Roots in XML Schema Part-2 Every simple and complex type is derived from
System.Object• Includes simple types (int, float)
•No "magic" types as in Java, C++
14©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
Type Characteristics
Value types
•Represented by sequence of bits in a location
•Common built-in data types
•Boxing: Unboxed: No associated metadata, pure data Boxed: Full metadata, all object features
Reference types
•Represented by location and sequence of bits
•Objects, Interfaces, References, boxed values
15©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
Built-In Value Types
Integer values• int8, int16, int32, int64
•unsigned counterparts
Super long decimal value•decimal (28 digits)
IEEE Floating point values•float32, float64
Unicode character values•char, string (immutable reference type)
Boolean value•bool
16©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
System.Object
Base class for each and every type• Inheritance from System.Object is typically
implicit
•All simple and complex types share the same base
Single base-class makes framework consistent•Collection classes can be used for everything
• Intrinsic model for handling variant types
•Strongly typed. No pointers, no structures.
System.Object is a reference type Value types (internally) inherit from ValueType
•Special class derived from Object
•No type is "magic"
17©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
Memory Management
The .NET memory manager is a garbage collector
All .NET languages (including C++) are GC'ed .NET Garbage Collector implementation:
•Automatically moves objects to optimize layout Supports "pinning" to temporarily suspend
moving for certain Interop scenarios.
• Implements multi-generation algorithm Youngest objects go first, Oldest objects go last
•Opt-out model for running Finalizers on shutdown
18©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
Application Domains
Fully isolated execution space for applications Independent of OS concept of thread, process CLR can be shared by multiple app domains
Process Process
AppDomain AppDomainAppDomain
Object Object
ObjectObjectObject
19©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
Threading
All .NET languages are fully multi-threaded Each .NET thread runs on an OS thread. Each process automatically maintains a
ThreadPool Thread binds to object-bound delegate
•Object-based thread entry points
Synchronization support through:•Monitor (critical sections, lightweight locks)
•Mutexes
• .NET Remoting Context based synchronization
20©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
Assemblies
Single-File or Multi-File group of code and "baggage"
An Assembly can consist of•Multiple modules (code containers)
•One module can host any number of classes
•Any number of auxiliary files (.jpg, .html, .anything)
Assembly "directory" is called the "Manifest"•Contains all internal and external file references
•Contains information about Versioning Code Originator (digital signature) External References Security Permission Requests …
21©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
Strong Name Assemblies
A "strong name" is a world-wide unique name Achieved by digitally signing Assemblies with
an X.509 PKI private/public key pair Strong Names enable:
•Seamless side-by-side installation and use of any number of versions of the same Assembly
•Automatic updates through versioning algorithms
•Code and "baggage" integrity through signature
Strong Name Assemblies can be shared• Installed in "Global Assembly Cache"
•Versioning Scheme: Major.Minor.Revision.Build Revisions override previous versions Major/Minor updates require configuration
22©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
.NET Security
Evidence and PKI based code access security
•Origin and integrity of code through signatures
•No code spoofing, unauthorized patches Rich permission-based system, configurable
sandbox
•Can turn off unsafe code, P/Invoke and COM/Interop
Role based and identity based user-level security Cascaded security policy model
•Configure security policies based on code origin, user groups, etc.
•Enterprise, Machine, User and AppDomain level
23©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
.NET Security (2)
Detects unauthorized code at load-time through manifest and code inspection
Dynamic permission management at runtime through stack walks
Assembly A1
Assembly A2
Assembly A3
Assembly A4
G1
G4
G3
G2
P
P
P
Call chain
24©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
.NET Reflection
[serializable]public class Person : { public event OnSaveChange onsv; public Date DOB; public string FirstName; public string LastName; public string Name { get { return FirstName + " " + LastName; } } public void Person(string First,string Last) { FirstName=First;LastName=Last; } public bool Save() { System.Type t = this.GetType(); foreach( FieldInfo f in t.GetFields() ) { ... } }
System.Type
Attributes
Fields
Properties
Constructors
Methods
Events
Parameters
25©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
.NET Reflection.Emit
Full representation of physical structure Allows building modules and assemblies at
runtime•Transient code only used at runtime
•Persistent code for reuse Create classes, types and emit IL Used by .NET compilers to build .NET apps Scenarios
•Build classes dynamically from script-like code .NET XPath, Regular Expressions do just that !
•Create dynamic wrappers for existing code
•Transfer code-chunks to remote machines Distributed processing scenarios (like SETI@home)
•Attribute-Driven Templates
26©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
.NET Remoting Infrastructure
Open Remoting channel architecture Channels can talk to any arbitrary endpoint No assumption is made about endpoint archtecture
•Can be Linux, Java, Solaris, you name it
In .NET: HTTP; SMTP and raw TCP-Sockets channels Extensible: You add APPC, MQSeries, etc.
ServerClient
Channel"Proxy"
Dis-patcher
27©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
.NET Remoting Infrastructure
Formatters: Turn data into wire formats In .NET: Binary and SOAP formatters Extensible architecture: You can supply RMI, IIOP
Channel
encode into wire format
decode from wire format
SOAP, Binary, Custom
28©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
.NET Remoting Contexts
Derived from COM+ context idea Encloses objects with same functional context Carries shared properties that describe behavior Allows message interception and manipulation
at any remoting boundary
RqTx Sync Thrd
remoting boundary
Object
ObjectObject
AppDomain
Context Context
Object Object
Object Object
29©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
Enterprise Service Integration
Transactions through COM+ Transaction integration•Uses attributed programming style
•Components are automatically registered in COM+ [Transaction(TransactionOption.Required)]public class MyComponent : ServicedComponent{ // everything transactional here}
Same level of integration for all other COM+ services
.NET Framework Level support for•Message Queuing, WBEM/WMI, Directory Services,
System Diagnostics, Performance Counters, etc.
30©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
ASP.NET Web Forms Execution Model
IIS
ASP.NET Runtime
Instantiate controls
Parse .aspx file
Generate page class
Request .aspx file
Response
Client Server
31©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
ASP.NET Web Forms Event Model
ServerWeb Client
parse messageevent
event handler
eventmessage
response
call appropriateevent handler
32©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
ASP.NET is compiled, native code
<%Page codebehind="pg"%><html><body> <asp:label/> <asp:textbox/></html></body>
ASP.NET compiler
Reflection
Page Assembly
IIS
ASP.NET runtime
1 2
2a 3
file exists? assembly exists, same timestamp?
no? compile run
class pg : Page{ ... }
33©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
Web Service Infrastructure
Web Service
(ASP.NET, .NET Remoting)
Web ServiceClient
(any .NET app,any SOAP client,
any device)
Discovery
Request disco
Return disco (XML)
Description
Request WSDL
Return WSDL (XML)
Protocol
Request .asmx / Endpoint
Return response (XML)
34©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
And what about Java ? JUMP!
OptionsOptions• Re-build existing VJ++ source to Re-build existing VJ++ source to
run on .NET CLRrun on .NET CLR• Continue writing new code in Continue writing new code in
Java Java • Can use Java.* class packages as Can use Java.* class packages as
defined by JDK 1.1.4defined by JDK 1.1.4• Regarding existing Java .class Regarding existing Java .class
filesfiles•Can reuse as isCan reuse as is•Can convert to ILCan convert to IL
What Microsoft is deliveringWhat Microsoft is delivering What this means for developersWhat this means for developers
ToolsTools• Java-to-IL translatorJava-to-IL translator• Binary component converterBinary component converter
• Convert .class files to ILConvert .class files to IL• Can reuse as isCan reuse as is• Can convert to ILCan convert to IL
• Interop layer – for library support at Interop layer – for library support at JDK1.1.4 levelJDK1.1.4 level
• Visual Studio.NET integrationVisual Studio.NET integration• Java as a 1Java as a 1stst class language class language
• Financial assistance with your Financial assistance with your therapytherapy
ToolsTools• Java-source-to-C# source Java-source-to-C# source
translator/convertertranslator/converter
OptionsOptions• Convert existing Java modules to Convert existing Java modules to
C# C# • New development in C#New development in C#• Projects can reference Java Projects can reference Java
classes running on the interop classes running on the interop layer (from above)layer (from above)
Path 1:Path 1:Use the Java Use the Java language language on .NETon .NET
Path 2:Path 2:Full Migration Full Migration to .NETto .NET
35©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
Questions?
??clemensv@newtelligence.com
36©2001 Clemens F. Vasters, ©2001 newtelligence AG – Unauthorized duplication, distribution prohibited. Only for your personal information. All rights reserved.
Further Information
On the Web:•www.microsoft.com/germany/msdn/
•msdn.microsoft.com
•www.microsoft.com/net
Newsgroups:•microsoft.public.dotnet.*
".NET Crashkurs"Vasters, Oellers, et. al.Microsoft Press DeutschlandISBN: 3860635131