Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .idea/libraries/ObjectSize.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

944 changes: 0 additions & 944 deletions .idea/workspace.xml

This file was deleted.

1 change: 1 addition & 0 deletions 03_01_JMM.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ https://www.cnblogs.com/z00377750/p/9180644.html
现代CPU的数据一致性实现 = 缓存锁(MESI ...) + 总线锁

读取缓存以cache line为基本单位,目前64bytes
(缓存行可以想到内存对齐的问题,组成原理里的)

位于同一缓存行的两个不同数据,被两个不同CPU锁定,产生互相影响的伪共享问题

Expand Down
12 changes: 0 additions & 12 deletions JVM.iml

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file removed out/production/JVM/com/mashibing/jvm/HeapOOM.class
Binary file not shown.
Binary file removed out/production/JVM/com/mashibing/jvm/Hello.class
Binary file not shown.
Binary file not shown.
Binary file removed out/production/JVM/com/mashibing/jvm/TestGC.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed out/production/JVM/com/mashibing/jvm/cms/Student.class
Binary file not shown.
Binary file removed out/production/JVM/com/mashibing/jvm/cms/Test.class
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;

/**
* 自定义classloader 并加密,防止别人反编译
*/
public class T007_MSBClassLoaderWithEncription extends ClassLoader {

public static int seed = 0B10110110;
Expand Down
3 changes: 3 additions & 0 deletions src/com/mashibing/jvm/c2_classloader/T010_Parent.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.mashibing.jvm.c2_classloader;

/**
* 指定父classloader
*/
public class T010_Parent {
private static T006_MSBClassLoader parent = new T006_MSBClassLoader();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.mashibing.jvm.c2_classloader;

/**
* 本类并未破坏双亲委派
*/
public class T011_ClassReloading1 {
public static void main(String[] args) throws Exception {
T006_MSBClassLoader msbClassLoader = new T006_MSBClassLoader();
Expand Down
30 changes: 23 additions & 7 deletions src/com/mashibing/jvm/c2_classloader/T012_ClassReloading2.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package com.mashibing.jvm.c2_classloader;

import com.mashibing.jvm.Hello;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URL;

/**
* 本类破坏了双亲委派模型
* 打破双亲委派,只能重写loadclass
*/
public class T012_ClassReloading2 {
private static class MyLoader extends ClassLoader {
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException {

File f = new File("C:/work/ijprojects/JVM/out/production/JVM/" + name.replace(".", "/").concat(".class"));

if(!f.exists()) return super.loadClass(name);
String filePath = getCurrentClassPath() + File.separator + name.replaceAll("\\.", File.separator).concat(".class");
File f = new File(filePath);
if (!f.exists()) return super.loadClass(name);

try {

Expand All @@ -32,12 +36,24 @@ public Class<?> loadClass(String name) throws ClassNotFoundException {
}

public static void main(String[] args) throws Exception {
String name = "com.mashibing.jvm.Hello";
MyLoader m = new MyLoader();
Class clazz = m.loadClass("com.mashibing.jvm.Hello");
Class clazz = m.loadClass(name);

m = new MyLoader();
Class clazzNew = m.loadClass("com.mashibing.jvm.Hello");
Class clazzNew = m.loadClass(name);

System.out.println(clazz == clazzNew);
}

private static String getCurrentClassPath() {
URL url = T012_ClassReloading2.class.getClassLoader().getResource("");
File f = null;
try {
f = new File(url.toURI());
} catch (URISyntaxException e) {
e.printStackTrace();
}
return f.getPath();
}
}
8 changes: 4 additions & 4 deletions src/com/mashibing/jvm/c3_jmm/T03_SizeOfAnObject.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.mashibing.jvm.c3_jmm;

import com.mashibing.jvm.agent.ObjectSizeAgent;
//import com.mashibing.jvm.agent.ObjectSizeAgent;

public class T03_SizeOfAnObject {
public static void main(String[] args) {
System.out.println(ObjectSizeAgent.sizeOf(new Object()));
System.out.println(ObjectSizeAgent.sizeOf(new int[] {}));
System.out.println(ObjectSizeAgent.sizeOf(new P()));
// System.out.println(ObjectSizeAgent.sizeOf(new Object()));
// System.out.println(ObjectSizeAgent.sizeOf(new int[] {}));
// System.out.println(ObjectSizeAgent.sizeOf(new P()));
}

//一个Object占多少个字节
Expand Down