Inside and Out…

An attempt to understand technology better…

Archive for the ‘Rotor’ Category

How the SSCLI [a.k.a. Rotor] managed "new" works

Posted by Gaurav Khanna on February 12, 2007

One of the best ways to understand how the CLR works internally is to have a look at the SSCLI [a.k.a Rotor] source code.

In How the SSCLI [a.k.a. Rotor] managed “new” works, I have used Rotor source code to discuss what happens behind the scenes when you use the managed new operator to instantiate a managed type, discussing implications of object size, how requests from multiple threads are handled, the different validations that are done, when out-of-memory exception is thrown, etc. If you are a managed code developer, you may learn a thing or two that can help you write better code besides understanding how the managed allocation works internally.

Advertisements

Posted in Articles, CLR, Development, Rotor | Leave a Comment »

Adding process enumeration support in Rotor v1.0

Posted by Gaurav Khanna on September 5, 2005

Share Source CLI, better known as Rotor, is one of the best ways to understand how .NET Framework works. And with the source code availability as part of Rotor distribution, its an excellent academic/hobby interest – you can extend it by adding more functionality, or modify the existing one and see how it behaves.

Yesterday, I went about doing the same. One of the functionality which I found missing in Rotor is that of enumerating system process list. .NET Framework’s System.Diagnostics.Process class has methods, like GetProcesses, that allow you to do the same.

So, I went about implementing GetProcesses method overloadsin System.Diagnostics.Process class that allow me to enumerate process list on the local machine only. This required modification in the Platform Adaptation Layer (PAL) of Rotor. Since, I just have it running on Win32 for the moment, I modified the Win32 PAL to implement the support via ToolHelpAPI. Now, on a Windows system, its possible to enumerate the system process list using Rotor, as exemplified by the snippet below:

You can download the updated source files for Rotor v1.0 from http://www.wintoolzone.com/showpage.aspx?url=rotor.aspx. The zipped archive contains Changes for Process Enumeration.txt that indicates where the updated files need to be copied. Once done, rebuild Rotor to get the changes into effect.

using System; 
using System.Diagnostics;

public class EnumProcess
{
    public static void Main()
    {
        Process[] arrProcess = Process.GetProcesses();
        if (arrProcess == null)
        {
            Console.WriteLine("Unable to get process list!");
            return;
        }

        Console.WriteLine("{0} processes enumerated.", arrProcess.Length);

        foreach (Process proc in arrProcess)
            Console.WriteLine("Process ID {0}, Handle: {1}", proc.Id, proc.Handle);
    }
}

Posted in CLR, Downloads, Rotor | Leave a Comment »

..and ThreadPool.GetMinThreads

Posted by Gaurav Khanna on July 25, 2004

And I am finally done with extending the Rotor’s ThreadPool class. Finished implementing the GetMinThreads method.

Download the source code from http://www.wintoolzone.com/showpage.aspx?url=rotor.aspx.

Posted in CLR, Development, Downloads, Rotor | Leave a Comment »

Rotor – SetMaxThreads, SetMinThreads

Posted by Gaurav Khanna on July 22, 2004

Just finished extending Rotor’s ThreadPool class to support SetMaxThreads and SetMinThreads methods – to modify the extent of the threadpool maintained by the Rotor runtime – just like .NET FX 2.0 has it.

Will post the source code soon…meanwhile, here’s my implementation of SetMinThreadsInternal in Win32ThreadPool.cpp:

/************************************************************************/
// Will be used to set the minimum number of threads in the Rotor Threadpool
// Kumar Gaurav Khanna - 22-Jul-2004
BOOL ThreadpoolMgr::SetMinThreads(DWORD MinWorkerThreads, 
                                     DWORD MinIOCompletionThreads)
{

    if (IsInitialized())
    {
        BOOL result = FALSE;

        // 1) cannot have minimum worker thread limit <=0
        // 2) cannot have minimum worker thread limit equal to 
// or greater than the maximum worker thread limit if ((MinWorkerThreads > 0) && (MinWorkerThreads < MaxLimitTotalWorkerThreads)) { if (MinWorkerThreads <= (DWORD) MinLimitTotalWorkerThreads) { MinLimitTotalWorkerThreads = MinWorkerThreads; result = TRUE; } } return result; } if (InterlockedCompareExchange(&Initialization, 1, 0) == 0) { Initialize(); BOOL result = FALSE; if ((MinWorkerThreads > 0) && (MinWorkerThreads < MaxLimitTotalWorkerThreads)) { if (MinWorkerThreads <= (DWORD) MinLimitTotalWorkerThreads) { MinLimitTotalWorkerThreads = MinWorkerThreads; result = TRUE; } } Initialization = -1; return result; } else // someone else is initializing. Too late, return false { return FALSE; } }

Posted in CLR, Downloads, Rotor | Leave a Comment »