harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexey Varlamov (JIRA)" <j...@apache.org>
Subject [jira] Assigned: (HARMONY-1939) [drlvm][classlib] loadClass method in ClassLoader is not synchronized
Date Tue, 30 Jan 2007 13:11:33 GMT

     [ https://issues.apache.org/jira/browse/HARMONY-1939?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Alexey Varlamov reassigned HARMONY-1939:
----------------------------------------

    Assignee: Alexey Varlamov

> [drlvm][classlib] loadClass method in ClassLoader is not synchronized
> ---------------------------------------------------------------------
>
>                 Key: HARMONY-1939
>                 URL: https://issues.apache.org/jira/browse/HARMONY-1939
>             Project: Harmony
>          Issue Type: Bug
>          Components: DRLVM
>         Environment: IA32, WinXP
>            Reporter: Mikhail Markov
>         Assigned To: Alexey Varlamov
>            Priority: Critical
>
> The following code is reproducing the following situation: 2 threads simultaneously run
Class.forName() method for the same classname and the same test classloader. It is expected
that findClass() method of the test classloader should be called only once otherwise this
lead to double call of defineClass() method (which is not allowed, see also HARMONY-1932).
> Output on RI:
> Test passed.
> Output on Harmony:
> Test failed: findClass was called 2 times.
> -------------Test.java---------------
> public class Test {
>     static TestClassLoader cl = new TestClassLoader();
>     static Object lock = new Object();
>     static int readyNum = 0;
>     static int findClassCalled = 0;
>     public static void main(String[] args) throws Exception {
>         TestThread tt1 = new TestThread();
>         TestThread tt2 = new TestThread();
>         tt1.start();
>         tt2.start();
>         while (readyNum < 2) {
>             Thread.sleep(100);
>         }
>         synchronized (lock) {
>             lock.notifyAll();
>         }
>         tt1.join();
>         tt2.join();
>         if (cl.findClassCalled() != 1) {
>             System.out.println("Test failed: findClass was called "
>                     + cl.findClassCalled() + " times.");
>         } else {
>             System.out.println("Test passed.");
>         }
>     }
>     static class TestClassLoader extends ClassLoader {
>         private int findClassCalled;
>         /*
>          * Byte array of bytecode equivalent to the following source code:
>          *     public class TestClass {
>          *     }
>          */
>         private byte[] classData = new byte[] {
>             -54, -2, -70, -66, 0, 0, 0, 49, 0, 13,
>             10, 0, 3, 0, 10, 7, 0, 11, 7, 0,
>             12, 1, 0, 6, 60, 105, 110, 105, 116, 62,
>             1, 0, 3, 40, 41, 86, 1, 0, 4, 67,
>             111, 100, 101, 1, 0, 15, 76, 105, 110, 101,
>             78, 117, 109, 98, 101, 114, 84, 97, 98, 108,
>             101, 1, 0, 10, 83, 111, 117, 114, 99, 101,
>             70, 105, 108, 101, 1, 0, 14, 84, 101, 115,
>             116, 67, 108, 97, 115, 115, 46, 106, 97, 118,
>             97, 12, 0, 4, 0, 5, 1, 0, 9, 84,
>             101, 115, 116, 67, 108, 97, 115, 115, 1, 0,
>             16, 106, 97, 118, 97, 47, 108, 97, 110, 103,
>             47, 79, 98, 106, 101, 99, 116, 0, 33, 0,
>             2, 0, 3, 0, 0, 0, 0, 0, 1, 0,
>             1, 0, 4, 0, 5, 0, 1, 0, 6, 0,
>             0, 0, 29, 0, 1, 0, 1, 0, 0, 0,
>             5, 42, -73, 0, 1, -79, 0, 0, 0, 1,
>             0, 7, 0, 0, 0, 6, 0, 1, 0, 0,
>             0, 1, 0, 1, 0, 8, 0, 0, 0, 2,
>             0, 9 };
>         protected Class findClass(String name) throws ClassNotFoundException {
>             findClassCalled++;
>             try {
>                 synchronized (lock) {
>                     lock.wait();
>                 }
>             } catch (InterruptedException ie) {
>             }
>             if (name.equals("TestClass")) {
>                 return defineClass(null, classData, 0, classData.length);
>             } else {
>                 throw new ClassNotFoundException("Class " + name + " not found.");
>             }
>         }
>         int findClassCalled() {
>             return findClassCalled;
>         }
>     }
>     static class TestThread extends Thread {
>         public void run() {
>             try {
>                 readyNum++;
>                 Class.forName("TestClass", false, cl);
>             } catch (Exception ex) {
>                 ex.printStackTrace();
>             }
>         }
>     }
> }
> ------------------------------------------

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


Mime
View raw message