Good catch! And thanks for the test case. Can we check if the array is null before we check its index?
Thanks, xiaofeng On Tue, Dec 30, 2008 at 4:42 PM, Chunrong Lai (JIRA) <[email protected]> wrote: > > [ > https://issues.apache.org/jira/browse/HARMONY-6020?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12659771#action_12659771 > ] > > Chunrong Lai commented on HARMONY-6020: > --------------------------------------- > > > (1) The test case can be further reduced as below: > > public class Main { > public static void main(String[] args) { > Child c = Parent.createChild(); > System.err.println(c); > System.err.println(Child.ROOT); > } > } > > class Parent { > //private static final Child childCache = new Child(); > private static final Child[] childCache = new Child[5]; > > public static Child createChild(){ > return childCache[0]; > //return childCache; > } > } > > class Child { > public static final Child ROOT = Parent.createChild(); > } > > While the exception raises from jitted codes of DRLVM: > > 01F00406 mov ecx,dword ptr ds:[34582A0h] //REturn: childCache > //Same as Non-Array Case > > 01F0040C cmp dword ptr [ecx+8],0 //If ArraySize is 0, > throw an exception? > 01F00410 ht ja 01F0043B //The exception > raises from here because the non-inited array has non-assigned length of 0 > > //According to JVM spec, we should just return null for non-inited field? > 01F0043B mov edx,dword ptr [ecx+0Ch] //Return childCache[0] > 01F0043E mov eax,edx > 01F00440 mov ebp,dword ptr [esp+0ACh] //We are returning, Same > as Non-Array Case > > (2) If the cyclic dependence happens not in Array but in a normal object > (comment the "Child[] childCache" in Class Parent but uncomment the "Child > childCache"), Harmony passes with an exactly same behavior with RI > (Child.Root=null, another valid Child object returns in main()). So I do not > see harmony has problem for cyclic class loading itself. > I checked the classloading code and class initialization code and saw it > is compatiable with JVM spec. > > (3) Anyway there are two valid fixes to me: the first is simply removing > the two lines of array length checking binaries (for getStatic). The second > is enforcing an array length for the static array field in the very beginning > of class initialization. I prefer the first one since I do not see > corresponding part in JVM spec for the second approach. > > Feedback? > >> [DRLVM] Cyclical class dependency causes a failure not seen in RI >> ----------------------------------------------------------------- >> >> Key: HARMONY-6020 >> URL: https://issues.apache.org/jira/browse/HARMONY-6020 >> Project: Harmony >> Issue Type: Bug >> Components: DRLVM >> Affects Versions: 5.0M8 >> Environment: Win Vista 32-bit >> Reporter: Nathan Beyer >> Assignee: Chunrong Lai >> Attachments: cycle-project.zip >> >> >> If two classes have a cyclical dependency, some unexpected results may >> occur, which are not seen on RI (Sun 6u10). > > -- > This message is automatically generated by JIRA. > - > You can reply to this email to add a comment to the issue online. > > -- http://xiao-feng.blogspot.com
