equal
deleted
inserted
replaced
37 import java.util.Map; |
37 import java.util.Map; |
38 import java.util.Objects; |
38 import java.util.Objects; |
39 import java.util.Set; |
39 import java.util.Set; |
40 import java.util.concurrent.atomic.AtomicInteger; |
40 import java.util.concurrent.atomic.AtomicInteger; |
41 import java.util.concurrent.atomic.AtomicLong; |
41 import java.util.concurrent.atomic.AtomicLong; |
42 import java.util.stream.Collectors; |
|
43 import java.util.stream.Stream; |
|
44 |
42 |
45 import jdk.internal.loader.BootLoader; |
43 import jdk.internal.loader.BootLoader; |
|
44 import jdk.internal.misc.JavaLangAccess; |
|
45 import jdk.internal.misc.SharedSecrets; |
46 import jdk.internal.module.Modules; |
46 import jdk.internal.module.Modules; |
47 import jdk.internal.misc.Unsafe; |
|
48 import jdk.internal.misc.VM; |
47 import jdk.internal.misc.VM; |
49 import jdk.internal.reflect.CallerSensitive; |
48 import jdk.internal.reflect.CallerSensitive; |
50 import jdk.internal.reflect.Reflection; |
49 import jdk.internal.reflect.Reflection; |
51 import jdk.internal.loader.ClassLoaderValue; |
50 import jdk.internal.loader.ClassLoaderValue; |
52 import sun.reflect.misc.ReflectUtil; |
51 import sun.reflect.misc.ReflectUtil; |
466 * If the module is not specified in this ProxyBuilder constructor, |
465 * If the module is not specified in this ProxyBuilder constructor, |
467 * it will map from the given loader and interfaces to the module |
466 * it will map from the given loader and interfaces to the module |
468 * in which the proxy class will be defined. |
467 * in which the proxy class will be defined. |
469 */ |
468 */ |
470 private static final class ProxyBuilder { |
469 private static final class ProxyBuilder { |
471 private static final Unsafe UNSAFE = Unsafe.getUnsafe(); |
470 private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess(); |
472 |
471 |
473 // prefix for all proxy class names |
472 // prefix for all proxy class names |
474 private static final String proxyClassNamePrefix = "$Proxy"; |
473 private static final String proxyClassNamePrefix = "$Proxy"; |
475 |
474 |
476 // next number to use for generation of unique proxy class names |
475 // next number to use for generation of unique proxy class names |
533 * Generate the specified proxy class. |
532 * Generate the specified proxy class. |
534 */ |
533 */ |
535 byte[] proxyClassFile = ProxyGenerator.generateProxyClass( |
534 byte[] proxyClassFile = ProxyGenerator.generateProxyClass( |
536 proxyName, interfaces.toArray(EMPTY_CLASS_ARRAY), accessFlags); |
535 proxyName, interfaces.toArray(EMPTY_CLASS_ARRAY), accessFlags); |
537 try { |
536 try { |
538 Class<?> pc = UNSAFE.defineClass(proxyName, proxyClassFile, |
537 Class<?> pc = JLA.defineClass(loader, proxyName, proxyClassFile, |
539 0, proxyClassFile.length, |
538 null, "__dynamic_proxy__"); |
540 loader, null); |
|
541 reverseProxyCache.sub(pc).putIfAbsent(loader, Boolean.TRUE); |
539 reverseProxyCache.sub(pc).putIfAbsent(loader, Boolean.TRUE); |
542 return pc; |
540 return pc; |
543 } catch (ClassFormatError e) { |
541 } catch (ClassFormatError e) { |
544 /* |
542 /* |
545 * A ClassFormatError here means that (barring bugs in the |
543 * A ClassFormatError here means that (barring bugs in the |