harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gregory Shimansky <gshiman...@gmail.com>
Subject Re: [drlvm][jni] NewGlobalRef() returns NULL for pending exception object
Date Fri, 23 Mar 2007 16:19:50 GMT
Ivan Popov wrote:
> Working on HARMONY-3304 [1] I noticed problem with JNI function
> NewGlobalRef() in DRLVM. If it is called for a pending exception
> object before ExceptionClear() is invoked, it returns NULL, which is
> interpreted as out of memory according to JNI spec [2]. This causes
> errors in debug support. In Sun/BEA VM non-NULL reference is returned
> in this case.

Actually JNI specification [1] states that only 3 JNI functions may be 
safely called in exception state. Looking at the code of NewGloabRef I 
see that the check for exception was added at revision 489694 as a 
result of committing HARMONY-2817.

> Simple workaround is to call ExceptionClear() before NewGlobalRef().
> However, I'm not sure if ExceptionClear() won't dispose exception

ExceptionClear zeroes a reference to exception object in TLS which is 
considered as no exception state. The object itself may be collected 
later if there are no live references to it left.

> object itself. To my mind it's better to fix NewGlobalRef() and make
> it compatible with RI.

[1] http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/design.html#wp17626

-- 
Gregory


Mime
View raw message