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

* [Bug libgcj/23182] instanceof sometimes fails if compiled with -findirect-dispatch
  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 ` tromey at gcc dot gnu dot org
  2005-08-23 19:58 ` tromey at gcc dot gnu dot org
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: tromey at gcc dot gnu dot org @ 2005-08-23 16:02 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From tromey at gcc dot gnu dot org  2005-08-23 16:02 -------
Also fails with cvs head.

Offhand I suspect a compiler bug.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2005-08-23 16:02:31
               date|                            |


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


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

* [Bug libgcj/23182] instanceof sometimes fails if compiled with -findirect-dispatch
  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
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: tromey at gcc dot gnu dot org @ 2005-08-23 19:58 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From tromey at gcc dot gnu dot org  2005-08-23 19:58 -------
Reduced test case.  Compile to .class, then compile with -findirect-dispatch.
Interpreting works fine.

public class pr23182 {
  static class Wrapper {
    Object w;
    Object get() {
      return w;
    }
    Wrapper(Object x) { w = x; }
  }

  static Wrapper instance = new Wrapper(null);

  public static String toString(Object val) {
    for (;;) {
      if (val == null)
	return "null";
      if (val instanceof Wrapper) {
	val = ((Wrapper) val).get();
	if (val != instance && val instanceof Wrapper)
	  throw new RuntimeException("bob");
	continue;
      }
      return val.toString();
    }
  }

  public static void main(String[] args) {
    System.out.println(toString(null));
    System.out.println(toString("maude"));
    System.out.println(toString(new Wrapper("liver")));
  }
}


-- 


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


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

* [Bug libgcj/23182] instanceof sometimes fails if compiled with -findirect-dispatch
  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
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: fitzsim at redhat dot com @ 2005-08-30 20:44 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From fitzsim at redhat dot com  2005-08-30 20:44 -------
I suspect this is the same problem manifesting itself in JNI.  This assertion
fails in the GTK peers:

  assert ((*env)->IsAssignableFrom(env, objclazz, table->clazz));

table->clazz points to GtkGenericPeer and objclazz points to GtkWindowPeer;
clearly IsAssignableFrom should return JNI_TRUE in this case.


-- 


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


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

* [Bug libgcj/23182] instanceof sometimes fails if compiled with -findirect-dispatch
  2005-08-01 15:50 [Bug libgcj/23182] New: instanceof sometimes fails if compiled with -findirect-dispatch hannes at helma dot at
                   ` (2 preceding siblings ...)
  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
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: aph at gcc dot gnu dot org @ 2005-09-05 16:06 UTC (permalink / raw)
  To: java-prs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |aph at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2005-08-23 16:02:31         |2005-09-05 16:06:47
               date|                            |


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


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

* [Bug libgcj/23182] instanceof sometimes fails if compiled with -findirect-dispatch
  2005-08-01 15:50 [Bug libgcj/23182] New: instanceof sometimes fails if compiled with -findirect-dispatch hannes at helma dot at
                   ` (3 preceding siblings ...)
  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
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: tromey at gcc dot gnu dot org @ 2005-09-05 16:15 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From tromey at gcc dot gnu dot org  2005-09-05 16:15 -------
One reason I suspect a compiler bug and not a bug in 'instanceof'
is that the code works in the interpreter but not when BC-compiled.

Tom F... I think the arguments are reversed to the call in your
assertion example.  The first class argument is the target class,
which must be the base class.  The second class argument is the source
class.


-- 


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


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

* [Bug libgcj/23182] instanceof sometimes fails if compiled with -findirect-dispatch
  2005-08-01 15:50 [Bug libgcj/23182] New: instanceof sometimes fails if compiled with -findirect-dispatch hannes at helma dot at
                   ` (4 preceding siblings ...)
  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
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: fitzsim at redhat dot com @ 2005-09-05 17:40 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From fitzsim at redhat dot com  2005-09-05 17:40 -------
>From http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/functions.html :

IsAssignableFrom

jboolean IsAssignableFrom(JNIEnv *env, jclass clazz1,
jclass clazz2);

Determines whether an object of clazz1 can be safely cast to clazz2.

GtkWindowPeer can be safely cast to GtkGenericPeer so IsAssignableFrom should
return JNI_TRUE.


-- 


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


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

* [Bug libgcj/23182] instanceof sometimes fails if compiled with -findirect-dispatch
  2005-08-01 15:50 [Bug libgcj/23182] New: instanceof sometimes fails if compiled with -findirect-dispatch hannes at helma dot at
                   ` (5 preceding siblings ...)
  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
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: fitzsim at redhat dot com @ 2005-09-05 18:55 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From fitzsim at redhat dot com  2005-09-05 18:55 -------
What I'm seeing is a bug in libgcj's implementation of IsAssignableFrom.  I've
filed a separate report:

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


-- 


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


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

* [Bug libgcj/23182] instanceof sometimes fails if compiled with -findirect-dispatch
  2005-08-01 15:50 [Bug libgcj/23182] New: instanceof sometimes fails if compiled with -findirect-dispatch hannes at helma dot at
                   ` (6 preceding siblings ...)
  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
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: aph at gcc dot gnu dot org @ 2005-09-08 14:09 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From aph at gcc dot gnu dot org  2005-09-08 14:09 -------
I found the cause of this bug.  A line of code was incorrectly removed from
pop_type_0() when the new verifier was added, a fairly long time ago.  This
patch should fix it.

Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/expr.c,v
retrieving revision 1.235
diff -u -2 -c -r1.235 expr.c
cvs diff: conflicting specifications of output style
*** expr.c	16 Aug 2005 16:06:43 -0000	1.235
--- expr.c	8 Sep 2005 14:08:53 -0000
***************
*** 351,354 ****
--- 351,357 ----
    if (TREE_CODE (type) == POINTER_TYPE && TREE_CODE (t) == POINTER_TYPE)
      {
+       if (type == ptr_type_node || type == object_ptr_type_node)
+         return t;
+ 
        /* Since the verifier has already run, we know that any
  	 types we see will be compatible.  In BC mode, this fact


-- 


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


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

* [Bug libgcj/23182] instanceof sometimes fails if compiled with -findirect-dispatch
  2005-08-01 15:50 [Bug libgcj/23182] New: instanceof sometimes fails if compiled with -findirect-dispatch hannes at helma dot at
                   ` (7 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: green at redhat dot com @ 2005-09-09  0:34 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From green at redhat dot com  2005-09-09 00:34 -------
(In reply to comment #7)
> I found the cause of this bug.  A line of code was incorrectly removed from
> pop_type_0() when the new verifier was added, a fairly long time ago.  This
> patch should fix it.

I ported this patch to the latest FC rawhide gcc RPM and rebuilt.

I'm happy to report that it solved another instance of this bug that I
discovered today in kawa-1.8beta.  Thanks Andrew!

-- 


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


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

* [Bug libgcj/23182] instanceof sometimes fails if compiled with -findirect-dispatch
  2005-08-01 15:50 [Bug libgcj/23182] New: instanceof sometimes fails if compiled with -findirect-dispatch hannes at helma dot at
                   ` (8 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-09-09 16:04 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-09-09 16:04 -------
Subject: Bug 23182

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	aph@gcc.gnu.org	2005-09-09 16:04:13

Modified files:
	gcc/java       : ChangeLog expr.c 

Log message:
	2005-09-09  Andrew Haley  <aph@redhat.com>
	
	PR libgcj/23182
	* expr.c (pop_type_0): If the expected type is object or ptr
	(i.e. void*), return the type of the object we just popped from
	the stack.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/ChangeLog.diff?cvsroot=gcc&r1=1.1662&r2=1.1663
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/expr.c.diff?cvsroot=gcc&r1=1.236&r2=1.237



-- 


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


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

* [Bug libgcj/23182] instanceof sometimes fails if compiled with -findirect-dispatch
  2005-08-01 15:50 [Bug libgcj/23182] New: instanceof sometimes fails if compiled with -findirect-dispatch hannes at helma dot at
                   ` (9 preceding siblings ...)
  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
  12 siblings, 0 replies; 14+ messages in thread
From: mckinlay at redhat dot com @ 2005-09-22 17:43 UTC (permalink / raw)
  To: java-prs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.0.3


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


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

* [Bug libgcj/23182] instanceof sometimes fails if compiled with -findirect-dispatch
  2005-08-01 15:50 [Bug libgcj/23182] New: instanceof sometimes fails if compiled with -findirect-dispatch hannes at helma dot at
                   ` (10 preceding siblings ...)
  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
  12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-09-30 15:53 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-09-30 15:53 -------
Subject: Bug 23182

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	aph@gcc.gnu.org	2005-09-30 15:52:56

Modified files:
	gcc/java       : ChangeLog expr.c 

Log message:
	2005-09-30  Andrew Haley  <aph@redhat.com>
	
	PR libgcj/23182
	* expr.c (pop_type_0): If the expected type is object or ptr
	(i.e. void*), return the type of the object we just popped from
	the stack.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.1556.2.31&r2=1.1556.2.32
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/expr.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.218.4.4&r2=1.218.4.5



-- 


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


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

* [Bug libgcj/23182] instanceof sometimes fails if compiled with -findirect-dispatch
  2005-08-01 15:50 [Bug libgcj/23182] New: instanceof sometimes fails if compiled with -findirect-dispatch hannes at helma dot at
                   ` (11 preceding siblings ...)
  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
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-09-30 16:17 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-09-30 16:17 -------
Fixed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


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).