.NET 2006 Using the.NET Profiler API to Collect Object Instances for Constraint Evaluation Presented by: Dave Arnold 4 th International Conference on.NET.

Slides:



Advertisements
Similar presentations
Eclipse TPTP TPTP Heap and Thread Profilers High-level Design Rev 1.0 Asaf Yaffe July, 2006.
Advertisements

CPSC 388 – Compiler Design and Construction
Enabling Speculative Parallelization via Merge Semantics in STMs Kaushik Ravichandran Santosh Pande College.
Lecture 10: Heap Management CS 540 GMU Spring 2009.
Chapter 22 UML Tooks and UML as Blueprint Model-Driven Architecture (MDA) Object-Constraint Language (OCL)
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
Irina Rychkova. 9/20061 Systemic approach towards model definition Model transformation semantics.
Software Engineering COMP 201
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
7 July 2003 MDA presentation Dennis Wagelaar 1 Model-Driven Architecture The current state of affairs.
Introduction to the C# Programming Language for the VB Programmer.
Compiler Summary Mooly Sagiv html://
Unified Modeling Language
Ranga Rodrigo. Class is central to object oriented programming.
Classes Mark Hennessy Dept. Computer Science NUI Maynooth C++ Workshop 18 th – 22 nd Spetember 2006.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes.
Overview of Previous Lesson(s) Over View  OOP  A class is a data type that you define to suit customized application requirements.  A class can be.
Database Systems Group Department for Mathematics and Computer Science Lars Hamann, Martin Gogolla, Mirco Kuhlmann OCL-based Runtime Monitoring of JVM.
Faculty of Informatics and Information Technologies Slovak University of Technology Peter Kajsa and Ľubomír Majtás Design.
MDA and QVT  Tom Gullion, Director of Product Management, Together Products.
Introduction to MDA (Model Driven Architecture) CYT.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Putting it all together: LINQ as an Example. The Problem: SQL in Code Programs often connect to database servers. Database servers only “speak” SQL. Programs.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Utilities (Part 2) Implementing static features 1.
Low-Level Detailed Design SAD (Soft Arch Design) Mid-level Detailed Design Low-Level Detailed Design Design Finalization Design Document.
Constructors CMSC 202. Object Creation Objects are created by using the operator new in statements such as… The following expression invokes a special.
Chapter 10 Analysis and Design Discipline. 2 Purpose The purpose is to translate the requirements into a specification that describes how to implement.
Run-Time Storage Organization Compiler Design Lecture (03/23/98) Computer Science Rensselaer Polytechnic.
CPS4200 Unix Systems Programming Chapter 2. Programs, Processes and Threads A program is a prepared sequence of instructions to accomplish a defined task.
CS536 Semantic Analysis Introduction with Emphasis on Name Analysis 1.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
Structures and Classes Version 1.0. Topics Structures Classes Writing Structures & Classes Member Functions Class Diagrams.
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
1  lecture slides online
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
Object Oriented Software Development 4. C# data types, objects and references.
CMSC 202 Advanced Section Classes and Objects: Object Creation and Constructors.
1 Becoming More Effective with C++ … Day Two Stanley B. Lippman
Chapter 5 System Modeling. What is System modeling? System modeling is the process of developing abstract models of a system, with each model presenting.
Object-Oriented Parsing and Transformation Kenneth Baclawski Northeastern University Scott A. DeLoach Air Force Institute of Technology Mieczyslaw Kokar.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
CIS 200 Test 01 Review. Built-In Types Properties  Exposed “Variables” or accessible values of an object  Can have access controlled via scope modifiers.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
The Execution System1. 2 Introduction Managed code and managed data qualify code or data that executes in cooperation with the execution engine The execution.
Kyung Hee University Class Diagramming Notation OOSD 담당조교 석사과정 이정환.
Design Pattern Support based on principles of model driven development Zihao Zhao.
Presented by : A best website designer company. Chapter 1 Introduction Prof Chung. 1.
© 2009 Artisan Software Tools. All rights reserved. Testing Solutions with UML/SysML Andrew Stuart, Matthew Hause.
RealTimeSystems Lab Jong-Koo, Lim
Lecture 9 Symbol Table and Attributed Grammars
Eine By: Avinash Reddy 09/29/2016.
Chapter 1 Introduction.
CIS 200 Test 01 Review.
Compiler Construction (CS-636)
Java Primer 1: Types, Classes and Operators
Chapter 1 Introduction.
CS 153: Concepts of Compiler Design November 28 Class Meeting
Compiler Lecture 1 CS510.
Mini Language Interpreter Programming Languages (CS 550)
Evaluating Compuware OptimalJ as an MDA tool
Pointers C#, pointers can only be declared to hold the memory addresses of value types int i = 5; int *p; p = &i; *p = 10; // changes the value of i to.
Object Oriented Programming in java
Object Constraint Language (OCL)
CMSC 202 Constructors Version 9/10.
Software Architecture & Design
Presentation transcript:

.NET 2006 Using the.NET Profiler API to Collect Object Instances for Constraint Evaluation Presented by: Dave Arnold 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 Outline Introduction to OCL 2.0 Relationship to UML and MDA Problem / Solution Compiling C# with OCL OclAny::AllInstances() The.NET Profiler API Getting the information back to the application Putting it all together Issues / Conclusion References 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 OCL 2.0 OCL – Object Constraint Language Standardized by the OMG in August 2003 Main use is for adding constraints to UML models –Pre-Conditions –Post-Conditions –Class Invariants Can also be used to define derived attributes and methods (Queries) 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 Relationship with UML UML diagrams alone do not contain enough information: The OCL can be used to specify additional information: –context Customer::age : Integer –init: 18 –context Customer inv: –self.age > 17 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 Model Driven Architecture Importance of using models in the development process Consists of three main steps: 1.Construct a model at a high level of abstraction, free of all implementation technologies (PIM) 2.Transform the PIM model into one or more models that contain implementation details (PSM) 3.Transform the PSM to implementation code 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 Model Driven Architecture 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 The Problem When a UML model is transformed into code what do we do with the OCL? –Ignore it? Then why use it? –Translate it into source code? How do we later determine what code was OCL and what was not? 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 A Solution Integrate the OCL directly into a high level language The OCL will be expressed separately from the language constructs Allows for enabling/disabling of the OCL and for extracting the OCL constraints from the code level back to the model 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 Code Example class Customer { OCL [ "context Customer::age : Integer" "init: 18" ] private int age; } 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 Why use C#? Multipurpose high level language Fully reflexive (round trip) Source code available for compilers –SSCLI –MONO.NET languages are compatible 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 Compiling C# without OCL 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 Compiling C# and OCL Steps to add the OCL to the compilation process: 1.Construct an OCL parser 2.Implement the OCL class library in C# 3.Map each OCL construct to a corresponding C# construct (or code block) 4.Merge the OCL parse tree(s) with the C# parse tree and generate executable code 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 Compiling C# and OCL The OCL lexical analyzer was written by hand 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 Compiling C# and OCL The parser was constructed using a parser generator (JAY) from the OCL grammar 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 Compiling C# and OCL During the C# semantic pass a reference model is created This reference model is used to perform the semantic pass on the OCL AST(s) 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 Compiling C# and OCL Once the OCL semantic pass is complete the result is merged into the C# augmented AST The resultant AST is then sent to the code generator to generate the executable code 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 Compiling C# and OCL 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 OclAny::allInstances() One of the issues that was encountered during the implementation of our specialized compiler was OclAny::allInstances() The evaluation of the allInstances operation requires determining the set of all active object instances for a given classifier As our application is being executed via the.NET CLR it is non-trivial to obtain such a set 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 Why is it non-trivial? The.NET CLR provides automated memory management for both allocation and garbage collection As memory management is abstracted away from the programmer, it is difficult to determine which object instances are allocated and active We have devised an approach for accessing memory management information from the CLR via the use of the.NET Profiler API 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 The big picture 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 Enter the.NET Profiler API To obtain the set of live object instances we will need to get inside the CLR and look at the managed heaps The.NET Profiler API allows for an external COM component to monitor the execution and memory usage of an application running under the CLR –Normally the profiler monitors the running application and does not interfere with it –In our approach we will monitor object instance allocation and garbage collection and we will return this information to the managed application 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 Implementing the Profiler The.NET Profiler API supports approximately sixty events We only need to specify behaviour for five of them 1.ICorProfilerCallback::Initialize() 2.ICorProfilerCallback::ObjectAllocated() 3.ICorProfilerCallback::MovedReferences() 4.ICorProfilerCallBack::ObjectReferences() 5.ICorProfilerCallback::RuntimeSuspendFinished() 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 Initialize(IUnknown * pICorProfilerInfoUnk) // Initialize - Sets up the profiler and registers for the CLR events that we want HRESULT COCLProfilerCallback::Initialize(IUnknown * pICorProfilerInfoUnk) { // Get the ICorProfilerInfo interface we need, and stuff it away in a member variable. HRESULT hr = pICorProfilerInfoUnk->QueryInterface(IID_ICorProfilerInfo, (LPVOID *)&m_pICorProfilerInfo); if(FAILED(hr)) return E_INVALIDARG; // Indicate which events we're interested in. m_dwEventMask = 0; m_dwEventMask += COR_PRF_MONITOR_SUSPENDS; // For GC notification m_dwEventMask += COR_PRF_MONITOR_GC; // For all GC calls except ObjectAllocated m_dwEventMask += COR_PRF_ENABLE_OBJECT_ALLOCATED; // For ObjectAllocated call m_dwEventMask += COR_PRF_MONITOR_OBJECT_ALLOCATED; // For ObjectAllocated call // Set the event mask m_pICorProfilerInfo->SetEventMask(m_dwEventMask); return S_OK; } 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 ObjectAllocated(UINT objectId, UINT classId) ObjectAllocated is invoked every time memory on the managed heap is allocated for a new object –The first parameter is a pointer to the managed heap location where the object instance is being stored –The second parameter is a pointer to the class descriptor The method stores the first parameter in an internal data structure so that the object instance can be found later –In order to reduce overhead, only classifiers which are required are stored 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 MovedReferences(…) MovedReferences is invoked to notify the profiler that the garbage collector has moved one or more object instance locations –The parameters specify the new locations for the object instances (pointers) The method simply updates the internal data structure to reflect the new locations 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 ObjectReferences(…) ObjectReferences is invoked once for each object instance that remains in the managed heap after a garbage collection operation When the method is called we will mark the corresponding object instance as active in our internal data structure 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 RuntimeSuspendFinished() RuntimeSuspendFinished is called once all of the execution threads have been suspended for a garbage collection operation HRESULT COCLProfilerCallback::RuntimeSuspendFinished() { // Loop through each of the objects and mark them as collected ObjectInstance* oi = m_objects.GetFirstItem(); while(oi != NULL) { oi->Collect(); oi = m_objects.GetNextItem(); } return S_OK; } 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 Getting the Information to the Managed Application The preceding five methods define a profiler that will keep track of which object instances are active at a given point in time The next step is getting this information to the managed application that is running –This is accomplished by having the profiler export five methods that can be called from within the managed application 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 Getting the Information to the Managed Application // Determines if the OCL Profiler is attached to this instance of the CLR VM [DllImport("OCLProfiler.dll")] private static extern bool IsOCLProfilerAttached(); // Registers the given classifier type with the OCL Profiler so that we keep information // about the classifier [DllImport("OCLProfiler.dll", CharSet=CharSet.Unicode)] private static extern void RegisterObject(string name); // Gets the number of instances that have been allocated of the given classifier type [DllImport("OCLProfiler.dll", CharSet=CharSet.Unicode)] private static extern int GetInstanceCount(string name); // Starts the instance copy operation. The instance copy operation is used to build the // allInstances set [DllImport("OCLProfiler.dll")] private static extern void StartInstanceCopy(); // Stops the instance copy operation. [DllImport("OCLProfiler.dll")] private static extern void StopInstanceCopy(); 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 Getting the Information to the Managed Application public static ArrayList GetInstancesFor(string value, Type t) { VerifyProfiler(); int count = GetInstanceCountFor(value); ArrayList result = new ArrayList(); StartInstanceCopy(); for(int i =0;i<count;i++) { // Use the type information to create a new object // The profiler will be informed of the new allocation // and will copy the memory used by the existing object // into our new object...thus creating an allInstances set // that is a complete copy of each object instance Object obj = t.InvokeMember(null, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance, null, null, null); result.Add(obj); } StopInstanceCopy(); return result; } 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 Putting it all together We have integrated the previous method into our specialized C#/OCL compiler Customer.allInstances()->forAll(c : Customer | c.age >= 18) bool result = true; foreach(Customer c in (Set)OCLProfilerControl.GetInstancesFor(“Customer”, System.Type.GetType(“Customer”))) { result = result & (c.age >= 18); } 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 Putting it all together OCL [ "context AllInstances::Main() : OclVoid" "post: Customer.allInstances()->forAll( c : Customer | c.age >= 18)" ] public static void Main() { Customer cs = new Customer(); cs.name = "Dave"; cs.age = 27; Customer cs2 = new Customer(); cs2.name = "Mary"; cs2.age = 16; } 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 Putting it all together 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 Issues Threading –Works in a single threaded model and uses critical sections to prevent new object instances from being created during the copying process, etc. Speed –The runtime profiler introduces significant overhead, thus reducing performance –As the OCL constraints are designed to be used during development only this may not be an issue 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 Conclusion The method presented here has been used to implement software based constraints via the OclAny::AllInstances operation –It would be interesting to explore other uses for the complete set of live object instances –We are currently exploring how our method can be used in the verification and validation of non-functional requirements 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006

.NET 2006 Acknowledgements & Additional Information Acknowledgements Funding for this work has been generously provided by the Natural Sciences and Engineering Research Council of Canada Additional Information + Source Code or Questions or Comments? 4 th International Conference on.NET Technologies. University of West Bohemia, Plzen, Czech Republic. May 29 – June 2 nd 2006