Problem Running ClojureScript on OpenJDK

558 views
Skip to first unread message

David Soria

unread,
Jul 20, 2011, 8:37:11 PM7/20/11
to Clojure
Hi, I try to run ClojureScript rev
e4ad8ed60ca05645e0ac96362d4c6ef1e1a2bd6f

my environment is:
Fedora Linux 15
java version "1.6.0_22"
OpenJDK Runtime Environment (IcedTea6 1.10.2) (fedora-58.1.10.2.fc15-
x86_64)
OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)

After bootstrapping, I try to run the repl and load the cljs compiler.
I get this error:

Clojure 1.3.0-beta1
user=> (require '[cljs.compiler :as comp])
CompilerException java.lang.RuntimeException:
java.lang.ClassNotFoundException:
sun.org.mozilla.javascript.internal.Context, compiling:(cljs/
compiler.clj:919)

Rhino is installed and correctly loaded into the classpath.
$ yum info rhino
Loaded plugins: langpacks, presto, refresh-packagekit
Installed Packages
Name : rhino
Arch : noarch
Version : 1.7

This looks like a problem with the sun.org.mozilla.javascript.internal
package. This is part of sun-jdk and not of openjdk.

David Soria

unread,
Jul 20, 2011, 10:08:21 PM7/20/11
to Clojure
Okay, it's a GNU classpath problem, as they don't include sun.*
namespaces. Sadly javax.script.ScriptEngineManager is available and
returns an impl of javax.script.Scriptable, which refers to some rhino
engine that is in the classpath, but the concrete needed
sun.org.mozilla.internals.Context is not in GNU classpath.

Switching from OpenJDK to Oracle JDK solved the problem

On Jul 21, 2:37 am, David Soria <experimentalwo...@googlemail.com>
wrote:

db

unread,
Jul 20, 2011, 10:45:58 PM7/20/11
to Clojure
I had the same problem with open jdk on ubuntu. It looks like open
jdk has the class, but drops the 'internal' from the package name.
You can remove the 'internal' in two places in compiler.clj and it
seems to work. Longer term, the implementation-specific internal
package should be removed or some checks for different implementations
added.

diff --git a/src/clj/cljs/compiler.clj b/src/clj/cljs/compiler.clj
index b1f2213..2f1a7ab 100644
--- a/src/clj/cljs/compiler.clj
+++ b/src/clj/cljs/compiler.clj
@@ -916,11 +916,11 @@ goog.require = function(rule)
{Packages.clojure.lang.RT[\"v
(print js))
(let [filename (.get jse javax.script.ScriptEngine/FILENAME)
linenum (or (:line (meta form)) Integer/MIN_VALUE)
- ctx (sun.org.mozilla.javascript.internal.Context/
enter)]
+ ctx (sun.org.mozilla.javascript.Context/enter)]
(try
(.evaluateString ctx (:global repl-env) js filename
linenum nil)
(finally
- (sun.org.mozilla.javascript.internal.Context/exit))))
+ (sun.org.mozilla.javascript.Context/exit))))
(catch Throwable ex
;;we eat ns errors because we know goog.provide() will
throw when rel
;;TODO - file bug with google, this is bs error


On Jul 20, 10:08 pm, David Soria <experimentalwo...@googlemail.com>
wrote:

Kevin

unread,
Jul 21, 2011, 12:44:06 AM7/21/11
to Clojure
I just saw this thread and that (use of internal class) does seem to
be the problem. I submitted a pull request for this problem a little
while ago:

https://github.com/clojure/clojurescript/pull/1

Sean Corfield

unread,
Jul 22, 2011, 2:15:19 AM7/22/11
to clo...@googlegroups.com
I made these changes but still got exceptions trying to start the cljs
repl (although code seemed to work just fine in the repl after this
exception). I'm about to move onto node.js installation on ubuntu 11
at this point...

sun.org.mozilla.javascript.EvaluatorException: Encountered code
generation error while compiling function "test_stuff": generated
bytecode for method exceeds 64K limit. (cljs/core.cljs#2743)
at sun.org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:109)
at sun.org.mozilla.javascript.Context.reportRuntimeError(Context.java:938)
at sun.org.mozilla.javascript.optimizer.Codegen.reportClassFileFormatException(Codegen.java:196)
at sun.org.mozilla.javascript.optimizer.Codegen.generateCode(Codegen.java:329)
at sun.org.mozilla.javascript.optimizer.Codegen.compileToClassFile(Codegen.java:182)
at sun.org.mozilla.javascript.optimizer.Codegen.compile(Codegen.java:91)
at sun.org.mozilla.javascript.Context.compileImpl(Context.java:2391)
at sun.org.mozilla.javascript.Context.compileString(Context.java:1359)
at sun.org.mozilla.javascript.Context.compileString(Context.java:1348)
at sun.org.mozilla.javascript.Context.evaluateString(Context.java:1101)
at cljs.compiler$eval1.invoke(compiler.clj:921)
at cljs.compiler$load_stream.invoke(compiler.clj:944)
at cljs.compiler$goog_require$fn__804.invoke(compiler.clj:966)
at cljs.compiler$goog_require.invoke(compiler.clj:965)
at clojure.lang.Var.invoke(Var.java:405)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at sun.org.mozilla.javascript.MemberBox.invoke(MemberBox.java:161)
at sun.org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:247)
at sun.org.mozilla.javascript.optimizer.OptRuntime.call2(OptRuntime.java:76)
at sun.org.mozilla.javascript.gen.c7._c1(goog/base.js:11)
at sun.org.mozilla.javascript.gen.c7.call(goog/base.js)
at sun.org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:66)
at sun.org.mozilla.javascript.gen.c1710._c0(cljs/core.cljs:1003)
at sun.org.mozilla.javascript.gen.c1710.call(cljs/core.cljs)
at sun.org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:398)
at sun.org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3065)
at sun.org.mozilla.javascript.gen.c1710.call(cljs/core.cljs)
at sun.org.mozilla.javascript.gen.c1710.exec(cljs/core.cljs)
at sun.org.mozilla.javascript.Context.evaluateString(Context.java:1104)
at cljs.compiler$eval1.invoke(compiler.clj:921)
at cljs.compiler$repl.doInvoke(compiler.clj:1001)
at clojure.lang.RestFn.invoke(RestFn.java:410)
at user$eval842.invoke(NO_SOURCE_FILE:10)
at clojure.lang.Compiler.eval(Compiler.java:6406)
at clojure.lang.Compiler.eval(Compiler.java:6372)
at clojure.core$eval.invoke(core.clj:2745)
at clojure.main$repl$read_eval_print__6016.invoke(main.clj:244)
at clojure.main$repl$fn__6021.invoke(main.clj:265)
at clojure.main$repl.doInvoke(main.clj:265)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.main$repl_opt.invoke(main.clj:331)
at clojure.main$main.doInvoke(main.clj:427)
at clojure.lang.RestFn.invoke(RestFn.java:397)
at clojure.lang.Var.invoke(Var.java:397)
at clojure.lang.AFn.applyToHelper(AFn.java:159)
at clojure.lang.Var.applyTo(Var.java:518)
at clojure.main.main(main.java:37)

> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

--
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/
Railo Technologies, Inc. -- http://www.getrailo.com/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)

Sean Corfield

unread,
Jul 22, 2011, 2:44:07 AM7/22/11
to clo...@googlegroups.com
FWIW, I get this same error trying to compile the basic examples for
Node.js as well:

cljsc nodehello.cljs {:optimizations :advanced :target :nodejs} > nodehello.js

sun.org.mozilla.javascript.EvaluatorException: Encountered code
generation error while compiling function "test_stuff": generated
bytecode for method exceeds 64K limit. (cljs/core.cljs#2743)
at sun.org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:109)
at sun.org.mozilla.javascript.Context.reportRuntimeError(Context.java:938)
at sun.org.mozilla.javascript.optimizer.Codegen.reportClassFileFormatException(Codegen.java:196)
at sun.org.mozilla.javascript.optimizer.Codegen.generateCode(Codegen.java:329)
at sun.org.mozilla.javascript.optimizer.Codegen.compileToClassFile(Codegen.java:182)
at sun.org.mozilla.javascript.optimizer.Codegen.compile(Codegen.java:91)
at sun.org.mozilla.javascript.Context.compileImpl(Context.java:2391)
at sun.org.mozilla.javascript.Context.compileString(Context.java:1359)
at sun.org.mozilla.javascript.Context.compileString(Context.java:1348)
at sun.org.mozilla.javascript.Context.evaluateString(Context.java:1101)
at cljs.compiler$eval1.invoke(compiler.clj:921)
at cljs.compiler$load_stream.invoke(compiler.clj:944)

at cljs.compiler$load_file.invoke(compiler.clj:954)
at cljs.closure$compile_form_seq.invoke(closure.clj:206)
at cljs.closure$compile_file.invoke(closure.clj:228)
at cljs.closure$eval1120$fn__1121.invoke(closure.clj:266)
at cljs.closure$eval1056$fn__1057$G__1047__1064.invoke(closure.clj:187)
at cljs.closure$eval1107$fn__1108.invoke(closure.clj:280)
at cljs.closure$eval1056$fn__1057$G__1047__1064.invoke(closure.clj:187)
at cljs.closure$build.invoke(closure.clj:695)
at user$eval1246.invoke(cljsc.clj:21)
at clojure.lang.Compiler.eval(Compiler.java:6406)
at clojure.lang.Compiler.load(Compiler.java:6843)
at clojure.lang.Compiler.loadFile(Compiler.java:6804)
at clojure.main$load_script.invoke(main.clj:282)
at clojure.main$script_opt.invoke(main.clj:342)
at clojure.main$main.doInvoke(main.clj:426)
at clojure.lang.RestFn.invoke(RestFn.java:512)
at clojure.lang.Var.invoke(Var.java:421)
at clojure.lang.AFn.applyToHelper(AFn.java:185)


at clojure.lang.Var.applyTo(Var.java:518)
at clojure.main.main(main.java:37)

Sean Corfield

unread,
Jul 22, 2011, 2:58:10 AM7/22/11
to clo...@googlegroups.com
And then you can't run the resulting JS on node - anything I can try
to get you guys more info?

sean@sean-netbook:~/node$ node nodehello.js

/home/sean/node/nodehello.js:1
(defn test-stuff
^^^^

node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
SyntaxError: Unexpected identifier
at Module._compile (module.js:397:25)
at Object..js (module.js:408:10)
at Module.load (module.js:334:31)
at Function._load (module.js:293:12)
at Array.<anonymous> (module.js:421:10)
at EventEmitter._tickCallback (node.js:126:26)

db

unread,
Jul 22, 2011, 10:08:43 PM7/22/11
to Clojure
I believe that the issue can be avoided with OpenJDK by disabling
Rhino optimization.

>> generated bytecode for method exceeds 64K limit. (cljs/core.cljs#2743)

This appears to be identical to what the fantom guys have encountered:

http://fantom.org/sidewalk/topic/1181

Although instead of switching jvms, I'm going to try to make it work
with OpenJDK.

I'm planning to try a few things:

- Use a newer version of Rhino (trunk from Mozilla).
- Try the change recommended by the Fantom team.
- Look for a JSR 223-compatible replacement for the Rhino impl-
specific Context usage.

I'll post the results shortly.
> >>>> Switching fromOpenJDKto Oracle JDK solved the problem
>
> >>>> On Jul 21, 2:37 am, David Soria <experimentalwo...@googlemail.com>
> >>>> wrote:
>
> >>>> > Hi, I try to run ClojureScript rev
> >>>> > e4ad8ed60ca05645e0ac96362d4c6ef1e1a2bd6f
>
> >>>> > my environment is:
> >>>> > Fedora Linux 15
> >>>> > java version
>
> ...
>
> read more »

Sean Corfield

unread,
Jul 22, 2011, 10:34:19 PM7/22/11
to clo...@googlegroups.com
On Fri, Jul 22, 2011 at 7:08 PM, db <donald...@gmail.com> wrote:
> I believe that the issue can be avoided with OpenJDK by disabling
> Rhino optimization.
>
>>>    generated bytecode for method exceeds 64K limit. (cljs/core.cljs#2743)
>
> This appears to be identical to what the fantom guys have encountered:
>
> http://fantom.org/sidewalk/topic/1181
>
> Although instead of switching jvms, I'm going to try to make it work
> with OpenJDK.

Thanx Donald!

I may just switch to the Sun, er, Oracle JVM since I've a feeling one
of my other projects (not yet migrated to my netbook) will require
that JVM anyway...

db

unread,
Jul 23, 2011, 2:35:53 AM7/23/11
to Clojure
The hello example runs after adding a call to setOptimizationLevel -1.

--- a/src/clj/cljs/compiler.clj
+++ b/src/clj/cljs/compiler.clj
@@ -916,11 +916,12 @@ goog.require = function(rule)
{Packages.clojure.lang.RT[\"var\"](\"cljs.compiler\
(print js))
(let [filename (.get jse javax.script.ScriptEngine/FILENAME)
linenum (or (:line (meta form)) Integer/MIN_VALUE)
- ctx (sun.org.mozilla.javascript.internal.Context/
enter)]
+ ctx (sun.org.mozilla.javascript.Context/enter)]
(try
+ (.setOptimizationLevel ctx -1)
(.evaluateString ctx (:global repl-env) js filename
linenum nil)
(finally
- (sun.org.mozilla.javascript.internal.Context/exit))))
+ (sun.org.mozilla.javascript.Context/exit))))
(catch Throwable ex
;;we eat ns errors because we know goog.provide() will
throw when reloaded
;;TODO - file bug with google, this is bs error

This is a fairly simple workaround for OpenJDK 6/ ubuntu.

I haven't looked at what it would take to replace the rhino-specific
code with the javax.script API equivalent, but I did look into
upgrading rhino or adding rhino to a jvm version that doesn't ship
with a js implementation (such as openjdk 7 built from source). So
far, this appears to be non-trivial, because rhino doesn't have its
own jsr 223 implementation. The two approaches to address this seem
to be to implement the jsr 223 classes for rhino, or use an existing
rhino 223 impl, as described here:

https://bugzilla.mozilla.org/show_bug.cgi?id=379385

I also haven't looked at what other jvms folks are using these days,
and whether they ship with a js implementation. One option would be
to go the other way, and replace the javax.script code with rhino, and
treat rhino as an explicit dependency. This could be the most
flexible and consistent approach across jvms.

On Jul 22, 10:34 pm, Sean Corfield <seancorfi...@gmail.com> wrote:
> On Fri, Jul 22, 2011 at 7:08 PM, db <donald.bl...@gmail.com> wrote:
> > I believe that the issue can be avoided with OpenJDK by disabling
> > Rhino optimization.
>
> >>>    generated bytecode for method exceeds 64K limit. (cljs/core.cljs#2743)
>
> > This appears to be identical to what the fantom guys have encountered:
>
> >http://fantom.org/sidewalk/topic/1181
>
> > Although instead of switching jvms, I'm going to try to make it work
> > with OpenJDK.
>
> Thanx Donald!
>
> I may just switch to the Sun, er, Oracle JVM since I've a feeling one
> of my other projects (not yet migrated to my netbook) will require
> that JVM anyway...
> --
> Sean A Corfield -- (904) 302-SEAN
> An Architect's View --http://corfield.org/
> World Singles, LLC. --http://worldsingles.com/
> Railo Technologies, Inc. --http://www.getrailo.com/

Sean Corfield

unread,
Jul 23, 2011, 2:38:15 AM7/23/11
to clo...@googlegroups.com
On Fri, Jul 22, 2011 at 7:34 PM, Sean Corfield <seanco...@gmail.com> wrote:
> I may just switch to the Sun, er, Oracle JVM since I've a feeling one
> of my other projects (not yet migrated to my netbook) will require
> that JVM anyway...

Just an update: I installed Oracle's JDK and everything is working
perfectly on my Ubuntu netbook :)

Tzach

unread,
Aug 14, 2011, 12:44:31 PM8/14/11
to Clojure
I have a similar problem, but I could not solve it like you did:
running on Ubuntu 11.04,
$JAVA_HOME set to /usr/lib/jvm/default-java, and default-java soft
link to java-6-sun

Still when I run script/repl, and
(require '[cljs.compiler :as comp])
(def jse (comp/repl-env))
(comp/repl jse)
CompilerException java.lang.RuntimeException:
java.lang.ClassNotFoundException:
sun.org.mozilla.javascript.internal.Context, compiling:(cljs/
compiler.clj:971)
user=> CompilerException java.lang.RuntimeException: No such
namespace: comp, compiling:(NO_SOURCE_PATH:2)
user=> CompilerException java.lang.RuntimeException: No such
namespace: comp, compiling:(NO_SOURCE_PATH:3)

Any idea?

Thanks
Tzach

On Jul 23, 9:38 am, Sean Corfield <seancorfi...@gmail.com> wrote:
> On Fri, Jul 22, 2011 at 7:34 PM, Sean Corfield <seancorfi...@gmail.com> wrote:
> > I may just switch to the Sun, er, Oracle JVM since I've a feeling one
> > of my other projects (not yet migrated to my netbook) will require
> > that JVM anyway...
>
> Just an update: I installed Oracle'sJDKand everything is working
> perfectly on myUbuntunetbook :)
> --
> Sean A Corfield -- (904) 302-SEAN
> An Architect's View --http://corfield.org/
> World Singles, LLC. --http://worldsingles.com/
> Railo Technologies, Inc. --http://www.getrailo.com/

Volker Schlecht

unread,
Oct 1, 2011, 11:23:28 AM10/1/11
to Clojure
Has anyone succeeded in solving this issue for OpenJDK yet?
So far all solutions I've seen discussed boiled down to using Oracle's
JDK ...

David Nolen

unread,
Oct 1, 2011, 11:41:57 AM10/1/11
to clo...@googlegroups.com
There's a good chance ClojureScript will be using a newer version of Rhino - which will address this problem. Should get rolled into master in the next few days.Thanks for your patience!

David

db

unread,
Oct 2, 2011, 1:59:02 PM10/2/11
to Clojure
The changes I posted previously solved the problem for me on open-jdk
6 on ubuntu. All I had to do was fix the package name and add the
optimization level and everything worked fine. I haven't checked to
see if master has changed in a way that would affect this patch. As I
mentioned above, there is a deeper issue at play here, because the
compiler uses a combination of the scripting API and exposes some
implementation details. The Java scripting API uses an SPI (service
provider interface), which means that the JVM has a public interface
that applications use, and a separate interface that can be used to
register different implementations of the interface outside of the
application. If ClojureScript was to continue using the javax.script
package, it would require removing the exposed implementation
mozilla.*, and relying on whatever version of a javascript engine was
registered on a given JVM, or requiring some messy and complex task of
registering a specific implementation of Rhino with the JVM itself.
The way around this mess is to declare rhino as an explicit dependency
and use the APIs directly, which would make it more difficult to
switch the javascript engine.

From what David mentions, it sounds like this is the direction taken,
if a new version of Rhino will be provided with ClojureScript soon.

David,

Do you have any more details on how the new version of Rhino will be
supplied with ClojureScript, and if there's a branch that could be
checked out to kick the tires before it's merged into master?

Stefan Kamphausen

unread,
Oct 2, 2011, 4:36:51 PM10/2/11
to clo...@googlegroups.com
Hi,

I hope, people are aware that Oracle considers OpenJDK to be the standard choice for Linux users now and removed the special distributor's license.  See http://robilad.livejournal.com/90792.html


Kind regards,
Stefan

db

unread,
Oct 2, 2011, 11:07:50 PM10/2/11
to Clojure
Here's what the patch looks like for openjdk-6 with the latest master,
where the mozilla-specific lines have moved to the rhino.js file:

diff --git a/src/clj/cljs/repl/rhino.clj b/src/clj/cljs/repl/rhino.clj
index cbe4f2a..15c5bf1 100644
--- a/src/clj/cljs/repl/rhino.clj
+++ b/src/clj/cljs/repl/rhino.clj
@@ -27,6 +27,7 @@ goog.require = function(rule)
{Packages.clojure.lang.RT[\"var\"
linenum (or line Integer/MIN_VALUE)
ctx (sun.org.mozilla.javascript.Context/enter)]
(try
+ (.setOptimizationLevel ctx -1)
{:status :success
:value (.evaluateString ctx (:global repl-env) js filename
linenum nil
(finally

This works for me on openjdk6, but will not work on openjdk7 because
it doesn't ship with Rhino. For openjdk7, it looks like a separate
version of Rhino needs to be downloaded.

David Nolen

unread,
Oct 2, 2011, 11:12:54 PM10/2/11
to clo...@googlegroups.com
Look at the rhino-eval branch of ClojureScript.

David

Brenton

unread,
Oct 3, 2011, 10:15:33 AM10/3/11
to Clojure
If you have been having problems the ClojureScript and OpenJDK, please
try the current master branch of ClojureScript.

I would be interested to know what problems still remain, if any,
after these changes.

db

unread,
Oct 3, 2011, 11:44:17 PM10/3/11
to Clojure
Works for me. Thanks.

Volker Schlecht

unread,
Oct 6, 2011, 4:43:03 PM10/6/11
to Clojure
Master works like a charm now - Thanks!!

On Oct 4, 5:44 am, db <donald.bl...@gmail.com> wrote:
> Works for me.  Thanks.
>
> On Oct 3, 10:15 am, Brenton <bashw...@gmail.com> wrote:
>
>
>
>
>
>
>
> > If you have been having problems the ClojureScript andOpenJDK, please
> > try the current master branch of ClojureScript.
>
> > I would be interested to know what problems still remain, if any,
> > after these changes.
>
> > On Oct 2, 11:07 pm, db <donald.bl...@gmail.com> wrote:
>
> > > Here's what the patch looks like foropenjdk-6 with the latest master,
> > > where the mozilla-specific lines have moved to the rhino.js file:
>
> > > diff --git a/src/clj/cljs/repl/rhino.clj b/src/clj/cljs/repl/rhino.clj
> > > index cbe4f2a..15c5bf1 100644
> > > --- a/src/clj/cljs/repl/rhino.clj
> > > +++ b/src/clj/cljs/repl/rhino.clj
> > > @@ -27,6 +27,7 @@ goog.require = function(rule)
> > > {Packages.clojure.lang.RT[\"var\"
> > >            linenum (or line Integer/MIN_VALUE)
> > >            ctx (sun.org.mozilla.javascript.Context/enter)]
> > >        (try
> > > +        (.setOptimizationLevel ctx -1)
> > >          {:status :success
> > >           :value (.evaluateString ctx (:global repl-env) js filename
> > > linenum nil
> > >          (finally
>
> > > This works for me on openjdk6, but will not work on openjdk7 because
> > > it doesn't ship with Rhino.  For openjdk7, it looks like a separate
> > > version of Rhino needs to be downloaded.
>
> > > On Oct 2, 4:36 pm, Stefan Kamphausen <ska2...@googlemail.com> wrote:
>
> > > > Hi,
>
> > > > I hope, people are aware that Oracle considersOpenJDKto be the standard
Reply all
Reply to author
Forward
0 new messages