Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Debug Assertion Violation Expression: 'm_pHackPInvokeTunnel != NULL' #2851

Closed
imkow opened this issue Feb 28, 2017 · 13 comments
Closed

Debug Assertion Violation Expression: 'm_pHackPInvokeTunnel != NULL' #2851

imkow opened this issue Feb 28, 2017 · 13 comments

Comments

@imkow
Copy link

imkow commented Feb 28, 2017

this pops up when running from compiled exe which is compiled from generated CPP
File: {corert}\src\Native\Runtime\thread.cpp

@MichalStrehovsky
Copy link
Member

@imkow Do you have a stack trace?

@imkow
Copy link
Author

imkow commented Feb 28, 2017

didn't notice there is stack trace? how can I get stack trace out?

@MichalStrehovsky
Copy link
Member

didn't notice there is stack trace? how can I get stack trace out?

Run the compiled app under a debugger and let the debugger generate the stack. (E.g. open the native EXE as a solution in Visual Studio and hit F5.)

@imkow
Copy link
Author

imkow commented Mar 1, 2017

@MichalStrehovsky
here you go:

reproNativeCpp.exe!Assert(const char * expr, const char * file, unsigned int line_num, const char * message) Line 50 C++
reproNativeCpp.exe!Thread::GetTransitionFrame() Line 52 C++
reproNativeCpp.exe!Thread::GcScanRoots(void * pfnEnumCallback, void * pvCallbackData) Line 403 C++
reproNativeCpp.exe!GCToEEInterface::GcScanRoots(void(*)(Object * *, ScanContext , unsigned int) fn, int condemned, int max_gen, ScanContext * sc) Line 79 C++
reproNativeCpp.exe!GCScan::GcScanRoots(void(
)(Object * *, ScanContext *, unsigned int) fn, int condemned, int max_gen, ScanContext * sc) Line 171 C++
reproNativeCpp.exe!WKS::gc_heap::mark_phase(int condemned_gen_number, unsigned int mark_only_p) Line 19494 C++
reproNativeCpp.exe!WKS::gc_heap::gc1() Line 15252 C++
reproNativeCpp.exe!WKS::gc_heap::garbage_collect(int n) Line 16754 C++
reproNativeCpp.exe!WKS::GCHeap::GarbageCollectGeneration(unsigned int gen, gc_reason reason) Line 35116 C++
reproNativeCpp.exe!WKS::gc_heap::try_allocate_more_space(alloc_context * acontext, unsigned __int64 size, int gen_number) Line 13063 C++
reproNativeCpp.exe!WKS::gc_heap::allocate_more_space(alloc_context * acontext, unsigned __int64 size, int alloc_generation_number) Line 13350 C++
reproNativeCpp.exe!WKS::gc_heap::allocate(unsigned __int64 jsize, alloc_context * acontext) Line 13381 C++
reproNativeCpp.exe!WKS::GCHeap::Alloc(gc_alloc_context * context, unsigned __int64 size, unsigned int flags) Line 34436 C++
reproNativeCpp.exe!RhpGcAlloc(EEType * pEEType, unsigned int uFlags, unsigned __int64 cbSize, void * pTransitionFrame) Line 272 C++
reproNativeCpp.exe!RhpNewArray(EEType * pArrayEEType, int numElements) Line 160 C++
reproNativeCpp.exe!System_Private_CoreLib::System::Runtime::InternalCalls::RhpNewArray(System_Private_CoreLib::Internal::Runtime::EEType * pEEType, int length) Line 268957 C++
reproNativeCpp.exe!System_Private_CoreLib::System::Runtime::RuntimeExports::RhNewArray(System_Private_CoreLib::System::EETypePtr pEEType, int length) Line 261972 C++
reproNativeCpp.exe!RhNewArray(System_Private_CoreLib::System::EETypePtr pEEType, int length) Line 261988 C++
reproNativeCpp.exe!_load_string_literal(const char * string) Line 176 C++
reproNativeCpp.exe!System_Private_CoreLib::System::Runtime::TypeCast::IsInstanceOfClass(System_Private_CoreLib::System::Object * obj, void * pvTargetType) Line 263267 C++
reproNativeCpp.exe!System_Private_CoreLib::System::Runtime::TypeCast::IsInstanceOf(System_Private_CoreLib::System::Object * obj, void * pvTargetType) Line 264927 C++
reproNativeCpp.exe!RhTypeCast_IsInstanceOf(System_Private_CoreLib::System::Object * obj, void * pvTargetType) Line 264943 C++
reproNativeCpp.exe!isinst(void * obj, MethodTable * pTargetMT) Line 103 C++
reproNativeCpp.exe!System_Private_CoreLib::System::Int32::Equals(int * this, System_Private_CoreLib::System::Object * obj) Line 455241 C++
reproNativeCpp.exe!System_Private_CoreLib::System::Collections::Generic::DefaultEqualityComparer_1_A__System_Private_CoreLib_System_Int32_V
::Equals_A__V
(System_Private_CoreLib::System::Collections::Generic::DefaultEqualityComparer_1_A__System_Private_CoreLib_System_Int32_V
* this, int x, int y) Line 583864 C++
reproNativeCpp.exe!System_Private_CoreLib::System::Array::IndexOf_4_A__System_Private_CoreLib_System_Int32_V
(System_Private_CoreLib::System::Int32___A_Array_V
* array, int value, int startIndex, int count) Line 400738 C++
reproNativeCpp.exe!System_Private_CoreLib::System::Collections::Generic::List_1_A__System_Private_CoreLib_System_Int32_V
::IndexOf_1_A__V
(System_Private_CoreLib::System::Collections::Generic::List_1_A__System_Private_CoreLib_System_Int32_V
* this, int item, int index, int count) Line 346524 C++
reproNativeCpp.exe!repro::XXXServer::Game::GameUtils::ClearPai(System_Private_CoreLib::System::Collections::Generic::List_1_A__System_Private_CoreLib_System_Int32_V
* allPai, int lIndex, int lCount, int rIndex, int rCount) Line 341743 C++
reproNativeCpp.exe!repro::XXXServer::Game::GameUtils::IsHupai(System_Private_CoreLib::System::Collections::Generic::List_1_A__System_Private_CoreLib_System_Int32_V
* allPai, int jingValue) Line 298893 C++
reproNativeCpp.exe!repro::Program::Benchmark() Line 295967 C++
reproNativeCpp.exe!repro::Program::Main(System_Private_CoreLib::System::String___A_Array_V
* args) Line 273767 C++
reproNativeCpp.exe!repro::Module::MainMethodWrapper(System_Private_CoreLib::System::String___A_Array_V
* _a0) Line 272421 C++
reproNativeCpp.exe!repro::Module::StartupCodeMain(int _a0, __int64 _a1) Line 260036 C++
reproNativeCpp.exe!__managed__Main(int _a0, __int64 _a1) Line 260043 C++
reproNativeCpp.exe!wmain(int argc, wchar_t * * argv) Line 319 C++
[External Code]

@MichalStrehovsky
Copy link
Member

Ah, okay - the code is taking a GC. CppCodegen-generated code currently can't survive a GC (we track this in #2033).

You could work around this by setting a higher Gen0 budget (the issue I'm linking to points to the code where you can do that), but eventually you'll hit limits.

I'm going to close this as a duplicate.

@imkow
Copy link
Author

imkow commented Mar 1, 2017

@MichalStrehovsky how to set a higher Gen0 budget? in C# or generated C++?

@MichalStrehovsky
Copy link
Member

From #2033:

Remove artificially high GC budget for CppCodeGen and make conservative GC stack scanning work.

Edit gcenv.h the link is pointing to and rebuild the repo. GetGCgen0size is currently 100 MB.

@imkow
Copy link
Author

imkow commented Mar 1, 2017

@MichalStrehovsky use the class EEConfig?

@imkow
Copy link
Author

imkow commented Mar 1, 2017

haha, almost simultaneously, I found the trick

@imkow
Copy link
Author

imkow commented Mar 1, 2017

@MichalStrehovsky just tried with code like this: g_pConfig->SetGCgen0size(1000 * 1024 * 1024);
still the problem

@MichalStrehovsky
Copy link
Member

You'll need to step through the GC setup in the debugger (step through the places that use the value).

The GC will ignore Gen0 sizes once it crosses a threshold that the GC can no longer tolerate (I don't know the places, but I've seen them a year ago when I was playing with this).

The code might also just be allocating too much. There's not much complex managed code that can run without a GC.

@imkow
Copy link
Author

imkow commented Mar 1, 2017

I had even tried 10000 * 1024 * 1024, same problem

@MichalStrehovsky
Copy link
Member

Try 200 * 1024 * 1024. Really, you'll need to step through this. There's code like

    // Generation 0 must never be more than 1/2 the segment size.
    if (gen0size >= (seg_size / 2))
        gen0size = seg_size / 2;

That kicks in in gc.cpp.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants