用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:
- 在Visual Studio 2008的环境下Build SSCLI 2.0(ROTOR)
- Build SSCLI20 under VS2008 full Document (完全手册)
- Debugging Whidbey / Rotor 2.0 / SSCLI2.0 in Visual Studio 2008
当然,windbg是不能少的,用来调试具体的托管程序,结合dump出来的信息,查看对应的cli代码,可以从将知识学习从逻辑层面过渡到实际的物理层面。
有关sscli整体学习,我还是不推荐自己抠代码,毕竟类似gc_heap这种类,光声明就好几千行,难以下手。看看大牛们的文章,例如CLR探索系列这个教程。里面从最基本的windbg载入sos调试程序开始,一步步介绍CLR基本概念,从CLR初始化到载入托管exe和dll,再到托管PE格式、GC机制等等,脉络清晰,图文并茂。另外还有一些针对具体问题的blog,例如《深入了解CLR的加载过程》等,结合阅读会事半功倍。
其他一些学习资源:
- Shared Source CLI Essentials
- Flier’s Sky,《用WinDbg探索CLR世界》系列,每篇都是按照CLR功能->windbg调试->IL code->cli实现这样的顺序讲解。blog内还有其他大量牛B文章。
- CLI研究 on NeoRAGEx2002’s Weblog
成为底层达人,就可以像这些大牛一样玩一些有趣的游戏了,比如自己定义新的IL Opcode或者是用托管代码让CLR挂掉之类。至于能不能在物质层面转化这些知识,就要看个人造化,但“天道酬勤”总是没错的。
canadian pharmacies without an rx
legitimate online pharmacy
sildenafil 20 mg tablet walgreens
generic viagra walmart https://sildenafilmg.shop/
order viagra online
what is viagra
canadian pharcharmy online viagra
viagra over the counter buy viagra online canada
https://sildenafilmg.shop/# viagra amazon
buy viagra online canada https://sildenafilmg.com/
order viagra online
viagra from canada https://sildenafilmg.com/
when will viagra be generic
price of viagra https://sildenafilmg.online/
where can i buy viagra over the counter
viagra cost sildenafil
viagra cost per pill viagra discount mexican viagra
buying viagra online viagra amazon viagra amazon
viagra over the counter best over the counter viagra best place to buy generic viagra online
viagra price viagra pills buy real viagra online
viagra from canada where to buy viagra online where to buy viagra online
There most be a solution for this problem, some people think there will be now solutions, but i think there wil be one.
price of viagra viagra discount viagra over the counter
cost of viagra viagra from india cheap viagra online
cost of viagra over the counter viagra where to buy viagra online
best place to buy viagra online where can i buy viagra over the counter viagra from canada
viagra over the counter buy generic 100mg viagra online generic viagra walmart
https://sildenafilmg.com/ viagra cost
viagra discount viagra over the counter walmart
best place to buy viagra online sildenafil 20 mg
You appear to know so much about this, and I see you’re a published author. Thanks
This information is critically needed, thanks.
You are not right. I am assured. I can prove it. Write to me in PM, we will talk.
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.
best place to buy viagra online sildenafil
Thanks for your patience and sorry for the inconvenience!
Nice post.Very useful info specifically the last part 🙂 Thank you and good luck.
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!
order viagra online viagra over the counter
zithromax z-pak price without insurance zithromax 500 mg lowest price online
buy zithromax online australia zithromax prescription
amoxicillin 500 how to get amoxicillin over the counter
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 .
2adroitly
Certainly. And I have faced it. Let’s discuss this question. Here or in PM.
I think I might disagree with some of your analysis. Are the figures solid?
how to get amoxicillin over the counter amoxicillin 500mg capsules antibiotic
where to get zithromax over the counter zithromax tablets
Well, I don’t know if that’s going to work for me, but definitely worked for you! 🙂 Excellent post!
zithromax online generic zithromax 500mg
https://clomidforsale.life/# clomid online order no script