2008年4月22日星期二

读“去家乐福前请确保你已经知道这几件事!!!!!”有感

从某二手博客看到这篇二手文章,心中郁闷,不吐不快。

1. 现代奥运的创始人顾拜旦男爵 Pierre de Coubertin(1863-1937),他是一个法国人。
如果这个法国人为了支持藏独而创办奥运会,我们宁可不办奥运会。相信男爵创办奥运会的本意应该不是分裂中国吧,你把他老人家搬出来干什么?我们反对的是一切支持藏独的人,管他是不是法国人?

2. 第一次有了现代奥运火炬传递始于1936年的柏林奥运会。当时的德国统治者是希特勒。
所以法国人不敢去打火炬的主意。

3. 这次运送奥运火种的飞机是法国生产的空客A330.
换飞机来不及了。

4. 历届奥运会都有人抵制,都发生过火炬被抢,被熄灭的事件。
大哥动动脑子好不好,抵制奥运和支持藏独两码事,就您这水平还写博客?

5. 到现在为止法国政府的官方发言是支持奥运,从未说过支持藏*独。Lv集团从未承认支持藏*独,也未有任何证据表明他支持。
到目前中国政府的官方发言没有提到支持抵制家乐福,日本人也从未承认侵略中国。

6. 中国家乐福卖的基本是中国商品,供货商基本为中国供货商,员工基本为中国员工,购物者基本为中国人。
老板基本是法国人,赚的基本是人民币

7. 你有在法律许可范围内到家乐福游行示威的权利。别人也有正常营业,到家乐福自由购物的权利。你们互相不能干涉,阻止。
我阻止我老妈上家乐福你管得着吗?

8. 你有认为抵制是爱国的观点,别人也有认为不抵制是爱国的观点。都可以表达,但互相之间不能言语威胁,人身伤害。
我鄙视总可以吧

9. 大部分藏*独分子他们还有一个身份叫中国人。
台独分子也是。

10. 每个人都有发表自己政治观点的权利,你可以争论,批判。但是任何一方如果使用暴力就是错误的。
你应该得诺贝尔和平奖。

11. 达*赖曾经获得过1989年的诺贝尔和平奖。
奖金都用于非和平事业了吧?

12. 你收到的各种消息应该有一个验证过程再接受,比如上面我告诉你的。比如说的家乐福拿出2500万美金来搞促销,法国使用的货币叫做欧元。
法国人用欧元在中国搞促销?

2008年4月7日星期一

Linux kernal development

许多人还在错误地以为,Linux还是一群黑客在写,这些家伙整天呆在他们父母的卧室里,唯一的社交活动就是在线玩玩角色扮演类游戏,或者在IRC聊天室里为Vi还是Emacs哪个更优秀而打口水仗、抑或为Picard何Kirk谁厉害而争论不休。仅此而已。

最 近Linux基金会发布了一份关于Linux内核的发展报告,其中关注的重点是Linux内核的发展方向,最新动态,以及如何做,还有就是谁对内核作出了 贡献等。这份报告主要基于Linux内核过去三年时间的开发情况,从2.6.11到2.6.24,最终得出结论:Linux内核开发的主要人员都是由企业 所赞助的。

说的更详细点那就是,过去三年中有70%到95%的Linux开发人员对Linux社区所作的开发工作都是有酬劳的,这些费用 是由企业支付的,报告还指出,超过70%的内核贡献是以下公司的员工做出的,这些公司主要是:IBM、Intel、Linux基金会、MIPS科技、 NontaVista、Movial、NetApp、Novell和Red Hat。

过去的3年中Linux Kernel的开发人员数目也得到了增长,在2.6.11版本的时候只有483人的代码最终被接受到内核中,到2.6.24版本的时候,有超过1057个 开发人员的代码被内核代码监护人员所采纳。在过去的三年中,总共有3678名开发人员的代码被Linux内核所接受。

报告认为,即使内核 开发人员的数量大量增加,但是做主要工作的的核心开发人员数量并没有增加。过去的三年中,前十名的开发者完成了将近15%的工作,前30名的开发者完成了 30%的工作量。事实上,前五名的开发人员完成了将近8.5%的工作,这些人员是:Al Viro (1.9%内核代码修改); David Miller (1.8%); Adrian Bunk (1.7%); Ralf Baechle (1.6%); and Andrew Morton (1.5%)。

在所有开发者中,有74.1%的开发人员在他们所在的公司从事Linux相关的工作,另外12.9%开发人员从事其他职业,并且他们贡献了10%的内核开发工作,只有剩下的13.9%的开发人员将Linux内核开发作为他们的业余爱好。

所以,作为爱好,Linux爱好者们对Linux内核作出了非常大的贡献,但是企业的开发人员才是Linux开发的主力军,按照对内核开发的贡献,这些企业排名如下:
1) Red Hat, 11.2 percent
2) Novell, 8.9 percent
3) IBM, 8.3 percent
4) Intel, 4.1 percent
5) LF, 3.5 percent
6) SGI, 2.0 percent
7) MIPS Technology, 1.6 percent
8) Oracle, 1.3 percent
9) MontaVista, 1.2 percent
10) Linutronix, 1.0 percent.

另外,咨询等方面的作用对Linux的发展也做出了2.5%的贡献。
这份报告的撰写人包括有Linux内核开发人员,兼LWN创始人Jonathan Corbet,资深Linux内核安全专家Greg Kroah-Hartman和Linux基金会的市场总监Amanda McPherson。
他 们在这份研究报告中还指出,报告中所看到的只是这些对Linux开发作出贡献的公司的一小部分,通过长尾理论来看,这些公司的数量非常巨大。同时,他们还 指出,这些公司对Linux内核的贡献并不是施舍,从很多事实中我们可以看到,这些公司对Linux内核的改进使得他们在市场中更富有竞争力。

报 告指出,除了Linux发行版厂商,比如红帽、Novell和MontaVista外,他们的利益驱使很明显,因为他们推广Linux,是为了更好的市场 占有率。他们的下游厂商在对Linux内核的贡献方面也是不遗余力,比如IBM、Intel、SGI、MIPS、Freescale和HP等等,因为他们 的硬件可以搭配Linux操作系统来吸引Linux用户,从而增加他们的销售额。

除了上述两类IT企业外,还有Sony、Nokia和三 星等消费类电子厂商,他们在他们的硬件产品中使用各种修改后的嵌入式Linux操作系统,比如电视机顶盒、游戏机、摄像机和行动电话等等。他们参与 Linux内核开发的动机也很简单,从中获取相应的Linux内核发展方向,从而为他们的产品软件系统开发获得一个稳固基础。

研究报告还 指出,现在的linux发展不仅仅是IT厂商的事情。例如,在最新的2.6.25内核中将包含有PF_CAN(Controller Area Network,控制域网络防火墙设备)协议的实现,而这些代码的实现是由大众汽车公司的开发人员所完成的。PF_CAN可以使得接口统一环境下的各种组 件进行可信通信,比如在汽车中的各种电子设备。Linux社区给了大众汽车公司一个很好的开发平台,以便于他们能够实现他们的协议代码,同时,大众公司也 发现,将这些代码重新返回到Linux社区中去对他们的技术改进有帮助。

到此为止,你心目中的的Linux开发工程师的形象是不是已经有 所变化了,因为现在的linux工程师更像是一个全职的、中上层的传统软件工程师,但是为什么还有各种有关Linux开发人员的流言蜚语呢? McPherson认为,这些都是因为大部分人对竞合开发模式的理解存在问题所导致的。这和过去的模式大不相同了,因为在过去看来,花钱让自己的员工开发 程序,让竞争对手无偿使用并且从中牟利简直不可想象。人们还不能从旧有的圈圈中专出来,但是正像研究报告所指出的那样,确实这些支持开源开发的公司从中牟 利了,而且这种分享式研发方式将越来越普遍,而且很快,大部分人的脑子就会转过来,拥抱这种开源的开发模式。

2008年3月30日星期日

有关单位和基金全称的中、英文对照

文末Acknowledgment
比如:The sponsorship of the National Natural Science Foundation of China (No.
xxxx) is gratefully acknowledged.


有关单位和基金全称的中、英文对照
中文 英文
“长江学者奖励计划”(批准号: )资助的课题. Project supported by the Cheung Kon
g Scholars Programme of China (Grant No. ).
北京市自然科学基金(批准号: )资助的课题. Project supported by the Natural Scie
nce Foundation of Beijing,China(Grant No. ).
高等学校博士学科点专项科研基金(批准号: )资助的课题. Project supported by the
Specialized Research Fund for the Doctoral Program of Higher Education of Chin
a (Grant No. ).
高等学校优秀青年教师教学、科研奖励基金(批准号: )资助的课题. Project supported
by the Research Award Fund for Outstanding Young Teachers in Higher Education
Institutions,China(Grant No. ).
广东省自然科学基金(批准号: )资助的课题. Project supported by the Natural Scie
nce Foundation of Guangdong Province,China (Grant No. ).
国防预研究基金(批准号: )资助的课题. Project supported by the National Defense
Pre-Research Foundation of China (Grant No. ).
国家博士后科学基金(批准号: )资助的课题. Project supported by the National Sci
ence Foundation for Post-doctoral Scientists of China (Grant No. ).
国家超导技术联合研究开发中心(批准号: )资助的课题. Project supported by the Na
tional Center for Research and Development on Superconductivity of China (Gran
t No. ).
国家创新研究群体科学基金. Project supported by the Funds for Creative Research
Groups of China (Grant No. ).
国家高技术项目联合(批准号: )资助的课题. Project supported by the National Hig
h Technology Joint Research Program of China(Grant No. ).
国家高技术研究发展计划(863)(批准号: )资助的课题. Project supported by the Nat
ional High Technology Research and Development Program of China (Grant No. ).

国家高技术研究发展计划(863)新材料领域(批准号: )资助的课题. Project supported
by the National High Technology Research and Development Program for Advanced
Materials of China (Grant No. ).
国家高技术研究发展计划(863)惯性约束聚变领域(批准号: )资助的课题. Project supp
orted by the National High Technology Research and Development Program for Ine
rtial Confinement Fusion of China (Grant No. ).
国家高性能计算基金(批准号: )资助的课题. Project supported by the National Hig
h Performance Computing Foundation of China(Grant No. ).
国家国防基金(批准号: )资助的课题. Project supported by the National Defense F
oundation of China (Grant No. ).
国家核科学基金(批准号: )资助的课题. Project supported by the Nuclear Science
Foundation of China (Grant No. ).
国家基础研究“非线性科学”基金(批准号: )资助的课题. Project supported by the
National Basic Research Foundation for “Nonlinear Science” of China (Grant N
o. ).
国家教育部高等学校骨干教师基金(批准号: )资助的课题. Project supported by the
Foundation for University Key Teachers from the Ministry of Education of China
(Grant No. ).
国家教育部光电子信息技术科学重点实验室(批准号: )资助的课题. Project supported
by the Key Laboratory of Optoelectronic Information Technical Science, Minist
ry of Education of China (Grant No. ).
国家教育部和国家人事部留学回国人员基金(批准号: )资助的课题. Project supported
by the Scientific Research Foundation of the State Human Resource Ministry an
d the Education Ministry for Returned Chinese Scholars, China (Grant No. )
国家教育部高等学校优秀青年教师研究基金(批准号: )资助的课题. Project supported
by the Foundation of the Ministry of Education of China for Outstanding Young
Teachers in University (Grant No. ).
国家教育部归国学者基金(批准号: )资助的课题. Project supproted by the Foundati
on of the Ministry of Education of China for Returned Scholars (Grant No. ).

国家教育部跨世纪人才训练基金(批准号: )资助的课题. Project supported by the Tr
ans-Century Training Program Foundation for Talents from the Ministry of Educa
tion of China (Grant No. ).
国家杰出青年科学基金(批准号: )资助的课题. Project supported by the National S
cience Found for Distinguished Young Scholars of China (Grant No. ).
国家科技部博士后基金(批准号: )资助的课题. Project supported by the Science Fo
undation for Post Doctorate Research from the Ministry of Science and Technolo
gy of China (Grant No. ).
国家科技部攀登计划二号重点项目基金(批准号: )资助的课题. Project supported by
a Grant for Key Research Items No.2 in “Climbing” Program from the Ministry
of Science and Technology of China (Grant No. ).
国家科技部攀登计划重点研究项目基金(批准号: )资助的课题. Project supported by
a Grant for Key Research Items in “Climbing” Program from the Ministry of Sc
ience and Technology of China (Grant No. ).
国家攀登计划(纳米晶体材料)(批准号: )资助的课题. Project supported by the Nati
onal “Climbing”Program for Nanocrystalline Materials, China (Grant No. ).
国家攀登计划(批准号: )资助的课题. Project supported by the National“Climbing
”Program of China (Grant No. ).
国家攀登计划基础研究(批准号: )资助的课题. Project supported by the National B
asic Research in “Climbing” Program of China (Grant No. ).
国家青年科学基金(批准号: )资助的课题. Project supported by the National Scien
ce Foundation for Young Scientists of China (Grant No. ).
国家重大国际(地区)合作研究项目. Project supported by the Major International (
Regional ) Joint Research Program of China(Grant No. )
国家重大基础研究项目(批准号: )资助的课题. Project supported by the National M
ajor Fundamental Research Program of China (Grant No. ).
国家重点基础研究发展计划(973)项目(批准号: )资助的课题. Project supported by t
he State Key Development Program for Basic Research of China (Grant No. ). 网上
写法为: Project supported by the National Basic Research Program of China(Gra
nt No. )
国家重点基础研究项目(批准号: )资助的课题. Project supported by the State Key
Program for Basic Research of China (Grant No. ).
国家重点基础研究项目特别基金(批准号: )资助的课题. Project Supported by the Na
tional Key Basic Research Special Foundation of China (NKBRSFC) (Grant No. ).

国家重点基础研究专项基金(批准号: )资助的课题. Project supported by the Specia
l Foundation for State Major Basic Research Program of China (Grant No. ).
国家重点实验室(光技术应用于微加工实验室),上海光学及电子研究所(批准号: )资助的
课题. Project supported by the State Key Laboratory of Optical Technology for
Micro-fabrication, Shanghai Institute of Optics and Electronics, China (Grant
No. ).
国家自然科学基金(批准号: )资助的课题. Project supported by the National Natur
al Science Foundation of China (Grant No. ).
国家自然科学基金重大项目(批准号: )资助的课题. Project supported by the Major
Program of the National Natural Science Foundation of China (Grant No. ).
国家自然科学基金重大研究计划(批准号: )资助的课题. Project supported by the Ma
jor Research plan of the National Natural Science Foundation of China(Grant No
. )
国家自然科学基金重点项目(批准号: )资助的课题. Project supported by the State
Key Program of National Natural Science of China(Grant No. ).
黑龙江省自然科学基金(批准号: )资助的课题. Project supported by the Natural Sc
ience Foundation of Heilongjiang Province,China(Grant No. ).
湖北省高等学校科研基金(批准号: )资助的课题. Project supported by the Scientif
ic Research Foundation of the Higher Education Institutions of Hubei Province,
China (Grant No. ).
湖南省教育厅重点项目和青年项目资助的课题 Project supported by the Research Fou
ndation of Education Bureau of Hunan Province,China(Grant No. ).
湖南省教育委员会青年骨干教师和国内访问学者基金(批准号: )资助的课题. Project s
upported by the Young Core Instructor and Domestic Visitor Foundation from the
Education Commission of Hunan Province, China (Grant No. ).
湖南省中青年科技基金资助的课题 Project supported by the Science-Technology Fou
ndation for Middle-aged and Young Scientist of Hunan Province,China(Grant No.
).
湖南省自然科学基金(批准号: )资助的课题. Project supported by the Natural Scie
nce Foundation of Hunan Province,China(Grant No. ).
霍英东教育基金(批准号: )资助的课题. Project supported by the Fok Ying-Tong Ed
ucation Foundation, China (Grant No. ).
霍英东教育基金会高等院校青年教师基金(批准号: )资助的课题. Project supported b
y the Fok Ying-Tong Education Foundation for Young Teachers in the Higher Educ
ation Institutions of China (Grant No. ).
吉林省基础研究计划基金(批准号: )资助的课题 Project supported by the Jilin Pro
vincial Research Foundation for Basic Research,China (Grant No. ).
江苏省高校自然科学研究项目(批准号: )资助的课题. Project supported by the Natu
ral Science Foundation of the Jiangsu Higher Education Institutions of China(G
rant No. ).
教育部磁学与磁性材料重点实验室(批准号: )资助的课题. Project supported by the
Key Laboratory for Magnetism and Magnetic Material of the Education Ministry o
f China (Grant No. ).
教育部科学技术研究重大项目基金(批准号: )资助的课题 Project supported by the F
oundation for Key Program of Ministry of Education,China(Grant No. ).
教育部量子光学重点实验室(批准号: )资助的课题. Project supported by the Key La
boratory of Quantum Optics, Ministry of Education, China (Grant No. ).
教育部留学回国人员科研启动基金(批准号: )资助的课题. Project supported by the
Scientific Research Starting Foundation for Returned Overseas Chinese Scholars
, Ministry of Education ,China (Grant No. )
教育部重大项目基金(批准号: )资助的课题 Project supported by the Research Foun
dation from Ministry of Education of China (Grant No. ).
科技部重大基础研究前期研究专项基金(批准号: )资助的课题. Project supported by
the Special Program for Key Basic Research of the Ministry of Science and Tech
nology,China(Grant No. ).
空间研究基金(批准号: )资助的课题. Project supported by the Aerospace Research
Foundation of China (Grant No. ).
人工微结构和介观物理国家重点实验室(批准号: )资助的课题. Project supported by
the State Key Laboratory for Artificial Microstructure and Mesoscopic Physics,
Peking University, Beijing, China (Grant No. ).
山西省归国学者基金(批准号: )资助的课题. Project supported by the Shanxi Provi
ncial Foundation for Returned Scholars(Main Program), China (Grant No. ).
山西省青年科技研究基金(批准号: )资助的课题 Project supported by the Natural S
cience Foundation for Young Scientists of Shanxi Province,China (Grant No. ).

山西省青年学术带头人基金(批准号: )资助的课题. Project supported by the Shanxi
Provincial Foundation for Leaders of Disciplines in Science, China (Grant No.
).
山西省青年学者基金(批准号: )资助的课题. Project supported by the Foundation f
or Young Scholars of Shanxi Province, China (Grant No. ).
山西省自然科学基金(批准号: )资助的课题. Project supported by the Natural Scie
nce Foundation of Shanxi Province, China (Grant No. ).
上海科技启明星基金(批准号: )资助的课题. Project supported by the Shanghai “P
hosphor” Science Foundation,China (Grant No. ).
上海市“曙光”计划(批准号: )资助的课题. Project supported by the “Dawn”Prog
ram of Shanghai Education Commission, China (Grant No. ).
上海市博士后基金(批准号: )资助的课题. Project supported by the Shanghai Postd
octoral Sustentation Fund,China(Grant No. ).
上海市科委科技基金(批准号: )资助的课题. Project supported by the Shanghai Com
mittee of Science and Technology,China(Grant No. ).
上海市科学技术发展基金(批准号: )资助的课题. Project supported by the Shanghai
Foundation for Development of Science and Technology, China (Grant No. ).
上海市科学技术委员会启明星基金(批准号: )资助的课题. Project supported by the
Shanghai “Post-Qi-Ming-Xing Plan” for Young Scientists, China (Grant No. ).

铁道部专项科研基金(批准号: )资助的课题. Project supported by the Special Rese
arch Foundation of the National Railway Ministry of China (Grant No. ).
武汉工业大学材料复合新技术国家重点实验室(批准号: )资助的课题. Project support
ed by the State Key Laboratory for Advanced Technology of Materials Compositiz
ation, Wuhan University of Technology, China (Grant No. ).
香港“求实”基金资助的课题. Project supported by the “Qiu Shi”Foundation of
Hong Kong, China
香港城市大学研究基金(批准号: )资助的课题. Project supported by the City Unive
rsity of Hong Kong Research Grant(Grant No. ).
香港特别行政区研究拨款委员会(批准号: )资助的课题. Project supported by the Re
search Grants Conncil of the Hong Kong Government, China (Grant No. ).
英中高级科学家交流基金(批准号: )资助的课题. Supported by the Exquota Study Vi
sit Funds China-U.K. (Grant No. ).
中国高等科学技术中心(世界实验室)理论物理分中心,北京8730信箱. Center of Theore
tical Physics, China Center of Advanced Science and Technology(CCAST)(World La
boratory), P.O.Box 8730.
中国工程物理研究院科学基金(批准号: )的课题. Project supported by the Science
Foundation of China Academy of Engineering Physics, China (Grant No. ).
中国工程研究院基金重大项目(批准号: )资助的课题. Project supported by the Key
Foundation of China Academy of Engineering Physics,China(Grant No. ).
中国国防科技预研项目(批准号: )资助的课题. Project supported by the Chinese De
fence Advance Research Program of Science and Technology ,China(Grant No. ).

中国科学院 Chinese Academy of Sciences
中国科学院“九五”基础性研究重点项目(批准号: )资助的课题. Project supported b
y the Key Basic Research Foundation of the Chinese Academy of Sciences, China
(Grant No. ).
中国科学院“九五”重大项目基金(批准号: )资助的课题. Project supported by the
Funds for Key Program of the Chinese Academy of Sciences in the National “9th
5-year Plan”,China (Grant No. ).
中国科学院百人计划基金(批准号: )资助的课题 Project supported by the '100 Tale
nts Project' of Chinese Academy of Sciences,China(Grant No. ).
中国科学院基础研究重大项目(批准号: )资助的课题. Project supported by the Majo
r Program for the Fundamental Research of the Chinese Academy of Sciences, Chi
na (Grant No. ).

2007年12月1日星期六

Five ways for tracing Java execution

Original address: http://zvikico.typepad.com/problog/2007/11/five-ways-for-t.html

I'm often faced with a situation where I need to dig into code that I didn't write. Most of it is poorly documented and, in some cases, I only have some of the sources, which means I need to decompile the rest. It's a tedious exploration. There are mainly two reasons for that: maintaining a code or using it. The later refers to 3rd party frameworks and class libraries I need to build upon. For example I may implement an interface of an event handler and I may be uncertain regarding which event fires when and what are the exact arguments I'm getting.

I usually find that it is faster to trace the code at runtime. Especially when it comes to non-trivial links between classes, like an interface with multiple implementations which may be picked at runtime. The smörgåsbord of design time tools is just insufficient.

In this post, I will summarize the common methods (I know of) for tracing the runtime execution. The tips and examples are assuming you're using Eclipse, but most of them can be achieved with other IDEs as well. I will provide some more detailed information regarding some of the techniques mentioned below in future posts.


The Basic: Breakpoints and Step-by-step Execution

Start with the simplest way: set up breakpoints and start tracing your execution.

Pros Cons
  • Very simple to use and setup. Practically, all you need is a running debugger.
  • Provides access to ALL the information, including method attributes, local variables, etc.
  • Does not modify the code.
  • Selective: you can decide where to break.
  • Stepping through code just takes too long. Moreover, you need constant attention. For each step you should decide whether you're stepping in, over or out. This makes this method impractical.
  • When debugging event handlers one must setup breakpoints on all methods, since you're not sure which method will be called.
  • Impossible to set breakpoints inside method when you don't have the source code.

It is best when: You need a quick and simple solution, you have all the code and you know where you want to stop. You need elaborate information in a given point (arguments, local variables, etc.).

My tip: Even if you don't have all the sources, it's possible to break when entering methods or classes by setting-up method breakpoints or class loading breakpoints.

  • Class loading breakpoints are simple to set up: from Eclipse Run menu, select "Add Class Load Breakpoint...".
  • In order to set method breakpoints, you will need to decompile the class file first. Use the JadClipse plug-in for that. After you decompile, you may select the method and choose "Toggle Method Breakpoint" from the "Run" menu (or by right clicking the left bar in the file next to the method header). Note that you may set regular breakpoints in decompiled sources as well, but these will not work.

The Primal: Debug messages

We continue by setting up debug messages. The simplest way is to use System.out.println statements to print out messages to the console. The next step would be to use a logging mechanism: the basic JDK logging, Apache Commons Logging or Log4j.

Pros Cons
  • Very selective.
  • Speedy execution (in case you didn't put too many).
  • Allows printing the exact information you're interested in.
  • Requires code modification. This makes this impractical when you don't own the sources.
  • Takes time to set up. In case you're not sure what you're looking for, you'll need to introduce debug messages to many methods.
  • Makes the code dirty and introduces run-time overhead if you don't take the debug messages out afterwards.

It is best when: You own the code and you have a good idea of what you're looking for. Very good solution for event handlers. It's high performance makes it practical for understanding which event is fired when throughout the execution of complex flows.

My tip: It's easy to set up one generic method that prints out the method currently executing. The best way I'm familiar with is to get the stack trace. The last entry on the call stack will be the debug message method. The entry before that will be the method invoking it. How to obtain a stack trace:

  • Since JDK 5.0: Use Thread.currentThread().getStackTrace().
  • Before (JDK 1.4): create a new exception instance and use getStackTrace to obtain your call stack from the new instance (no need to "throw" it).

The Hot Shot: Dynamic Proxy

An improvement over simple debug messages. Dynamic Proxy is a special Java feature which enables the developer to introduce a proxy class, sitting in front of a given class and intercepting all the calls through a given interface. Once you intercept the calls, you may print out appropriate debug messages with all the information you require.

Pros Cons
  • No need to infest the code with debug messages. The debug messages can be done in one central location.
  • Simple to remove once you're done, thus, has no affect on performance.
  • Only works through interfaces. Useless for non-public methods and public methods which are not defined in an interface.
  • Requires code modification: you need to own the code.
  • Non selective messages printed.

It is best when: It's a great solution for event handlers. You can set up a dummy event handler with a generic proxy in seconds and see the sequence of events. This is simplest and quickest method when it comes to understanding event handlers.

My tip: You can find a code for a generic dynamic proxy on Sun's site. It's OK, but it has one small minus: it only implements the immediate interfaces implemented by the class of the instance being wrapped by the proxy. It does not implement any interface of its' ancestors. This can be easily fixed by traversing the list of ancestors and picking all the interfaces along the way. In one of the future posts I'll give a better version.


The Brute Force: Run-time Profiler

Profilers are powerful tools that trace all the calls in the system through special JVM hooks. However, it's like using a 10 pound hammer on a half inch nail.

Pros Cons
  • No code modification.
  • Can trace all the execution, even without source code.
  • Most tools provide the ability to filter data which is less interesting (like JDK calls, getters and setters, etc).
  • Most good tools are expensive.
  • Most tools take time to setup and master.
  • Profiling will greatly degrade the system performance. It's impractical to have a long execution with the profiler collecting information.
  • Most tools are geared towards performance measurement and neglect showing an execution path according to the actual time line.
  • Most tools provide the calls but not the arguments.

It is best when: You want a complete picture for a very specific operation (i.e. very short execution flow).

My tip: The good tools cost around $500 per seat. Most free tools are very basic. IMHO, The best free open-source tool for the job is Eclipse Testing and Performance Tools Platform (TPTP). I've had very good experience with the tool and I highly recommend it. It can provide a sequence diagram which is one of the best ways for understanding execution. TPTP used to be my favorite before I switched to the Mac and found it's incompatible (maybe I'll try to fix it if I'll have some spare time).


The New Age: Aspects

Aspect Oriented Programming (AOP) is a non-trivial idea. Without going into the concept of Aspects, I'm just looking at the bottom line: it's a quick and easy way of intercepting the execution of your code. You can selectively set hooks around methods, constructors, field access, etc., without modifying the original code. In these hooks you can print debug messages.

Pros Cons
  • Very quick and easy to setup.
  • Selective: you can trace just the classes or method you require.
  • Provides all the information, including arguments.
  • No modification to the original code. Very easy to remove once you're done.
  • Good performance. May be used in long executions.
  • Requires some basic understanding of AOP. Especially for setting up more complex filters.
  • Requires rebuilding your code. This can be a problem when you need to trace a code found in a packaged JAR.

It is best when: You want to trace the execution of a code you can rebuild.

My tip: Use it. AOP is still far from the mainstream. It is uncertain whether it will ever get there. Without debating its' qualities and features, most developers can be up and running with AOP based logging in about an hour. I'll show the exact steps in one of the future posts. For Eclipse users, I recommend the Aspect Java Development Toots (AJDT).


Conclusion

What method should you choose? I'll divide this into two different cases: tracing the complete execution of a short sequence and tracing events to/from a given class or tier.

When tracing the complete execution:

  1. A profiler is the simplest way. IMHO, every developer should be able to operate a profiler and have one readily available in the arsenal.
  2. The next choice would be AOP. It's the second choice only because setting up a profiler is simpler when it comes packaged JARs. However, AOP gives more control. For example, I can see the method arguments and print them.
  3. Use debug messages.

When tracing events:

  1. Use AOP. Selectively capture just the interesting calls.
  2. Use a Dynamic Proxy. It's like using debug messages, but a more elegant solution. AOP may be more complex first, but in the long run I would go for AOP.
  3. Use debug messages.
  4. Use breakpoints.

As you can see, I'm not a big fan of breakpoints in this context. Breakpoints are great when debugging your code, but not for tracing execution. There are far more efficient methods of doing that.

2007年11月5日星期一

互联互通

每天打开电脑,我都要打开IM,一个qq,一个popo,不算太多.现在的IM铺天盖地的发展,热门的还有msn,yahoo messenger,uc等等,各有各的好,我喜欢每一种都试一下,比较一下不同的IM有什么区别,即使一个好友也没有,也会装上看看.时间长了,装的 IM越来越多,机器受不了了,只好精简.我工作忙,没时间聊天,用IM都是为了干正事,所以那些没有好友的IM都作为尝鲜后的垃圾被删掉了,最后就只剩下 这两个.随着很多好友不再用qq转向msn,似乎我的IM应该再多一个,幸好popo有msn的插件,可以让我的机器少装一个,不会太影响我的洁癖. 于是我很希望IM之间能够互联互通,哪怕是有一个类似gaim的软件做一个大全也好,实在不想看着任务栏一大堆IM把我的系统资源无情地占用.最近国内的 主流IM终于有人迈出了第一步:yahoo通和msn互联互通了,欣喜之余,立刻试一下.打开yahoo的下载页面,看到如下信息:您的MSN好友必须在 使用Windows live messenger正式版,并且具备互通资格;如果对方没有使用Windows live messenger正式版,或没有互通资格,则无法互通。也就是说如果我用雅虎通去和我的msn好友互通的话,我要一个一个通知他们去申请互通资格,那还 不如我直接用msn不要去麻烦大家的好. 互通还需要资格?头一回听说.互通不就是文字图片可以传来传去吗?不就是在一个IM上可以看到另一个IM的人吗?干什么要设置这么复杂的规则呢?还要申请 资格,没听说移动的短信发给联通还要申请互通资格的,既然是互通,就别设置的这么麻烦,单点登录满大街都是了,你还故意给大家设置障碍,这不是成心吗?反 正我看到这个消息立刻就打消了下载的念头,原来怎么着还是怎么着吧,不费这个劲. 好在现在互通的资格还是免费的,不知道以后会不会出现这样的情况,仅需xxQQ币就可以申请与xx互联互通,享受沟通的乐趣. 沟通在没有障碍的情况下才是有乐趣的.

2007年6月8日星期五

宕机

销魂大街从昨天开始就不能访问了,已开始我还以为是教育网那位管理员大仙又随手屏蔽了blogspot,后来发现几个好友的blog也同样无法访问,我知道blogspot有被隔离在中国人民的视野之外了。好在blogspot的首页还是可以打开,也就是说我还可以庆幸即使没人能看到我的blog,但是我还可以继续写我的blog,不知道这算不算悲哀过后一点点的慰藉。我用过好几个blog,最后辗转到blogspot,尽管它的声名实在是狼籍的可以,但是我还是决定把这里作为新家。想象一下刚刚乔迁的新居就被人加上了一把大锁,实在让我无言以对。就在我编辑这段文字的时候,页面底下一行粉底提示告诉我,无法连接到blogger.com,存档和发表可能无效。

2007年6月7日星期四

洋人的奴才

我去奥地利使馆办签证咨询。由于是第一次去,道路不熟,一路上是问着执勤的武警战士过来的,每个人都对我非常客气,让我尽管在呼啸的冷气团中奔波了一个半小时,心里还是暖洋洋的。到了签证处门口,把门的保安有序地组织着人群,对每个来办理签证的人也是笑脸相迎,如果有什么问题的话也尽力回答。我就在这样“友好”的气氛中进了签证处大厅。
回答我咨询的问题的是一位中年,或者是更年期妇女,当我说明来意后她给了我一张纸,上面写着办理商务签证所需要的材料。因为我是出国参加学术会议,又是第一次办理签证,自然有好多问题不明白。于是我想更年期问了几个问题,立刻她就变得既不耐烦,让我仔细看说明,说道:“上面不是都写着吗?哪有你这么问的?都象你这样还怎么办公啊?”于是我不敢问了,后面还有很多人排队,如果我和她做无谓的争吵肯定会耽误后面的人的时间。仔细看了说明后,带着满腹狐疑走了出来。
外面有几个办理保险的人很热情地接住我,问我详细情况,并解答我提出的各种疑问,尽管我知道他们是希望我能在他们这里办理业务,但是我觉得要比个更年期打交道愉快的多了。事实上我根本没有流露出一点要在这里办保险的意思,他们应该也能感觉到,只不过把我当成一个潜在客户来培养。但是却并不妨碍他们耐心地回答我的问题,最后我的问题大部分是由他们解答的,虽然我不知道权威性如何。我没有给他们带来任何好处,但是他们却使我没有白来一趟,感谢他们。
在回来的路上我想起老罗的一段话:“我们生活中总是有这样的小人,拿着鸡毛当令箭。”难道给洋人当了奴才,自己就变成洋狗可以肆意咬人了吗?在现场我没有跟更年期辩解,毕竟现场还有外国人,不能丢中国人的脸,另外我也不想让亲切的保安小伙子为难,要不然我早就当场开骂了。如果更年期没见过像我这么问的,今天爷就让她见识一回。
回家后发文纪念,以后再见到这样的洋奴才一定不说“您好”和“谢谢”。坚决鄙视!!!