This is the mail archive of the
java-prs@gcc.gnu.org
mailing list for the Java project.
[Bug libgcj/23182] New: instanceof sometimes fails if compiled with -findirect-dispatch
- From: "hannes at helma dot at" <gcc-bugzilla at gcc dot gnu dot org>
- To: java-prs at gcc dot gnu dot org
- Date: 1 Aug 2005 15:50:43 -0000
- Subject: [Bug libgcj/23182] New: instanceof sometimes fails if compiled with -findirect-dispatch
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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