8264774: Implementation of Foreign Function and Memory API (Incubator)

Co-authored-by: Paul Sandoz <psandoz@openjdk.org>
Co-authored-by: Jorn Vernee <jvernee@openjdk.org>
Co-authored-by: Vladimir Ivanov <vlivanov@openjdk.org>
Co-authored-by: Athijegannathan Sundararajan <sundar@openjdk.org>
Co-authored-by: Chris Hegarty <chegar@openjdk.org>
Reviewed-by: psandoz, chegar, mchung, vlivanov
This commit is contained in:
Maurizio Cimadamore 2021-06-02 10:53:06 +00:00
parent 71425ddfb4
commit a223189b06
219 changed files with 10936 additions and 5695 deletions

View file

@ -109,6 +109,8 @@ public final class Module implements AnnotatedElement {
// the module descriptor
private final ModuleDescriptor descriptor;
// true, if this module allows restricted native access
private volatile boolean enableNativeAccess;
/**
* Creates a new named Module. The resulting Module will be defined to the
@ -133,6 +135,10 @@ public final class Module implements AnnotatedElement {
String loc = Objects.toString(uri, null);
Object[] packages = descriptor.packages().toArray();
defineModule0(this, isOpen, vs, loc, packages);
if (loader == null || loader == ClassLoaders.platformClassLoader()) {
// boot/builtin modules are always native
implAddEnableNativeAccess();
}
}
@ -244,6 +250,30 @@ public final class Module implements AnnotatedElement {
return null;
}
/**
* Update this module to allow access to restricted methods.
*/
Module implAddEnableNativeAccess() {
enableNativeAccess = true;
return this;
}
/**
* Update all unnamed modules to allow access to restricted methods.
*/
static void implAddEnableNativeAccessAllUnnamed() {
ALL_UNNAMED_MODULE.enableNativeAccess = true;
}
/**
* Returns true if module m can access restricted methods.
*/
boolean implIsEnableNativeAccess() {
return isNamed() ?
enableNativeAccess :
ALL_UNNAMED_MODULE.enableNativeAccess;
}
// --
// special Module to mean "all unnamed modules"

View file

@ -62,7 +62,6 @@ import java.util.Set;
import java.util.function.Supplier;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Stream;
import jdk.internal.misc.Unsafe;
import jdk.internal.util.StaticProperty;
import jdk.internal.module.ModuleBootstrap;
@ -2274,6 +2273,15 @@ public final class System {
public boolean isReflectivelyOpened(Module m, String pn, Module other) {
return m.isReflectivelyOpened(pn, other);
}
public Module addEnableNativeAccess(Module m) {
return m.implAddEnableNativeAccess();
}
public void addEnableNativeAccessAllUnnamed() {
Module.implAddEnableNativeAccessAllUnnamed();
}
public boolean isEnableNativeAccess(Module m) {
return m.implIsEnableNativeAccess();
}
public ServicesCatalog getServicesCatalog(ModuleLayer layer) {
return layer.getServicesCatalog();
}

View file

@ -1467,6 +1467,11 @@ abstract class MethodHandleImpl {
return GenerateJLIClassesHelper.generateHolderClasses(traces);
}
@Override
public void ensureCustomized(MethodHandle mh) {
mh.customize();
}
@Override
public VarHandle memoryAccessVarHandle(Class<?> carrier, boolean skipAlignmentMaskCheck, long alignmentMask,
ByteOrder order) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -58,7 +58,7 @@ import static java.lang.invoke.MethodHandleStatics.newInternalError;
throw new IllegalArgumentException("Type must only contain primitives: " + type);
if (type != fallback.type())
throw new IllegalArgumentException("Type of fallback must match");
throw new IllegalArgumentException("Type of fallback must match: " + type + " != " + fallback.type());
LambdaForm lform = preparedLambdaForm(type);
return new NativeMethodHandle(type, lform, fallback, nep);