作者Oreilly (怕寂寞却爱自由)
看板java
标题Re: [问题] 请教物件生成的流程
时间Sun Mar 5 12:19:43 2006
MyClass my=new MyClass();
这行code做了以下事情
step1.宣告 MyClass型态的变数my
step2.在heap上建立MyClass 物件
step3.执行MyClass的建构子
step4.把记忆体的位置 asign reference给变数my
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
可是这篇文章
http://www-128.ibm.com/developerworks/java/library/j-dcl.html
Listing 6. Assembly code produced from code in Listing 5
;asm code generated for getInstance
054D20B0 mov eax,[049388C8] ;load instance ref
054D20B5 test eax,eax ;test for null
054D20B7 jne 054D20D7
054D20B9 mov eax,14C0988h
054D20BE call 503EF8F0 ;allocate memory
054D20C3 mov [049388C8],eax ;store pointer in
;instance ref. instance
;non-null and ctor
;has not run
054D20C8 mov ecx,dword ptr [eax]
054D20CA mov dword ptr [ecx],1 ;inline ctor - inUse=true;
054D20D0 mov dword ptr [ecx+4],5 ;inline ctor - val=5;
054D20D7 mov ebx,dword ptr ds:[49388C8h]
054D20DD jmp 054D20B0
这篇文章推论出
step3和step4顺序应该倒过来
这在多执行绪的情况下是合理的
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
所以小弟我只想知道单一执行绪底下且不考虑继承
有没有人能证明物件生成的流程
感谢ing...
--
dd
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.221.67.175