JVM学习分享-练习题
2019-09-23 08:48:22来源:博客园 阅读 ()
JVM学习分享-练习题
package org.fenixsoft.clazz;
public class TestClass {
private int m;
public int inc() {
return m + 1;
}
}
//----------- javap -verbose TestClass
package zero.desk.metaspace;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
/**
* @author:Zero
* @Description:
* @since 2019/6/11.
* 练习1
* VM Options:-XX:MetaspaceSize=10M -XX:MaxMetaspaceSize=10M
*/
public class MetaspaceOutmemory {
public static void main(String[] args) {
try {
System.out.println("MetaspaceOOM.java");
while (true) {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(OOMObject.class);
enhancer.setUseCache(false);
enhancer.setCallback(
(MethodInterceptor) (obj, method, args1, methodProxy) -> methodProxy.invokeSuper(obj, args1)
);
enhancer.create();
}
} catch (Exception e) {
e.printStackTrace();
}
}
static class OOMObject {
}
}
//------------------
package zero.desk.metaspace;
import java.util.ArrayList;
import java.util.List;
/**
* @author:Zero
* @Description:
* @since 2019/6/11.
* 练习2
* VM Options:-Xmx1M -Xms1M
*/
public class StringOutmemory {
static String base = "string";
public static void main(String[] args) {
try {
Thread.sleep(1000);
List<String> list = new ArrayList<String>();
for (int i = 0; i < Integer.MAX_VALUE; i++) {
String str = base + base;
base = str;
list.add(str.intern());
}
}catch (Exception e) {
e.printStackTrace();
}
}
}
//-------------
package zero.desk.gc;
/**
* @author Zero
* @since 2019-09-08.
* Description:使用默认垃圾收集器,Parallel Scavenge + Parallel Old
* 练习3
* VM Options:-XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -XX:+PrintGCDetails
*/
public class ReferenceCountingGC {
public Object instance = null;
private static final int ONE_MB = 1024 * 1024;
private byte[] bigSize = new byte[2 * ONE_MB];
public static void main(String[] args) throws InterruptedException {
Thread.sleep(1000);
testGC();
Thread.sleep(1000);
}
public static void testGC() {
ReferenceCountingGC objA = new ReferenceCountingGC();
ReferenceCountingGC objB = new ReferenceCountingGC();
objA.instance = objB;
objB.instance = objA;
objA = null;
objB = null;
System.gc();
}
}
//-------------
package zero.desk.gc;
/**
* @author Zero
* @since 2019-09-08.
* Description:使用CMS收集器,ParNew + CMS
* 练习4
* VM Options:-XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:+PrintClassHistogram -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC
*/
public class ReferenceCountingGCOpen {
public Object instance = null;
private static final int ONE_MB = 1024 * 1024;
private byte[] bigSize = new byte[2 * ONE_MB];
public static void main(String[] args) throws InterruptedException {
Thread.sleep(2000);
testGC();
Thread.sleep(1000);
}
public static void testGC() {
ReferenceCountingGCOpen objA = new ReferenceCountingGCOpen();
ReferenceCountingGCOpen objB = new ReferenceCountingGCOpen();
objA.instance = objB;
objB.instance = objA;
objA = null;
objB = null;
System.gc();
}
}
//--------------
package zero.desk.constantpool;
/**
* @author Zero
* @since 2019-09-08.
* Description:
* 练习5
* javap -verbose ConstantPool
*/
public class ConstantPool extends C implements A,B{
private String str = "test string";
private final int a = 10;
private final long b = 10;
private final long bb = 100;
private int c = 11;
private float d = 12f;
private float e = 12f;
private double ee = 12f;
private int m;
public int inc() {
return m + 1;
}
}
原文链接:https://www.cnblogs.com/DeskZero/p/11537520.html
如有疑问请与原作者联系
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
下一篇:线上问题排查神器 Arthas
- 学习Java 8 Stream Api (4) - Stream 终端操作之 collect 2020-06-11
- java学习之第一天 2020-06-11
- JVM常见面试题解析 2020-06-11
- Java学习之第二天 2020-06-11
- Spring WebFlux 学习笔记 - (一) 前传:学习Java 8 Stream Ap 2020-06-11
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash