Just a note that Unsafe definitely is portable. We investigated it when Geronimo started using it (rather OpenEJB uses it for CMP and other things). It's the one exception to the "not portable" rule and is considerably faster than any alternative because it goes directly at memory addresses, skips security checks, etc. Hence the name Unsafe. A secret uber-tool and De Facto standard of the JVM.
It's been regularly tested on 8 different platforms, from Windows to zOS, and a handful of JVMs (Sun linux/windows, mac, IBM everything) for the last 6+ years and we've never seen a portability issue. -David On Dec 31, 2012, at 3:15 AM, Mark Struberg <strub...@yahoo.de> wrote: > hi folks! > > While looking at the ASM proxy David imported to OWB I saw that it's based on > the sun.misc.Unsafe class. > This makes this approach non-portable to other JVMs. > > I now played around with an alternative way to do the same: I just invoke the > protected ClassLoader#defineClass method via reflection instead. In my tests > this works pretty well already. See defineAndLoadClass in [1]. Maybe I can > even remove the 2nd explicit loadClass. It also works without in java6 but > the docs says that the class is only available after doing a loadClass. Would > need some more tests to make sure it also works portable without this > redundant call. > > Happy about any feedback. > > > LieGrue, > strub > > > [1] > http://svn.apache.org/repos/asf/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/asm/InterceptorDecoratorProxyFactory.java > >