Java运行期追踪堆栈信息

字符串常量池与堆空间
运行后 为了不会被回收空间,sleep一小时
jps命令查询Java程序
使用jamp查询堆空间
jmap -dump:=b,file=aa.bin(aa.bin=随意名字) pid(pid=Java线程id)
jhat aa.bin

Java运行期追踪堆栈信息

文章插图
访问 :7000/
我是访问的是:7000/oql/
OQL Java虚拟机语言 查询字符串地址
s.value.() from java.lang. s
where //.test(s.value.())
查询结果只有一个 说明只在堆中存在,而字符串常量池中保存的是引用地址
Java运行期追踪堆栈信息

文章插图
gfdss 查询结果有两个 说明只在堆中存在,而字符串常量池中保存的是也是字符串,所以地址不一样
在使用"" 时 编译期就会存入常量池,也会在堆中放入,但是在后就被修改为,所以查询结果只剩下一个 。
lsof -i:7000
查询7000端口使用者
方法的解释
/*** Returns a canonical representation for the string object.* * A pool of strings, initially empty, is maintained privately by the* class {@code String}.* * When the intern method is invoked, if the pool already contains a* string equal to this {@code String} object as determined by* the {@link #equals(Object)} method, then the string from the pool is* returned. Otherwise, this {@code String} object is added to the* pool and a reference to this {@code String} object is returned.* * It follows that for any two strings {@code s} and {@code t},* {@code s.intern() == t.intern()} is {@code true}* if and only if {@code s.equals(t)} is {@code true}.* 【Java运行期追踪堆栈信息】* All literal strings and string-valued constant expressions are* interned. String literals are defined in section 3.10.5 of the* The Java™ Language Specification.** @returna string that has the same contents as this string, but is*guaranteed to be from a pool of unique strings.*/public native String intern();