回复:VM crashed at StringTable expansion

向伟(识月) shiyue.xw at alibaba-inc.com
Wed Feb 26 11:40:38 UTC 2020


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.

Thanks,
Wei Xiang
------------------------------------------------------------------
发件人:Florian Weimer <fweimer at redhat.com>
发送时间:2020年2月26日(星期三) 19:13
收件人:向伟(识月) <shiyue.xw at alibaba-inc.com>
抄 送:hotspot-runtime-dev <hotspot-runtime-dev at openjdk.java.net>; core-libs-dev <core-libs-dev at openjdk.java.net>
主 题:Re: VM crashed at StringTable expansion

* 向伟(识月):

> We create a simple case to reproduce the issue:
>
> import java.lang.reflect.Field;
> import java.lang.reflect.Modifier;
> 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"));
>         for (int i = 0; i < 4_000_000; i++) {
>             ("s_" + i).intern();
>         }
>     }
> }

Doesn't this change the value of the "s1" string literal to the string
"s2"?

I don't think this is supportable at all.  For example, if the
implementation happens to use "s1" anywhere, it's no longer getting the
string "s1", as expected.  There's also a non-trivial interaction with
string deduplication.

Thanks,
Florian



More information about the core-libs-dev mailing list