Review request (S): 6539281 -Xcheck:jni should validate char* argument to ReleaseStringUTFChars

Dmitry Samersoff Dmitry.Samersoff at
Thu Dec 2 09:12:34 PST 2010


1. Logically string argument of GetStringChars and ReleaseStringChars 
have to be the same.
        chars_to_check = GetStringChars(env,str,isCopy);
        memcmp(chars,chars_to_check, len > 10 ? 10 : len);

could be a better approach.


As far as I know GetStringChars do alloc/memcpy inside it
Could we avoid extra copying?

Code below:
jint *tagLocation = ((jint*) chars) - 1;

Could lead to cryptic crash e.g. if we pass 0 as a char (common case) to 
this code we will have a crash on read from 0xFFFFFFFF rather than much 
more clean crash on zero-access. So either gurantee chars != 0 have to 
be there or tag should be placed at the end of chars, after terminating 


On 2010-12-02 17:18, Staffan Larsen wrote:
> Validate that ReleaseStringUTFChars/ReleaseStringChars is called with
> something allocated by GetStringUTChars/GetStringChars when running with
> -Xcheck:jni. This is accomplished by adding a well-known tag in the
> memory immediately before the pointer that is returned to the user. This
> tag is verified in ReleaseStringUTFChars.
> Thanks,
> /Staffan

Dmitry Samersoff
J2SE Sustaining team, SPB04
* Give Rabbit time and he'll always get the answer ...

More information about the hotspot-runtime-dev mailing list