|
| 1 | +<!doctype html> |
| 2 | +<!-- |
| 3 | + Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. |
| 4 | + DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 5 | +
|
| 6 | + This code is free software; you can redistribute it and/or modify it |
| 7 | + under the terms of the GNU General Public License version 2 only, as |
| 8 | + published by the Free Software Foundation. Oracle designates this |
| 9 | + particular file as subject to the "Classpath" exception as provided |
| 10 | + by Oracle in the LICENSE file that accompanied this code. |
| 11 | +
|
| 12 | + This code is distributed in the hope that it will be useful, but WITHOUT |
| 13 | + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 15 | + version 2 for more details (a copy is included in the LICENSE file that |
| 16 | + accompanied this code). |
| 17 | +
|
| 18 | + You should have received a copy of the GNU General Public License version |
| 19 | + 2 along with this work; if not, write to the Free Software Foundation, |
| 20 | + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | +
|
| 22 | + Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 23 | + or visit www.oracle.com if you need additional information or have any |
| 24 | + questions. |
| 25 | +--> |
| 26 | +<html lang="en"> |
| 27 | +<head> |
| 28 | + <title>Restricted methods</title> |
| 29 | +</head> |
| 30 | +<body> |
| 31 | +<h1 id="restricted">Restricted methods</h1> |
| 32 | +<p>Various methods in the Java SE API allow Java code to interoperate with resources outside the Java runtime |
| 33 | + in such a way that the runtime cannot prove correct or safe use of the resources. These methods can, |
| 34 | + when used incorrectly, violate the integrity of the Java Virtual Machine, but are conditionally made available |
| 35 | + to users, as they provide essential functionality. They are known as <em>restricted methods</em>.</p> |
| 36 | +<p>Given the potential danger of restricted methods, the Java runtime issues a warning on |
| 37 | + the standard error stream every time a restricted method is invoked. Such warnings can |
| 38 | + be disabled by granting access to restricted methods to selected modules. This can be |
| 39 | + done either via implementation-specific command line options or programmatically, e.g. |
| 40 | + by calling <a href="{@docRoot}/java.base/java/lang/ModuleLayer.Controller.html#enableNativeAccess(java.lang.Module)"><code>ModuleLayer.Controller.enableNativeAccess(java.lang.Module)</code></a>.</p> |
| 41 | +<p>When a restricted method is invoked by <a href="{@docRoot}/../specs/jni/index.html">JNI code</a>, |
| 42 | + or from an <a href="{@docRoot}/java.base/java/lang/foreign/Linker.html#upcallStub(java.lang.invoke.MethodHandle,java.lang.foreign.FunctionDescriptor,java.lang.foreign.Arena,java.lang.foreign.Linker.Option...)">upcall stub</a> |
| 43 | + and there is no caller class on the stack, it is as if the restricted method call occurred in an <em>unnamed module</em>.</p> |
| 44 | +<p>In the reference implementation, access to restricted methods can be granted to |
| 45 | + specific modules using the command line option <code>--enable-native-access=M1,M2, ... Mn</code>, |
| 46 | + where <code>M1</code>, <code>M2</code>, <code>... Mn</code> are module names (for the unnamed module, |
| 47 | + the special value <code>ALL-UNNAMED</code> can be used). Access to restricted methods |
| 48 | + from modules not listed by that option is deemed <em>illegal</em>. Clients can |
| 49 | + control how access to restricted methods is handled, using the command line |
| 50 | + option <code>--illegal-native-access</code>. If this option is not specified, |
| 51 | + illegal access to restricted methods will result in runtime warnings.</p> |
| 52 | +</body> |
| 53 | +</html> |
0 commit comments