<div dir="ltr">I'm not sure that it's JNI stack problem.<div>Let me show you log with comments:</div><div><br></div><div>// invoke index() from java to native</div><div><div>10-11 15:35:15.463: ERROR/CLANG_DEBUG(2491): env: [0x40194ce8]</div>
<div>10-11 15:35:15.463: ERROR/CLANG_DEBUG(2491): createIndex();</div><div><br></div><div>// &index = 0xbeb06704</div><div>10-11 15:35:15.463: ERROR/CLANG_DEBUG(2491): call mapIndex [0xbeb06704]</div><div>10-11 15:35:15.473: ERROR/CLANG_DEBUG(2491): found IndexClass</div>
<div>10-11 15:35:15.473: ERROR/CLANG_DEBUG(2491): found IndexConstructor</div><div>10-11 15:35:15.473: ERROR/CLANG_DEBUG(2491): found IndexPointerField</div><div><br></div><div>// hold CXIndex in array in [0] in native code</div>
<div>// return 0 to java</div><div>10-11 15:35:15.473: ERROR/CLANG_DEBUG(2491): <0x6564805c> hold to index=0 (0x6564805c) -> 0xbeb06704</div><div>10-11 15:35:15.473: ERROR/CLANG_DEBUG(2491): env (parse): [0x40194ce8]</div>
<div><br></div><div>// invoke parse from java and pass 0 as index </div><div>10-11 15:35:15.473: ERROR/CLANG_DEBUG(2491): unmapIndex()</div><div>10-11 15:35:15.473: ERROR/CLANG_DEBUG(2491): <0x6564805c> get from index=0 (0x6564805c) -> 0xbeb06704</div>
<div><br></div><div>// unmapped correctly as index pointer is still 0xbeb06704</div><div>10-11 15:35:15.473: ERROR/CLANG_DEBUG(2491): restored index 0xbeb06704</div><div><br></div><div>// now invoking clang parse</div><div>
10-11 15:35:15.473: ERROR/CLANG_DEBUG(2491): argument filename: [./testfile.cpp]</div><div>10-11 15:35:15.473: ERROR/CLANG_DEBUG(2491): args = 0</div><div>10-11 15:35:15.473: ERROR/CLANG_DEBUG(2491): unsaved files = 1</div>
<div>10-11 15:35:15.473: ERROR/CLANG_DEBUG(2491): found UnsavedFileClass</div><div>10-11 15:35:15.473: ERROR/CLANG_DEBUG(2491): found UnsavedFileConstructor</div><div>10-11 15:35:15.473: ERROR/CLANG_DEBUG(2491): found UnsavedFileFilenameField</div>
<div>10-11 15:35:15.473: ERROR/CLANG_DEBUG(2491): found UnsavedFileSourceField</div><div>10-11 15:35:15.473: ERROR/CLANG_DEBUG(2491): unsaved file:</div><div>10-11 15:35:15.473: ERROR/CLANG_DEBUG(2491): ./testfile.cpp</div>
<div>10-11 15:35:15.473: ERROR/CLANG_DEBUG(2491): unsaved file content:</div><div>10-11 15:35:15.473: ERROR/CLANG_DEBUG(2491): { int a = 10; }</div><div>10-11 15:35:15.473: ERROR/CLANG_DEBUG(2491): parsing: index=0xbeb06704 filename=./testfile.cpp args_count=0 files_count=1</div>
<div> file=./testfile.cpp</div><div><br></div><div>// oops, where is filename ? (probably CXIndex at 0xbeb06704 is corrupted for some reason)</div><div>10-11 15:35:15.503: ERROR/CLANG_DEBUG(2491): after parse filename: []</div>
<div>10-11 15:35:15.503: ERROR/CLANG_DEBUG(2491): mapTranslationUnit()</div><div>10-11 15:35:15.503: ERROR/CLANG_DEBUG(2491): found TranslationUnitClass</div><div>10-11 15:35:15.503: ERROR/CLANG_DEBUG(2491): found TranslationUnitConstructor</div>
<div>10-11 15:35:15.503: ERROR/CLANG_DEBUG(2491): found TranslationUnitPointerField</div><div><br></div><div>// pack translation unit and return index to java</div><div>10-11 15:35:15.503: ERROR/CLANG_DEBUG(2491): hold translationUnit to index=0 (0x656480dc) -> 0xbeb066c8</div>
<div><br></div><div>// invoke tokenize() from java with tu index = 0</div><div>10-11 15:35:15.503: ERROR/CLANG_DEBUG(2491): tokenize: length = 17</div><div>10-11 15:35:15.503: ERROR/CLANG_DEBUG(2491): get tu from index=0 (0x656480dc) -> 0xbeb066c8</div>
<div>10-11 15:35:15.503: ERROR/CLANG_DEBUG(2491): unmapped tu 0xbeb066c8</div><div>// unpakced ok (the same tu pointer 0xbeb066c8)</div><div><br></div><div>10-11 15:35:15.503: ERROR/CLANG_DEBUG(2491): checking unboxed..</div>
<div>10-11 15:35:15.503: ERROR/CLANG_DEBUG(2491): before tokenize filename: []</div><div>10-11 15:35:15.503: ERROR/CLANG_DEBUG(2491): <0> tokens</div></div><div><br></div><div>It seems that CXIndex instance was corrupted (during return and next invocation) somehow as if i invoke clang methods within one native code method it's okay.</div>
<div><br></div><div>As i said i can try to pack and unpack within one native code method and it's still okay, so packing/unpacking does not hurt.</div><div><br></div><div>JNI env pointer is the same in all java->native code invocations.</div>
<div><br></div><div>I'm in stuck.</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/10/11 Renato Golin <span dir="ltr"><<a href="mailto:renato.golin@linaro.org" target="_blank">renato.golin@linaro.org</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="im">On 11 October 2013 10:17, Anton Smirnov <span dir="ltr"><<a href="mailto:dev@antonsmirnov.name" target="_blank">dev@antonsmirnov.name</a>></span> wrote:<br>
</div><div class="gmail_extra"><div class="gmail_quote"><div class="im">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">i tried to hold CXIndex as static variable in native code (array of pointers to be more detailed) and pass just index to java back and then pass index to native code in order to hold variable in native code without passing.<div>
<br></div><div>Still the same result.</div></div></blockquote><div><br></div></div><div>So, IIRC, it's not the stack itself (stack variables), but the return value, that on Intel is at the bottom of the stack. So it doesn't matter where your native objects live, if you try to return them (or a pointer to them), and the stack itself is too small, it'd subtract too much from the stack pointer and then wouldn't find the correct return value because the offset would be negative, and you get corrupted pointers.</div>
<div><br></div><div>Adding a "int a[1024]" to each function fixed the problem because even subtracting a lot, it'd never be negative when compared to the return value, and going back to the return address was still possible. Give it a try, at least to see if that's the problem we're looking for.</div>
<div><br></div><div>Be wary that that was 10 years ago, JNI may have bred some new bugs since then...</div><div><br></div><div>cheers,</div><div>--renato</div></div></div></div>
</blockquote></div><br></div>