BZ #83: global references broken

Status fields:

creation_ts:2008-06-19 11:06
version:default branch
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 on 2008-06-26 09:29:51

This is the preliminary fix:

and was shipped in the new releases.

Comment #2 by 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:

Comment #3 by 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 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:

Comment #5 by 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 on 2012-04-19 09:24:08

Doesn't seem to be a problem.