Re: 回复:回复:VM crashed at StringTable expansion

Remi Forax forax at univ-mlv.fr
Wed Feb 26 13:03:16 UTC 2020



----- Mail original -----
> De: "向伟(识月)" <shiyue.xw at alibaba-inc.com>
> À: "Florian Weimer" <fweimer at redhat.com>
> Cc: "core-libs-dev" <core-libs-dev at openjdk.java.net>, "hotspot-runtime-dev" <hotspot-runtime-dev at openjdk.java.net>
> Envoyé: Mercredi 26 Février 2020 13:45:52
> Objet: 回复:回复:VM crashed at StringTable expansion

> Hi Florian, Alan,
> 
>    public static void main(String[] args) throws Exception {
>        String s1 = "s1".intern();
>        System.out.println("before reflect s1 = " + s1);
>        Field f = String.class.getDeclaredField("value");
>        f.setAccessible(true);
>        f.set("s1".intern(), f.get("s2"));
>        System.out.println("after reflect s1 = " + s1);
>    }
> Print:
> before reflect s1 = s1
> after reflect s1 = s2
> 
> I see the warning, but it isn't forbidden for the usage in JDK11 or a higher
> version.

It is !
It's what "illegal" means.

> When we modify a normal String, we also get the same warning message.
> 
> It is an internal library, we may suggest the user to change their code.
> But actually, it isn't easy to find the code if the other users have similar
> usage.

It's easy, run your program with --illegal-access=deny

At some point in the future (and sooner than you think), --illegal-access=deny will be the default.
I think Mark Reinhold said something along that line at last JFokus.

> 
> We may need a way to avoid the crash or locate the problem in user code quickly.
> 
> Thanks,
> Wei Xiang

regards,
Rémi

> 
> 
> ------------------------------------------------------------------
> 发件人:Florian Weimer <fweimer at redhat.com>
> 发送时间:2020年2月26日(星期三) 20:08
> 收件人:向伟(识月) <shiyue.xw at alibaba-inc.com>
> 抄 送:core-libs-dev <core-libs-dev at openjdk.java.net>; hotspot-runtime-dev
> <hotspot-runtime-dev at openjdk.java.net>
> 主 题:Re: 回复:VM crashed at StringTable expansion
> 
> * 向伟(识月):
> 
>> Hi Florian,
>>
>> This isn't a common usage.
>> For the below code:
>>
>> String s1 = "s1".intern();
>> f.set("s1".intern(), f.get("s2"));
>>
>> After calling reflection, the value of s1 is changed to "s2".
>> In some special scenarios, the original jar file can't be modified. But the user
>> expects to change the value of some string, and uses the above code to
>> implement it.
>>
>> Although this usage isn't recommended, it isn't forbidden. We don't expect
>> the crash because of the usage.
> 
> That's not what I see.  A modified reproducer:
> 
> import java.lang.reflect.Field;
> public class StringTableTest {
>    public static void main(String[] args) throws Exception {
>        Field f = String.class.getDeclaredField("value");
>        f.setAccessible(true);
>        f.set("s1".intern(), f.get("s2"));
>        System.out.println("s1");
>        System.out.println("s2");
>    }
> }
> 
> Prints this:
> 
> s2
> s2
> 
> It also has a clear warning:
> 
> WARNING: An illegal reflective access operation has occurred
> WARNING: Illegal reflective access by StringTableTest (file:/tmp/) to field
> java.lang.String.value
> WARNING: Please consider reporting this to the maintainers of StringTableTest
> WARNING: Use --illegal-access=warn to enable warnings of further illegal
> reflective access operations
> WARNING: All illegal access operations will be denied in a future release
> 
> I'm not sure what else we can do.
> 
> Thanks,
> Florian


More information about the hotspot-runtime-dev mailing list