Way to statically initialize a class before or during MethodHandle creation, Unsafe crashes JVM
Jochen Theodorou
blackdrag at gmx.org
Fri Nov 16 06:36:29 PST 2012
Hi all,
in another thread I was already explaining, that I do need for a certain
method call the initialized class, to select the right method. Remi for
example then adviced me to use Unsafe and the method
ensureClassInitialized... well after adding that I get a nice hs_err log
file with
> Stack: [0x00007f8fc9ae4000,0x00007f8fc9be5000], sp=0x00007f8fc9be1520, free space=1013k
> Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
> V [libjvm.so+0x888857] Unsafe_EnsureClassInitialized+0x67
> j sun.misc.Unsafe.ensureClassInitialized(Ljava/lang/Class;)V+0
> j org.codehaus.groovy.vmplugin.v7.Selector$MethodSelector.getMetaClass()V+63
Is this another bug? I assume it is... unless someone can explain me how
to workaround in my workaround ;)
Anyway... since that is crashing the JVM (and it must be some special
case) I am wondering now how I can ensure class initialization in my
bootstrap method. Or another solution for the problem without changing
the language.
Background is that in Groovy we may have something like this:
> class A {
> static {
> A.metaClass.static.empty << {-> '123' }
> }
> }
> assert A.empty() == '123'
Since the method empty() does not exist before the static initializer is
executed, I have to somehow enforce the execution of that, because
otherwise the meta class will not have the empty() method.
bye Jochen
--
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org
More information about the mlvm-dev
mailing list