用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. Sildenafil说道:

    generic viagra walmart https://sildenafilmg.shop/
    order viagra online

  2. Michaeljealp说道:

    viagra over the counter buy viagra online canada

  3. Sildenafil说道:

    buy viagra online canada https://sildenafilmg.com/
    order viagra online

  4. Sildenafil说道:

    viagra from canada https://sildenafilmg.com/
    when will viagra be generic

  5. Sildenafil说道:

    price of viagra https://sildenafilmg.online/
    where can i buy viagra over the counter

  6. Viagrak说道:

    viagra cost per pill viagra discount mexican viagra

  7. Viagrak说道:

    buying viagra online viagra amazon viagra amazon

  8. Viagrak说道:

    viagra over the counter best over the counter viagra best place to buy generic viagra online

  9. Viagrak说道:

    viagra price viagra pills buy real viagra online

  10. Viagrak说道:

    viagra from canada where to buy viagra online where to buy viagra online

  11. There most be a solution for this problem, some people think there will be now solutions, but i think there wil be one.

  12. Viagrak说道:

    price of viagra viagra discount viagra over the counter

  13. Viagrak说道:

    cost of viagra viagra from india cheap viagra online

  14. Viagrak说道:

    cost of viagra over the counter viagra where to buy viagra online

  15. Viagrak说道:

    best place to buy viagra online where can i buy viagra over the counter viagra from canada

  16. Viagrak说道:

    viagra over the counter buy generic 100mg viagra online generic viagra walmart

  17. Michaeljealp说道:

    viagra discount viagra over the counter walmart

  18. Brandonblona说道:

    best place to buy viagra online sildenafil 20 mg

  19. Scrum vs Agile说道:

    You appear to know so much about this, and I see you’re a published author. Thanks

  20. This information is critically needed, thanks.

  21. You are not right. I am assured. I can prove it. Write to me in PM, we will talk.

  22. Hi, I just hopped over to your web-site through StumbleUpon. Not somthing I might typically browse, but I liked your views none the less. Thanks for making something worthy of reading through.

  23. Brandonblona说道:

    best place to buy viagra online sildenafil

  24. Thanks for your patience and sorry for the inconvenience!

  25. Nice post.Very useful info specifically the last part 🙂 Thank you and good luck.

  26. Thank you a lot for sharing this with all folks you actually recognize what you’re speaking about! Bookmarked. Please additionally visit my site =). We can have a hyperlink trade contract among us!

  27. Michaeljealp说道:

    order viagra online viagra over the counter

  28. Georgegip说道:

    zithromax z-pak price without insurance zithromax 500 mg lowest price online

  29. Raymondnougs说道:

    buy zithromax online australia zithromax prescription

  30. Buy RDP说道:

    Hi my family member! I want to say that this article is amazing, great written and include approximately all important infos. I’d like to see more posts like this .

  31. free rdp account说道:

    Certainly. And I have faced it. Let’s discuss this question. Here or in PM.

  32. cheap rdp vps说道:

    I think I might disagree with some of your analysis. Are the figures solid?

  33. Rickyjonee说道:

    how to get amoxicillin over the counter amoxicillin 500mg capsules antibiotic

  34. RobertRaw说道:

    where to get zithromax over the counter zithromax tablets

  35. Well, I don’t know if that’s going to work for me, but definitely worked for you! 🙂 Excellent post!

  36. Georgegip说道:

    zithromax online generic zithromax 500mg

  37. Stephenloano说道:

    https://clomidforsale.life/# clomid online order no script