1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. We’re giving 2017.1 beta testers a chance to win t-shirts and a Nintendo Switch. Read more on the blog.
    Dismiss Notice
  4. Unity 2017.1 beta is now available for download.
    Dismiss Notice
  5. Unity 5.6 is now released.
    Dismiss Notice
  6. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  7. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  8. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    Dismiss Notice

Nasty crash: JNI local reference table summary (512 entries)

Discussion in 'Android' started by srrngames, Dec 22, 2011.

  1. srrngames

    srrngames

    Joined:
    Jul 17, 2011
    Posts:
    11
    Hi guys! We're getting a particularly interesting crash on our 3.2.1 Asus Eee Pad Transformer 3.2.1 Motorola Xoom.
    The only thing I can think of is that we're not properly disposing of some of the items in the ref table (shown in log below) that we're supposed to manually handle.

    At the moment, I'm a bit green at Android, so any light you guys can shed on this would be greatly appreciated. Let me know what bits of information I've inevitably omitted that may be useful. Thanks! :)

    Logcat:

    Code (csharp):
    1. D/OpenFeintFacade( 1062): GetHighScoresFromLeaderBoardId: success!
    2. D/dalvikvm( 1062): JIT unchain all for threadid=9
    3. D/dalvikvm( 1062): GC_CONCURRENT freed 1211K, 14% free 8729K/10055K, paused 3ms+4ms
    4. D/OpenFeintFacade( 1062): GetHighScoresFromLeaderBoardId: success!
    5. W/dalvikvm( 1062): ReferenceTable overflow (max=512)
    6. [B]W/dalvikvm( 1062): Last 10 entries in JNI local reference table:[/B]
    7. W/dalvikvm( 1062): * 502: 0x4083a418 cls=Ljava/lang/Class; 'Lcom/unity3d/player/UnityPlayer;' (308 bytes)
    8. W/dalvikvm( 1062): * 503: 0x40afb3a8 cls=Ljava/lang/reflect/Field; (36 bytes)
    9. W/dalvikvm( 1062): * 504: 0x4083a418 cls=Ljava/lang/Class; 'Lcom/unity3d/player/UnityPlayer;' (308 bytes)
    10. W/dalvikvm( 1062): * 505: 0x4099c0d0 cls=Ljava/lang/reflect/Field; (36 bytes)
    11. W/dalvikvm( 1062): * 506: 0x4083a418 cls=Ljava/lang/Class; 'Lcom/unity3d/player/UnityPlayer;' (308 bytes)
    12. W/dalvikvm( 1062): * 507: 0x40b5c748 cls=Ljava/lang/reflect/Field; (36 bytes)
    13. W/dalvikvm( 1062): * 508: 0x409b9528 cls=Ljava/lang/String; (28 bytes)
    14. W/dalvikvm( 1062): * 509: 0x409abef0 cls=Lcom/openfeint/api/resource/Score; (68 bytes)
    15. W/dalvikvm( 1062): * 510: 0x408961a0 cls=Ljava/lang/Class; 'Lcom/openfeint/api/resource/Score;' (164 bytes)
    16. W/dalvikvm( 1062): * 511: 0x4083a418 cls=Ljava/lang/Class; 'Lcom/unity3d/player/UnityPlayer;' (308 bytes)
    17. W/dalvikvm( 1062): JNI local reference table summary (512 entries):
    18. W/dalvikvm( 1062): * *73 of Ljava/lang/Class; 164B (2 unique)
    19. W/dalvikvm( 1062): * * 2 of Ljava/lang/Class; 212B (1 unique)
    20. W/dalvikvm( 1062): * 150 of Ljava/lang/Class; 308B (1 unique)
    21. W/dalvikvm( 1062): * 138 of Ljava/lang/reflect/Field; 36B (138 unique)
    22. W/dalvikvm( 1062): * * 6 of Ljava/lang/reflect/Field; 44B (6 unique)
    23. W/dalvikvm( 1062): * * 4 of Ljava/lang/reflect/Method; 60B (4 unique)
    24. W/dalvikvm( 1062): * * 1 of Ljava/lang/reflect/Method; 68B
    25. W/dalvikvm( 1062): * *38 of Ljava/lang/String; 28B (38 unique)
    26. W/dalvikvm( 1062): * * 2 of Ljava/util/ArrayList; 20B (2 unique)
    27. W/dalvikvm( 1062): * *25 of Lcom/unity3d/player/WWW; 100B (25 unique)
    28. W/dalvikvm( 1062): * *36 of Lcom/openfeint/api/resource/User; 68B (36 unique)
    29. W/dalvikvm( 1062): * *37 of Lcom/openfeint/api/resource/Score; 68B (37 unique)
    30. W/dalvikvm( 1062): Memory held directly by tracked refs is 14956 bytes
    31. E/dalvikvm( 1062): Failed adding to JNI local ref table (has 512 entries)
    32. I/dalvikvm( 1062): "GLThread 11" prio=5 tid=9 RUNNABLE
    33. I/dalvikvm( 1062): * | group="main" sCount=0 dsCount=0 obj=0x4082e668 self=0x194e98
    34. I/dalvikvm( 1062): * | sysTid=1184 nice=0 sched=0/0 cgrp=default handle=1658808
    35. I/dalvikvm( 1062): * | schedstat=( 25666002000 7188588000 28132 ) utm=2300 stm=266 core=1
    36. I/dalvikvm( 1062): * at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
    37. I/dalvikvm( 1062): * at com.unity3d.player.UnityPlayer.onDrawFrame((null):-1)
    38. I/dalvikvm( 1062): * at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1429)
    39. I/dalvikvm( 1062): * at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1184)
    40. I/dalvikvm( 1062):
    41. E/dalvikvm( 1062): VM aborting
    42. I/DEBUG * ( * 85): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
     
    Last edited: Jan 4, 2012
  2. srrngames

    srrngames

    Joined:
    Jul 17, 2011
    Posts:
    11
    Working fix:

    Code (csharp):
    1.  
    2. AndroidJNI.PushCurrentFrame();
    3.  
    4. ...
    5.  
    6. // Crappy OpenFeint C# code that overflows the reference table reliably
    7.  
    8. ...
    9.  
    10. AndroidJNI.PopCurrentFrame(IntPtr.Zero);
    11.  
    http://unity3d.com/support/documentation/ScriptReference/AndroidJNI.html

    I pass IntPtr.Zero based on a) the Unity docs' method signature requesting an IntPtr, b) These docs explaining that NULL (native, not C sharp's "null") is valid if you don't care: http://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/functions.html#pop_local_frame, and c) some googling :)
     
  3. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    Thanks for the hint. I can browse files now without crashing the VM when the list gets too big.

    Code (csharp):
    1.     private string TestStatic()
    2.     {
    3.         // again, make sure the thread is attached..
    4.  
    5.         AndroidJNI.PushLocalFrame(0);
    6.  
    7.         try
    8.         {
    9.             using (AndroidJavaClass ajc = new AndroidJavaClass(JAVA_CLASS))
    10.             {
    11.                 string result = ajc.CallStatic<string>("testStatic");
    12.                 //Debug.Log(string.Format("received test: {0}", result));
    13.                 return result;
    14.             }
    15.         }
    16.         catch (Exception ex)
    17.         {
    18.             return string.Empty;
    19.         }
    20.         finally
    21.         {
    22.             AndroidJNI.PopLocalFrame(IntPtr.Zero);
    23.         }
    24.     }