JNI and java threading
Michael Hall
mik3hall at gmail.com
Fri Jun 21 14:59:03 PDT 2013
I am going to more or less cross-post this since there may be people on different lists with more experience in the domains concerned, OS X, etc.
I have posted a question to the openjdk nio-dev list but aren't seeing any suggestions yet.
I have JNI that implements a kqueue Java 7 nio.2 WatchService. Part of my trz package below.
I am having trouble getting that to run the nio.2 stress test LotsOfEvents.
(jdk/test/java/nio/file/WatchService/LotsOfEvents.java)
Basically, the test, at this point, creates 4096 files in a temp directory and then sleeps a while to try to build up a backlog.
Then it invokes a timed poll method against the events.
The first time this finds maybe 25-45 of the create events that have been called back from the native to java.
Then the test tries to timer re-poll for 2 seconds to see if it gets more.
For some reason the native thread posts no new events in that time period and the test fails.
Almost right after the test fails the native code resumes posting event callbacks until the error caused test shutdown completes.
Is there some reason the java thread(s) are blocking the native thread? Has anyone run into similar.
What the native does…
// Start new thread that fetches and processes our events:
keepThreadRunning = YES;
[NSThread detachNewThreadSelector:@selector(watcherThread:) toTarget:self withObject:nil];
It appears to be at the kevent invocation during the 'blocked' period.
struct timespec timeout = { 5, 0 }; // 5 seconds timeout.
n = kevent64( queueFD, NULL, 0, &ev, 1, 0, &timeout );
This is the one time I've done anything with kqueue so maybe there is something I'm not understanding right there. Is there some reason I'm not aware of that it would go into an extended wait? With this invocation it normally seems to have about 12 events/sec throughput. Why would it go 3 seconds+ with 0 unless java is somehow blocking or priority pre-empting it? Is there some way I can be sure to get it to fire in time to keep the java 2 second poll alive?
Roughly what the java does for completeness….
WatchKey key = watcher.poll(15, TimeUnit.SECONDS);
while (key != null) {
List<WatchEvent<?>> events = key.pollEvents();
for (WatchEvent<?> event: events) {
}
key = watcher.poll(2, TimeUnit.SECONDS);
}
Michael Hall
trz nio.2 for OS X http://www195.pair.com/mik3hall/index.html#trz
HalfPipe Java 6/7 shell app http://www195.pair.com/mik3hall/index.html#halfpipe
AppConverter convert Apple jvm to openjdk apps http://www195.pair.com/mik3hall/index.html#appconverter
More information about the macosx-port-dev
mailing list