--- a/nashorn/src/jdk/internal/dynalink/support/LinkerServicesImpl.java Thu Jan 30 19:28:40 2014 +0530
+++ b/nashorn/src/jdk/internal/dynalink/support/LinkerServicesImpl.java Thu Jan 30 20:13:27 2014 +0100
@@ -98,6 +98,9 @@
*/
public class LinkerServicesImpl implements LinkerServices {
+ private static final RuntimePermission GET_CURRENT_LINK_REQUEST = new RuntimePermission("dynalink.getCurrentLinkRequest");
+ private static final ThreadLocal<LinkRequest> threadLinkRequest = new ThreadLocal<>();
+
private final TypeConverterFactory typeConverterFactory;
private final GuardingDynamicLinker topLevelLinker;
@@ -135,6 +138,26 @@
@Override
public GuardedInvocation getGuardedInvocation(LinkRequest linkRequest) throws Exception {
- return topLevelLinker.getGuardedInvocation(linkRequest, this);
+ final LinkRequest prevLinkRequest = threadLinkRequest.get();
+ threadLinkRequest.set(linkRequest);
+ try {
+ return topLevelLinker.getGuardedInvocation(linkRequest, this);
+ } finally {
+ threadLinkRequest.set(prevLinkRequest);
+ }
+ }
+
+ /**
+ * Returns the currently processed link request, or null if the method is invoked outside of the linking process.
+ * @return the currently processed link request, or null.
+ * @throws SecurityException if the calling code doesn't have the {@code "dynalink.getCurrentLinkRequest"} runtime
+ * permission.
+ */
+ public static LinkRequest getCurrentLinkRequest() {
+ SecurityManager sm = System.getSecurityManager();
+ if(sm != null) {
+ sm.checkPermission(GET_CURRENT_LINK_REQUEST);
+ }
+ return threadLinkRequest.get();
}
}