用sscli学习.NET实现

在Blog上记录过两篇和.NET中GC机制相关的学习笔记(这里这里),但都是从概念上泛泛而谈,所学习、参考和引用的资料也都是从概念上进行介绍,并没有涉及到代码层面的实现。由于工作中也用不到,所以没有继续关注下去。

最近则是在学习.NET Framework Library时想要更清楚地了解.NET对象的内存布局,才知道其实微软早就在10年前发布了开源的CLI实现sscli(Shared Source Common Language Infrastructure),代号Rotor。,并且于06年发布了它的2.0版本。尽管在之后这个项目就没再更新(有消息说已经下线),而且微软后续对于.NET Framework的更新使得现在的实现肯定和之前的大相径庭,但对于这个层面的代码来说,光是sscli2.0就够一般的学习者喝一壶,其中VM、JIT Compiler以及更上层的GC机制等实现,也远远还没有到过时的程度。如果非要追最新的实现,可以参考.NET CF 4.0,它现在从CLR层次就是开源的。

对于sscli,关注它的人并不多,毕竟这是底层到直接涉及托管程序运行、管理的框架。平时大家只要知道怎么编写和载入Assembly、让托管程序或网页跑起来,满足老板/PM/甲方的需求就行了,至于个中具体流程,没有必要关心。甚至于说,只要通读《CLR via C#》后清楚.NET各种概念的实现和关系、知道IL一级的实现,再加上了解大部分运行在CLR上层的机制,就能应付90%以上的工作场景。但sscli还是有必要看看:

  • 解决一些疑难杂症,例如奇怪的内存泄露、CPU满载问题。
  • 更清楚地了解原理。就拿刚才提到的Object内存布局问题来说,利用概念层次的讲解文章《浅析.NET中的引用类型和值类型(上)》以及文中提到的《Pro .NET Performance》这本书,结合sscli具体实现才能做到有自信掌握看破这一话题的能力。
  • 满足自己的好奇心……不是开玩笑,例如GC实现中的各种算法、safe point、hijacking什么的,你说知道具体实现又有何用?单纯是想知道而已。尽管如此,我觉得这类“Under the hood”学习应该算是程序员的自我修养,也是进行“写程序的人”和“程序员”之鉴别的标准之一。

下载了sscli2.0的代码之后,会发现除了clr文件夹内的核心实现外,还有.net相关工具集,以及一部分(老的).NET Framework代码,例如HttpRequest、Xml等实现。这些代码中有最近正在学的正则表达式引擎的完整实现,算是意外收获。另外还附送一个完整的jscript引擎。具体内容可以看docs文档。

接着可以参考下面几篇文章进行build和debug:

当然,windbg是不能少的,用来调试具体的托管程序,结合dump出来的信息,查看对应的cli代码,可以从将知识学习从逻辑层面过渡到实际的物理层面。

有关sscli整体学习,我还是不推荐自己抠代码,毕竟类似gc_heap这种类,光声明就好几千行,难以下手。看看大牛们的文章,例如CLR探索系列这个教程。里面从最基本的windbg载入sos调试程序开始,一步步介绍CLR基本概念,从CLR初始化到载入托管exe和dll,再到托管PE格式、GC机制等等,脉络清晰,图文并茂。另外还有一些针对具体问题的blog,例如《深入了解CLR的加载过程》等,结合阅读会事半功倍。

其他一些学习资源:

成为底层达人,就可以像这些大牛一样玩一些有趣的游戏了,比如自己定义新的IL Opcode或者是用托管代码让CLR挂掉之类。至于能不能在物质层面转化这些知识,就要看个人造化,但“天道酬勤”总是没错的。

247 Responses to “用sscli学习.NET实现”

  1. Clomid说道:

    clomid for sale buy clomid 50mg online buy clomid 50mg

  2. Clomid说道:

    clomid for sale buy clomid 50mg clomid for sale canada

  3. Clomid说道:

    clomid tablets buy clomid clomid

  4. Clomid说道:

    clomid clomid tablets for sale where to buy cheap clomid online

  5. Clomid说道:

    buy clomid 50mg clomid for sale canada clomid for sale

  6. Clomid说道:

    clomid tablets for sale buy clomid 50mg buy clomid 50mg online

  7. Clomid说道:

    clomid for sale buy clomid 50mg where to buy cheap clomid online

  8. Clomid说道:

    clomid buy clomid 50mg clomid tablets for sale

  9. Michaelacoum说道:

    buy clomid clomid clomid tablets

  10. Michaelacoum说道:

    stromectol 12 mg tablets stromectol pills for humans stromectol for sale

  11. Michaelacoum说道:

    online purchase of tadalafil in india price of cialis 20 mg price of cialis 20 mg

  12. Michaelacoum说道:

    where to buy cheap clomid online clomid clomid for sale canada

  13. Stromectol说道:

    ivermectin for humans walgreens https://stromectolrate.com/
    ivermectin for sale near me

  14. Stromectol说道:

    stromectol for pinworms https://stromectolrate.com/
    worming sheep with ivermectin

  15. Stromectol说道:

    ivermectin for demodex in humans https://stromectolrate.com/
    ivermectin dog

  16. JamesMed说道:

    stromectol tablets for humans stromectol for sale ivermectin meta-analysis

  17. Stromectol说道:

    ivermectin? https://stromectolrate.com/
    how to get ivermectin

  18. Stromectol说道:

    ivermectin for cats ear mites https://stromectolrate.com/
    ivermectin dog

  19. Stromectol说道:

    ivermectin covid-19 https://stromectolrate.com/
    stromectol for scabies merck

  20. Stromectol说道:

    mexico city ivermectin https://stromectolrate.com/
    ivermectin walgreens

  21. Stromectol说道:

    does ivermectin kill bacteria https://stromectolrate.com/
    ivermectin 3mg dosage for scabies

  22. JamesMed说道:

    stromectol for sale stromectol 12 mg tablets why is stromectol prescribed

  23. JamesMed说道:

    ivermectin overdose cattle what worms does ivermectin kill in dogs ivermectin dosage for guinea pigs

  24. Ivermectin说道:

    ivermectin for gapeworm scabies ivermectin ivermectin guinea pig

  25. JamesMed说道:

    ivermectin injection stromectol 12 mg tablets stromectol 12 mg tablets

  26. Viagraus说道:

    viagra cost viagra over the counter viagra 100mg price

  27. CraigKeymn说道:

    viagra over the counter viagra pills where can i buy viagra over the counter

  28. Viagraus说道:

    viagra without a doctor prescription usa viagra over the counter buy viagra online canada

  29. Viagraus说道:

    viagra without a doctor prescription online doctor prescription for viagra generic viagra walmart

  30. Viagraus说道:

    viagra from india buy generic 100mg viagra online when will viagra be generic

  31. Viagraus说道:

    how much is viagra cost of viagra viagra without a doctor prescription usa

  32. Viagraus说道:

    viagra without a doctor prescription usa buy viagra online usa viagra from canada

  33. ViagraUs说道:

    viagra without a doctor prescription https://viagrasus.com/

  34. ViagraUs说道:

    online doctor prescription for viagra https://viagrasus.com/

  35. CraigKeymn说道:

    100mg viagra viagra pills where to buy viagra

  36. AndrewPag说道:

    cialis professional india tadalafil without a doctor’s prescription cialis generics

  37. AndrewPag说道:

    generic cialis? best price for daily cialis 36 hour cialis mg

  38. video说道:

    That is really fascinating, You’re an excessively skilled blogger. I’ve joined your rss feed and look forward to in the hunt for extra of your magnificent post. Additionally, I’ve shared your website in my social networks!

  39. hub说道:

    Greetings… your blog is very interesting and beautifully written.

  40. AndrewPag说道:

    cialis where can i buy tadalafil 20mg best price how much does cialis cost

  41. movie说道:

    The post is absolutely fantastic! Lots of great info and inspiration, both of which we all need! Also like to admire the time and effort you put into your website and detailed info you offer! I will bookmark your website!

  42. top说道:

    I simply could not leave your site before suggesting that I actually enjoyed the usual info a person supply in your visitors? Is going to be back often to inspect new posts

  43. movie说道:

    Pretty nice post. I just stumbled upon your weblog and wanted to say that I’ve really enjoyed surfing around your blog posts. After all I’ll be subscribing in your feed and I am hoping you write again very soon!