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
55 changes: 55 additions & 0 deletions XlassLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package jvm;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.Method;

public class XlassLoader extends ClassLoader {
public static void main(String[] args) throws Exception {
// 类名和方法名
String className = "Hello";
String methodName = "hello";

ClassLoader classLoader = new XlassLoader();

Class<?> aClass = classLoader.loadClass(className);

// for (Method m : aClass.getMethods()) {
// System.out.println(m.getName());
// }

// 创建对象
Object obj = aClass.getDeclaredConstructor().newInstance();

// 调用方法
Method method = aClass.getMethod(methodName);
method.invoke(obj);
}

@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
try (FileInputStream input = new FileInputStream("E:\\IdeaProjects\\geektime-java\\out\\production\\geektime-java\\resource\\Hello.xlass")) {
int len = input.available();
byte[] bytes = new byte[len];
input.read(bytes);
// 按字节转换xlass
byte[] classBytes = decode(bytes);
return defineClass(name, classBytes, 0, classBytes.length);
} catch (IOException e) {
throw new ClassNotFoundException(name, e);
}
}

private byte[] decode(byte[] bytes) {
int len = bytes.length;
byte[] targetBytes = new byte[len];
for (int i = 0; i < len; i++) {
targetBytes[i] = (byte) (0b11111111 ^ bytes[i]);
}
return targetBytes;
}


}
Binary file added java内存关系.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 不同GC的分析.docx
Binary file not shown.