advanced computer science teaching with the shared source common language infrastructure
TRANSCRIPT
Overview
In this session we will discuss> What is the Shared Source Common Language Infrastructure
(SSCLI)?> Key SSCLI components> Differences between SSCLI and .NET> Working with the SSCLI> Using the SSCLI for teaching> Deploying the SSCLI in a teaching lab environment
ECMA Common Language Infrastructure (CLI)
An international standard for a virtual execution environment> produced by Microsoft
Implementation of this standard is a subset of the .NET framework
The specification (ECMA 335/ISO 23271/2 ) defines common type system intermediate language component model
A minimum implementation consists of a C# compiler CLI execution engine component frameworks
SSCLI – A Shared Source CLI
Microsoft’s free, modifiable and redistributable implementation of the CLI, codenamed Rotor
Platform independent > Currently executes on MS Windows, FreeBSD and Mac OS/X> Third party ports to Linux, Windows CE and others
Virtually identical to .NET 1.1 except for> retooled JIT compiler and garbage collector> C# generics support (Gyro)
Source written in C, C++, C#, Perl and assembly language
Other implementations of CLI are Ximian’s Mono and DotGNU’s Portable.NET
Implemented for Learning
Many areas of interest (3 million lines of code!) Good, real-world example of how software is built Contains useful component-based frameworks
> Standard programming constructs
> Web-service oriented networking and remoting
Contains compilers, tools, and utilities> C#, JScript, and IL JIT compilers
> Assembler, disassembler, linker, debuggers
> Configuration utilities
Extensive tests and build harness
Relationship of SSCLI and .NET Framework Both SSCLI and .NET implement complete ECMA
> SSCLI is a superset of ECMA, subset of commercial .NET Frameworks
Shared source CLI implementation differs in> JIT and garbage collector replaced with more portable, more approachable,
implementations> Only supports C# and JScript as development languages> Windows-specific features not included
COM interop Windows Forms “It Just Works!”(managed/unmanaged C++ integration)
> Commercially competitive features not included ADO.NET (database access) enterprise services NGEN (install-time, JIT-ahead precompilation) ASP.NET (web application / web service development)
The .NET Framework
VS.NET
Common Language Runtime
System
System.Data (ADO.NET) System.Xml
Design
ADO
Adapters
SQL
Globalization
Diagnostics
Configuration
Collections
Resources
Reflection
Net
IO
Threading
Text
ServiceProcess
Security RuntimeInteropServices
Remoting
Serialization
XPath
XSLTSerialization
System.Drawing
JITGC
MSIL
App Domain Loader
Common Type System Class Loader
System.Web (ASP.NET)
Configuration
SessionStateCachingSecurity
Simple Web Services
DescriptionProtocols
UIHtmlControls
WebControls
Discovery
C#
VC/MC++
Imaging
Drawing2D
Text
Printing
JScript
VB
Windows PlatformIIS
MSMQCOM+
Networking
Active Directory Filesystem
System.WinForms
Design ComponentModel
Debugger
Designers
SDK Tools
CorDBG
ILAsm
ILDbDump
SN
ILDAsm
MetaInfo
PEVerify
SSCLI
VS.NET
Common Language Runtime
System
System.Data (ADO.NET) System.Xml
Design
ADO
Adapters
SQL
Globalization
Diagnostics
Configuration
Collections
Resources
Reflection
Net
IO
Threading
Text
ServiceProcess
Security RuntimeInteropServices
Remoting
Serialization
XPath
XSLTSerialization
System.Drawing
JITGC
MSIL
App Domain Loader
Common Type System Class Loader
System.Web (ASP.NET)
Configuration
SessionStateCachingSecurity
Simple Web Services
DescriptionProtocols
UIHtmlControls
WebControls
Discovery
C#
VC/MC++
Imaging
Drawing2D
Text
Printing
JScript
VB
Platform Adaptation Layer
System.WinForms
Design ComponentModel
Debugger
Designers
SDK Tools
CorDBG
ILAsm
ILDbDump
SN
ILDAsm
MetaInfo
PEVerify
Platform Adaptation Layer
SSCLI is built on top of a Platform Adaptation Layer (PAL)
The PAL > isolates CLI implementation from the OS and hardware> runs co-operatively with native code> implements security and control, threading and exceptions> offers equivalent functionality to many Win32 OS functions> eases porting to new platforms - a student project?
The SSCLI Distribution
SSCLI can be freely downloaded from the Web Packaged as single compressed file archive 1.9 million lines of code in first release (now ~3 million)
> 1.15M of C and C++> 625K of C#> 125K of CIL (intermediate language)> Smattering of assembly code, Perl (test harnesses) and Tcl/Tk (UI)
5900 source files (9700 total)> 2900 tests
Build output> 1200 defined types> About 20 dynamically loadable libraries> About 22 executable programs
The SSCLI Source Tree
Four major areas in source code1) Runtime “execution engine”
2) Base class library
3) Compilers and tools
4) Portability layer, tests, and build infrastructure
Other important points of interest> License
> Documentation
> Samples
SSCLI Execution Engine
Heart of component-oriented infrastructure Converts metadata, resources, and CIL (on disk as
PE/COFF image) into running code JIT compilation and IL verification Cross-language exception handling Language-agnostic, object-capable, type system Automatic heap and stack management Dynamic code loading Evidence-based security (code access security)
Common Intermediate Language
Basis for most managed code execution in the CLI Simple stack-based machine model – see vm directory Typeless opcodes, defined in opcode.def
> Verifiable subset – see fjit directory for verification> Signed and unsigned via opcode, not type
CIL code is JIT compiled to run under CLI management> Type layout, control, and dispatching
Typed variable argument lists, dynamically typed pointers Tail calls, virtual dispatch, call via function pointer
> Rich set of conversion operations, calling conventions> Exception handling> Garbage collection
Frameworks
A “minimal toolkit” for the 21st century programmer Base class library is a key feature of the ECMA CLI
spec> Collections, arrays, strings, and other compound data types> Globalization and formatting> System services (threads, I/O, synchronization, etc.)> Security
SSCLI augments this with> Floating point and extended arrays libraries> Networking, regular expressions, and XML libraries> Access to runtime infrastructure
Reflection and custom attributes Remoting, unmanaged interop, serialization, and marshaling AppDomains, Assemblies, GC, other execution engine features
Compilers and Tools
Full-featured C# compiler > also used in build process
JScript compiler written entirely in C# Additional developer tools
>clix, the shared source CLI program launcher> Assembly tools: resource compiler, assembly linker, metainfo
metadata viewer, assembler, disassembler> Debuggers: cordbg managed command line debugger, plus
a debug extension for working on managed code from C/C++ via windbg
SSCLI Build Process
Complex build which occurs in two phases and is driven by several build tools> nmake, build, Perl scripts
Initial phase builds> PAL using native toolchain> Build tools (nmake, build) against PAL for portability> resource compiler and PAL runtime using newly compiled build tools
Main phase has complex interdependencies> Unmanaged frameworks, compilers, and tools, are built> Managed portions of runtime and frameworks are built using compilers built previously> Assemblies and runtime are configured
Possible to rebuild individual SSCLI components> Allows teaching activities to focus on smaller parts of the SSCLI and rebuild those only> e.g. Hull JScript compiler modification exercises
Good example of how large software systems are built> Unfamiliar to most students
SSCLI Test Suite
Incredibly handy when modifying code! Two major areas: managed code and PAL PAL suites
> Test driver script is pvtrun.pl> Used on new PAL implementations to verify compliance with PAL
specification
Quality suites> Test driver script is rrun.pl> Tests for three primary aspects of SSCLI functionality
IL verification “BVT” smoke tests – many small programs Tests for the BCL
Possibilities for Teaching
The SSCLI implementation touches upon many aspects of a standard Computer Science syllabus
> Programming languages and skills> Object-oriented development> Framework design> Software testing> Security> Networking> Virtual machine implementation> etc, etc, etc
Many possible uses in the curriculum> Allows students to see the relevance of many of the aspects of the
curriculum in the implementation of a large commercially-produced software product
The SSCLI at Hull
Hull University uses both the .NET Framework and the SSCLI for teaching at Master level
> MSc in Distributed Systems Development
.NET provides> overreaching example of distributed systems concepts,
techniques and technologies
SSCLI provides > “down to the metal” implementation details> excellent environment for enhancing testing/ debugging skills
We introduce three ways in which the SSCLI is used at Hull
MSc Distributed Systems Development
Our Masters course aims to> Give advanced coverage of modern distributed computing
techniques> Develop an understanding of contemporary managed code
environments and how they work> Develop skills in working with large codebases > Develop “active practitioners”> Provide hands-on practical experience underpinned by
advanced theoretical concepts
Software Maintenance Exercise
Designed to improve students skills in> Navigating and comprehending unfamiliar code> Maintaining code written by others> Designing and implementing for maintenance
Requires students to make modifications to the JScript compiler
> Modify the abstract syntax tree of the compiler> JScript compiler written in C# => easy introduction to SSCLI> JScript compiler can be built and deployed independently
JIT Profiling Exercise
Designed to provide> an introduction to key aspects of the virtual machine and JIT
compiler implementation> An appreciation for how JIT compilation works to transform
intermediate code to native code> A basis for further, more detailed study
Requires students to > Introduce new data structures> Modify JIT compiler to count CIL instructions > Sort and output profiling statistics on program completion> Code in an unmanaged language (unfamiliar to many)
Debugging Exercise
Optional exercise for students wanting to improve their debugging skills which is designed to
> Get the students thinking about all aspects of the compilation and execution cycle
> Provide opportunities to develop debugging and testing skills
> Familiarise the student with the SSCLI code and the techniques used to implement it
> Introduce problem solving and hypothesis testing skills relevant to debugging
> Set the “worst case” scenario:
Deliberate bugs introduced in the underlying language and VM implementation; student’s code is fine, but it still doesn’t work!
Our Experience
Feedback suggests that the students > Find the exercises initially challenging (particularly the JScript
exercise)> Value what these exercises have taught them as they reach
the latter stages of our Masters programme> Observe an improvement in their own coding, code
comprehension and debugging skills as a direct consequence of being exposed to commercially produced code
SSCLI in the Teaching Lab
The SSCLI is really designed for a single developer working exclusively on a single machine - i.e. not the normal lab environment
> Students use a different machine each session> Modifications made to the SSCLI by one student must not be
visible to other students> Complete built installation requires ~1GB disk space> Building on a network drive => high network traffic> Managed code executed from a network drive is less trusted
than code run from the local machine and may generate security exceptions
Our Solutions
Provide two local copies of the SSCLI distribution> Students have read/write permissions on one copy, read
permissions on the other> Students use local modifiable copy for their work> Read-only copy manually copied over modifiable copy at start of
each session and automatically each evening Use source control system
> Students use a source control system to store their changes to SSCLI components (not entire source tree)
> Changes checked out over clean local copy at start of session> Changes checked back in at start of sessions> Promotes good development practice but significant overhead in
administering source control system Virtual PC (with Undo Disks) ?
Windows Deployment Issues
SSCLI requires Visual C++ to build under Windows> Will not build against Visual C++ 8 / Visual Studio 2005
Vanilla distribution does not execute correctly on Windows XP Service Pack 2
> Changes made to XP in SP2 break the exception handling mechanism
> CD’s issued today have fixed copy of SSCLI source Build harness attempts to create file association for
Perl files> Our configuration does not permit students to create file associations> Easily fixed by removing a line from the build scripts
SummarySummary
In this presentation we have introduced> The SSCLI and its source code distribution
> SSCLI organization and operation
> Building and using the SSCLI
> Opportunities for teaching using the SSCLI
> Teaching lab deployment issues
Reading and ResourcesReading and Resources
Reading Stutz, Neward & Shilling, Shared Source CLI Essentials, O’Reilly & Associates Inc,
2003
Resources Shared Source CLI
http://msdn.microsoft.com/msdnmag/issues/02/07/sharedsourcecli/
ECMA Specificationshttp://msdn.microsoft.com/net/ecma
David Stutz’s MSDN announcement of Rotorhttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/Dndotnet/html/mssharsourcecli.asp
Jason Whittington’s MSDN Rotor articlehttp://msdn.microsoft.com/msdnmag/issues/02/07/sharedsourcecli/