RFR: 8025922 JNI access to Strings need to check if the value field is non-null
David Holmes
david.holmes at oracle.com
Sat Oct 5 20:14:59 PDT 2013
On 5/10/2013 12:35 AM, Daniel D. Daugherty wrote:
> On 10/4/13 6:24 AM, David Holmes wrote:
>> On 4/10/2013 10:02 PM, Staffan Larsen wrote:
>>>
>>> On 4 okt 2013, at 13:54, David Holmes <David.Holmes at oracle.com> wrote:
>>>
>>>> Hi Staffan,
>>>>
>>>> On 4/10/2013 9:23 PM, Staffan Larsen wrote:
>>>>> If the String constructor has not completed, then we can't access
>>>>> the String value. It is still possible to do this from JNI, but it
>>>>> should not crash the VM.
>>>>>
>>>>> This was found while fixing a debugger issue (JDK-8021897) where
>>>>> stepping into the String constructor crashes the JVM. The fix for
>>>>> JDK-8021897 requires changes on the JDK side. Those changes will
>>>>> also include a JDI test for that issue, but won't be pushed until
>>>>> this change reaches jdk8-tl.
>>>>
>>>> Other than the debugger case is there any other case where these JNI
>>>> calls can occur before the constructor has completed? At the moment
>>>> I'm not sure if this is really a JNI problem or a debugger problem -
>>>> surely there are many objects that the debugger may access partially
>>>> initialized which might then lead to errors/crashes?
>>>
>>> From JNI you can do AllocObject() and then GetStringLength() and it
>>> will cause the same crash. I'd love to include a test for this, but
>>> alas, our test harness does not support native code.
>>
>> Hmmmm. So that exposes a hole in the JNI specification. You can create
>> unconstructed objects and then invoke JNI functions on them and there
>> is no clear spec as to what should happen. What you have coded seems
>> quite reasonable but for the get*Chars method contradicts the
>> specification which states that it "Returns NULL if and only if an
>> invocation of this function has thrown an exception." And the only
>> exception listed is OOME.
>
> Maybe I'm reading it wrong, but for GetStringChars(), I see:
>
> http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/functions.html#wp17158
>
>
> > GetStringChars
> >
> > const jchar * GetStringChars(JNIEnv *env, jstring string,
> > jboolean *isCopy);
>
> <snip>
>
> > RETURNS:
> >
> > Returns a pointer to a Unicode string, or NULL if the operation fails.
>
>
> And for GetStringUTFChars(), I see:
>
> http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/functions.html#wp17265
>
>
> > GetStringUTFChars
> >
> > const char * GetStringUTFChars(JNIEnv *env, jstring string,
> > jboolean *isCopy);
>
> <snip>
>
> > RETURNS:
> >
> > Returns a pointer to a modified UTF-8 string, or NULL if the
> operation fails.
>
>
> I'm not finding this phrase:
>
> "Returns NULL if and only if an invocation of this function has
> thrown an exception."
>
> associated with either of these functions.
Looks like another case where the online version of the "spec" has lost
stuff that was in the original book version :( But at least in this case
it means no changes are now needed.
David
-----
> Dan
>
>
>>
>> Impossible to meet that spec given the existence of AllocObject.
>>
>> Reviewed. ;-)
>>
>> Thanks,
>> David
>>
>>
>>
>>> /Staffan
>>>
>
More information about the hotspot-runtime-dev
mailing list