Java运行期追踪堆栈信息

字符串常量池与堆空间
字符串常量池与堆空间
运行后 为了不会被回收空间,sleep一小时

jps命令查询Java程序
使用jamp查询堆空间
jmap -dump:format=b,file=aa.bin(aa.bin=随意名字) pid(pid=Java线程id)
jhat aa.bin
在这里插入图片描述
访问 http://localhost:7000/

我是访问的是http://localhost:7000/oql/
OQL Java虚拟机语言 查询字符串地址

select s.value.toString() from java.lang.String s
where /kjlhgfc/.test(s.value.toString())
在这里插入图片描述
kjlhgfc 查询结果只有一个 说明只在堆中存在,而字符串常量池中保存的是引用地址
在这里插入图片描述
gfdss 查询结果有两个 说明只在堆中存在,而字符串常量池中保存的是也是字符串,所以地址不一样

在使用"kjlhgf" 时 编译期就会存入常量池,也会在堆中放入,但是在append后就被修改为kjlhgfc,所以查询结果只剩下一个。

lsof -i:7000
查询7000端口使用者

intern方法的解释

/**
     * Returns a canonical representation for the string object.
     * <p>
     * A pool of strings, initially empty, is maintained privately by the
     * class {@code String}.
     * <p>
     * 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.
     * <p>
     * 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}.
     * <p>
     * All literal strings and string-valued constant expressions are
     * interned. String literals are defined in section 3.10.5 of the
     * <cite>The Java&trade; Language Specification</cite>.
     *
     * @return  a string that has the same contents as this string, but is
     *          guaranteed to be from a pool of unique strings.
     */
    public native String intern();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值