l03 – mono - .net for linux - sine nomine · § c# compiler § ado.net & asp.net for web...

25
Title of PPT 16-Mar-05 © Software AG, 2003 1 L03 – Mono - .NET for Linux Neale Ferguson S/390 JIT Developer Introduction to Mono March/April 2005 2 Attributions n Eric Dasque – “Mono: Introduction for Developers” – Novell n Miguel de Icaza – “The Mono Project”

Upload: hoanghanh

Post on 14-Oct-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

Title of PPT 16-Mar-05

© Software AG, 2003 1

L03 – Mono - .NET for Linux

Neale FergusonS/390 JIT Developer

Introduction to Mono March/April 20052

Attributions

n Eric Dasque – “Mono: Introduction for Developers” –Novell

n Miguel de Icaza – “The Mono Project”

Title of PPT 16-Mar-05

© Software AG, 2003 2

Introduction to Mono March/April 20053

Rationale for Mono

n Developing Linux Applications is challenging

n Linux development technologies are immature and fragmented§ Today’s Linux tools are not suitable for IT application

development§ Corporations have not standardized

n Managed languages (C#/.NET, Java) are growing

n Sun is pushing Java for application development on the desktop (Sun JDS)

n ISVs are looking to port their application to Linux

Introduction to Mono March/April 20054

Fragmented Approach to Development

“Everyone builds their own development platform on Unix”

Title of PPT 16-Mar-05

© Software AG, 2003 3

Introduction to Mono March/April 20055

What is Mono…

n Mono means “Monkey” in Spanishn Not a product: a technology toolkit for developers

§ Compilers § Common Language Runtime (CLR) Virtual Machine§ Set of libraries

n Mono is a Free Software/Open Source implementation of:§ Common Language Infrastructure§ C# Compiler§ ADO.NET & ASP.NET for web application and web services development § Set of APIs (.NET and Linux/Gnome bindings)

n Mono's .NET implementation is based on the ECMA standards for C# and the Common Language Infrastructure

n Sponsored by Novelln Begun by Miguel de Icaza – lead developer of GNOME

Introduction to Mono March/April 20056

What is Mono

Title of PPT 16-Mar-05

© Software AG, 2003 4

Introduction to Mono March/April 20057

What is Mono

Introduction to Mono March/April 20058

Benefits of Mono

n The class library is very goodn C# is deemed excellent n Support for other languages forthcoming§ Java, Python and VB.NET

n Easily accessible by large community of developers (C#, VB.NET, .NET)

n Mono provides a complete and robust implementation of 100% of .NET 1.1

n Provides wrappers to a lot of Linux and open source APIs and projects including the Gnome Toolkit

n Makes it easy (trivial ?) to wrap GNOME C APIs to use with Mono/.NET supported languages

n Used by Novell to provide API-level access to Enterprise Linux Services

Title of PPT 16-Mar-05

© Software AG, 2003 5

Introduction to Mono March/April 20059

Mono – Multi Language / Multi Platform

Introduction to Mono March/April 200510

Benefits of Mono

n Mono is a great foundation for ISVs

n Today ISVs do not know what development environment to use to port their software to Linux

n Mono through .NET and C# provides them with a clean implementation that leverage competences they’re most likely to have in house. Linux appears less foreign

n A great alternative to C-based SDKs available for Embedded systems and PDAs

Title of PPT 16-Mar-05

© Software AG, 2003 6

Introduction to Mono March/April 200511

Benefits of Mono

n Cross language interoperabilityn Secure runtime environmentn Detailed and complete class librariesn Extensibility

n Deployment toolsn Integrated web servicesn Over C/C++§ Security§ Class libraries§ Reflection

n Over Java§ Multiple languages§ Better GUI performance and appearance§ Code Access Security

Introduction to Mono March/April 200512

Mono 1.0 Contents

n In July 2004, the Mono community released Mono 1.0, which included the following features:§ C# compiler§ VM, with JIT and pre -compiler§ IL assembler, disassembler§ Development and security tools§ Core libraries: mscorlib, System, System.XML§ Unix and open source bindings (GTK#, Mozilla#, ZipLib, …)§ System.Data and Mono database providers§ System.Web: Web applications platform§ System.Web.Services: client and server support§ Embedding API

Title of PPT 16-Mar-05

© Software AG, 2003 7

Introduction to Mono March/April 200513

Mono Roadmap

n Mono 1.0: July 2004§ Implement .NET 1.0 and 1.1 APIs§ Core, ADO.NET, ASP.NET, C# 1.0§ MonoDoc

n Mono 1.2: 2Q2005§ Add C# 2.0§ Add ASP.NET 2.0§ Adds XML 2.0§ .NET 1.0, .NET 1.1 and .NET 1.2 APIs

n Mono 2.0: 2Q2006§ A complete implementation of .NET 2.0 features as well as

updates to Mono exclusive APIs

Introduction to Mono March/April 200514

Current Release – 1.1.4

n Code Access Security (CAS) support:§ Policy resolution - including assembly-level RequestMinimum,

RequestOptional and RequestRefuse attributes§ Declarative/Imperative demands§ Declarative stack modifiers (Assert, Deny and PermitOnly)

n Cryptographic performance improvements

n ASP .NET 2.0 features

n New implementation of Windows.Forms

n XML .NET 2.0:§ XmlSchemaValidator is implemented. As well, significant

refactoring on XML Schema validating reader has been done§ SchemaInfo on DOM is now provided§ There is new support for reading Binary content: Base64/BinHex

Title of PPT 16-Mar-05

© Software AG, 2003 8

Introduction to Mono March/April 200515

Current Release – 1.1.4

n A new statistical profiler is included in the default Mono profiler

n Performance enhancements:§ Exception throwing is now a lot faster § SSA-based partial redundancy elimination has been updated.

Work on Alias Analysis is being done to enhance this optimization§ Array Bounds Check (ABC) Removal removes more checks§ Many System.Threading.Interlocked operations are implemented

using inline assembly for the x86§ Various peephole and Linear Scan improvements have been

made to increase code quality§ Throw blocks are now placed in an out-of-bound block to improve

locality and branch prediction§ Remoting for TCP and HTTP transport is vastly faster now (few

orders of magnitude) § A more scalable threadpool for remoting for incoming

connections.

Introduction to Mono March/April 200516

Current Release – 1.1.4

n Memory Usage Improvements:§ Many metadata structures are now delay-loaded, reducing

memory consumption, especially in long running GUI applications§ Memory leaks have been audited, especially in terms of

application domain unloading§ The symbol file for --debug is now loaded with mmap, reducing

memory consumption by a few megabytes§ XmlDocument and its helper classes now use less memory.

n C# 2.0 features:§ Anonymous methods § Iterators§ Partial classes§ Static classes§ Covariance and contra -variance § Property accessor accessibility § Inline warning control

Title of PPT 16-Mar-05

© Software AG, 2003 9

Introduction to Mono March/April 200517

The .NET development platform

n Common Language Infrastructure§ JIT converts the intermediate language into native code

n Multiple language interoperability§ C++, C#, JavaScript, Visual Basic, Eiffel, Ada, COBOL, Pascal, C

n A new language: C#§ VERY similar to Java

n Class Libraries

n Benefits:

§ Advanced platform for end-user application development§ Multiple language support§ Interoperability (SOAP, .NET)§ Grants access for Window ISVs to UNIX

Introduction to Mono March/April 200518

Mono and Eclipse

IKVM.NET is an implementation of Java for Mono and .NET Framework. It includes:§ A Java Virtual Machine implemented in .NET§ A .NET implementation of the Java class libraries§ Tools that enable Java and .NET interoperability

Title of PPT 16-Mar-05

© Software AG, 2003 10

Introduction to Mono March/April 200519

ADO.NET

n ADO.NET stands for ActiveX Data Objects for .NETn It refers to the suite of data access technologies used to

manipulate databasesn Mono has many ADO.NET Data Providers to get you

connected:§ IBM DB2 Universal Database§ MySQL§ ODBC§ Oracle§ OLE DB§ PostgreSQL§ Microsoft SQL Server§ SQL Lite§ Sybase§ Older Microsoft SQL Server and Sybase databases

Introduction to Mono March/April 200520

ASP.NET

n Active Server Pages - Microsoft's IIS-based server side scripting architecture

n ASP.NET support is divided in two pieces:

§ Web Forms (Web Applications infrastructure)§ Web Services (the SOAP-based RPC system)

n Using ASP.NET System.Web.Hosting namespace classes you can make your own ASP.NET enabled server

n Or use two provided methods:

§ XSP: A light-weight web server written in C#§ mod_mono: An Apache plug-in module that works with both 1.3

and 2.0 versions

Title of PPT 16-Mar-05

© Software AG, 2003 11

Introduction to Mono March/April 200521

ASP.NET Example…

Introduction to Mono March/April 200522

…ASP.NET Example…

<%@ Page Language="C#" %><html><head><title>DataGrid</title><script runat="server">

void Page_Load (object o, EventArgs e) {if (!IsPostBack) {

ArrayList list = new ArrayList ();list.Add (new Datum ("Spain", "es", "Europe"));list.Add (new Datum ("Japan", "jp", "Asia"));list.Add (new Datum ("Mexico", "mx", "America"));dg.DataSource = list;dg.DataBind ();

}}public class Datum{

private string country;private string abbr;private string continent;

public Datum (string country, string abbr, string continent) {this.country = country;this.abbr = abbr;this.continent = continent;

}public string Country {

get { return country; }}

public string Abbr {get { return abbr; }

}

public string Continent {get { return continent; }

}

public override string ToString () {return country + " " + abbr + " " + continent;

}}

</script></head>

Title of PPT 16-Mar-05

© Software AG, 2003 12

Introduction to Mono March/April 200523

…ASP.NET Example…

<body><h3>DataGrid sample</h3><form runat="server">

<asp:datagrid id="dg" border="1" AutoGenerateColumns="false"EnableViewState="false" runat="server">

<Columns><asp:BoundColumn HeaderText="Country" DataField="Country"

ItemStyle-CssClass="Normal" HeaderStyle-Cssclass="Bold" /><asp:BoundColumn HeaderText="Continent" DataField="Continent"

ItemStyle-CssClass="Normal" HeaderStyle-Cssclass="Bold"/><asp:BoundColumn HeaderText="Abbr" DataField="Abbr"

ItemStyle-CssClass="Normal" HeaderStyle-Cssclass="Bold"/></Columns>

</asp:datagrid></form></body></html>

Introduction to Mono March/April 200524

…ASP.NET Example

Title of PPT 16-Mar-05

© Software AG, 2003 13

Introduction to Mono March/April 200525

Web Services…

Introduction to Mono March/April 200526

…Web Services…

Title of PPT 16-Mar-05

© Software AG, 2003 14

Introduction to Mono March/April 200527

…Web Services…

using System;using System.Web.Services;

class sample {

static void Main (){

int result;

TestService service = new TestService();result = service.Add(100,200);Console.WriteLine("{0}",result.ToString());Console.WriteLine(service.Echo("String of characters"));

}}

> mono testserv.exe300String of characters

Introduction to Mono March/April 200528

…Web Services…

Title of PPT 16-Mar-05

© Software AG, 2003 15

Introduction to Mono March/April 200529

…Web Services…

Introduction to Mono March/April 200530

…Web Services – C#

> wsdl http://localhost/demo/ConverterService.asmx?wsdlMono Web Services Description Language UtilityWriting file 'ConverterService.cs'

Title of PPT 16-Mar-05

© Software AG, 2003 16

Introduction to Mono March/April 200531

WSDL Generated C#

///Web service that can make currency conversions///</remarks>[System.Web.Services.WebServiceBinding(Name="ConverterServiceSoap",Namespace="http://tempuri.org/"),System.Diagnostics.DebuggerStepThroughAttribute(),System.ComponentModel.DesignerCategoryAttribute("code")]public class ConverterService : System.Web.Services.Protocols.SoapHttpClientProtocol {

public UserInfo UserInfoValue;

public ConverterService () {this.Url = "http://resc011/demo/ConverterService.asmx";

}

/// <remarks>///Registers the user into the system///</remarks>

[System.Web.Services.Protocols.SoapHeaderAttribute("UserInfoValue",Required=false,Direction=System.Web.Services.Protocols.SoapHeaderDirection.Out),

System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/Login",RequestNamespace="http://tempuri.org/",ResponseNamespace="http://tempuri.org/",ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped,Use=System.Web.Services.Description.SoapBindingUse.Literal)]

public void Login(string a) {this.Invoke("Login", new object[] {

a});}

Introduction to Mono March/April 200532

Web Services - VB

> wsdl –l:VB http://localhost/demo/ConverterService.asmx?wsdlMono Web Services Description Language UtilityWriting file 'ConverterService.vb'

Title of PPT 16-Mar-05

© Software AG, 2003 17

Introduction to Mono March/April 200533

WSDL Generated VB

''' <remarks/>''' <remarks>Web service that can make currency conversions</remarks><System.Web.Services.WebServiceBinding(Name="ConverterServiceSoap",Namespace="http://tempuri.org/"),System.Diagnostics.DebuggerStepThroughAttribute(),System.ComponentModel.DesignerCategoryAttribute("code")> _Public Class ConverterService

Inherits System.Web.Services.Protocols.SoapHttpClientProtocol

Public UserInfoValue As UserInfo

Public Sub New()Me.Url = "http://resc011/demo/ConverterService.asmx"

End Sub

''' <remarks>Registers the user into the system</remarks>

<System.Web.Services.Protocols.SoapHeaderAttribute("UserInfoValue",Required=False,Direction=System.Web.Services.Protocols.SoapHeaderDirection.Out),

System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/Login",RequestNamespace="http://tempuri.org/",ResponseNamespace="http://tempuri.org/",ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped,Use=System.Web.Services.Description.SoapBindingUse.Literal)> _

Public Sub Login(a As String)Me.Invoke("Login", New Object {

a})End Sub

Introduction to Mono March/April 200534

Interfacing to Existing Services…

n Experimental Adabas Interface§ Provide a “data -orientated” view to programmer§ Implement direct call interface§ Hide low-level control block and buffer interactions§ Programmer only interacts with fields§ Similar in concept and operation to our “Jadabas” product

Title of PPT 16-Mar-05

© Software AG, 2003 18

Introduction to Mono March/April 200535

…Interfacing to Existing Services…

public int AdaOpen (ref AdaBuffer rb){

AdaCB openCB = new AdaCB();

SetDBFile(ref openCB);openCB.cmdCode = AdaCmdCode.AdaOpOP;openCB.rbLen = rb.bufSize;openCB.ISNLL = TNAA;openCB.ISNqty = TNAX;openCB.cmdOpt1 = cmdOption1;openCB.cmdOpt2 = cmdOption2;openCB.add1 = GetBytes(sessionUser, 8);openCB.add2 = BitConverter.GetBytes(0);openCB.add4 = BitConverter.GetBytes(additions4);adabas (ref openCB, nullFB.bufData, rb.bufData,

nullSB.bufData, nullVB.bufData, nullIB.isnBuffer);respCode = openCB.respCode;TNAA = openCB.ISNLL;TNAX = openCB.ISNqty;additions2 = BitConverter.ToUInt32(openCB.add2, 0);additions4 = BitConverter.ToUInt64(openCB.add4, 0);additions5 = BitConverter.ToUInt64(openCB.add5, 0);reason = additions2 & 0x0000ffff;xNode = additions2 >> 16;commandTime = openCB.cmdTime;return (respCode);

}

Introduction to Mono March/April 200536

…Interfacing to Existing Services…

using System;using System.Text;using SAG.Data.Adabas;

public class main {

static void Main() {int rc;string openSpec = "ACC=255.";string formatBuf = "LA,LC.";AdabasAPI myAPI = new AdabasAPI();string line;

rc = myAPI.AdaInit("resc011","usanefe");Console.WriteLine("AdaInit: {0}",rc.ToString());myAPI.dbID = 1;myAPI.sessionUser = "*neale";

rc = myAPI.AdaOpen(openSpec);Console.WriteLine("AdaOpen: {0},{1} Node: {2}",

rc.ToString(),myAPI.reason.ToString(),myAPI.xNode);line = Console.ReadLine();

Title of PPT 16-Mar-05

© Software AG, 2003 19

Introduction to Mono March/April 200537

…Interfacing to Existing Services

n Next steps§ Extract field names from DDM§ Automatically generate C# code from DDM information§ Result: C# code that can be included by programmers to access

and update an Adabas database

Introduction to Mono March/April 200538

Just-in-Time Compilers

n Available for:§ x86§ amd64§ PowerPC§ Sparc§ s390 (32-bit)

n In progress:§ s390x (64-bit)

Title of PPT 16-Mar-05

© Software AG, 2003 20

Introduction to Mono March/April 200539

JIT Optimization

n Optimization Types

SSA based partial redundancyssapreArray bound checks removalabcremPre-compile all methods before executing mainprecompUsage of Ahead of Time compiled codeaotLeaf procedures optimizationsleafFast x86 FP comparesfcmovLoop related optimizationsloopTail recursing and tail callstailcIntrinsic method implementationintrinsInstruction schedulingschedEmit per-domain codesharedConditional movescmovLinear scan global register allocationlinearsDead code eliminationdeadceCopy propagationcopypropConstant propagationconspropConstant foldingcfoldInline method callsinlineBranch optimizationbranchPeephole PostpasspeepholeDescriptionOptimization

Introduction to Mono March/April 200540

S/390 Just In Time Compiler (JIT)

n 32-bit

n zSeries only

§ Uses “N3” instructions like LARL/BRCL§ Use interpreter for non z -boxes (although development has

ceased on the interpreter)

n Bytecodes compiled as required:§ Class loaded§ “Trampoline” created§ Code compiled§ Control passed to compiled code

n Efficient for things more complex than “Hello World”

n Will compile code only used once

§ May result in more overhead than interpreter§ Unlike “Hotspot” compiler Sun uses for Java

Title of PPT 16-Mar-05

© Software AG, 2003 21

Introduction to Mono March/April 200541

JIT Operation…

1. Create “trampoline” that causes method to be compiled when first referenced

2. Compile method into native instruction sequences:

3. Patch trampoline so that it branches to compiled method4. Branch to compile method

case OP_SBB_IMM: if (ins->dreg != ins->sreg1) {

s390_lr (code, ins->dreg, ins->sreg1);}if (s390_is_uimm16 (-ins->inst_imm)) {

s390_lhi (code, s390_r0, ins->inst_imm);s390_slbr (code, ins->dreg, s390_r0);

} else {s390_basr (code, s390_r13, 0);s390_j (code, 4);s390_word (code, ins->inst_imm);s390_slb (code, ins->dreg, 0, s390_r13, 4);

}

Introduction to Mono March/April 200542

…JIT Operation…

n Source fragmentstatic public int test_1028_sieve () {

int NUM = 2000;byte[] flags = new byte[8192 + 1];int i, k;int count = 0;

while (NUM-- != 0) {count = 0;for (i=2; i <= 8192; i++) {

flags[i] = 1;}for (i=2; i <= 8192; i++) {

if (flags[i] != 0) {for (k=i+i; k <= 8192; k+=i) {

flags[k] = 0;}count++;

}}

}return(count);

}

Title of PPT 16-Mar-05

© Software AG, 2003 22

Introduction to Mono March/April 200543

…JIT Operation…

n Bytecode fragment(in B6: stack: 0) IL_0021: ldloc.1(in B6: stack: 1) IL_0022: ldloc.3(in B6: stack: 2) IL_0023: ldc.i4.1(in B6: stack: 3) IL_0024: stelem.i1(in B6: stack: 0) IL_0025: ldloc.3(in B6: stack: 1) IL_0026: ldc.i4.1(in B6: stack: 2) IL_0027: add(in B6: stack: 1) IL_0028: stloc.3(in B5: stack: 0) IL_0029: ldloc.3(in B5: stack: 1) IL_002a: ldc.i4 8192(in B5: stack: 2) IL_002f: ble IL_0021

Introduction to Mono March/April 200544

…JIT Operation…

n Unoptimized DUMP BLOCK 6:(stind.i1 (ldelema (ldind.ref regoffset[0x64(s390_r15)]) (ldind.i4

regoffset[0x6c(s390_r15)])) iconst[1])(stind.i4 regoffset[0x6c(s390_r15)] (add (ldind.i4 regoffset[0x6c(s390_r15)])

iconst[1]))DUMP BLOCK 5:(ble[B6B13] (compare (ldind.i4 regoffset[0x6c(s390_r15)]) iconst[8192]))

8e: 58 30 f0 64 l %r3,100(%r15)92: 58 20 f0 6c l %r2,108(%r15)96: 58 40 30 0c l %r4,12(%r3)9a: 15 42 clr %r4,%r29c: c0 d4 00 00 00 bc jgnh 214 <Tests_test_1028_sieve+0x214>a2: a7 d8 00 01 lhi %r13,1a6: b2 52 00 2d msr %r2,%r13aa: 1a 23 ar %r2,%r3ac: a7 2a 00 10 ahi %r2,16b0: a7 08 00 01 lhi %r0,1b4: 42 00 20 00 stc %r0,0(%r2)b8: 58 20 f0 6c l %r2,108(%r15)bc: a7 2a 00 01 ahi %r2,1c0: 50 20 f0 6c st %r2,108(%r15)c4: 58 20 f0 6c l %r2,108(%r15)c8: a7 08 20 00 lhi %r0,8192cc: 19 20 cr %r2,%r0ce: c0 d4 ff ff ff e0 jgnh 8e <Tests_test_1028_sieve+0x8e>

Title of PPT 16-Mar-05

© Software AG, 2003 23

Introduction to Mono March/April 200545

…JIT Operation

n Optimized DUMP BLOCK 6:(stind.i1 (ldelema (ldind.ref regoffset[0x60(s390_r15)]) (ldind.i4 regvar[s390_r10]))

iconst[1])(stind.i4 regvar[s390_r10] (add (ldind.i4 regvar[s390_r10]) iconst[1]))nop

DUMP BLOCK 5:nop(ble[B6B13] (compare (ldind.i4 regvar[s390_r10]) iconst[8192]))

4a: 58 30 f0 60 l %r3,96(%r15)4e: 18 2a lr %r2,%r1050: 58 40 30 0c l %r4,12(%r3)54: 15 42 clr %r4,%r256: c0 d4 00 00 00 8f jgnh 174 <Tests_test_1028_sieve+0x174>5c: 1a 23 ar %r2,%r35e: a7 2a 00 10 ahi %r2,1662: a7 08 00 01 lhi %r0,166: 42 00 20 00 stc %r0,0(%r2)6a: 18 2a lr %r2,%r106c: a7 2a 00 01 ahi %r2,170: 18 a2 lr %r10,%r272: a7 08 20 00 lhi %r0,819276: 19 a0 cr %r10,%r078: c0 d4 ff ff ff e9 jgnh 4a <Tests_test_1028_sieve+0x4a>

Introduction to Mono March/April 200546

Effect of Optimization

0

20

40

60

80

100

120

1 2 3 4 5 6 7 8 9 10 11 12 13 14

Optimization Type

Effect of Optimization

Elapsed Time

Code Size (/100)

Title of PPT 16-Mar-05

© Software AG, 2003 24

Introduction to Mono March/April 200547

Optimization Key

1. none2. peephole3. branch4. cfold5. fcmov6. peephole,branch,intrins7. peephole,branch,linears8. peephole,branch,copyprop,linears9. peephole,branch,cfold,linears10.peephole,branch,consprop,copyprop,deadce,linears11.peephole,branch,inline,consprop,copyprop,deadce,linears,intrins,loop12.peephole,branch,inline,consprop,copyprop,deadce,linears,intrins,loop,

abcrem13.peephole,branch,inline,consprop,copyprop,deadce,linears,intrins,loop,

ssapre14.peephole,branch,inline,consprop,copyprop,deadce,linears,shared,intri

ns,loop,abcrem

Introduction to Mono March/April 200548

Resources

n S/390 RPMs§ SLES9 § SLES8

§ http://www.mono-project.com/downloads§ 1.1.3 is there§ 1.1.4 should be there soon

n Main mono website: http://www.mono-project.com

Title of PPT 16-Mar-05

© Software AG, 2003 25