Re: Non-NIO dynamic shared memory mapping
On Thu, 23 Jul 2009, Todd wrote:
I have spent some time trying to locate information on creating a
dynamic, shared memory-map that does not map a file, but uses the memory
allocated by the JVM. Does anyone have any suggestions as to what I
might search for? Or even better, if you have information about how to
implement such a thing, that would be great.
If you can't find a way to do this in java, it shouldn't be that hard with
JNI: you need a function on the donor side which takes a pointer to a
direct ByteBuffer, does a GetDirectBufferAddress/GetDirectBufferCapacity,
then a shmget, and returns the shared memory ID, and one on the acceptor
side which takes a shared memory ID (and the length of the buffer), does a
shmat, then a NewDirectByteBuffer, and returns a pointer to the buffer.
These are the kind of short, straight-line functions that are fairly
painless with JNI.
Assuming you're on unix.
Basically, I am trying to allow a JVMTI enabled agent to read/write
memory for a user process. I understand how to use the NIO to do this,
but FileLock can't guarantee that it will actually lock (system
dependent). This will present some access contention that is not
acceptable for my situation.
Hang on, do you mean that FileLock doesn't guarantee a mandatory rather
than advisory lock, or something else?
tom
--
Formal logical proofs, and therefore programs - formal logical proofs
that particular computations are possible, expressed in a formal system
called a programming language - are utterly meaningless. To write a
computer program you have to come to terms with this, to accept that
whatever you might want the program to mean, the machine will blindly
follow its meaningless rules and come to some meaningless conclusion. --
Dehnadi and Bornat