Please note: Although this question involves microcontrollers, it is at its core, a Java question, and so I believe it can be answered by any battle-weary Java guru.
I stumbled accross this blog talking about
sun.misc.Unsafe and was trying to understand its full capabilities to see if it was appropriate for a hobby project of mine.
At the 30,000 foot view, I am trying to program an ARM chip (Arduino Due - an ARM SAM3X8E MCU) to drive some IO peripherals (flash some LEDs, drive servos, etc.) on a simple electronics device. For good sport, I would love to do this in pure Java if at all possible. Up until reading that article, I didn't even think this was possible, and figured I'd have to do most if not all the programming in C. Because this flavor of ARM can support Linux, especially a stripped down "unikernel-style" of Linux, I'd like to write my controller program entirely in Java, and deploy it to a location (say
/opt/myapp) on a Linux image that I can then flash to the ARM chip. With a little tinkering/hacking, I should be able to get the ARM chip to run the Java app when the device powers up.
To drive my device's IO peripherals, I need to access specific memory addresses that will exist outside the JVM process running my app. Up until now I was under the impression that JVMs "sandbox" their resident apps, disallowing them to access anything in system memory directly. And so my plan was to write a bunch of C code (which actually drives the peripherals, flashes LEDs, etc.) and then have my app invoke that C code through JNI.
But if I'm reading that blog correctly, it seems that
sun.misc.Unsafe gives me acess to system memory outside of the JVM. If this is true, then technically I don't need any C code. Of course, I am committing all sorts of security no-no's, making my code non-portable, etc. But that's fine: this is just a hobby project running on a specific platform that I don't intend to change.
So I ask: am I understanding
Unsafe correctly, and if so, are there any other caveats/restrictions/limitations I should be considering while using it?