428 // This means a package-private superinterface exist in the unnamed
429 // package of a named module.
430 throw new InternalError("Unnamed package cannot be added to " + module);
431 }
432
433 if (!module.getDescriptor().packages().contains(packageName)) {
434 throw new InternalError(packageName + " not exist in " + module.getName());
435 }
436
437 if (!module.isOpen(packageName, Proxy.class.getModule())) {
438 // Required for default method invocation
439 throw new InternalError(packageName + " not open to " + Proxy.class.getModule());
440 }
441 } else {
442 if (Modifier.isPublic(accessFlags)) {
443 // All proxy superinterfaces are public, must be in named dynamic module
444 throw new InternalError("public proxy in unnamed module: " + module);
445 }
446 }
447
448 if ((accessFlags & ~Modifier.PUBLIC) != 0) {
449 throw new InternalError("proxy access flags must be Modifier.PUBLIC or 0");
450 }
451 }
452 }
453
454 private static Class<?> defineProxyClass(ProxyClassContext context, List<Class<?>> interfaces) {
455 /*
456 * Choose a name for the proxy class to generate.
457 */
458 long num = nextUniqueNumber.getAndIncrement();
459 String proxyName = context.packageName().isEmpty()
460 ? proxyClassNamePrefix + num
461 : context.packageName() + "." + proxyClassNamePrefix + num;
462
463 ClassLoader loader = context.module().getClassLoader();
464 trace(proxyName, context.module(), loader, interfaces);
465
466 /*
467 * Generate the specified proxy class.
468 */
469 byte[] proxyClassFile = ProxyGenerator.generateProxyClass(loader, proxyName, interfaces,
470 context.accessFlags() | Modifier.FINAL);
471 try {
472 Class<?> pc = JLA.defineClass(loader, proxyName, proxyClassFile,
473 null, "__dynamic_proxy__");
474 reverseProxyCache.sub(pc).putIfAbsent(loader, Boolean.TRUE);
475 return pc;
476 } catch (ClassFormatError e) {
477 /*
478 * A ClassFormatError here means that (barring bugs in the
479 * proxy class generation code) there was some other
480 * invalid aspect of the arguments supplied to the proxy
481 * class creation (such as virtual machine limitations
482 * exceeded).
483 */
484 throw new IllegalArgumentException(e.toString());
485 }
486 }
487
488 /**
489 * Test if given class is a class defined by
490 * {@link #defineProxyClass(ProxyClassContext, List)}
|
428 // This means a package-private superinterface exist in the unnamed
429 // package of a named module.
430 throw new InternalError("Unnamed package cannot be added to " + module);
431 }
432
433 if (!module.getDescriptor().packages().contains(packageName)) {
434 throw new InternalError(packageName + " not exist in " + module.getName());
435 }
436
437 if (!module.isOpen(packageName, Proxy.class.getModule())) {
438 // Required for default method invocation
439 throw new InternalError(packageName + " not open to " + Proxy.class.getModule());
440 }
441 } else {
442 if (Modifier.isPublic(accessFlags)) {
443 // All proxy superinterfaces are public, must be in named dynamic module
444 throw new InternalError("public proxy in unnamed module: " + module);
445 }
446 }
447
448 if ((accessFlags & ~(Modifier.PUBLIC | Modifier.IDENTITY)) != 0) {
449 throw new InternalError("proxy access flags must be Modifier.PUBLIC or 0");
450 }
451 }
452 }
453
454 private static Class<?> defineProxyClass(ProxyClassContext context, List<Class<?>> interfaces) {
455 /*
456 * Choose a name for the proxy class to generate.
457 */
458 long num = nextUniqueNumber.getAndIncrement();
459 String proxyName = context.packageName().isEmpty()
460 ? proxyClassNamePrefix + num
461 : context.packageName() + "." + proxyClassNamePrefix + num;
462
463 ClassLoader loader = context.module().getClassLoader();
464 trace(proxyName, context.module(), loader, interfaces);
465
466 /*
467 * Generate the specified proxy class.
468 */
469 byte[] proxyClassFile = ProxyGenerator.generateProxyClass(loader, proxyName, interfaces,
470 context.accessFlags() | Modifier.FINAL | Modifier.IDENTITY);
471 try {
472 Class<?> pc = JLA.defineClass(loader, proxyName, proxyClassFile,
473 null, "__dynamic_proxy__");
474 reverseProxyCache.sub(pc).putIfAbsent(loader, Boolean.TRUE);
475 return pc;
476 } catch (ClassFormatError e) {
477 /*
478 * A ClassFormatError here means that (barring bugs in the
479 * proxy class generation code) there was some other
480 * invalid aspect of the arguments supplied to the proxy
481 * class creation (such as virtual machine limitations
482 * exceeded).
483 */
484 throw new IllegalArgumentException(e.toString());
485 }
486 }
487
488 /**
489 * Test if given class is a class defined by
490 * {@link #defineProxyClass(ProxyClassContext, List)}
|