8327218: Add an ability to specify modules which should have native access enabled

Co-authored-by: Maurizio Cimadamore <mcimadamore@openjdk.org>
Reviewed-by: mcimadamore, erikj, alanb, ihse
This commit is contained in:
Jan Lahoda 2024-03-08 11:21:24 +00:00
parent d0d4912c3b
commit 27a03e0dc3
9 changed files with 123 additions and 26 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2024, 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
@ -881,6 +881,24 @@ public final class ModuleLayer {
.findAny();
}
/**
* Updates the module with the given {@code name} in this layer
* to allow access to restricted methods.
*
* @param name the name of the module for which the native access
* should be enabled
* @return {@code true} iff the module is present in this layer,
* {@code false} otherwise
*/
boolean addEnableNativeAccess(String name) {
Module m = nameToModule.get(name);
if (m != null) {
m.implAddEnableNativeAccess();
return true;
} else {
return false;
}
}
/**
* Returns the {@code ClassLoader} for the module with the given name. If