-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to access language classes
- Loading branch information
Showing
6 changed files
with
93 additions
and
7 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
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
52 changes: 52 additions & 0 deletions
52
src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/util/ReflectionUtils.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,52 @@ | ||
/* | ||
* Copyright (c) 2022 Software Architecture Group, Hasso Plattner Institute | ||
* Copyright (c) 2022 Oracle and/or its affiliates | ||
* | ||
* Licensed under the MIT License. | ||
*/ | ||
package de.hpi.swa.trufflesqueak.util; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import jdk.internal.module.Modules; | ||
|
||
public final class ReflectionUtils { | ||
public static Method lookupMethod(final Class<?> declaringClass, final String methodName, final Class<?>... parameterTypes) { | ||
try { | ||
final Method result = declaringClass.getDeclaredMethod(methodName, parameterTypes); | ||
openModule(declaringClass); | ||
result.setAccessible(true); | ||
return result; | ||
} catch (final ReflectiveOperationException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
/** | ||
* Ensure that this class is allowed to call setAccessible for an element of the provided | ||
* declaring class. | ||
*/ | ||
private static void openModule(final Class<?> declaringClass) { | ||
openModuleByClass(declaringClass, ReflectionUtils.class); | ||
} | ||
|
||
private static void openModuleByClass(final Class<?> declaringClass, final Class<?> accessingClass) { | ||
final Module declaringModule = declaringClass.getModule(); | ||
final String packageName = declaringClass.getPackageName(); | ||
Module namedAccessingModule = null; | ||
if (accessingClass != null) { | ||
final Module accessingModule = accessingClass.getModule(); | ||
if (accessingModule.isNamed()) { | ||
namedAccessingModule = accessingModule; | ||
} | ||
} | ||
if (namedAccessingModule != null ? declaringModule.isOpen(packageName, namedAccessingModule) : declaringModule.isOpen(packageName)) { | ||
return; | ||
} | ||
if (namedAccessingModule != null) { | ||
Modules.addOpens(declaringModule, packageName, namedAccessingModule); | ||
} else { | ||
Modules.addOpensToAllUnnamed(declaringModule, packageName); | ||
} | ||
} | ||
} |
Submodule image
updated
5 files
e1296bf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performance Report (e1296bf)
Benchmarks ran on
graalvm-ce-java11-22.0.0.2
.Steady (after 50 iterations)
Warmup (first 50 iterations)