New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lots of external assembly references - JNI ERROR (app bug): local reference table overflow (max=512) #2257

Closed
NikolayKash opened this Issue Oct 2, 2018 · 11 comments

Comments

Projects
None yet
5 participants
@NikolayKash
Copy link

NikolayKash commented Oct 2, 2018

Steps to Reproduce

  1. create a Xamarin.Forms project which has many references to external assemblies e.g. more than 300 references.
  2. Compile and try to run such APK on Android device

Our solution has 313 references

We noticed if we delete around 14 random references, e.g. App has less than 300 references, App starts OK.

Expected Behavior

Run normal

Actual Behavior

App crashes with

10-02 20:54:10.304 D/Mono ( 5132): Assembly Ref addref Xamarin.Android.Support.Vector.Drawable[0x7f95fb961380] -> Mono.Android[0x7f95fba0fa00]: 21 10-02 20:54:10.309 F/art ( 5132): art/runtime/indirect_reference_table.cc:98] JNI ERROR (app bug): local reference table overflow (max=512) 10-02 20:54:10.309 F/art ( 5132): art/runtime/indirect_reference_table.cc:98] local reference table dump: 10-02 20:54:10.309 F/art ( 5132): art/runtime/indirect_reference_table.cc:98] Last 10 entries (of 512): 10-02 20:54:10.309 F/art ( 5132): art/runtime/indirect_reference_table.cc:98] 511: 0x12cd2cc0 java.lang.String "CompanyX.Utilitie... (47 chars) 10-02 20:54:10.309 F/art ( 5132): art/runtime/indirect_reference_table.cc:98] 510: 0x12cd2ca0 java.lang.String "CompanyX.Utilitie... (52 chars) 10-02 20:54:10.310 F/art ( 5132): art/runtime/indirect_reference_table.cc:98] 509: 0x12cd2c80 java.lang.String "CompanyX.Utilitie... (49 chars) 10-02 20:54:10.310 F/art ( 5132): art/runtime/indirect_reference_table.cc:98] 508: 0x12cd2c60 java.lang.String "CompanyX.Utilitie... (36 chars) 10-02 20:54:10.310 F/art ( 5132): art/runtime/indirect_reference_table.cc:98] 507: 0x12cd2c40 java.lang.String "CompanyX.Utilitie... (48 chars) 10-02 20:54:10.310 F/art ( 5132): art/runtime/indirect_reference_table.cc:98] 506: 0x12cd2c20 java.lang.String "CompanyX.Utilitie... (46 chars) 10-02 20:54:10.310 F/art ( 5132): art/runtime/indirect_reference_table.cc:98] 505: 0x12cd2c00 java.lang.String "CompanyX.Utilitie... (51 chars) 10-02 20:54:10.310 F/art ( 5132): art/runtime/indirect_reference_table.cc:98] 504: 0x12cd2be0 java.lang.String "CompanyX.DA... (38 chars) 10-02 20:54:10.310 F/art ( 5132): art/runtime/indirect_reference_table.cc:98] 503: 0x12cd2bc0 java.lang.String "CompanyX.DA... (43 chars) 10-02 20:54:10.310 F/art ( 5132): art/runtime/indirect_reference_table.cc:98] 502: 0x12cd2ba0 java.lang.String "CompanyX.DA... (32 chars) 10-02 20:54:10.310 F/art ( 5132): art/runtime/indirect_reference_table.cc:98] Summary: 10-02 20:54:10.310 F/art ( 5132): art/runtime/indirect_reference_table.cc:98] 3 of java.lang.Class (3 unique instances) 10-02 20:54:10.310 F/art ( 5132): art/runtime/indirect_reference_table.cc:98] 1 of java.lang.String[] (4 elements) 10-02 20:54:10.310 F/art ( 5132): art/runtime/indirect_reference_table.cc:98] 508 of java.lang.String (262 unique instances) 10-02 20:54:10.310 F/art ( 5132): art/runtime/indirect_reference_table.cc:98] 10-02 20:54:10.449 F/art ( 5132): art/runtime/runtime.cc:289] Runtime aborting... 10-02 20:54:10.449 F/art ( 5132): art/runtime/runtime.cc:289] Aborting thread: 10-02 20:54:10.449 F/art ( 5132): art/runtime/runtime.cc:289] "main" prio=5 tid=1 Runnable

Version Information

Microsoft Visual Studio Professional 2017
Version 15.8.5
VisualStudio.15.Release/15.8.5+28010.2036
Microsoft .NET Framework
Version 4.7.02558

Installed Version: Professional

Visual C++ 2017 00369-60000-00001-AA005
Microsoft Visual C++ 2017

ADL Tools Service Provider 1.0
This package contains services used by Data Lake tools

ASP.NET and Web Tools 2017 15.8.05085.0
ASP.NET and Web Tools 2017

ASP.NET Core Razor Language Services 15.8.31590
Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2017 5.2.60618.0
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0 15.8.05023.0
Azure App Service Tools v3.0.0

Azure Data Lake Node 1.0
This package contains the Data Lake integration nodes for Server Explorer.

Azure Data Lake Tools for Visual Studio 2.3.5001.1
Microsoft Azure Data Lake Tools for Visual Studio

Azure Stream Analytics Tools for Visual Studio 2.3.5001.1
Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools 2.9.0-beta8-63208-01
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus 1.1.49 (remotes/origin/d15-8@ee674f3)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Fabric.DiagnosticEvents 1.0
Fabric Diagnostic Events

ILSpy.AddIn 1.0
Integration of the ILSpy Decompiler into Visual Studio.

IntelliCode Extension 1.0
IntelliCode Extension

IntellicodePackage Extension 1.0
IntellicodePackage Visual Studio Extension Detailed Info

JavaScript Language Service 2.0
JavaScript Language Service

Microsoft Azure HDInsight Azure Node 2.3.5001.1
HDInsight Node under Azure Node

Microsoft Azure Hive Query Language Service 2.3.5001.1
Language service for Hive query

Microsoft Azure Service Fabric Tools for Visual Studio 2.3
Microsoft Azure Service Fabric Tools for Visual Studio

Microsoft Azure Stream Analytics Language Service 2.3.5001.1
Language service for Azure Stream Analytics

Microsoft Azure Stream Analytics Node 1.0
Azure Stream Analytics Node under Azure Node

Microsoft Azure Tools 2.9
Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.10730.2

Microsoft Continuous Delivery Tools for Visual Studio 0.4
Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager 1.0
Install client-side libraries easily to any web project

Microsoft MI-Based Debugger 1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards 1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio Tools for Containers 1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Microsoft Visual Studio VC Package 1.0
Microsoft Visual Studio VC Package

Mono Debugging for Visual Studio 4.11.11-pre (8fb558f)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager 4.6.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

ProjectServicesPackage Extension 1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

ResourcePackage Extension 1.0
ResourcePackage Visual Studio Extension Detailed Info

ResourcePackage Extension 1.0
ResourcePackage Visual Studio Extension Detailed Info

SQL Server Data Tools 15.1.61808.07020
Microsoft SQL Server Data Tools

SQLite & SQL Server Compact Toolbox 4.7
SQLite & SQL Server Compact Toolbox adds scripting, import, export, rename, query execution and much more to SQL Server Compact & SQLite Data Connections.

Syntax Visualizer 1.0
An extension for visualizing Roslyn SyntaxTrees.

ToolWindowHostedEditor 1.0
Hosting json editor into a tool window

TypeScript Tools 15.8.20822.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 2.9.0-beta8-63208-01
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 10.2 for F# 4.5 15.8.0.0. Commit Hash: 55a3dc3231c95c77f81ee53f7d29152029da7408.
Microsoft Visual F# Tools 10.2 for F# 4.5

Visual Studio Code Debug Adapter Host Package 1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for CMake 1.0
Visual Studio Tools for CMake

Visual Studio Tools for Containers 1.0
Visual Studio Tools for Containers

VisualStudio.Mac 1.0
Mac Extension for Visual Studio

WiX Toolset Visual Studio Extension 0.9.21.62588
WiX Toolset Visual Studio Extension version 0.9.21.62588
Copyright (c) .NET Foundation and contributors. All rights reserved.

Xamarin 4.11.0.776 (d15-8@1ae9b59d7)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 4.15.9 (d000f568b)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates 1.1.116 (9619170)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK 9.0.0.20 (HEAD/86d33f45b)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK 12.0.0.15 (84552a4)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Android Emulator

image

Log File

logcat.txt

VS bug #752036

@NikolayKash NikolayKash changed the title Lots of exernal assembly references - JNI ERROR (app bug): local reference table overflow (max=512) Lots of external assembly references - JNI ERROR (app bug): local reference table overflow (max=512) Oct 2, 2018

@NikolayKash

This comment has been minimized.

Copy link

NikolayKash commented Oct 3, 2018

Additional call stack

F/art ( 4278): art/runtime/runtime.cc:289] Runtime aborting... F/art ( 4278): art/runtime/runtime.cc:289] Aborting thread: F/art ( 4278): art/runtime/runtime.cc:289] "main" prio=5 tid=1 Runnable F/art ( 4278): art/runtime/runtime.cc:289] | group="" sCount=0 dsCount=0 obj=0x73e13fa8 self=0x7f9107495000 F/art ( 4278): art/runtime/runtime.cc:289] | sysTid=4278 nice=0 cgrp=default sched=0/0 handle=0x7f910ae843e0 F/art ( 4278): art/runtime/runtime.cc:289] | state=R schedstat=( 0 0 0 ) utm=346 stm=35 core=1 HZ=100 F/art ( 4278): art/runtime/runtime.cc:289] | stack=0x7fff5a998000-0x7fff5a99a000 stackSize=8MB F/art ( 4278): art/runtime/runtime.cc:289] | held mutexes= "abort lock" "mutator lock"(shared held) F/art ( 4278): art/runtime/runtime.cc:289] native: #00 pc 00006f79 /system/lib64/libbacktrace_libc++.so (UnwindCurrent::Unwind(unsigned long, ucontext*)+57) F/art ( 4278): art/runtime/runtime.cc:289] native: #01 pc 00399a40 /system/lib64/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, int, char const*, art::mirror::ArtMethod*)+96) F/art ( 4278): art/runtime/runtime.cc:289] native: #02 pc 00368317 /system/lib64/libart.so (art::Thread::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const+215) F/art ( 4278): art/runtime/runtime.cc:289] native: #03 pc 0034ed21 /system/lib64/libart.so (art::AbortState::DumpThread(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, art::Thread*) (.isra.144)+49) F/art ( 4278): art/runtime/runtime.cc:289] native: #04 pc 0034f0b6 /system/lib64/libart.so (art::AbortState::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)+502) F/art ( 4278): art/runtime/runtime.cc:289] native: #05 pc 0034f2b6 /system/lib64/libart.so (art::Runtime::Abort()+102) F/art ( 4278): art/runtime/runtime.cc:289] native: #06 pc 000fce7c /system/lib64/libart.so (art::LogMessage::~LogMessage()+1852) F/art ( 4278): art/runtime/runtime.cc:289] native: #07 pc 00217a91 /system/lib64/libart.so (art::IndirectReferenceTable::Add(unsigned int, art::mirror::Object*)+1121) F/art ( 4278): art/runtime/runtime.cc:289] native: #08 pc 002b09d1 /system/lib64/libart.so (art::JNI::GetObjectArrayElement(_JNIEnv*, _jobjectArray*, int)+401) F/art ( 4278): art/runtime/runtime.cc:289] native: #09 pc 0011a54b /system/lib64/libart.so (art::CheckJNI::GetObjectArrayElement(_JNIEnv*, _jobjectArray*, int)+91) F/art ( 4278): art/runtime/runtime.cc:289] native: #10 pc 00010767 /data/app/com.companyX.productZ-1/lib/x86_64/libmonodroid.so (???) F/art ( 4278): art/runtime/runtime.cc:289] native: #11 pc 0000f71c /data/app/com.companyX.productZ-1/lib/x86_64/libmonodroid.so (Java_mono_android_Runtime_init+7052) F/art ( 4278): art/runtime/runtime.cc:289] native: #12 pc 0043bb25 /data/dalvik-cache/x86_64/data@app@com.companyX.productZ-1@base.apk@classes.dex (Java_mono_android_Runtime_init__Ljava_lang_String_2_3Ljava_lang_String_2Ljava_lang_String_2_3Ljava_lang_String_2Ljava_lang_ClassLoader_2_3Ljava_lang_String_2_3Ljava_lang_String_2Ljava_lang_String_2+441) F/art ( 4278): art/runtime/runtime.cc:289] at mono.android.Runtime.init(Native method) F/art ( 4278): art/runtime/runtime.cc:289] at mono.MonoPackageManager.LoadApplication(MonoPackageManager.java:49) F/art ( 4278): art/runtime/runtime.cc:289] - locked <0x0f863a00> (a java.lang.Object) F/art ( 4278): art/runtime/runtime.cc:289] at mono.MonoRuntimeProvider.attachInfo(MonoRuntimeProvider.java:22) F/art ( 4278): art/runtime/runtime.cc:289] at android.app.ActivityThread.installProvider(ActivityThread.java:4999) F/art ( 4278): art/runtime/runtime.cc:289] at android.app.ActivityThread.installContentProviders(ActivityThread.java:4594) F/art ( 4278): art/runtime/runtime.cc:289] at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4534) F/art ( 4278): art/runtime/runtime.cc:289] at android.app.ActivityThread.access$1500(ActivityThread.java:151) F/art ( 4278): art/runtime/runtime.cc:289] at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364) F/art ( 4278): art/runtime/runtime.cc:289] at android.os.Handler.dispatchMessage(Handler.java:102) F/art ( 4278): art/runtime/runtime.cc:289] at android.os.Looper.loop(Looper.java:135) F/art ( 4278): art/runtime/runtime.cc:289] at android.app.ActivityThread.main(ActivityThread.java:5254) F/art ( 4278): art/runtime/runtime.cc:289] at java.lang.reflect.Method.invoke!(Native method) F/art ( 4278): art/runtime/runtime.cc:289] at java.lang.reflect.Method.invoke(Method.java:372) F/art ( 4278): art/runtime/runtime.cc:289] at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) F/art ( 4278): art/runtime/runtime.cc:289] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) F/art ( 4278): art/runtime/runtime.cc:289] Dumping all threads without appropriate locks held: thread list lock F/art ( 4278): art/runtime/runtime.cc:289] All threads: F/art ( 4278): art/runtime/runtime.cc:289] DALVIK THREADS (12): F/art ( 4278): art/runtime/runtime.cc:289] "main" prio=5 tid=1 Runnable F/art ( 4278): art/runtime/runtime.cc:289] | group="" sCount=0 dsCount=0 obj=0x73e13fa8 self=0x7f9107495000

@dellis1972 dellis1972 added this to the d16-0 milestone Oct 4, 2018

@NikolayKash

This comment has been minimized.

Copy link

NikolayKash commented Oct 9, 2018

Additional info.

The same apk package works ok on Android version 8.1 - API27. Other versions from 5.1 till 7.1 produces the above error

@NikolayKash

This comment has been minimized.

Copy link

NikolayKash commented Oct 9, 2018

Left side: logcat of v8.1 , right v5.1
image

@NikolayKash

This comment has been minimized.

Copy link

NikolayKash commented Oct 17, 2018

Hello @vargaz.

Could this issue be related to Mono?

Thanks!

@radekdoulik

This comment has been minimized.

Copy link
Contributor

radekdoulik commented Oct 17, 2018

That might be related to #1967, which was fixed in master.

To confirm that, could you create a project which would reproduce that issue so that I can try it locally?

@radekdoulik

This comment has been minimized.

Copy link
Contributor

radekdoulik commented Oct 17, 2018

Actually it should have been already fixed in 15.8.2, so I guess it is different problem. Anyway, having project which reproduce the issue would really help.

@radekdoulik

This comment has been minimized.

Copy link
Contributor

radekdoulik commented Oct 17, 2018

I think I found the issue in our code, preparing a fix.

radekdoulik added a commit to radekdoulik/xamarin-android that referenced this issue Oct 17, 2018

[monodroid] Release local refs earlier
Should fix xamarin#2257

We should release local ref earlier in these cases, because with
higher number of assemblies we can overflow the local reference table
soon enough, before returning from native code.

In case of apks it is not as much probable, but why not release it and
not take a chance.

jonpryor added a commit that referenced this issue Oct 17, 2018

[monodroid] Release local refs earlier (#2312)
Fixes: #2257

We should release local ref earlier in these cases, because with
higher number of assemblies we can overflow the local reference table
soon enough, before returning from native code.

In case of apks it is not as much probable, but why not release it and
not take a chance.
@NikolayKash

This comment has been minimized.

Copy link

NikolayKash commented Oct 18, 2018

Hi @radekdoulik.

Do you know when we can get a new release with this fix?

Or is there any guide I can test the fix?

Thanks!

@NikolayKash

This comment has been minimized.

Copy link

NikolayKash commented Oct 31, 2018

@radekdoulik

This comment has been minimized.

Copy link
Contributor

radekdoulik commented Nov 27, 2018

@NikolayKash I think it will be available in Dev16.0 Preview 2, as I see the commit included here:

https://github.com/xamarin/xamarin-android/commits/d16-0-p2?after=86c0e4749c9a0800b57b7e6c5e6053edad7c0dc3+34

@xamarin-release-manager xamarin-release-manager modified the milestones: d16-0, d15-9 Dec 15, 2018

jonpryor added a commit to jonpryor/xamarin-android that referenced this issue Dec 20, 2018

[monodroid] Release local refs earlier (xamarin#2312)
Fixes: xamarin#2257

We should release local ref earlier in these cases, because with
higher number of assemblies we can overflow the local reference table
soon enough, before returning from native code.

In case of apks it is not as much probable, but why not release it and
not take a chance.

jonpryor added a commit that referenced this issue Dec 20, 2018

[monodroid] Release local refs earlier (#2312) (#2555)
Fixes: #2257

We should release local ref earlier in these cases, because with
higher number of assemblies we can overflow the local reference table
soon enough, before returning from native code.

In case of apks it is not as much probable, but why not release it and
not take a chance.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment