Way to statically initialize a class before or during MethodHandle creation, Unsafe crashes JVM
Remi Forax
forax at univ-mlv.fr
Fri Nov 16 07:05:22 PST 2012
Jochen,
can you extract a simple test class that reproduce the bug ?
Also, methods of sun.misc.Unsafe are not protected again send null as
arguments,
so you have to do the check before calling unsafe.XXX.
Rémi
On 11/16/2012 03:36 PM, Jochen Theodorou wrote:
> 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
>
More information about the mlvm-dev
mailing list