Writing Mobile Code Essential Software Engineering for Building Mobile Applications [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Writing Mobile Code Essential Software Engineering for Building Mobile Applications [Electronic resources] - نسخه متنی

Ivo Salmre

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید











How Code Is Executed and Run


When a managed code application is first started up, several steps occur to load, verify, and start code execution. When the managed-code application is up and running, the managed-code runtime continues to play an important role in loading new classes, JIT compiling code when necessary and managing the memory of the application. It is useful to have a good conceptual understanding of how this happens. The process of starting up and running an application can be explained in the six steps described here:


1.

A managed application is loaded.
The binary header of the application indicates to the operating system that it is not a native application. Instead of simply starting to execute instructions, the .NET Compact Framework execution engine is loaded and told to get the application running.

2.

The execution engine finds the class with the "main" entry point for it to execute.
This is a class with a function signature matching static void Main(). If a type with this signature is found, the class is loaded and the "main" procedure is attempted to be run (Steps 3 and 4).

3.

The class is loaded.
Information about the class is loaded and verified to make certain that it is a consistent and well-formed class definition. All methods (that is, code-execution entry points) in the class are marked as "uncompiled."

4.

The execution engine attempts to run the specified procedure.
If the procedure already has compiled code associated with it, the code is run.

5.

If the execution engine discovers that the property or method it is about to run has not been compiled, it gets compiled on demand.
The class information for the method is loaded. The code contained is verified to ensure that it contains safe, legal and well-formed IL instructions and then it is JIT compiled. If the method references other types that have not yet been loaded, the class or type definitions are loaded as needed. Note: The methods inside these classes are not compiled until needed; this is the meaning of JIT (just in time).

6.

The now-compiled method is executed.
Any type or object allocations required are requested from the execution engine. Any method calls to classes bring us back to Step 5.


This all sounds like a lot of work but in reality it happens very quickly.


What's a "Type"?


Note:
Any data that a programmer can work with is a "type." Another way of saying this is that all data types and classes are types. Everything is a type, including integers, decimals, other scalars, strings, and classes. Any "thing" you can pass around in code is an instance of a type. Classes are special types in that they contain not just data but also code and support object-oriented behaviors such as inheritance.

Note:
As classes and other types have their definitions loaded into memory and get verified and compiled, this data goes into allocated memory just like other data that developers allocate in their application. Example: If you create an ArrayList object:

[View full width]

System.Collections.ArrayList aList = new System.Collections
.ArrayList();

You are doing several things:

The code above is represented in your application as IL. This IL gets JIT complied at runtime right before it is first run. The code is placed into allocated memory.

When the code gets JITed, the execution engine looks to see whether it has the information for the type System.Collections.ArrayList loaded into memory; if not, memory for this type definition is allocated and it is loaded into memory and associated with the class ArrayList.

When the actual code above is run, a constructor for the ArrayList object needs to be run. If this code has not been loaded and JITed yet, memory gets allocated and the constructor's code gets JITed. The code is loaded, verified, and JITed, and the memory for this constructor's code is associated with the ArrayList class' constructor.

The same holds true for any type that gets loaded or method that gets called; if the work has not been done before to load it, it will get loaded and compiled as needed, and the memory used to do that is associated with the type.

This memory allocation and tracking is important. As you will see below, code and class definition data, just like objects, can get garbage collected.


/ 159