Subj : Re: Is rhino's Codegen.generateCode() method thread safe? To : tomi@osaka.niss.co.jp From : Igor Bukanov Date : Wed Mar 12 2003 02:38 pm Tomita Tomohiro wrote: > Hi, > I have some question about rhino. What version of Rhino do you use and what is your JVM name/version/platform? > > I'm using rhino in multi thread. > Is the Codegen.generateCode() method thread safe? Codegen is not thread safe but its usage is safe since its instances are accessed only by the single thread that creates them. > #I have no time to trace or debug rhino source,so I ask this ML :-) > > in my enviroment(j9VM) the error occures very often as follows: > java.lang.StringIndexOutOfBoundsException > Stack trace: > java/lang/Throwable.()V > java/lang/String.charAt(I)C > org/mozilla/classfile/ClassFileWriter.sizeOfParameters(Ljava/lang/String;)I > org/mozilla/classfile/ClassFileWriter.add(BLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V > org/mozilla/javascript/optimizer/Codegen.addStaticInvoke(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V > org/mozilla/javascript/optimizer/Codegen.visitRegularCall(Lorg/mozilla/javascript/Node;ILorg/mozilla/javascript/Node;Z)V > org/mozilla/javascript/optimizer/Codegen.visitCall(Lorg/mozilla/javascript/Node;ILorg/mozilla/javascript/Node;)V > org/mozilla/javascript/optimizer/Codegen.generateCodeFromNode(Lorg/mozilla/javascript/Node;Lorg/mozilla/javascript/Node;II)V > org/mozilla/javascript/optimizer/Codegen.generateCodeFromNode(Lorg/mozilla/javascript/Node;Lorg/mozilla/javascript/Node;II)V > org/mozilla/javascript/optimizer/Codegen.generateCodeFromNode(Lorg/mozilla/javascript/Node;Lorg/mozilla/javascript/Node;II)V > org/mozilla/javascript/optimizer/Codegen.generateCode(Lorg/mozilla/javascript/Node;Ljava/util/Vector;Ljava/util/Vector;Lorg/mozilla/javascript/ClassNameHelper;)Ljava/lang/String; > org/mozilla/javascript/optimizer/Codegen.compile(Lorg/mozilla/javascript/Context;Lorg/mozilla/javascript/Scriptable;Lorg/mozilla/javascript/Node;Ljava/lang/Object;Lorg/mozilla/javascript/SecuritySupport;Lorg/mozilla/javascript/ClassNameHelper;)Ljava/lang/Object; > org/mozilla/javascript/Context.compile(Lorg/mozilla/javascript/Scriptable;Lorg/mozilla/javascript/TokenStream;Ljava/lang/Object;Ljava/io/Reader;Z)Ljava/lang/Object; > org/mozilla/javascript/Context.compile(Lorg/mozilla/javascript/Scriptable;Ljava/io/Reader;Ljava/lang/String;ILjava/lang/Object;Z)Ljava/lang/Object; > org/mozilla/javascript/Context.compileReader(Lorg/mozilla/javascript/Scriptable;Ljava/io/Reader;Ljava/lang/String;ILjava/lang/Object;)Lorg/mozilla/javascript/Script; > tomi.run()V > java/lang/Thread.run()V > > if compiling JavaScript in single thread, then it works good. The fact that org/mozilla/classfile/ClassFileWriter.sizeOfParameters() accesses a character outside string is a bug in sizeOfParameters since the function is supposed to check for bad method signatures and throw exlicit exception about it. But its usage in org/mozilla/javascript/optimizer/Codegen.java is correct, so I suspect a bug in JVM. Regards, Igor .