VisualVM

堆的内存模型

僤鯓⒐⒋嵵緔 提交于 2020-02-26 14:15:28
堆内存模型如下图 堆内存中,分为年轻代,老年代。 new出来的对象,放在堆内存中,具体会放到eden区。 当堆的内存设置为600M时,老年代会占400M内存,年轻代会占200M。而eden区,会占160M内存,整个survivor区占40M。 当程序一直在运行,eden区被占满时,java虚拟机(后台)会执行一个minor gc(也叫young gc)线程,对eden区来执行垃圾收集。 可达性分析算法 GC线程在eden区收集垃圾,会用到可达性分析算法。 将“GC ROOTS”对象作为起点,从这些节点开始向下搜索引用的对象,找到的对象都标记为非垃圾对象,其余未标记的对象都是垃圾对象。 GC Roots根节点:线程栈的本地变量、类方法区中的静态变量、线程栈的本地方法栈的变量等。 GC线程,顺着GC Roots一步一步往下找,能找到的对象,都是有效对象,都会被转移到survivor区域,eden区剩下的对象就是垃圾对象。 对象头: 每个对象,都内存中,都存着自己的对象头信息。 对象的信息头中,会标识它,每经历过一次minor gc,分代年龄就会加一。 第一次做minor gc的时候,会清理eden区域,将非垃圾对象,转移到survivor的From区域中,这些对象在对象头中,会增加自己的分代年龄(对象头中的Age计数器)。 当eden区再次满了之后,gc不但会清理eden区的对象

软帝学院:Java对象大小的计算方式

╄→尐↘猪︶ㄣ 提交于 2020-02-26 00:51:48
Java对象大小的计算方式 首先我们需要知道的是 Java 对象是包含三部分数据的: 1.对象头 2.实例数据 3.对齐填充(可能没有,因为 java 中规定对象的起始地址必须是 8 bytes 的正数倍) 对于普通对象而言,对象头中包括 mark word(8 bytes)、kclass(没有开启压缩的时候是 8 bytes,开启压缩了的话,就是 4 bytes),如果是数组类型的对象话,这里还有一个数组长度字段,4字节. 在 JDK6 64位 23 update+ 之后都默认开启了指针压缩功能. 现在验证 java 对象占几个字节. public class Person { int age; } 我使用的是64位jdk1.8,按照理论分析,Person 对象应该占的字节数: 8(mark word) + 4(kclass) + 4(实例数据) + 0(不需要对齐填充) = 16B. 而通过 visualVM 工具查看的结果也是 16B. 现在来分析下数组的内存占用情况. public class ObjectHeaderSizeTest { public static void main(String[] args) { Person[] person = new Person[4]; System.out.println(person); Thread

OQL in VisualVM v1.4.4 - Get A Class's Field Names

◇◆丶佛笑我妖孽 提交于 2020-02-24 07:02:22
问题 I would like to execute an OQL query in VisualVM (v1.4.4) to retrieve the (non-static) field names for an object. The OQL documentation describes heap.findClass(className) . This returns an object which includes a fields property (an array of field names). When I execute the following OQL... heap.findClass('java.io.ByteArrayInputStream').fields; ... it returns an array of 4 field objects ( ByteArrayInputStream has 4 fields - buf , count , mark , and pos - I am assuming these are what are

jvisualvm: Stuck on “Loading Heap Dump” screen

≡放荡痞女 提交于 2020-01-29 21:24:25
问题 I created a heap dump file with hprof using this command: java -agentlib:hprof -cp "..\..\jars\trove.jar;.\bin" com.mysite.MyApp This successfully created the file "java.hprof.txt" which was about 5MB. I then opened up jvisualvm to view this file, and loaded it in. But visualvm appears to be stuck on the loading screen. The screen below has been up for about 10 minutes now. Did I miss a step? Should I have used different options on the command line with hprof? How can I read this heap dump

Nested ArrayList.ParallelStream() in custom ForkJoinPool uses threads unevenly [duplicate]

若如初见. 提交于 2020-01-24 14:19:44
问题 This question already has answers here : Why does stream parallel() not use all available threads? (2 answers) Closed yesterday . I want to use my custom ForkJoinPool to have more parallelism with ArrayList.parallelStream() (by default it uses common pool). I do this: List<String> activities = new ArrayList<>(); for (int i = 0; i < 3000; i++) { activities.add(String.valueOf(i)); } ForkJoinPool pool = new ForkJoinPool(10); pool.submit(() -> activities.parallelStream() .map(s -> { try { System

Nested ArrayList.ParallelStream() in custom ForkJoinPool uses threads unevenly [duplicate]

天涯浪子 提交于 2020-01-24 14:19:17
问题 This question already has answers here : Why does stream parallel() not use all available threads? (2 answers) Closed yesterday . I want to use my custom ForkJoinPool to have more parallelism with ArrayList.parallelStream() (by default it uses common pool). I do this: List<String> activities = new ArrayList<>(); for (int i = 0; i < 3000; i++) { activities.add(String.valueOf(i)); } ForkJoinPool pool = new ForkJoinPool(10); pool.submit(() -> activities.parallelStream() .map(s -> { try { System

Not able to Connect a Remote Host to the VisualVM

风格不统一 提交于 2020-01-11 15:38:41
问题 I am new to Java and I'm facing a problem in connecting a Remote Host to the JVisualVM . I've searched the Internet and followed all the steps mentioned there but still am not able to resolve the issue. The steps I followed are: I started the jstatd on the remote server by first creating a jstatd.all.policy file in the $JAVA_HOME/bin . The file contained: grant codebase "file:${java.home}/../lib/tools.jar" { permission java.security.AllPermission;}; I started the Jstatd as jstatd -J-Djava

Not able to Connect a Remote Host to the VisualVM

萝らか妹 提交于 2020-01-11 15:38:12
问题 I am new to Java and I'm facing a problem in connecting a Remote Host to the JVisualVM . I've searched the Internet and followed all the steps mentioned there but still am not able to resolve the issue. The steps I followed are: I started the jstatd on the remote server by first creating a jstatd.all.policy file in the $JAVA_HOME/bin . The file contained: grant codebase "file:${java.home}/../lib/tools.jar" { permission java.security.AllPermission;}; I started the Jstatd as jstatd -J-Djava

性能优化 = 改改代码?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-10 10:52:28
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 这里是Z哥的个人公众号 每周五11:45 按时送达 当然了,也会时不时加个餐~ 我的第「124」篇原创敬上 大家好,我是Z哥。 好久没写技术文章了,最近正好有进行一些思考,顺手写出来分享给大家。 上了一定规模的系统,特别是To C的系统,性能优化或多或少都会被逼着去做一下。否则,系统便无法支撑业务的发展,技术成了拖后腿,不是引领业务了。 一旦线上出现了性能问题,就会很棘手。因为它和业务功能上的Bug不同,后者的分析和解决思路更清晰,只要日志记录到位,沿着一条已知的业务逻辑线,很容易就能找到问题根源。 而性能问题就会复杂的多,导致的因素有很多,甚至会是多种因素共同作用下的结果。比如,代码质量低下、业务发展太快、架构设计不合理等等。 而且一般情况下,性能问题处理起来比较耗时,涉及到的分析链路可能会很长,特别是自己小组之外的上下游系统,很多人不愿意干,或者说有心无力。最多采用一些临时性的补救手段,碰碰运气。比如,扩容增加机器、重启大招、……。 有些临时性的补救措施,有时候不但不能解决问题,还会埋下新的隐患。 比如,从表象上看到某个程序因为给的资源不足导致产生性能问题。临时增加更多资源给它,可能从表面上看,问题是解决了。但是实则可能是因为程序内部对资源的使用上存在不合理的地方,增加资源只是延缓问题发作的时间

有一天你会明白,有些人不再回来

▼魔方 西西 提交于 2020-01-09 13:17:02
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 1、环境 jdk8、jdk11、go、node 2、数据库 mysql、neo4j、mongodb、redis、elasticsearch 3、开发工具 git、idea、postman、The Unarchiver、FinalShell 4、可视化工具 kibana、navicat、datagrip、redismanager、NoSqlBootstrap for Mongodb、Visual Vm 5、辅助工具 QQ影音、护眼宝、火狐、QQ浏览器、磨刀、百度网盘 6、系统 nacos、rocketmq、rabbitmq、jenkins、docker、 来源: oschina 链接: https://my.oschina.net/mdxlcj/blog/3155251