JavaMemoryModel: how to insert a memory barrier when using java.nio shared memory?

From: McLachlan, Paul (paul.mclachlan@compuware.com)
Date: Tue Oct 07 2003 - 13:50:01 EDT


My apologies in advanced if this question is hopelessly naive.

Does (or, perhaps "should", because I didn't see it) JSR 133 say anything
about java.nio based shared memory use?

I ask because I'm looking at using shared memory to communicate between a
native program and Java program, where the Java program periodically
"samples" the (frequently written to) shared memory being maintained by the
native program. It doesn't matter if it samples an old value.

I don't think I really have a problem while the java program only reads from
the shared memory, because from the native program I can insert memory
barriers when necessary for the particular data structures I'm updating.

However, I don't see a way to insert a memory barrier for the shared memory
if the java program wished to do the writing.

Granted, I could use an OS level locking mechanism, but it doesn't seem
necessary for this particular application and I'd prefer to avoid the
overhead. I suppose I could (for this exact problem) also simply use a JNI
call to insert a memory barrier.

But if you want to have two java programs communicate using this kind of
mechanism (maybe via a memory mapped file) it wouldn't be possible without
resorting to JNI, right?

[ Having read some of the java.nio API's more closely, I suspect that the
answer will be that no-one wants to provide/specify anything in this area --
after all, the java.nio API is deliberately vague on this topic. But, from
the mailing list archives, no-one else seems to have asked, so I thought it
wouldn't hurt too much if I did. :) ]

Thanks,
Paul

The contents of this e-mail are intended for the named addressee only. It
contains information that may be confidential. Unless you are the named
addressee or an authorized designee, you may not copy or use it, or disclose
it to anyone else. If you received it in error please notify us immediately
and then destroy it.

-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel



This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:51 EDT