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

    stromectol 3mg buy ivermectin near me does ivermectin kill lyme disease

  2. Stromectol说道:

    ivermectin ingredients ivermectin rabbits ivermectin benefits for humans

  3. Stromectol说道:

    ivermectin covid treatment ivermectin plus dosage of ivermectin for dogs

  4. CharlesCrave说道:

    canadian pharmacy legal to buy prescription drugs from canada pet antibiotics without vet prescription

  5. CanadaEd说道:

    ed pills pills for ed ed medications list

  6. CanadaEd说道:

    impotence pills medicine for impotence ed meds online without doctor prescription

  7. CanadaEd说道:

    ed treatment pills medicine for impotence erection pills online

  8. CanadaEd说道:

    herbal ed treatment the best ed pills ed pill

  9. CanadaEd说道:

    ed pills that work medication for ed generic ed pills

  10. CanadaEd说道:

    best ed treatment pills best ed pills online cures for ed

  11. CanadaEd说道:

    online ed medications non prescription ed drugs ed treatment review

  12. CanadaEd说道:

    ed treatment pills ed drugs compared the best ed pill

  13. CharlesCrave说道:

    buy prescription drugs without doctor cheap pet meds without vet prescription canadian online pharmacy

  14. Stromectol说道:

    ivermectin for goat mites ivermectin for.covid ivermectin for rabbits

  15. CharlesCrave说道:

    canadian pharmacy comfortis without vet prescription best canadian pharmacy online

  16. CharlesCrave说道:

    ivermectin-pyrantel – generic to heartgard plus ivermectin clinical trials ivermectin 1 cream

  17. CharlesCrave说道:

    propecia buy finasteride 1mg finasteride proscar

  18. CanadaThext说道:

    india pharmacy india pharmacy without dr prescriptions generic drugs without doctor’s prescription

  19. CanadaThext说道:

    prescribing stromectol prescribing stromectol stromectol for sale

  20. Onlikoel说道:

    buy prescription online from india india pharmacies online india pharmacies online

  21. Okisdlf说道:

    recommended canadian pharmacies online pharmacies without prior prescription canada rx drugs online

  22. Okisdlf说道:

    discount prescription drugs online buying from canadian online pharmacies buy prescription drugs online cheap

  23. Okisdlf说道:

    trusted online canadian pharmacy reviews trusted online canadian pharmacy reviews canadian pharmacy online ship to usa

  24. Okisdlf说道:

    recommended canadian pharmacies meds online without doctor prescription canadian pharmacy online ship to usa

  25. Okisdlf说道:

    reputable canadian mail order pharmacies prescription drugs without doctor approval highest rated canadian pharmacies

  26. Okisdlf说道:

    ordering prescription drugs from canada highest rated canadian pharmacies canadian pharmacy online ship to usa

  27. Okisdlf说道:

    pharmacy without dr prescriptions buying from canadian online pharmacies generic drugs without doctor’s prescription

  28. Okisdlf说道:

    canadian pharmacies not requiring prescription canadian pharmaceuticals online safe canadian pharmaceuticals online safe

  29. CanadaThext说道:

    stromectol prescribing stromectol stromectol pills for humans

  30. Edpilol说道:

    medicine erectile dysfunction male ed drugs ed pills cheap

  31. Stromectol说道:

    stromectol pills for humans stromectol 3 mg tablets price stromectol 12 mg tablets

  32. Stromectol说道:

    buy stromectol online stromectol stromectol for sale

  33. Stromectol说道:

    stromectol without a doctor prescription stromectol stromectol for humans for sale

  34. Stromectol说道:

    buy stromectol online stromectol for humans for sale stromectol pills for humans

  35. Stromectol说道:

    stromectol for humans for sale stromectol without a doctor prescription stromectol pills for humans

  36. CanadaThext说道:

    reputable canadian mail order pharmacies reputable canadian mail order pharmacies discount prescription drugs online

  37. Sildenafil说道:

    sildenafil citrate 100mg for sale viagra sildenafil 20 mg

  38. Sildenafil说道:

    sildenafil citrate 100mg for sale viagra pills viagra tablets for men

  39. Michaelacoum说道:

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

  40. Sildenafil说道:

    viagra tablets for men sildenafil 100 mg lowest price sildenafil 100 mg

  41. Sildenafil说道:

    sildenafil citrate tablets 100 mg sildenafil citrate tablets 100 mg sildenafil 100 mg lowest price

  42. Sildenafil说道:

    viagra pills viagra where to buy sildenafil 100 mg lowest price

  43. Sildenafil说道:

    price for viagra sildenafil 100 mg sildenafil 100 mg lowest price

  44. Sildenafil说道:

    viagra tablets for men viagra viagra pills

  45. Sildenafil说道:

    sildenafil 100 mg lowest price viagra where to buy viagra

  46. Michaelacoum说道:

    ivermectin without a doctor prescription stromectol price usa stromectol price usa

  47. Tadalafil说道:

    generic tadalafil 20mg india cialis pharmacy where to buy liquid cialis

  48. Stromectol说道:

    stromectol price usa stromectol for humans for sale stromectol 3 mg tablets price

  49. Clomid说道:

    clomid tablets clomid for sale buy clomid 50mg online