public inbox for java-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug libgcj/23182] New: instanceof sometimes fails if compiled with -findirect-dispatch
@ 2005-08-01 15:50 hannes at helma dot at
  2005-08-23 16:02 ` [Bug libgcj/23182] " tromey at gcc dot gnu dot org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: hannes at helma dot at @ 2005-08-01 15:50 UTC (permalink / raw)
  To: java-prs

I'm compiling Rhino 1.5R5
<ftp://ftp.mozilla.org/pub/mozilla.org/js/rhino1_5R5.zip> with the following
command:

gcj --main=org.mozilla.javascript.tools.shell.Main -findirect-dispatch js.jar -o
rhino

The resulting Rhino JavaScript shell throws exceptions on some String functions:

js> "foo".charAt(0);
js: "<stdin>", line 1: Primitive type expected (had java.lang.String instead)

The code that throws the exception is in class
src/org/mozilla/javascript/ScriptRuntime.java, static method toString(Object) at
line 522:

    public static String toString(Object val) {
        for (;;) {
            if (val == null)
                return "null";
            if (val instanceof Scriptable) {
                val = ((Scriptable) val).getDefaultValue(StringClass);
                if (val != Undefined.instance && val instanceof Scriptable) {
                    throw errorWithClassName("msg.primitive.expected", val);
                }
                continue;
            }
            ...

The val argument first refers to an instance of
org.mozilla.javascript.NativeString, so instanceof Scriptable rightly evaluates
to true. However, after the assignment val refers to an instance of
java.lang.String, yet the second instanceof Scriptable still evaluates to true,
and the exception is thrown.

The String class actually looks ok (i.e. it doesn't contain Scriptable in the
array returned by Class.getInterfaces(), so I guess this might be a caching bug
in the implementation of instanceof.

This only happens if the code is compiled with -findirect-dispatch. It still
exists in gcj (GCC) 4.0.1 20050701 (prerelease), so chances are it is still
present in the final 4.0.1 release.

-- 
           Summary: instanceof sometimes fails if compiled with -findirect-
                    dispatch
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libgcj
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: hannes at helma dot at
                CC: gcc-bugs at gcc dot gnu dot org,java-prs at gcc dot gnu
                    dot org
  GCC host triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23182


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2005-09-30 16:17 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-01 15:50 [Bug libgcj/23182] New: instanceof sometimes fails if compiled with -findirect-dispatch hannes at helma dot at
2005-08-23 16:02 ` [Bug libgcj/23182] " tromey at gcc dot gnu dot org
2005-08-23 19:58 ` tromey at gcc dot gnu dot org
2005-08-30 20:44 ` fitzsim at redhat dot com
2005-09-05 16:06 ` aph at gcc dot gnu dot org
2005-09-05 16:15 ` tromey at gcc dot gnu dot org
2005-09-05 17:40 ` fitzsim at redhat dot com
2005-09-05 18:55 ` fitzsim at redhat dot com
2005-09-08 14:09 ` aph at gcc dot gnu dot org
2005-09-09  0:34 ` green at redhat dot com
2005-09-09 16:04 ` cvs-commit at gcc dot gnu dot org
2005-09-22 17:43 ` mckinlay at redhat dot com
2005-09-30 15:53 ` cvs-commit at gcc dot gnu dot org
2005-09-30 16:17 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).