princehaku / jav8

Automatically exported from code.google.com/p/jav8
0 stars 0 forks source link

V8 fatal error when runing in a multithreaded environment #17

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,

   I have a problem while using the jav8 lib in a multithreaded environment. I describe the problem below.

Best regards and thanks in advance for your help,
Marco Vaz

What steps will reproduce the problem?
1. create a pool of threads
2. create a script engine with the following instructions (from the main thread 
or a thread from the pool):
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("jav8");
3. from a thread from the pool call engine.eval("javascript:file.js");

What is the expected output? What do you see instead?
I expect that the javascript file is correctly evaluated by V8 engine. It is 
produced a fatal error. I attach the error trace.

What version of the product are you using? On what operating system?
I tested with the version 0.3 that I downloaded from the "Downloads" section 
and with a version compiled by myself. I tested it in a linux machine (RHEL 
6.3).

Original issue reported on code.google.com by marcov...@gmail.com on 13 Apr 2013 at 7:27

Attachments:

GoogleCodeExporter commented 8 years ago
In fact, V8 doesn't support multithread at all, please ensure you lock the 
engine before execute script. Jav8 may provide engine level lock later, but 
JSR223 seems doesn't have any interface about it :(

Original comment by flier...@gmail.com on 23 Dec 2013 at 11:26

GoogleCodeExporter commented 8 years ago
Had the same problem... Putting scriptEngine.eval(...) inside a synchronized 
block solved the issue.

Original comment by konrad.p...@actiworks.de on 8 Jan 2014 at 11:16

GoogleCodeExporter commented 8 years ago
synchronizing the eval block doesn't "solve" the issue. The benefit of a 
multithreading environment for a scripting engine is to be able to execute 
multiple evaluations concurrently. By the way, JSR-223 is very clear about it:

"
Multithreaded Engine 
Multi-threaded Evaluation - The implementation of the API and the 
engine itself are capable of supporting concurrent evaluations by 
multiple threads on a single engine instance. However the exact 
behavior of such concurrent execution is ultimately determined by the 
script or scripts themselves. An engine which supports concurrent 
execution is "multi-threaded" in the same sense that the Java language 
is "multi-threaded": Evaluation by concurrent threads is allowed and 
produces side effects that can be seen by other threads. The threads 
may interact or not interact, utilize synchronization or not utilize 
synchronization, in scripting language dependent ways.

"

http://download.oracle.com/otn-pub/jcp/java_scripting-1.0-fr-oth-JSpec/java_scri
pting-1_0-fr-spec.pdf, page 163

Current implementation is not compliant with spec. I am not criticising, jav8 
is a great initiative, but this issue is a real blocker for real application 
cases.

Original comment by bhlangon...@gmail.com on 8 Mar 2014 at 7:18

GoogleCodeExporter commented 8 years ago
Another correction: V8 does support a multithreading environment by using 
Isolates and Lockers. A thread-isolated engine would suffice for making jav8 
ScriptEngine implementation thread safe and thus supporting a multi-threaded 
environment.

Original comment by bhlangon...@gmail.com on 8 Mar 2014 at 8:27

GoogleCodeExporter commented 8 years ago
Agree, jav8 hard to meet requirements of "Multithreaded Engine", but we could 
catch up  thread-isolated base on V8 isolated mechanism. 

Original comment by flier...@gmail.com on 10 Mar 2014 at 9:16

GoogleCodeExporter commented 8 years ago
Yes, it is definitely a fix and comply with specs if done that way. I am 
looking forward to it.

Original comment by bhlangon...@gmail.com on 10 Mar 2014 at 11:54