Calling the same function twice cause error JNI and MASM









up vote
-1
down vote

favorite












I've function that converts image applying some filter. When i trigger it (via .dll) and JNI interface in java for the first time I recive correct result. But when i want to call it second time, I get an access violation exception. I may add that i don't use any constant in this assembly program. What can cause such issues? I've debugged by this program and it seems it is getting wrong value



 mov rcx, env
mov rdx, image
mov r8, count
mov rax, functionTable
call QWORD PTR[rax + 173 * 8]
mov rdx, rax


these call return to me 0 in rax. In the first call it returns proper value



My JNI function



public native void function(int image, int width, int height);


I may add that I've exacly the same code but written in .cpp also called by java and there everything works fine. MASM is written for Windows x64 ABI










share|improve this question























  • It could be any number of things: count could be out of bounds; you might have a pending Java exception from a previous JNI call; you might have deleted a necessary Java reference, etc. You'll have to provide more information.
    – Michael
    Nov 11 at 16:32










  • @Michael I'm invoking the same code twice with exacly the same parameters, but as I mention with different behaviour. Every varibale is initialized by passed parameters by java so I highly doubt it is connected with this. You have pointed that it might be caused by previous exception from JNI. After performing ret in the first function call i'm getting some exceptions but overall the program returns from MASM to java and correctly display result. May it be connected? I assumed that after one call everything (especially exceptions are being cleared)
    – Michal
    Nov 11 at 22:33











  • I may also add that every of exceptions i mentioned (after ret) and during second call of assembler function are thrown in Exception thrown at 0x0000000... (jvm.dll) in java.exe: -> jvm.dll
    – Michal
    Nov 11 at 22:39






  • 1




    Calling the same JNI function twice is not a problem. So obviously the problem is something else that you're doing (or not doing). But we don't know what that might be, because we only have a short code fragment that in and of itself is not a problem. So e.g. where is your call to ReleaseIntArrayElements? Where is all your error handling (checking for exceptions and bad return values)?
    – Michael
    Nov 12 at 8:14














up vote
-1
down vote

favorite












I've function that converts image applying some filter. When i trigger it (via .dll) and JNI interface in java for the first time I recive correct result. But when i want to call it second time, I get an access violation exception. I may add that i don't use any constant in this assembly program. What can cause such issues? I've debugged by this program and it seems it is getting wrong value



 mov rcx, env
mov rdx, image
mov r8, count
mov rax, functionTable
call QWORD PTR[rax + 173 * 8]
mov rdx, rax


these call return to me 0 in rax. In the first call it returns proper value



My JNI function



public native void function(int image, int width, int height);


I may add that I've exacly the same code but written in .cpp also called by java and there everything works fine. MASM is written for Windows x64 ABI










share|improve this question























  • It could be any number of things: count could be out of bounds; you might have a pending Java exception from a previous JNI call; you might have deleted a necessary Java reference, etc. You'll have to provide more information.
    – Michael
    Nov 11 at 16:32










  • @Michael I'm invoking the same code twice with exacly the same parameters, but as I mention with different behaviour. Every varibale is initialized by passed parameters by java so I highly doubt it is connected with this. You have pointed that it might be caused by previous exception from JNI. After performing ret in the first function call i'm getting some exceptions but overall the program returns from MASM to java and correctly display result. May it be connected? I assumed that after one call everything (especially exceptions are being cleared)
    – Michal
    Nov 11 at 22:33











  • I may also add that every of exceptions i mentioned (after ret) and during second call of assembler function are thrown in Exception thrown at 0x0000000... (jvm.dll) in java.exe: -> jvm.dll
    – Michal
    Nov 11 at 22:39






  • 1




    Calling the same JNI function twice is not a problem. So obviously the problem is something else that you're doing (or not doing). But we don't know what that might be, because we only have a short code fragment that in and of itself is not a problem. So e.g. where is your call to ReleaseIntArrayElements? Where is all your error handling (checking for exceptions and bad return values)?
    – Michael
    Nov 12 at 8:14












up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I've function that converts image applying some filter. When i trigger it (via .dll) and JNI interface in java for the first time I recive correct result. But when i want to call it second time, I get an access violation exception. I may add that i don't use any constant in this assembly program. What can cause such issues? I've debugged by this program and it seems it is getting wrong value



 mov rcx, env
mov rdx, image
mov r8, count
mov rax, functionTable
call QWORD PTR[rax + 173 * 8]
mov rdx, rax


these call return to me 0 in rax. In the first call it returns proper value



My JNI function



public native void function(int image, int width, int height);


I may add that I've exacly the same code but written in .cpp also called by java and there everything works fine. MASM is written for Windows x64 ABI










share|improve this question















I've function that converts image applying some filter. When i trigger it (via .dll) and JNI interface in java for the first time I recive correct result. But when i want to call it second time, I get an access violation exception. I may add that i don't use any constant in this assembly program. What can cause such issues? I've debugged by this program and it seems it is getting wrong value



 mov rcx, env
mov rdx, image
mov r8, count
mov rax, functionTable
call QWORD PTR[rax + 173 * 8]
mov rdx, rax


these call return to me 0 in rax. In the first call it returns proper value



My JNI function



public native void function(int image, int width, int height);


I may add that I've exacly the same code but written in .cpp also called by java and there everything works fine. MASM is written for Windows x64 ABI







assembly jni x86-64 masm masm64






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 8:14









Michael

42.2k84292




42.2k84292










asked Nov 11 at 15:26









Michal

13




13











  • It could be any number of things: count could be out of bounds; you might have a pending Java exception from a previous JNI call; you might have deleted a necessary Java reference, etc. You'll have to provide more information.
    – Michael
    Nov 11 at 16:32










  • @Michael I'm invoking the same code twice with exacly the same parameters, but as I mention with different behaviour. Every varibale is initialized by passed parameters by java so I highly doubt it is connected with this. You have pointed that it might be caused by previous exception from JNI. After performing ret in the first function call i'm getting some exceptions but overall the program returns from MASM to java and correctly display result. May it be connected? I assumed that after one call everything (especially exceptions are being cleared)
    – Michal
    Nov 11 at 22:33











  • I may also add that every of exceptions i mentioned (after ret) and during second call of assembler function are thrown in Exception thrown at 0x0000000... (jvm.dll) in java.exe: -> jvm.dll
    – Michal
    Nov 11 at 22:39






  • 1




    Calling the same JNI function twice is not a problem. So obviously the problem is something else that you're doing (or not doing). But we don't know what that might be, because we only have a short code fragment that in and of itself is not a problem. So e.g. where is your call to ReleaseIntArrayElements? Where is all your error handling (checking for exceptions and bad return values)?
    – Michael
    Nov 12 at 8:14
















  • It could be any number of things: count could be out of bounds; you might have a pending Java exception from a previous JNI call; you might have deleted a necessary Java reference, etc. You'll have to provide more information.
    – Michael
    Nov 11 at 16:32










  • @Michael I'm invoking the same code twice with exacly the same parameters, but as I mention with different behaviour. Every varibale is initialized by passed parameters by java so I highly doubt it is connected with this. You have pointed that it might be caused by previous exception from JNI. After performing ret in the first function call i'm getting some exceptions but overall the program returns from MASM to java and correctly display result. May it be connected? I assumed that after one call everything (especially exceptions are being cleared)
    – Michal
    Nov 11 at 22:33











  • I may also add that every of exceptions i mentioned (after ret) and during second call of assembler function are thrown in Exception thrown at 0x0000000... (jvm.dll) in java.exe: -> jvm.dll
    – Michal
    Nov 11 at 22:39






  • 1




    Calling the same JNI function twice is not a problem. So obviously the problem is something else that you're doing (or not doing). But we don't know what that might be, because we only have a short code fragment that in and of itself is not a problem. So e.g. where is your call to ReleaseIntArrayElements? Where is all your error handling (checking for exceptions and bad return values)?
    – Michael
    Nov 12 at 8:14















It could be any number of things: count could be out of bounds; you might have a pending Java exception from a previous JNI call; you might have deleted a necessary Java reference, etc. You'll have to provide more information.
– Michael
Nov 11 at 16:32




It could be any number of things: count could be out of bounds; you might have a pending Java exception from a previous JNI call; you might have deleted a necessary Java reference, etc. You'll have to provide more information.
– Michael
Nov 11 at 16:32












@Michael I'm invoking the same code twice with exacly the same parameters, but as I mention with different behaviour. Every varibale is initialized by passed parameters by java so I highly doubt it is connected with this. You have pointed that it might be caused by previous exception from JNI. After performing ret in the first function call i'm getting some exceptions but overall the program returns from MASM to java and correctly display result. May it be connected? I assumed that after one call everything (especially exceptions are being cleared)
– Michal
Nov 11 at 22:33





@Michael I'm invoking the same code twice with exacly the same parameters, but as I mention with different behaviour. Every varibale is initialized by passed parameters by java so I highly doubt it is connected with this. You have pointed that it might be caused by previous exception from JNI. After performing ret in the first function call i'm getting some exceptions but overall the program returns from MASM to java and correctly display result. May it be connected? I assumed that after one call everything (especially exceptions are being cleared)
– Michal
Nov 11 at 22:33













I may also add that every of exceptions i mentioned (after ret) and during second call of assembler function are thrown in Exception thrown at 0x0000000... (jvm.dll) in java.exe: -> jvm.dll
– Michal
Nov 11 at 22:39




I may also add that every of exceptions i mentioned (after ret) and during second call of assembler function are thrown in Exception thrown at 0x0000000... (jvm.dll) in java.exe: -> jvm.dll
– Michal
Nov 11 at 22:39




1




1




Calling the same JNI function twice is not a problem. So obviously the problem is something else that you're doing (or not doing). But we don't know what that might be, because we only have a short code fragment that in and of itself is not a problem. So e.g. where is your call to ReleaseIntArrayElements? Where is all your error handling (checking for exceptions and bad return values)?
– Michael
Nov 12 at 8:14




Calling the same JNI function twice is not a problem. So obviously the problem is something else that you're doing (or not doing). But we don't know what that might be, because we only have a short code fragment that in and of itself is not a problem. So e.g. where is your call to ReleaseIntArrayElements? Where is all your error handling (checking for exceptions and bad return values)?
– Michael
Nov 12 at 8:14

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250210%2fcalling-the-same-function-twice-cause-error-jni-and-masm%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250210%2fcalling-the-same-function-twice-cause-error-jni-and-masm%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

ReactJS Fetched API data displays live - need Data displayed static

政党