What is an Assembly?
What is Manifest?
CorFlags.exe or Dumpbin.exe can be used to examine the header information emitted in the managed module by the compiler
Execution Steps of EXE file
What is IL?
What is JIT? What are the execution steps of JIT?
What is Verification in CLR?
Why should each process run in its own address space?
PEVerify.exe
NGen.exe
What is Common Type System(CTS)?
What is an Event?
Event allows a notification mechanism between the object and the interested objects.
[assembly:CLSCompliant(true)]
Managed PE File(EXE or DLL)
What is Culture Neutral Assemby?
An assembly that isn’t assigned a culture is referred to as being Culture Neutral assembly.
What is Satellite Assembly?
Assembly marked with culture are known as Satellite assembly. Access a satellite assembly’s resources by using the System.Resources.ResourceManager class.
Privately Deployed Assemblies
Assemblies deployed to the same directory as the application are called privately deployed
assemblies
Two kinds of assemblies
All types are derived from System.Object.
Finalize
Why Main method is static?
When a program is launched, no instances of any class are present in memory. As the Main method is static, it can be called without creating an object and can then assume control of the program. It is the Main method's task to create the objects that the program requires to function correctly.
Type casting
Assume Manager class is derived from Employee class
Example 1
Manager m = new Manager();
Employee e = (Employee) m;
Example 2 (this way we should be type casting for type safety)
Manager m = new Manager;
Employee e = m as Employee;
Namespaces
Primitive Type
Checked and Unchecked operators
Reference Types and Value Types
Boxing
UnBoxing
Converting a reference type to a value type.
Constants
Constructor
Constructors are special methods that allow an instance of a type to be initialized to a good state.
type constructors (also known as static constructors, class constructors, or type initializers).
An
assembly is a logical grouping of one or more modules or resources. Its
the smallest unit of resuse, security and versioning. We can generate
single file or mutiple file assembly.
What is Manifest?
Manifest
describes the files that makes up the assembly, the publicly exported
types implemented by the files in the assembly and the resource/data
files associated with the assembly.They also describe the assembly’s
version, culture, publisher,
publicly exported types, and all of the files that comprise the assembly.
CorFlags.exe or Dumpbin.exe can be used to examine the header information emitted in the managed module by the compiler
Execution Steps of EXE file
- Windows first examines the EXE’s file header to determine whether the application requires 32-bit, 64-bit or Itanium address space.
- After identifying the address space it loads the corresponding MSCOREE.dll into the process’s address space.
- Then process’s primary thread calls the method with in the MSCOREE.dll.
- The method inside MSCOREE.dll does the following activities
- Initializes CLR
- Loads the EXE assembly
- Calls the entry point (Main method) of the EXE. Now the exe should be up and running.
What is IL?
- IL is higher language than most CPU machine languages.
- IL can access and manipulate object types.
- Has Instructions to create and initialize objects.
- Can call virtual methods of objects
- Also can manipulate Array elements directly.
- Has instructions for exception handling
- It can be considered as object-oriented machine language.
- IL can even be written in Assembly language and can be complied/Assembled using ILASM.exe
- IL can be disassembled using ILDASM.exe
What is JIT? What are the execution steps of JIT?
- Complier used by CLR to convert IL to native CPU instructions.
- Checks the assembly that implements the type(console) and looks up for the method (WriteLine) being called in the metadata
- From the metadata, JIT retrieves the IL Code for this method
- Allocates a block of memory
- Compiles the IL into native CPU instructions and saved in the allocated block of memory
- Modifies the method’s entry to point it to the allocated memory space.
- JIT Compiler jumps to the code in the memory block, executes it and returns back to the main method.
- If the same method is called for second or more times JIT compilation is skipped and the method is directly executed and the returns back to the main method.
What is Verification in CLR?
- Verification examines the high level IL and ensures that whatever the code does is safe.
- Verification checks whether each method is called with correct number of parameters
- Each parameter passed to a method is of correct type
- Ensures whether every method has a return statement and every method’s return value is used properly.
- Mananged module’s metadata contains all the information required for verification process.
Why should each process run in its own address space?
- Each Process has its own virtual address space.
- it is required to avoid reading/writing to/from invalid address space.
- Avoids one process affecting the other process activities
- Also application gains robustness and stability.
PEVerify.exe
- Examines all of the assembly’s methods and notifies you any method that contains unsafe code.
NGen.exe
- Used to compile IL code into native CPU code when installing on user’s machine.
- Code will be compiled from IL to native at installation time and hence JIT doesn’t have to compile it again at runtime.
- Can be used to improve application startup time.
- To reduce application working set.
- Allows the native file to be memory-mapped into multiple processes address spaces simultaneously allowing the code to be shared and hence avoiding each process to have its own copy of code.
What is Common Type System(CTS)?
- Describes how types are defined and how they behave.
What is an Event?
Event allows a notification mechanism between the object and the interested objects.
[assembly:CLSCompliant(true)]
This
attribute tells the compiler to ensure that any publicly exposed type
doesn’t have any construct that would prevent the type from being
accessed from any other programming language
Managed PE File(EXE or DLL)
- It has four parts
- PE32(+) Header - Indicates whether the PE file is built for 32-bit,64-bit or Itanium
- CLR Header -
- Includes CLR Version
- Flags details
- Entry point method detail for EXE
- optional strong name digital signature
- Also contains size and offsets of certain metadata tables contained in the module.
- Metadata
- It contains 3 tables
- Definition tables
- reference tables
- manifest tables
- IL
What is Culture Neutral Assemby?
An assembly that isn’t assigned a culture is referred to as being Culture Neutral assembly.
What is Satellite Assembly?
Assembly marked with culture are known as Satellite assembly. Access a satellite assembly’s resources by using the System.Resources.ResourceManager class.
Privately Deployed Assemblies
Assemblies deployed to the same directory as the application are called privately deployed
assemblies
Two kinds of assemblies
- Weakly Named Assemblies
- Strongly Named Assemblies
- Difference between these two assemblies are
- Strongly named assembly is signed with a publisher’s public/private key pair that uniquely identifies the assembly’s publisher
- A weakly named assembly can be deployed only privately
- A strongly named assembly can be deployed privately or globally
- A strongly named assembly contain 4 attributes
- File Name
- Version
- Culture
- Public Key
All types are derived from System.Object.
Finalize
This virtual method is called when the garbage collector determines that
the object is garbage before the memory for the object is reclaimed. Types
that require cleanup when collected should override this method.
Why Main method is static?
When a program is launched, no instances of any class are present in memory. As the Main method is static, it can be called without creating an object and can then assume control of the program. It is the Main method's task to create the objects that the program requires to function correctly.
Type casting
Assume Manager class is derived from Employee class
Example 1
Manager m = new Manager();
Employee e = (Employee) m;
Example 2 (this way we should be type casting for type safety)
Manager m = new Manager;
Employee e = m as Employee;
If cast above fails: no exception is thrown, but e is set to null.
Namespaces
Namespaces allow for the logical grouping of related types
Primitive Type
Any data type that compiler directly supports are known as
Checked and Unchecked operators
UInt32 invalid = unchecked((UInt32) (-1)); // OK
Byte b = 100;
b = checked((Byte) (b + 200)); // Overflow-Exception is thrown
b = (Byte) checked(b + 200); // b contains 44; no OverflowException
checked
{ // Start of checked block
Byte b = 100;
b = (Byte) (b + 200); // This expression is checked for overflow.
} // End of checked block
Reference Types and Value Types
Reference types are always allocated from the managed heap, and the C# new operator
returns the memory address of the object—the memory address refers to the object’s bits.
Boxing
Convert a value type to a reference type.
UnBoxing
Converting a reference type to a value type.
Constants
A constant is a symbol that identifies a never-changing data value
Constructor
Constructors are special methods that allow an instance of a type to be initialized to a good state.
type constructors (also known as static constructors, class constructors, or type initializers).
No comments:
Post a Comment