• Post Reply Bookmark Topic Watch Topic
  • New Topic

JNI + interrupts handling  RSS feed

 
Georgy Bolyuba
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

I want to write Java class, which can react on hardware interrupts (I'm talking about Intel 586 and Linux). So I have to use JNI API.

Question is: how can I do this?

I can write driver on C, which can catch hardware interrupts. It's done for now. But how can I call method of java class (static or instance is not importent) from my C-code?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sun's JNI tutorial talks about calling Java methods from native code here.

But there's no way this is going to work out. What will happen when an interrupt comes while Java code is executing? The JVM is most certainly not designed for that kind of reentrancy -- you'll have quite a mess on your hands.

Why do you want to do this?
 
Henry Wong
author
Sheriff
Posts: 22866
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by George Bolyuba:
Hi.

I want to write Java class, which can react on hardware interrupts (I'm talking about Intel 586 and Linux). So I have to use JNI API.

Question is: how can I do this?

I can write driver on C, which can catch hardware interrupts. It's done for now. But how can I call method of java class (static or instance is not importent) from my C-code?


This is *not* a good idea. You should not be calling Java, or any application in user space from the interrupt handler. What I would recommend is to add an IOCTL call to your driver. Java will use JNI to call some C code, which will call the IOCTL, which will block waiting for information from the interrupt handler. All the interrupt handler then needs to do is to store the information, that will be gathered, and returned via the IOCTL call.

Henry
 
Georgy Bolyuba
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, let me describe situation:

I have a hardware system. I has main program that should wath for events in the system. There are two ways to make make program know that there was an event: 1. interrupt or 2. examination of register state.

I understood that I cannot work this interrupts in way I wanted to. I have to
find another way.

Still, I've got one more question if I may. :roll:

In my program I have class Port8. It works with real port of ISA Bus.
I wrote function in C - "read" and "write". They do almost the same as "in" and "out" commads of intel x86 do.

For example, "read" looks like this:


So, my question is : Can execution of native code be interrupted?
[ April 18, 2005: Message edited by: George Bolyuba ]
 
Georgy Bolyuba
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> So, my question is : Can execution of native code be interrupted?

I was talking about "interrupted by JVM". I've found answer in JNI Tut:
...you must assume that there can be multiple threads of control executing a native method at any given time.


Henry, I've got your idea. I think it may help me to solve this problem.

Thanks alot to both of you, guys.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!