Some concepts of Dart confused me

28 views
Skip to first unread message

Jim Xu

unread,
Dec 11, 2019, 8:42:46 AM12/11/19
to Dart Compiler Developers
hi, guru,
When I went through Dart's source code, I found some concept confused me. Here they are:
1. Tagged Object. what is this?
2. lib owned scripts. What is this?
3. finalized class. Does that mean the class is compiled, and the internal Code object is assemblied by instructions
4. Patchability's patchable. Does that mean some function are able to be patched?

Hope some guy could shed me some light, thank you very much.


Jim

Vyacheslav Egorov

unread,
Dec 16, 2019, 8:28:07 AM12/16/19
to Jim Xu, Dart Compiler Developers
> 1. Tagged Object. what is this?

Dart VM uses pointer tagging to avoid boxing "small" integer values (abbreviated as smi in the code base). 

When you have a pointer (RawObject*) it can be either: 

- a pointer to an object in the heap

- an immediate smi value which "pretends" to be a pointer. 

These two situations are distiguished by the least significant bit of the value - if it is 1 then the value is a pointer into the heap, if it is 0 then it is a small integer. 

- If the value is a tagged pointer (least significant bit is 1) then the actual pointer can be obtained by subtracting 1 from it

- If the value is a tagged small integer (least significant bit is 0) then the actual integer value can be obtained by shifting the value to right by 1.

> 2. lib owned scripts. What is this?

Scripts represent sources of Dart code (e.g. individual files). Libraries might be split into many scripts (e.g. because they use part files). 

> 3. finalized class. Does that mean the class is compiled, and the internal Code object is assemblied by instructions

Finalized just means that the class is fully loaded from the source (including the list of methods and fields it has and their signutures, superclass, etc).

It means this class is ready to be used by the VM - e.g. to create instances of this class. 

There is no connection to generating native code for class'es methods. (for methods of the class to be compiled the owner class needs to be finalized - but if the class is finalized that does not mean that all methods are compiled).

> 4. Patchability's patchable. Does that mean some function are able to be patched?

When native code is generated assembler builds object pool for that native code. 

In general we try to deduplicate entries inside this object pool. 

However in some occasions we should not - because later during execution we might want to dynamically change the entry in the object pool (e.g. to implement inline caching aka switchable calls).

This is indicated by the patchability attribute of the entry pool - it tells assembler that it needs to allocate a completely independent entry in the object pool.

Hope this helps. 


// Vyacheslav Egorov


--
To unsubscribe from this group and stop receiving emails from it, send an email to compiler-dev...@dartlang.org.

Jim Xu

unread,
Dec 18, 2019, 9:07:17 PM12/18/19
to Dart Compiler Developers, xujia...@gmail.com
Thanks
To unsubscribe from this group and stop receiving emails from it, send an email to compil...@dartlang.org.
Reply all
Reply to author
Forward
0 new messages