8295044: Implementation of Foreign Function and Memory API (Second Preview)

Co-authored-by: Jorn Vernee <jvernee@openjdk.org>
Co-authored-by: Per Minborg <pminborg@openjdk.org>
Co-authored-by: Maurizio Cimadamore <mcimadamore@openjdk.org>
Reviewed-by: jvernee, pminborg, psandoz, alanb, sundar
This commit is contained in:
Maurizio Cimadamore 2022-12-05 13:49:53 +00:00
parent bd381886e0
commit 73baadceb6
252 changed files with 9221 additions and 7889 deletions

View file

@ -44,15 +44,17 @@ import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import jdk.internal.javac.PreviewFeature;
import jdk.internal.loader.ClassLoaderValue;
import jdk.internal.loader.Loader;
import jdk.internal.loader.LoaderPool;
import jdk.internal.module.ServicesCatalog;
import jdk.internal.misc.CDS;
import jdk.internal.reflect.CallerSensitive;
import jdk.internal.reflect.Reflection;
import jdk.internal.vm.annotation.Stable;
import sun.security.util.SecurityConstants;
/**
* A layer of modules in the Java virtual machine.
*
@ -297,6 +299,39 @@ public final class ModuleLayer {
source.implAddOpens(pn, target);
return this;
}
/**
* Enables native access for a module in the layer if the caller's module
* has native access.
*
* <p> This method is <a href="foreign/package-summary.html#restricted"><em>restricted</em></a>.
* Restricted methods are unsafe, and, if used incorrectly, their use might crash
* the JVM or, worse, silently result in memory corruption. Thus, clients should refrain
* from depending on restricted methods, and use safe and supported functionalities,
* where possible.
*
* @param target
* The module to update
*
* @return This controller
*
* @throws IllegalArgumentException
* If {@code target} is not in the module layer
*
* @throws IllegalCallerException
* If the caller is in a module that does not have native access enabled
*
* @since 20
*/
@PreviewFeature(feature=PreviewFeature.Feature.FOREIGN)
@CallerSensitive
public Controller enableNativeAccess(Module target) {
ensureInLayer(target);
Reflection.ensureNativeAccess(Reflection.getCallerClass(), Module.class,
"enableNativeAccess");
target.implAddEnableNativeAccess();
return this;
}
}