用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挂掉之类。至于能不能在物质层面转化这些知识,就要看个人造化,但“天道酬勤”总是没错的。
A colleague in the field told me to check out your website.
I dont think Ive caught all the angles of this subject the way youve pointed them out. Youre a true star, a rock star man. Youve got so much to say and know so much about the subject that I think you should just teach a class about it
I saw a similar post on another website but the points were not as well articulated.
Appreciation for taking the time to discuss this topic, I would love to discover more on this topic. If viable, as you gain expertise, would you object to updating the website with further information? It is tremendously beneficial for me.
I like this weblog very much so much great info .
cialis male enhancement tadalafil 20mg cialis dosing
We absolutely love your blog and find the majority of your post’s to be exactly what I’m looking for. Do you offer guest writers to write content to suit your needs? I wouldn’t mind composing a post or elaborating on a number of the subjects you write about here. Again, awesome weblog!
Thanks , I’ve recently been searching for info about this topic for ages and yours is the best I have discovered so far. But, what concerning the bottom line? Are you certain concerning the source?
cialis drug interactions tadalafil cialis 10mg tablets
A neighbor of mine encouraged me to take a look at your blog site couple weeks ago, given that we both love similar stuff and I will need to say I am quite impressed.
cialis versus viagra cialis pills generic cialis india
Woah this is just an insane amount of information, must of taken ages to compile so thanx so much for just sharing it with all of us. If your ever in any need of related information, just check out my own site!
Hi, possibly i’m being a little off topic here, but I was browsing your site and it looks stimulating. I’m writing a blog and trying to make it look neat, but everytime I touch it I mess something up. Did you design the blog yourself?
cialis australia paypal tadalafil without a doctor’s prescription
stromectol how much it cost stromectol covid 19 ivermectin price comparison
can you buy stromectol over the counter https://stromectolgf.com/
ivermectin 200mg stromectol for sale
https://stromectolgf.online/# stromectol ivermectin tablets
buy ivermectin online stromectol online
canadian medications buy prescription drugs without doctor
coupon for cialis tadalafil without a doctor’s prescription
https://drwithoutdoctorprescription.com/# legal to buy prescription drugs without prescription
perfect
thank you for a very good article
prescription drugs online without doctor prescription drugs online
buy prescription drugs best canadian online pharmacy
Spot on with this write-up, I truly believe this website requirements a lot much more consideration. I’ll probably be once more to read much much more, thanks for that info.
whoah this weblog is great i really like studying your articles. Stay up the great work! You already know, lots of persons are looking round for this information, you can aid them greatly.
free samples for cialis generic tadalafil 20mg india
https://drwithoutdoctorprescription.com/# canadian drug prices
buy prescription drugs online prescription drugs online without doctor
ed meds online without prescription or membership buy prescription drugs without doctor
Sometimes, the sheer magnitude of the information seems overwhelming.
How come you do not have your website viewable in mobile format? cant see anything in my Droid.
viagra online usa mexican viagra
best place to buy generic viagra online mexican viagra cheap viagra online
generic viagra walmart
over the counter viagra viagra over the counter viagra over the counter
viagra from india
cost of viagra cost of viagra best place to buy viagra online
viagra price
best place to buy generic viagra online how much is viagra buy viagra online canada
generic viagra walmart
buy viagra online canada best place to buy generic viagra online viagra discount
buy viagra online usa
buying viagra online viagra without a doctor prescription usa cheap viagra online
viagra over the counter walmart
buy generic 100mg viagra online best over the counter viagra viagra from canada
best place to buy generic viagra online
viagra from canada where can i buy viagra over the counter mexican viagra
viagra over the counter
viagra discount viagra over the counter viagra without a doctor prescription usa
generic viagra walmart
buying viagra online viagra 100mg price viagra amazon
https://sildenafilmg.com/ order viagra online
sildenafil 20 mg tablet walgreens
canadian online pharmacy
over the counter viagra viagra pills
where to buy viagra online https://sildenafilmg.online/
viagra cost
how much is viagra viagra 100mg price buy generic 100mg viagra online