< prev index next >

src/java.base/share/classes/jdk/internal/reflect/MethodAccessorGenerator.java

Print this page




 375 
 376         // Methods count and methods
 377         asm.emitShort(NUM_METHODS);
 378 
 379         emitConstructor();
 380         emitInvoke();
 381 
 382         // Additional attributes (none)
 383         asm.emitShort(S0);
 384 
 385         // Load class
 386         vec.trim();
 387         final byte[] bytes = vec.getData();
 388         // Note: the class loader is the only thing that really matters
 389         // here -- it's important to get the generated code into the
 390         // same namespace as the target class. Since the generated code
 391         // is privileged anyway, the protection domain probably doesn't
 392         // matter.
 393         return AccessController.doPrivileged(
 394             new PrivilegedAction<MagicAccessorImpl>() {

 395                 public MagicAccessorImpl run() {
 396                         try {
 397                         return (MagicAccessorImpl)
 398                         ClassDefiner.defineClass
 399                                 (generatedName,
 400                                  bytes,
 401                                  0,
 402                                  bytes.length,
 403                                  declaringClass.getClassLoader()).newInstance();
 404                         } catch (InstantiationException | IllegalAccessException e) {
 405                             throw new InternalError(e);
 406                         }
 407                     }
 408                 });
 409     }
 410 
 411     /** This emits the code for either invoke() or newInstance() */
 412     private void emitInvoke() {
 413         // NOTE that this code will only handle 65535 parameters since we
 414         // use the sipush instruction to get the array index on the




 375 
 376         // Methods count and methods
 377         asm.emitShort(NUM_METHODS);
 378 
 379         emitConstructor();
 380         emitInvoke();
 381 
 382         // Additional attributes (none)
 383         asm.emitShort(S0);
 384 
 385         // Load class
 386         vec.trim();
 387         final byte[] bytes = vec.getData();
 388         // Note: the class loader is the only thing that really matters
 389         // here -- it's important to get the generated code into the
 390         // same namespace as the target class. Since the generated code
 391         // is privileged anyway, the protection domain probably doesn't
 392         // matter.
 393         return AccessController.doPrivileged(
 394             new PrivilegedAction<MagicAccessorImpl>() {
 395                 @SuppressWarnings("deprecation") // Class.newInstance
 396                 public MagicAccessorImpl run() {
 397                         try {
 398                         return (MagicAccessorImpl)
 399                         ClassDefiner.defineClass
 400                                 (generatedName,
 401                                  bytes,
 402                                  0,
 403                                  bytes.length,
 404                                  declaringClass.getClassLoader()).newInstance();
 405                         } catch (InstantiationException | IllegalAccessException e) {
 406                             throw new InternalError(e);
 407                         }
 408                     }
 409                 });
 410     }
 411 
 412     /** This emits the code for either invoke() or newInstance() */
 413     private void emitInvoke() {
 414         // NOTE that this code will only handle 65535 parameters since we
 415         // use the sipush instruction to get the array index on the


< prev index next >