You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Evgueni Brevnov <ev...@gmail.com> on 2006/09/22 12:49:53 UTC

[drlvm] What should return org.apache...VMStack.getClassLoader(j.l.Class) method for native frames?

HI All,

While implementing Invocation API for DRLVM I ran into interesting
situation. Assume we are in native code and just created VM by
JNI_CreateJavaVM(). The next step is to call Class.forName(name)
method through JNI. If you look at forName method implementation you
will find it calls org.apache....VMStack.getCallerClass(0). Which
means it wants to get the caller's class of the forName() method. In
that case we get null since forName was called from native code. Later
Class.forName(name) method passes obtained class to
org.apache...VMStack.getClassLoader(j.l.Class) method to get caller's
class loader.

The question is: What class loader should be returned in that case?

I think we need to return current thread's context class loader in
that case. So it will be bootstrap class loader for any thread
attached through AttachCurrentThread except main thread which has
system class loader as its context class loader.

Any ideas?

Evgueni

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Re: [drlvm] What should return org.apache...VMStack.getClassLoader(j.l.Class) method for native frames?

Posted by Alexey Varlamov <al...@gmail.com>.
2006/9/22, Evgueni Brevnov <ev...@gmail.com>:
> HI All,
>
> While implementing Invocation API for DRLVM I ran into interesting
> situation. Assume we are in native code and just created VM by
> JNI_CreateJavaVM(). The next step is to call Class.forName(name)
> method through JNI. If you look at forName method implementation you
> will find it calls org.apache....VMStack.getCallerClass(0). Which
> means it wants to get the caller's class of the forName() method. In
> that case we get null since forName was called from native code. Later
> Class.forName(name) method passes obtained class to
> org.apache...VMStack.getClassLoader(j.l.Class) method to get caller's
> class loader.
>
> The question is: What class loader should be returned in that case?
>
> I think we need to return current thread's context class loader in
> that case. So it will be bootstrap class loader for any thread
> attached through AttachCurrentThread except main thread which has
> system class loader as its context class loader.

Sounds very reasonable and is aligned with the API specification:

"The context ClassLoader is provided by the creator of the thread for
use by code running in this thread when loading classes and resources.
If not set, the default is the ClassLoader context of the parent
Thread. The context ClassLoader of the primordial thread is typically
set to the class loader used to load the application."

Actually I see no alternatives anyway - so just go ahead!

--
Alexey

>
> Any ideas?
>
> Evgueni
>
> ---------------------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>
>

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org