You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Gregory Shimansky (JIRA)" <ji...@apache.org> on 2007/01/29 13:01:49 UTC

[jira] Created: (HARMONY-3074) [drlvm][classloader][jni] When FindClass is called from JNI_OnLoad function it cannot load user application classes

[drlvm][classloader][jni] When FindClass is called from JNI_OnLoad function it cannot load user application classes
-------------------------------------------------------------------------------------------------------------------

                 Key: HARMONY-3074
                 URL: https://issues.apache.org/jira/browse/HARMONY-3074
             Project: Harmony
          Issue Type: Bug
          Components: DRLVM
            Reporter: Gregory Shimansky
            Priority: Minor
         Attachments: JNI_OnLoad Test.zip

I've created a program which has a native library and it has JNI_OnLoad function. When this function tries to load a user application class via FindClass, loading attempt fails. It looks like it happens because this class is attempted to be loaded with bootstrap class loader which loads classes only from boot class path. So user class cannot be loaded since it is not in boot class path.

RI loads this user class with system application class loader.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (HARMONY-3074) [drlvm][classloader][jni] When FindClass is called from JNI_OnLoad function it cannot load user application classes

Posted by "Pavel Pervov (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-3074?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Pavel Pervov updated HARMONY-3074:
----------------------------------

    Attachment: H3074.patch

> [drlvm][classloader][jni] When FindClass is called from JNI_OnLoad function it cannot load user application classes
> -------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-3074
>                 URL: https://issues.apache.org/jira/browse/HARMONY-3074
>             Project: Harmony
>          Issue Type: Bug
>          Components: DRLVM
>            Reporter: Gregory Shimansky
>            Priority: Minor
>         Attachments: H3074.patch, JNI_OnLoad Test.zip
>
>
> I've created a program which has a native library and it has JNI_OnLoad function. When this function tries to load a user application class via FindClass, loading attempt fails. It looks like it happens because this class is attempted to be loaded with bootstrap class loader which loads classes only from boot class path. So user class cannot be loaded since it is not in boot class path.
> RI loads this user class with system application class loader.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-3074) [drlvm][classloader][jni] When FindClass is called from JNI_OnLoad function it cannot load user application classes

Posted by "Alexey Varlamov (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-3074?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12468577 ] 

Alexey Varlamov commented on HARMONY-3074:
------------------------------------------

You are rigth, I meant storing CL somewhere in thread local during loading.  Not sure which variant to prefer, but TLS looks a bit more elegant...

> [drlvm][classloader][jni] When FindClass is called from JNI_OnLoad function it cannot load user application classes
> -------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-3074
>                 URL: https://issues.apache.org/jira/browse/HARMONY-3074
>             Project: Harmony
>          Issue Type: Bug
>          Components: DRLVM
>            Reporter: Gregory Shimansky
>            Priority: Minor
>         Attachments: JNI_OnLoad Test.zip
>
>
> I've created a program which has a native library and it has JNI_OnLoad function. When this function tries to load a user application class via FindClass, loading attempt fails. It looks like it happens because this class is attempted to be loaded with bootstrap class loader which loads classes only from boot class path. So user class cannot be loaded since it is not in boot class path.
> RI loads this user class with system application class loader.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-3074) [drlvm][classloader][jni] When FindClass is called from JNI_OnLoad function it cannot load user application classes

Posted by "Alexey Varlamov (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-3074?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12472194 ] 

Alexey Varlamov commented on HARMONY-3074:
------------------------------------------

Guys, I'm curious what for the FIXME here:

@@ -1006,7 +1005,10 @@ void ClassLoader::LoadNativeLibrary( con
// load native library
bool just_loaded;
NativeLoadStatus status;
+ // FIXME: add storing class loader here
+ p_TLS_vmthread->onload_caller = this;
NativeLibraryHandle handle = natives_load_library(lib_name->bytes, &just_loaded, &status);
+ p_TLS_vmthread->onload_caller = NULL;
if( !handle || !just_loaded ) {
// create error message
char apr_error_message[1024];


> [drlvm][classloader][jni] When FindClass is called from JNI_OnLoad function it cannot load user application classes
> -------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-3074
>                 URL: https://issues.apache.org/jira/browse/HARMONY-3074
>             Project: Harmony
>          Issue Type: Bug
>          Components: DRLVM
>            Reporter: Gregory Shimansky
>         Assigned To: Gregory Shimansky
>            Priority: Minor
>         Attachments: H3074.patch, JNI_OnLoad Test.zip
>
>
> I've created a program which has a native library and it has JNI_OnLoad function. When this function tries to load a user application class via FindClass, loading attempt fails. It looks like it happens because this class is attempted to be loaded with bootstrap class loader which loads classes only from boot class path. So user class cannot be loaded since it is not in boot class path.
> RI loads this user class with system application class loader.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-3074) [drlvm][classloader][jni] When FindClass is called from JNI_OnLoad function it cannot load user application classes

Posted by "Pavel Pervov (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-3074?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12468309 ] 

Pavel Pervov commented on HARMONY-3074:
---------------------------------------

The idea of the fix is as follows: we should treat JNI_OnLoad as user's native function (required by FindClass) and skip all "loadLibrary" frames:

        at java.lang.VMClassRegistry.loadLibrary(Native Method)
        at java.lang.Runtime.load0(Unknown Source)
        at java.lang.Runtime.loadLibrary0(Unknown Source)
        at java.lang.System.loadLibrary(Unknown Source)
        at Test.main(Test.java:5)

up to this one - i.e. 4 frames - and only then determine class loader of caller.



> [drlvm][classloader][jni] When FindClass is called from JNI_OnLoad function it cannot load user application classes
> -------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-3074
>                 URL: https://issues.apache.org/jira/browse/HARMONY-3074
>             Project: Harmony
>          Issue Type: Bug
>          Components: DRLVM
>            Reporter: Gregory Shimansky
>            Priority: Minor
>         Attachments: JNI_OnLoad Test.zip
>
>
> I've created a program which has a native library and it has JNI_OnLoad function. When this function tries to load a user application class via FindClass, loading attempt fails. It looks like it happens because this class is attempted to be loaded with bootstrap class loader which loads classes only from boot class path. So user class cannot be loaded since it is not in boot class path.
> RI loads this user class with system application class loader.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-3074) [drlvm][classloader][jni] When FindClass is called from JNI_OnLoad function it cannot load user application classes

Posted by "Pavel Pervov (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-3074?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12472286 ] 

Pavel Pervov commented on HARMONY-3074:
---------------------------------------

I forgot to remove this. :D

> [drlvm][classloader][jni] When FindClass is called from JNI_OnLoad function it cannot load user application classes
> -------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-3074
>                 URL: https://issues.apache.org/jira/browse/HARMONY-3074
>             Project: Harmony
>          Issue Type: Bug
>          Components: DRLVM
>            Reporter: Gregory Shimansky
>         Assigned To: Gregory Shimansky
>            Priority: Minor
>         Attachments: H3074.patch, JNI_OnLoad Test.zip
>
>
> I've created a program which has a native library and it has JNI_OnLoad function. When this function tries to load a user application class via FindClass, loading attempt fails. It looks like it happens because this class is attempted to be loaded with bootstrap class loader which loads classes only from boot class path. So user class cannot be loaded since it is not in boot class path.
> RI loads this user class with system application class loader.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (HARMONY-3074) [drlvm][classloader][jni] When FindClass is called from JNI_OnLoad function it cannot load user application classes

Posted by "Gregory Shimansky (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-3074?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gregory Shimansky updated HARMONY-3074:
---------------------------------------

    Patch Info: [Patch Available]
      Assignee: Gregory Shimansky

> [drlvm][classloader][jni] When FindClass is called from JNI_OnLoad function it cannot load user application classes
> -------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-3074
>                 URL: https://issues.apache.org/jira/browse/HARMONY-3074
>             Project: Harmony
>          Issue Type: Bug
>          Components: DRLVM
>            Reporter: Gregory Shimansky
>         Assigned To: Gregory Shimansky
>            Priority: Minor
>         Attachments: H3074.patch, JNI_OnLoad Test.zip
>
>
> I've created a program which has a native library and it has JNI_OnLoad function. When this function tries to load a user application class via FindClass, loading attempt fails. It looks like it happens because this class is attempted to be loaded with bootstrap class loader which loads classes only from boot class path. So user class cannot be loaded since it is not in boot class path.
> RI loads this user class with system application class loader.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-3074) [drlvm][classloader][jni] When FindClass is called from JNI_OnLoad function it cannot load user application classes

Posted by "Gregory Shimansky (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-3074?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12468569 ] 

Gregory Shimansky commented on HARMONY-3074:
--------------------------------------------

VM knows what class loader loads the library, but FindClass doesn't know how it was called. We can remember ClassLoader somewhere in TLS just to handle this situation (or maybe some other situations are possible), so in case ClassLoader in TLS is not NULL, it will be used, otherwise FindClass will find ClassLoader in the conventional way using st_get_frame.

> [drlvm][classloader][jni] When FindClass is called from JNI_OnLoad function it cannot load user application classes
> -------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-3074
>                 URL: https://issues.apache.org/jira/browse/HARMONY-3074
>             Project: Harmony
>          Issue Type: Bug
>          Components: DRLVM
>            Reporter: Gregory Shimansky
>            Priority: Minor
>         Attachments: JNI_OnLoad Test.zip
>
>
> I've created a program which has a native library and it has JNI_OnLoad function. When this function tries to load a user application class via FindClass, loading attempt fails. It looks like it happens because this class is attempted to be loaded with bootstrap class loader which loads classes only from boot class path. So user class cannot be loaded since it is not in boot class path.
> RI loads this user class with system application class loader.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-3074) [drlvm][classloader][jni] When FindClass is called from JNI_OnLoad function it cannot load user application classes

Posted by "Alexey Varlamov (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-3074?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12468518 ] 

Alexey Varlamov commented on HARMONY-3074:
------------------------------------------

Yep, this is the most straightforward way, except the number of frames may vary depending on the API being called:
j.l.Runtime.load()/loadLibrary() or j.l.System.load()/loadLibrary().

On the other hand, VM surely knows which classloader loads the library - does it make sense to exploit this?

> [drlvm][classloader][jni] When FindClass is called from JNI_OnLoad function it cannot load user application classes
> -------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-3074
>                 URL: https://issues.apache.org/jira/browse/HARMONY-3074
>             Project: Harmony
>          Issue Type: Bug
>          Components: DRLVM
>            Reporter: Gregory Shimansky
>            Priority: Minor
>         Attachments: JNI_OnLoad Test.zip
>
>
> I've created a program which has a native library and it has JNI_OnLoad function. When this function tries to load a user application class via FindClass, loading attempt fails. It looks like it happens because this class is attempted to be loaded with bootstrap class loader which loads classes only from boot class path. So user class cannot be loaded since it is not in boot class path.
> RI loads this user class with system application class loader.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-3074) [drlvm][classloader][jni] When FindClass is called from JNI_OnLoad function it cannot load user application classes

Posted by "Gregory Shimansky (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-3074?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12472319 ] 

Gregory Shimansky commented on HARMONY-3074:
--------------------------------------------

I removed it in 506474.

> [drlvm][classloader][jni] When FindClass is called from JNI_OnLoad function it cannot load user application classes
> -------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-3074
>                 URL: https://issues.apache.org/jira/browse/HARMONY-3074
>             Project: Harmony
>          Issue Type: Bug
>          Components: DRLVM
>            Reporter: Gregory Shimansky
>         Assigned To: Gregory Shimansky
>            Priority: Minor
>         Attachments: H3074.patch, JNI_OnLoad Test.zip
>
>
> I've created a program which has a native library and it has JNI_OnLoad function. When this function tries to load a user application class via FindClass, loading attempt fails. It looks like it happens because this class is attempted to be loaded with bootstrap class loader which loads classes only from boot class path. So user class cannot be loaded since it is not in boot class path.
> RI loads this user class with system application class loader.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (HARMONY-3074) [drlvm][classloader][jni] When FindClass is called from JNI_OnLoad function it cannot load user application classes

Posted by "Gregory Shimansky (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-3074?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gregory Shimansky closed HARMONY-3074.
--------------------------------------

    Resolution: Fixed

Patch and regression test for this bug are applied at 505334.

> [drlvm][classloader][jni] When FindClass is called from JNI_OnLoad function it cannot load user application classes
> -------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-3074
>                 URL: https://issues.apache.org/jira/browse/HARMONY-3074
>             Project: Harmony
>          Issue Type: Bug
>          Components: DRLVM
>            Reporter: Gregory Shimansky
>         Assigned To: Gregory Shimansky
>            Priority: Minor
>         Attachments: H3074.patch, JNI_OnLoad Test.zip
>
>
> I've created a program which has a native library and it has JNI_OnLoad function. When this function tries to load a user application class via FindClass, loading attempt fails. It looks like it happens because this class is attempted to be loaded with bootstrap class loader which loads classes only from boot class path. So user class cannot be loaded since it is not in boot class path.
> RI loads this user class with system application class loader.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (HARMONY-3074) [drlvm][classloader][jni] When FindClass is called from JNI_OnLoad function it cannot load user application classes

Posted by "Gregory Shimansky (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-3074?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gregory Shimansky updated HARMONY-3074:
---------------------------------------

    Attachment: JNI_OnLoad Test.zip

Test which reproduces this bug.

> [drlvm][classloader][jni] When FindClass is called from JNI_OnLoad function it cannot load user application classes
> -------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-3074
>                 URL: https://issues.apache.org/jira/browse/HARMONY-3074
>             Project: Harmony
>          Issue Type: Bug
>          Components: DRLVM
>            Reporter: Gregory Shimansky
>            Priority: Minor
>         Attachments: JNI_OnLoad Test.zip
>
>
> I've created a program which has a native library and it has JNI_OnLoad function. When this function tries to load a user application class via FindClass, loading attempt fails. It looks like it happens because this class is attempted to be loaded with bootstrap class loader which loads classes only from boot class path. So user class cannot be loaded since it is not in boot class path.
> RI loads this user class with system application class loader.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.