mirror of
https://github.com/FranzHaidnor/haidnorJVM.git
synced 2026-03-22 04:23:41 +08:00
update Main
This commit is contained in:
@@ -35,12 +35,12 @@ public class Main {
|
|||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
if (cmd.hasOption("class")) {
|
if (cmd.hasOption("class")) {
|
||||||
|
JvmThreadHolder.set(new JvmThread());
|
||||||
String path = cmd.getOptionValue("class");
|
String path = cmd.getOptionValue("class");
|
||||||
ClassLoader bootClassLoader = new ClassLoader("ApplicationClassLoader");
|
ClassLoader bootClassLoader = new ClassLoader("ApplicationClassLoader");
|
||||||
Klass mainMeteKlass = bootClassLoader.loadClassWithAbsolutePath(path);
|
Klass mainMeteKlass = bootClassLoader.loadClassWithAbsolutePath(path);
|
||||||
KlassMethod mainKlassMethod = JavaClassUtil.getMainMethod(mainMeteKlass);
|
KlassMethod mainKlassMethod = JavaClassUtil.getMainMethod(mainMeteKlass);
|
||||||
Metaspace.registerJavaClass(mainMeteKlass);
|
Metaspace.registerJavaClass(mainMeteKlass);
|
||||||
JvmThreadHolder.set(new JvmThread());
|
|
||||||
|
|
||||||
JavaExecutionEngine.callMainStaticMethod(mainKlassMethod);
|
JavaExecutionEngine.callMainStaticMethod(mainKlassMethod);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,11 +22,11 @@ public class TestJVM {
|
|||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static void runMainClass(java.lang.Class<?> mainClass) {
|
public static void runMainClass(java.lang.Class<?> mainClass) {
|
||||||
|
JvmThreadHolder.set(new JvmThread());
|
||||||
ClassLoader bootClassLoader = new ClassLoader("ApplicationClassLoader");
|
ClassLoader bootClassLoader = new ClassLoader("ApplicationClassLoader");
|
||||||
Klass mainMeteKlass = bootClassLoader.loadClass(mainClass.getName().replace('.', '/'));
|
Klass mainMeteKlass = bootClassLoader.loadClass(mainClass.getName().replace('.', '/'));
|
||||||
KlassMethod mainKlassMethod = JavaClassUtil.getMainMethod(mainMeteKlass);
|
KlassMethod mainKlassMethod = JavaClassUtil.getMainMethod(mainMeteKlass);
|
||||||
Metaspace.registerJavaClass(mainMeteKlass);
|
Metaspace.registerJavaClass(mainMeteKlass);
|
||||||
JvmThreadHolder.set(new JvmThread());
|
|
||||||
|
|
||||||
JavaExecutionEngine.callMainStaticMethod(mainKlassMethod);
|
JavaExecutionEngine.callMainStaticMethod(mainKlassMethod);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,10 @@ package haidnor.jvm.test.demo;
|
|||||||
|
|
||||||
public class Demo5 {
|
public class Demo5 {
|
||||||
|
|
||||||
|
static {
|
||||||
|
System.out.println("hello,world");
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
String str = method1("hello world");
|
String str = method1("hello world");
|
||||||
method1(str);
|
method1(str);
|
||||||
|
|||||||
Reference in New Issue
Block a user