255 if (loader == null && name.equals("java.base")) {
256 return ModuleLayer.boot();
257 }
258 }
259 return null;
260 }
261
262 /**
263 * Update this module to allow access to restricted methods.
264 */
265 Module implAddEnableNativeAccess() {
266 EnableNativeAccess.trySetEnableNativeAccess(this);
267 return this;
268 }
269
270 /**
271 * Returns {@code true} if this module can access
272 * <a href="foreign/package-summary.html#restricted"><em>restricted</em></a> methods.
273 *
274 * @return {@code true} if this module can access <em>restricted</em> methods.
275 * @since 20
276 */
277 @PreviewFeature(feature = PreviewFeature.Feature.FOREIGN)
278 public boolean isNativeAccessEnabled() {
279 Module target = moduleForNativeAccess();
280 return EnableNativeAccess.isNativeAccessEnabled(target);
281 }
282
283 /**
284 * This class is used to be able to bootstrap without using Unsafe
285 * in the outer Module class as that would create a circular initializer dependency.
286 */
287 private static final class EnableNativeAccess {
288
289 private EnableNativeAccess() {}
290
291 private static final Unsafe UNSAFE = Unsafe.getUnsafe();
292 private static final long FIELD_OFFSET = UNSAFE.objectFieldOffset(Module.class, "enableNativeAccess");
293
294 private static boolean isNativeAccessEnabled(Module target) {
295 return UNSAFE.getBooleanVolatile(target, FIELD_OFFSET);
296 }
297
|
255 if (loader == null && name.equals("java.base")) {
256 return ModuleLayer.boot();
257 }
258 }
259 return null;
260 }
261
262 /**
263 * Update this module to allow access to restricted methods.
264 */
265 Module implAddEnableNativeAccess() {
266 EnableNativeAccess.trySetEnableNativeAccess(this);
267 return this;
268 }
269
270 /**
271 * Returns {@code true} if this module can access
272 * <a href="foreign/package-summary.html#restricted"><em>restricted</em></a> methods.
273 *
274 * @return {@code true} if this module can access <em>restricted</em> methods.
275 * @since 22
276 */
277 public boolean isNativeAccessEnabled() {
278 Module target = moduleForNativeAccess();
279 return EnableNativeAccess.isNativeAccessEnabled(target);
280 }
281
282 /**
283 * This class is used to be able to bootstrap without using Unsafe
284 * in the outer Module class as that would create a circular initializer dependency.
285 */
286 private static final class EnableNativeAccess {
287
288 private EnableNativeAccess() {}
289
290 private static final Unsafe UNSAFE = Unsafe.getUnsafe();
291 private static final long FIELD_OFFSET = UNSAFE.objectFieldOffset(Module.class, "enableNativeAccess");
292
293 private static boolean isNativeAccessEnabled(Module target) {
294 return UNSAFE.getBooleanVolatile(target, FIELD_OFFSET);
295 }
296
|