Feed on
Posts
Comments

IPL - Indian Premier League - has finally brought the club based cricket in India. The 20-20 (T20) tournament is witnessing 8 teams fight for the top highest honor. Each team will play the other twice - one at it’s home ground and the other at the second team’s home ground. Here is how the points table is right now.

Team Won / Played

Delhi 4/5

Chennai 4/5

Rajasthan 4/5

Punjab 4/6

Kolkata 2/6

Bangalore 2/6

Hyderabad 1/6

Mumbai 1/5

And here are the most talked about points about IPL this season.

  • Cheer leaders
  • Slap (hey between the brothers guys…)
  • “It’s all about teams gelling well…” - Gel with it’s other verb forms is the most used word this summer :)
  • Sehwag and Gambhir
  • McGrath and Asif
  • Why Hyderabad fails so often even after the most formidable batting line up?
  • M S Dhoni from Chennai - Fast bowlers Rascalla, Mind it
  • Some of the best players are the Indian domestic cricketers
  • Preity and Shahrukh
  • Rajasthan team has made the people realize that the underdogs can bite - both with on-field and off-field
  • Finally, when will Sachin get back?

The tournament is half-way through and turning out to be a very interesting one.

It’s 40 deg. cel. out there in the open. Welcome to Hyderabad or as a matter of fact any where in India except a few blessed ones. So how do you spend your time when going out is not the best options. Here is my formula.

Fun + Chill = PS2 + God of War + Pepsi

Although I have already played this game once, this has a great replay value.

  • A tight storyline
  • Awesome graphics
  • Great sound
  • Very smooth game play

Oh! It’s time to be back in the Greek mythological world.

Beware Ares! Kratos is back …

In this post I’ll explore the MSIL generated for delegates and events when a project is compiled in Visual C# or any other language that target the .NET platform. This is my fourth post on exploring MSIL - Microsoft Intermediate Language.

Here are the links for my last three posts.

The lies of the C# compiler : It explores the MSIL equivalent of the C# accessors like protected, internal etc.

Exploring MSIL - Static and Instance Methods : It explores the difference in the MSIL generated for static and instance methods.

Exploring MSIL - Properties : It explores the generated MSIL for properties of a class.

As in the last posts, I’ll create a project with a class - Traffic light that contains the event SignalChanged. This event uses the delegate SignalChangedDelegate that encapsulates the methods that can be called once the event is triggered. Here goes the code.

public delegate void SignalChangedDelegate(string newSignal);

class TrafficLight
{
public event SignalChangedDelegate SignalChanged;
}

Now let us start by looking at the MSIL generated generated for the delegate - SignalChangedDelegate.delegate_msil.jpg

The delegate, SignalChangedDelegate, is actually a class that extends the class MulticastDelegate. The constructor, .ctor, takes 2 arguments - an object and a native int. Apart from the constructor there are three other methods -

1. BeginInvoke() method takes a string , a AsyncCallback and an object as arguments and returns an IAsyncResult.

2. EndInvoke() method takes an IAsyncResult and returns a void.

3. Invoke() method takes a string and returns void.

And here is the MSIL for the class TrafficLight that defines the event SignalChanged.event_msil1.jpg

The points to note are

1. A private field of the type of the SignalChangedDelegate is generated. The name of the field is same as that of the event which is shown by an inverted green triangle at the bottom of the image.

2. Two additional methods - add_SignalChanged and remove_SignalChanged are also generated and both of them take the SignalChangedDelegate as argument. Actually these are the methods that are called once listeners add or remove themselves for the SignalChanged event.

3. The event SignalChanged is also present which is as it is in the source code.

In the next post I am directly diving into the MSIL instructions and I’ll start with the example that every one starts with - The Hello World Program.

This is my third post on MSIL - Microsoft Intermediate Language - which is generated by the Visual C# compiler once the code is compiled. In this post I’ll take a look at the intermediate language generated for the properties of a class.

Here are my last two posts on MSIL.

The lies of the C# compiler : It explores the MSIL equivalent of the C# accessors like protected, internal etc.

Exploring MSIL - Static and Instance Methods : It explores the difference in the MSIL generated for static and instance methods.

I’ll create create a class BankAccount and add the properties CustomerName and Balance. CustomerName gives both read and write access while Balance is only read-only. The class members have been kept on minimum to focus on the MSIL generated for a property. Here is the code.

public class BankAccount
{
private string customerName;
private float balance;

public BankAccount(string name, float bal)
{
this.customerName = name;
this.balance = bal;
}

public string CustomerName
{
get { return customerName; }
set { customerName = value; } // both read and write access
}

public float Balance
{
get { return balance; } // read-only
}
}

And here is the intermediate language that is generated once the project is compiled.

properties_msil.jpg

The following points are worth observing.

1. Apart from generating the properties, the get_xxx and set_xxx methods have also been generated.

2. The get_xxx method is generated for the get accessor and the set_xxx method is generated for the set acessors in the property.

3. The get_xxx method returns a value of the same type as the field that is encapsulated by the property. For example, get_Balance() returns a float that is of the same type as the field balance.

4. The set_xxx method takes an argument and returns void. Again the type of the argument is same as the field that is encapsulated by the property.

Now let us have a closer look at the intermediate language generated for the property - CustomerName and it’s get and set accessors.

.property instance string CustomerName()
{
.get instance string BankAccount::get_CustomerName()
.set instance void BankAccount::set_CustomerName(string)
} // end of property BankAccount::CustomerName

The property, CustomerName, is an instance one and the field that it encapsulates is a string. It provides both read and write access. In case this property had encapsulated a static field, the word instance would had been missing and NOT replaced by static.

.method public hidebysig specialname instance string
get_CustomerName() cil managed
{
// Code size 12 (0xc)
.maxstack 1
.locals init ([0] string CS$1$0000)
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldfld string BankAccount::customerName
IL_0007: stloc.0
IL_0008: br.s IL_000a
IL_000a: ldloc.0
IL_000b: ret
} // end of method BankAccount::get_CustomerName

The get acessor of the property is actually an instance method that returns a string. I’ll explain the IL instructions in another post.

.method public hidebysig specialname instance void
set_CustomerName(string ‘value’) cil managed
{
// Code size 9 (0×9)
.maxstack 8
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldarg.1
IL_0003: stfld string BankAccount::customerName
IL_0008: ret
} // end of method BankAccount::set_CustomerName

The set acessor of the property is also an instance method that takes a string argument - value.

I believe this post gives a little more insight into the MSIL generated for the properties.

Last week I wrote my first post on MSIL - The lies of the C# compiler. It explores the MSIL equivalent of the C# accessors like protected, internal etc. In this post I’ll look into the difference in the MSIL for static and instance methods.

What are instance methods? The methods that can be accessed only through an object of the class are called instance methods. On the other hand static methods do not need an object to be accessed. They can be directly accessed through the class.

I’ll create a class - Test and add a static and a dynamic method. Here goes the code.

class Test
{
public void InstanceMethod()
{
// the instance method
}

public static void StaticMethod()
{
// the static method
}
}

Now let me show you the MSIL that is generated on compiling the solution.

.method public hidebysig instance void InstanceMethod() cil managed
{
// Code size 2 (0×2)
.maxstack 8
IL_0000: nop
IL_0001: ret
} // end of method Test::InstanceMethod

.method public hidebysig static void StaticMethod() cil managed
{
// Code size 2 (0×2)
.maxstack 8
IL_0000: nop
IL_0001: ret
} // end of method Test::StaticMethod

As is clear from the MSIL the InstanceMethod() is explicitly marked with the keyword instance in the generated intermediate language. The static method is anyhow marked as static in the source code.

Any non-static method is by default marked as instance by the C# compiler and can be seen in the generated intermediate language.

Here is the link to my next post : Exploring MSIL - Properties

Older Posts »