182 throw new AssertionError();
183 }
184 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
185 for (int i = 0; i < methods.length; i++) {
186 if (method.equals(methods[i]))
187 return vaTargets[i].invokeExact(args);
188 }
189 if (method.getDeclaringClass() == WrapperInstance.class)
190 return getArg(method.getName());
191 if (isObjectMethod(method))
192 return callObjectMethod(proxy, method, args);
193 throw newInternalError("bad proxy method: "+method);
194 }
195 };
196
197 final Object proxy;
198 if (System.getSecurityManager() != null) {
199 // sun.invoke.WrapperInstance is a restricted interface not accessible
200 // by any non-null class loader.
201 final ClassLoader loader = proxyLoader;
202 proxy = AccessController.doPrivileged(new PrivilegedAction<Object>() {
203 public Object run() {
204 return Proxy.newProxyInstance(
205 loader,
206 new Class<?>[]{ intfc, WrapperInstance.class },
207 ih);
208 }
209 });
210 } else {
211 proxy = Proxy.newProxyInstance(proxyLoader,
212 new Class<?>[]{ intfc, WrapperInstance.class },
213 ih);
214 }
215 return intfc.cast(proxy);
216 }
217
218 private static MethodHandle bindCaller(MethodHandle target, Class<?> hostClass) {
219 MethodHandle cbmh = MethodHandleImpl.bindCaller(target, hostClass);
220 if (target.isVarargsCollector()) {
221 MethodType type = cbmh.type();
222 int arity = type.parameterCount();
|
182 throw new AssertionError();
183 }
184 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
185 for (int i = 0; i < methods.length; i++) {
186 if (method.equals(methods[i]))
187 return vaTargets[i].invokeExact(args);
188 }
189 if (method.getDeclaringClass() == WrapperInstance.class)
190 return getArg(method.getName());
191 if (isObjectMethod(method))
192 return callObjectMethod(proxy, method, args);
193 throw newInternalError("bad proxy method: "+method);
194 }
195 };
196
197 final Object proxy;
198 if (System.getSecurityManager() != null) {
199 // sun.invoke.WrapperInstance is a restricted interface not accessible
200 // by any non-null class loader.
201 final ClassLoader loader = proxyLoader;
202 proxy = AccessController.doPrivileged(new PrivilegedAction<>() {
203 public Object run() {
204 return Proxy.newProxyInstance(
205 loader,
206 new Class<?>[]{ intfc, WrapperInstance.class },
207 ih);
208 }
209 });
210 } else {
211 proxy = Proxy.newProxyInstance(proxyLoader,
212 new Class<?>[]{ intfc, WrapperInstance.class },
213 ih);
214 }
215 return intfc.cast(proxy);
216 }
217
218 private static MethodHandle bindCaller(MethodHandle target, Class<?> hostClass) {
219 MethodHandle cbmh = MethodHandleImpl.bindCaller(target, hostClass);
220 if (target.isVarargsCollector()) {
221 MethodType type = cbmh.type();
222 int arity = type.parameterCount();
|