src/jdk/internal/dynalink/support/LinkerServicesImpl.java

changeset 719
11b83c913cca
parent 101
f8221ce53c2e
child 952
6d5471a497fb
child 962
ac62e33a99b0
equal deleted inserted replaced
718:c59fb10cb0b5 719:11b83c913cca
96 * 96 *
97 * @author Attila Szegedi 97 * @author Attila Szegedi
98 */ 98 */
99 public class LinkerServicesImpl implements LinkerServices { 99 public class LinkerServicesImpl implements LinkerServices {
100 100
101 private static final RuntimePermission GET_CURRENT_LINK_REQUEST = new RuntimePermission("dynalink.getCurrentLinkRequest");
102 private static final ThreadLocal<LinkRequest> threadLinkRequest = new ThreadLocal<>();
103
101 private final TypeConverterFactory typeConverterFactory; 104 private final TypeConverterFactory typeConverterFactory;
102 private final GuardingDynamicLinker topLevelLinker; 105 private final GuardingDynamicLinker topLevelLinker;
103 106
104 /** 107 /**
105 * Creates a new linker services object. 108 * Creates a new linker services object.
133 return typeConverterFactory.compareConversion(sourceType, targetType1, targetType2); 136 return typeConverterFactory.compareConversion(sourceType, targetType1, targetType2);
134 } 137 }
135 138
136 @Override 139 @Override
137 public GuardedInvocation getGuardedInvocation(LinkRequest linkRequest) throws Exception { 140 public GuardedInvocation getGuardedInvocation(LinkRequest linkRequest) throws Exception {
138 return topLevelLinker.getGuardedInvocation(linkRequest, this); 141 final LinkRequest prevLinkRequest = threadLinkRequest.get();
142 threadLinkRequest.set(linkRequest);
143 try {
144 return topLevelLinker.getGuardedInvocation(linkRequest, this);
145 } finally {
146 threadLinkRequest.set(prevLinkRequest);
147 }
148 }
149
150 /**
151 * Returns the currently processed link request, or null if the method is invoked outside of the linking process.
152 * @return the currently processed link request, or null.
153 * @throws SecurityException if the calling code doesn't have the {@code "dynalink.getCurrentLinkRequest"} runtime
154 * permission.
155 */
156 public static LinkRequest getCurrentLinkRequest() {
157 SecurityManager sm = System.getSecurityManager();
158 if(sm != null) {
159 sm.checkPermission(GET_CURRENT_LINK_REQUEST);
160 }
161 return threadLinkRequest.get();
139 } 162 }
140 } 163 }

mercurial