BZ #83: global references broken

Status fields:

creation_ts:2008-06-19 11:06
component:jni
version:default branch
rep_platform:All
op_sys:All
bug_status:RESOLVED
resolution:FIXED
reporter:twisti@complang.tuwien.ac.at
We have not implemented global references handling correctly, again.  I'll try to fix it
for the cacao-1.0.x branch and will rewrite the whole thing for the default branch.

Comment #1 by twisti@complang.tuwien.ac.at on 2008-06-26 09:29:51

This is the preliminary fix:

http://mips.complang.tuwien.ac.at/hg/cacao/rev/93decefa1711

and was shipped in the new releases.

Comment #2 by michi@complang.tuwien.ac.at on 2008-12-28 13:09:05

I am taking over this one. It will be fixed in the handles branch. Global references are
used throughout our native code in this branch, so they need to be reworked anyways.

My first plan was to use the same implementation for our internal globalrefs and for JNI
globalrefs. This way we would reduce code duplication. My only concern is that malicious
JNI functions could then delete globalrefs held by the VM. That is the reason why we
might need two separate implementations after all. Below is a simple (mis)use case
scenario which would lead to that problem:

1) VM create globalref for A - refcount is 1
2) JNI-code creates globalref for A - refcount is 2 (JNI now has same globalref)
3) JNI-code deletes globalref for A - refcount is 1 (JNI has done a good job)
4) JNI-code deletes globalref for A - refcount is 0 (This should not be allowed)
5) GC collects A (This is bad!)

Any comments? Since I want to open a discussion here, I added the mailinglist to CC for
this bug.

As a reference: http://java.sun.com/docs/books/jni/html/refs.html

Comment #3 by stefan@complang.tuwien.ac.at on 2008-12-29 14:29:32

Decrementing a refcount too often is arguably a bug in the JNI code, and because JNI
code can do anything anyway, I would not care what happens then. Or does the spec say
anything about this?

Comment #4 by michi@complang.tuwien.ac.at on 2009-01-04 17:13:19

I commited the new global reference implementation. As you can see it is still on the
handles branch, so I will leave this report open until the branch is merged back. This
is the changeset:

http://mips.complang.tuwien.ac.at/hg/cacao/rev/871aea8a6bb4

Comment #5 by stefan@complang.tuwien.ac.at on 2010-05-18 21:26:00

The handle branch is merged now. Is this still an issue? Is --enable-handles required in
order to profit from this fix?

Comment #6 by stefan@complang.tuwien.ac.at on 2012-04-19 09:24:08

Doesn't seem to be a problem.