Closed Bug 291408 Opened 20 years ago Closed 13 years ago

Basic liveconnect javascript to java function call causes infinite loop reported in console

Categories

(Core Graveyard :: Java: Live Connect, defect)

x86
Windows XP
defect
Not set
major

Tracking

(Not tracked)

RESOLVED INCOMPLETE

People

(Reporter: russell, Unassigned)

References

()

Details

User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.5) Gecko/20050109 Debian/1.7.5-0.backports.org.1 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b2) Gecko/20050421 Calling a java function in an applet from javascript causes an infinite loop with messages reported to the java console when tracing is enabled. Reproducible: Always Steps to Reproduce: 1. Make sure the following are enabled in the java control panel: - In the advanced tab, enable all the debugging options (Settings->Debugging) - You can also choose "Show console" (Settings->Java Console) 2. Navigate to http://www.kliese.wattle.id.au/~russell/test/liveconnect_bug/Test.html 3. click on the button. Actual Results: An infinite loop begins in the java console writing out the following two lines: liveconnect: JavaScript: calling Java system code liveconnect: JavaScript: default security policy = http://www.kliese.wattle.id.au Expected Results: "A test function" should be printed to the java console Platform Details: Windows XP Service pack 2 java version 1.5.0_02 The test works under Internet Explorer 6.0.2900.2180.xpsp_sp2_gdr.050401-1519. The bug is also present in firefox 1.0.2.
Java Test source code: import javax.swing.*; public class Test extends JApplet { public static void testFunction() { System.out.println("A test function"); } }
further testing has shown that it may not be an infinite loop, however the messages may be reported around 1000 times or so.
same problem, reproducible every time. using firefox 1.5.01, winxp sp1. to debug have set JavaConsole Advanced-> Security-> Use Certificates and keys.. option [off], and have set General-> Network-> Direct Connection. this is because prefs were being read from a Mozilla\Netscape profile instead of the Firefox one (???). anyway, site is here: https://custom.marketwatch.com/custom/ameritrade-com/ameritradeplus/javacharting.asp?symb=DIGE&x=19&y=11 Java Console is here: Java Plug-in 1.5.0_06 Using JRE version 1.5.0_06 Java HotSpot(TM) Client VM User home directory = C:\Documents and Settings\mark network: Loading user-defined proxy configuration ... network: Done. network: Loading direct proxy configuration ... network: Done. network: Proxy Configuration: No proxy basic: Cache is enabled basic: Location: C:\Temp\Sun\Java\Deployment\cache\javapi\v1.0 basic: Maximum size: unlimited basic: Compression level: 1 ---------------------------------------------------- c: clear console window f: finalize objects on finalization queue g: garbage collect h: display this help message l: dump classloader list m: print memory usage o: trigger logging p: reload proxy configuration q: hide console r: reload policy configuration s: dump system and deployment properties t: dump thread list v: dump thread stack x: clear classloader cache 0-5: set trace level to <n> ---------------------------------------------------- basic: Registered modality listener basic: Referencing classloader: sun.plugin.ClassLoaderInfo@1ad77a7, refcount=1 basic: Added progress listener: sun.plugin.util.GrayBoxPainter@d6c16c basic: Loading applet ... basic: Initializing applet ... basic: Starting applet ... network: Connecting https://custom.marketwatch.com/java/a5/JavaCharter.jar with proxy=DIRECT security: Loading Root CA certificates from C:\PROGRA~1\Java\JRE15~2.0_0\lib\security\cacerts security: Loaded Root CA certificates from C:\PROGRA~1\Java\JRE15~2.0_0\lib\security\cacerts security: Loading SSL Root CA certificates from C:\PROGRA~1\Java\JRE15~2.0_0\lib\security\cacerts security: Loaded SSL Root CA certificates from C:\PROGRA~1\Java\JRE15~2.0_0\lib\security\cacerts security: Loading certificates from Deployment session certificate store security: Loaded certificates from Deployment session certificate store network: Connecting https://custom.marketwatch.com/java/a5/JavaCharter.jar with cookie "BC31HAPPY=1; id=1F3BD614-8D43-472F-9B79-8F4133A4D781; mw_segQS=; RMID=5237e872440734a0; RMFD=011FEsEAO40AD4|P10AEw; DMSEG=474BCA790C12967D&L03436&4406B07D&44089E18&0&&44069103&E178728E627A89FE00B17217C3125B2C; ameritradeJavaBG=style=1; AMTDRTUSER=" basic: Loading https://custom.marketwatch.com/java/a5/JavaCharter.jar from cache basic: No certificate info, this is unsigned JAR file. network: Connecting https://custom.marketwatch.com/custom/ameritrade-com/ameritradeplus/JAVACharter/styles.asp?style=1 with proxy=DIRECT network: Connecting https://custom.marketwatch.com/custom/ameritrade-com/ameritradeplus/JAVACharter/styles.asp?style=1 with cookie "BC31HAPPY=1; id=1F3BD614-8D43-472F-9B79-8F4133A4D781; mw_segQS=; RMID=5237e872440734a0; RMFD=011FEsEAO40AD4|P10AEw; DMSEG=474BCA790C12967D&L03436&4406B07D&44089E18&0&&44069103&E178728E627A89FE00B17217C3125B2C; ameritradeJavaBG=style=1; AMTDRTUSER=" basic: Stopped loading ... basic: Stopping applet ... basic: Removed progress listener: sun.plugin.util.GrayBoxPainter@d6c16c basic: Finding information ... basic: Releasing classloader: sun.plugin.ClassLoaderInfo@1ad77a7, refcount=0 basic: Caching classloader: sun.plugin.ClassLoaderInfo@1ad77a7 basic: Current classloader cache size: 1 basic: Done ... basic: Joining applet thread ... basic: Destroying applet ... basic: Disposing applet ... basic: Quiting applet ... basic: Loaded image: https://custom.marketwatch.com/custom/ameritrade-com/ameritradeplus/JAVACharter/bgs/java-top.gif network: Connecting https://custom.marketwatch.com/custom/ameritrade-com/ameritradeplus/JAVACharter/bgs/java-top.gif with proxy=DIRECT Cookie service is not available - use cache to determine "Cookie" basic: Loaded image: https://custom.marketwatch.com/custom/ameritrade-com/ameritradeplus/JAVACharter/bgs/java-bottom.gif basic: Loaded image: https://custom.marketwatch.com/custom/ameritrade-com/ameritradeplus/JAVACharter/bgs/java-bottom.gif basic: Loading https://custom.marketwatch.com/custom/ameritrade-com/ameritradeplus/JAVACharter/bgs/java-top.gif from cache network: Connecting https://custom.marketwatch.com/custom/ameritrade-com/ameritradeplus/JAVACharter/bgs/java-bottom.gif with proxy=DIRECT Cookie service is not available - use cache to determine "Cookie" basic: Loading https://custom.marketwatch.com/custom/ameritrade-com/ameritradeplus/JAVACharter/bgs/java-bottom.gif from cache network: Connecting https://custom.marketwatch.com/java/a5/JAVACharter/ChartModules/SlowStoc.class with proxy=DIRECT Cookie service is not available - use cache to determine "Cookie" basic: Loading https://custom.marketwatch.com/java/a5/JAVACharter/ChartModules/SlowStoc.class from cache basic: Loaded image: https://custom.marketwatch.com/custom/ameritrade-com/ameritradeplus/JAVACharter/bgs/java-bottom-2.gif network: Connecting https://custom.marketwatch.com/java/a5/JAVACharter/ChartModules/MACD.class with proxy=DIRECT Cookie service is not available - use cache to determine "Cookie" basic: Joined applet thread ... basic: Unregistered modality listener basic: Registered modality listener basic: Referencing classloader: sun.plugin.ClassLoaderInfo@1ad77a7, refcount=1 basic: Added progress listener: sun.plugin.util.GrayBoxPainter@1865b28 basic: Loading applet ... basic: Initializing applet ... basic: Starting applet ... basic: Loading https://custom.marketwatch.com/java/a5/JAVACharter/ChartModules/MACD.class from cache network: Connecting https://custom.marketwatch.com/custom/ameritrade-com/ameritradeplus/JAVACharter/bgs/java-bottom-2.gif with proxy=DIRECT network: Connecting https://custom.marketwatch.com/custom/ameritrade-com/ameritradeplus/JAVACharter/bgs/java-bottom-2.gif with cookie "BC31HAPPY=1; id=1F3BD614-8D43-472F-9B79-8F4133A4D781; mw_segQS=; RMID=5237e872440734a0; RMFD=011FEsEAO40AD4|P10AEw; DMSEG=474BCA790C12967D&L03436&4406B07D&44089E18&0&&44069103&E178728E627A89FE00B17217C3125B2C; ameritradeJavaBG=style=1; AMTDRTUSER=" basic: Loading https://custom.marketwatch.com/custom/ameritrade-com/ameritradeplus/JAVACharter/bgs/java-bottom-2.gif from cache network: Connecting https://custom.marketwatch.com/java/a5/stuff.javadatafeed?ver=2&freq=1&symb=DIGE&countries=us+ca&partnerid=13&clientid=null&StartExtra=35&LeftFill=1&RightFill=1&MockTick=1&StartDate=3%252F02%252F2005+04%253A58%253A00+PM&enddate=3%252F02%252F2006+11%253A58%253A33+PM&datatype=0 with proxy=DIRECT network: Connecting https://custom.marketwatch.com/custom/ameritrade-com/ameritradeplus/JAVACharter/styles.asp?style=1 with proxy=DIRECT network: Connecting https://custom.marketwatch.com/java/a5/stuff.javadatafeed?ver=2&freq=1&symb=DIGE&countries=us+ca&partnerid=13&clientid=null&StartExtra=35&LeftFill=1&RightFill=1&MockTick=1&StartDate=3%252F02%252F2005+04%253A58%253A00+PM&enddate=3%252F02%252F2006+11%253A58%253A33+PM&datatype=0 with cookie "BC31HAPPY=1; id=1F3BD614-8D43-472F-9B79-8F4133A4D781; mw_segQS=; RMID=5237e872440734a0; RMFD=011FEsEAO40AD4|P10AEw; DMSEG=474BCA790C12967D&L03436&4406B07D&44089E18&0&&44069103&E178728E627A89FE00B17217C3125B2C; ameritradeJavaBG=style=1; AMTDRTUSER=" security: Loading certificates from Deployment session certificate store security: Loaded certificates from Deployment session certificate store network: Connecting https://custom.marketwatch.com/custom/ameritrade-com/ameritradeplus/JAVACharter/styles.asp?style=1 with cookie "BC31HAPPY=1; id=1F3BD614-8D43-472F-9B79-8F4133A4D781; mw_segQS=; RMID=5237e872440734a0; RMFD=011FEsEAO40AD4|P10AEw; DMSEG=474BCA790C12967D&L03436&4406B07D&44089E18&0&&44069103&E178728E627A89FE00B17217C3125B2C; ameritradeJavaBG=style=1; AMTDRTUSER=" basic: Loaded image: https://custom.marketwatch.com/custom/ameritrade-com/ameritradeplus/JAVACharter/bgs/java-top.gif basic: Loaded image: https://custom.marketwatch.com/custom/ameritrade-com/ameritradeplus/JAVACharter/bgs/java-bottom.gif basic: Loaded image: https://custom.marketwatch.com/custom/ameritrade-com/ameritradeplus/JAVACharter/bgs/java-bottom.gif basic: Loaded image: https://custom.marketwatch.com/custom/ameritrade-com/ameritradeplus/JAVACharter/bgs/java-bottom-2.gif network: Connecting https://custom.marketwatch.com/java/a5/stuff.javadatafeed?ver=2&freq=1&symb=DIGE&countries=us+ca&partnerid=13&clientid=null&StartExtra=35&LeftFill=1&RightFill=1&MockTick=1&StartDate=3%252F02%252F2005+04%253A58%253A00+PM&enddate=3%252F02%252F2006+11%253A58%253A35+PM&datatype=0 with proxy=DIRECT network: Connecting https://custom.marketwatch.com/java/a5/stuff.javadatafeed?ver=2&freq=1&symb=DIGE&countries=us+ca&partnerid=13&clientid=null&StartExtra=35&LeftFill=1&RightFill=1&MockTick=1&StartDate=3%252F02%252F2005+04%253A58%253A00+PM&enddate=3%252F02%252F2006+11%253A58%253A35+PM&datatype=0 with cookie "BC31HAPPY=1; id=1F3BD614-8D43-472F-9B79-8F4133A4D781; mw_segQS=; RMID=5237e872440734a0; RMFD=011FEsEAO40AD4|P10AEw; DMSEG=474BCA790C12967D&L03436&4406B07D&44089E18&0&&44069103&E178728E627A89FE00B17217C3125B2C; ameritradeJavaBG=style=1; AMTDRTUSER=" the applet loads, but any attempt to select a checkbox or drop folder item causes thousands of: liveconnect: JavaScript: calling Java system code liveconnect: JavaScript: default security policy = https://custom.marketwatch.com liveconnect: JavaScript: calling Java system code liveconnect: JavaScript: default security policy = https://custom.marketwatch.com
Reproducible on Solaris with Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.8.1) Gecko/20061211 Firefox/2.0 and Java 1.6.0.
I also have the output of "A test function" in the Java Console.
I am also able to reproduce problem with OJI plugin on XP. However, the described symptom is a known performance issue with LiveConnect treatment in OJI and cannot be (simply) fixed. In order to fix this problem, OJI LiveConnect on the browser side itself must be redesigned. Let me explain what causing this problem. For OJI plugin, LiveConnect module uses JNI to communicate with Java. The use of JNI cannot abstract the communication protocol between the browser and plugin and results in performance issue caused by agressive reflection every time JS calls to a member or function of a Java Object or Java Class. For the testcase provided (shown below for easy reference), this is what the OJI LiveConnect module in the browser (LC) does in order to call Test.testFunction(): ----- Test.html ---------- <html> <body> <h1>Liveconnect Bug Test</h1> <applet code="Test.class" name="Test" height="30" width="30"></applet> <button onclick="document.applets['Test'].testFunction()">Click to test</button> </body> </html> ------- Test.java ------------ import javax.swing.*; public class Test extends JApplet { public static void testFunction() { System.out.println("A test function"); } } LC first grabs the Test applet object from OJI plugin. Then it tries to get all the methods, contructors and fields information and cache it inside a member descriptor table associated with the JavaObject itself. Even though it sounds like a trivial task, for a simple object such as Test applet, aggressive reflection for java.lang.Class.getMethods() returns hundreds of methods and for each method, at least 3 JNI calls have to be made: one is to get the array element from the method array, one is to call java.lang.reflect.Method.getModifiers() to get the method modifier, and the last one is to call java.lang.reflect.Method.getName() to get the method name. Adding all these JNI calls together, this is why you see over a thousand of "calling Java system code" messages on the Java Console with the simple testcase provided. Besides this performance issue, OJI also carries several other disadvantages including XPCOM dependencies and un-scriptability. Fortunately, with 6u10, Sun will introduce a new generation of Java Plugin. For Firefox browser, this plugin is npruntime based instead of OJI based, and has a major redesign around LiveConnect abstraction layer between the browser and the plugin. You can download the pre-released version of 6u10 here to test this testcase with new Java Plugin and see the difference: http://www.java.net/download/jdk6/6u10/promoted/b11/binaries/jre-6u10-ea-bin-b11-windows-i586-p-24_jan_2008.exe The new Java Plugin is the default plugin in 6u10. With 6u10, I only see a total of 5 LiveConnect calls in order for Test.testFunction() to be found and invoked when running the provided testcase.
Product: Core → Core Graveyard
Firefox code moved from custom Liveconnect code to the NPAPI/NPRuntime bridge a while back. Mass-closing the bugs in the liveconnect component which are likely invalid. If you believe that this bug is still relevant to modern versions of Firefox, please reopen it and move it the "Core" product, component "Plug-Ins".
Status: UNCONFIRMED → RESOLVED
Closed: 13 years ago
Resolution: --- → INCOMPLETE
You need to log in before you can comment on or make changes to this bug.