Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 41625 invoked from network); 12 Jan 2007 08:33:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 12 Jan 2007 08:33:54 -0000 Received: (qmail 514 invoked by uid 500); 12 Jan 2007 08:33:55 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 501 invoked by uid 500); 12 Jan 2007 08:33:55 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 427 invoked by uid 99); 12 Jan 2007 08:33:55 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 Jan 2007 00:33:55 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO brutus.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 Jan 2007 00:33:47 -0800 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 805087142FA for ; Fri, 12 Jan 2007 00:33:27 -0800 (PST) Message-ID: <13450091.1168590807522.JavaMail.jira@brutus> Date: Fri, 12 Jan 2007 00:33:27 -0800 (PST) From: "Mikhail Markov (JIRA)" To: commits@harmony.apache.org Subject: [jira] Commented: (HARMONY-1939) [drlvm][classlib] loadClass method in ClassLoader is not synchronized MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/HARMONY-1939?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12464118 ] Mikhail Markov commented on HARMONY-1939: ----------------------------------------- When i filed this JIRA, defineClass was not synchronized thus i have on DRLVM the output in JIRA's description. Now when the problems with defineClass is resolved, DRLVM behaves as you wrote (i.e. throws LinkageError). But the problem is that RI (and J9) does not throw it :-) - thus i could simultaneously call Class.forName() from anywhere in multi-threading application and should not afraid of LinkageError and could not safely do this in DRLVM. BTW, i've caught this problem while working with multi-threading enterprise application. So, I'd not call this "non-bug" difference. Perhaps "very critical improvement". > [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 > 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. - If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira