-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
416 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
java-api/src/java22/java/xyz/wagyourtail/jvmdg/j22/stub/java_base/J_L_Module.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package xyz.wagyourtail.jvmdg.j22.stub.java_base; | ||
|
||
import xyz.wagyourtail.jvmdg.version.Ref; | ||
import xyz.wagyourtail.jvmdg.version.Stub; | ||
|
||
public class J_L_Module { | ||
@Stub(ref = @Ref("java/lang/Module")) | ||
public static boolean isNativeAccessEnabled(Module module) { | ||
return true; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
java-api/src/java9/java/xyz/wagyourtail/jvmdg/j9/intl/module/ModuleConstantHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package xyz.wagyourtail.jvmdg.j9.intl.module; | ||
|
||
import xyz.wagyourtail.jvmdg.j9.stub.java_base.J_L_M_ModuleDescriptor; | ||
import xyz.wagyourtail.jvmdg.j9.stub.java_base.J_L_Module; | ||
import xyz.wagyourtail.jvmdg.j9.stub.java_base.J_L_ModuleLayer; | ||
|
||
import java.util.*; | ||
|
||
public class ModuleConstantHelper { | ||
private static final Map<String, J_L_Module> MODULES = new HashMap<>(); | ||
private static final Map<String, J_L_Module> MODULES_FROM_PACKAGE = new HashMap<>(); | ||
private static final ClassLoader ORIGINAL_SYSTEM_CLASS_LOADER = ClassLoader.getSystemClassLoader(); | ||
public static final J_L_ModuleLayer BOOT_LAYER = | ||
// Note: This field is in this class as it's initialization is execution order sensitive as it need | ||
// to be loaded after "MODULES" HashMap is initialized, but before initializing any boot "Module" | ||
new J_L_ModuleLayer(Collections.emptyList(), MODULES); | ||
|
||
static { | ||
// TODO: Auto generate this data in a separate "ModuleConstants" class | ||
registerBootModule("java.base", "java.io", "java.lang", "java.math", | ||
"java.net", "java.nio", "java.security", "java.text", "java.time", "java.util", | ||
"javax.crypto", "javax.net", "javax.security"); | ||
registerBootModule("java.logging", "java.util.logging"); | ||
registerBootModule("java.net.http", "java.net.http"); | ||
registerBootModule("jdk.httpserver", "com.sun.net.httpserver"); | ||
registerBootModule("jdk.jfr", "jdk.jfr"); | ||
} | ||
|
||
private static void registerBootModule(String name, String... packages) { | ||
J_L_M_ModuleDescriptor descriptor = new J_L_M_ModuleDescriptor.Builder(name, false, Collections.emptySet()) | ||
.packages(new HashSet<>(Arrays.asList(packages))).build(); | ||
J_L_Module module = new J_L_Module(ORIGINAL_SYSTEM_CLASS_LOADER, BOOT_LAYER, descriptor); | ||
MODULES.put(name, module); | ||
for (String packageName : packages) { | ||
MODULES_FROM_PACKAGE.put(packageName, module); | ||
} | ||
} | ||
|
||
public static J_L_Module bootModuleFromClass(Class<?> clazz) { | ||
boolean bootClassLoader; | ||
if ((bootClassLoader = clazz.getClassLoader() == null) || | ||
clazz.getClassLoader() == ORIGINAL_SYSTEM_CLASS_LOADER) { | ||
J_L_Module module = bootModuleFromClassName(clazz.getName()); | ||
// Unnamed modules must have a class loader | ||
// but on java8, the boot class loader is null | ||
// Making Object.class.getClassLoader() return null on java8 | ||
if (module == null && bootClassLoader) { | ||
return MODULES.get("java.base"); | ||
} | ||
return module; | ||
} | ||
return null; | ||
} | ||
|
||
// Return null to make JvmDowngrader use | ||
public static J_L_Module bootModuleFromClassName(String className) { | ||
String packageName = className; | ||
while (true) { | ||
int pkgEnd = packageName.lastIndexOf('.'); | ||
if (pkgEnd == -1) return null; | ||
packageName = packageName.substring(0, pkgEnd); | ||
J_L_Module module = MODULES_FROM_PACKAGE.get(packageName); | ||
if (module != null) return module; | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
java-api/src/java9/java/xyz/wagyourtail/jvmdg/j9/intl/module/ModuleFinderImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package xyz.wagyourtail.jvmdg.j9.intl.module; | ||
|
||
import xyz.wagyourtail.jvmdg.j9.stub.java_base.J_L_M_ModuleDescriptor; | ||
import xyz.wagyourtail.jvmdg.j9.stub.java_base.J_L_M_ModuleFinder; | ||
import xyz.wagyourtail.jvmdg.j9.stub.java_base.J_L_M_ModuleReference; | ||
|
||
import java.util.Collections; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
public class ModuleFinderImpl implements J_L_M_ModuleFinder { | ||
public static final ModuleFinderImpl EMPTY = new ModuleFinderImpl(Collections.emptySet()); | ||
private final Set<J_L_M_ModuleReference> moduleReferences; | ||
|
||
public ModuleFinderImpl(Set<J_L_M_ModuleReference> moduleReferences) { | ||
this.moduleReferences = moduleReferences; | ||
} | ||
|
||
@Override | ||
public Optional<J_L_M_ModuleReference> find(String name) { | ||
for (J_L_M_ModuleReference moduleReference : this.moduleReferences) { | ||
J_L_M_ModuleDescriptor descriptor = moduleReference.descriptor(); | ||
if (descriptor != null && descriptor.name().equals(name)) { | ||
return Optional.of(moduleReference); | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public Set<J_L_M_ModuleReference> findAll() { | ||
return this.moduleReferences; | ||
} | ||
} |
18 changes: 4 additions & 14 deletions
18
java-api/src/java9/java/xyz/wagyourtail/jvmdg/j9/stub/java_base/J_L_Class.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...pi/src/java9/java/xyz/wagyourtail/jvmdg/j9/stub/java_base/J_L_IllegalCallerException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package xyz.wagyourtail.jvmdg.j9.stub.java_base; | ||
|
||
import xyz.wagyourtail.jvmdg.version.Adapter; | ||
|
||
@Adapter("java/lang/IllegalCallerException") | ||
public class J_L_IllegalCallerException extends RuntimeException { | ||
public J_L_IllegalCallerException() { | ||
super(); | ||
} | ||
|
||
public J_L_IllegalCallerException(String s) { | ||
super(s); | ||
} | ||
|
||
public J_L_IllegalCallerException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
public J_L_IllegalCallerException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
Oops, something went wrong.