src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File jdk Sdiff src/java.base/share/classes/java/lang/invoke

src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java

Print this page


   1 /*
   2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 269 
 270     /**
 271      * Extract the MemberName of a newly-defined method.
 272      */
 273     private MemberName loadMethod(byte[] classFile) {
 274         Class<?> invokerClass = loadAndInitializeInvokerClass(classFile, cpPatches(classFile));
 275         return resolveInvokerMember(invokerClass, invokerName, invokerType);
 276     }
 277 
 278     /**
 279      * Define a given class as anonymous class in the runtime system.
 280      */
 281     private static Class<?> loadAndInitializeInvokerClass(byte[] classBytes, Object[] patches) {
 282         Class<?> invokerClass = UNSAFE.defineAnonymousClass(HOST_CLASS, classBytes, patches);
 283         UNSAFE.ensureClassInitialized(invokerClass);  // Make sure the class is initialized; VM might complain.
 284         return invokerClass;
 285     }
 286 
 287     private static MemberName resolveInvokerMember(Class<?> invokerClass, String name, MethodType type) {
 288         MemberName member = new MemberName(invokerClass, name, type, REF_invokeStatic);
 289         //System.out.println("resolveInvokerMember => "+member);
 290         //for (Method m : invokerClass.getDeclaredMethods())  System.out.println("  "+m);
 291         try {
 292             member = MEMBERNAME_FACTORY.resolveOrFail(REF_invokeStatic, member, HOST_CLASS, ReflectiveOperationException.class);
 293         } catch (ReflectiveOperationException e) {
 294             throw newInternalError(e);
 295         }
 296         //System.out.println("resolveInvokerMember => "+member);
 297         return member;
 298     }
 299 
 300     /**
 301      * Set up class file generation.
 302      */
 303     private void classFilePrologue() {
 304         final int NOT_ACC_PUBLIC = 0;  // not ACC_PUBLIC
 305         cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
 306         cw.visit(Opcodes.V1_8, NOT_ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER, className, null, superName, null);
 307         cw.visitSource(sourceFile, null);
 308 
 309         String invokerDesc = invokerType.toMethodDescriptorString();
 310         mv = cw.visitMethod(Opcodes.ACC_STATIC, invokerName, invokerDesc, null, null);
 311     }
 312 
 313     /**
 314      * Tear down class file generation.
 315      */
 316     private void classFileEpilogue() {


   1 /*
   2  * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 269 
 270     /**
 271      * Extract the MemberName of a newly-defined method.
 272      */
 273     private MemberName loadMethod(byte[] classFile) {
 274         Class<?> invokerClass = loadAndInitializeInvokerClass(classFile, cpPatches(classFile));
 275         return resolveInvokerMember(invokerClass, invokerName, invokerType);
 276     }
 277 
 278     /**
 279      * Define a given class as anonymous class in the runtime system.
 280      */
 281     private static Class<?> loadAndInitializeInvokerClass(byte[] classBytes, Object[] patches) {
 282         Class<?> invokerClass = UNSAFE.defineAnonymousClass(HOST_CLASS, classBytes, patches);
 283         UNSAFE.ensureClassInitialized(invokerClass);  // Make sure the class is initialized; VM might complain.
 284         return invokerClass;
 285     }
 286 
 287     private static MemberName resolveInvokerMember(Class<?> invokerClass, String name, MethodType type) {
 288         MemberName member = new MemberName(invokerClass, name, type, REF_invokeStatic);


 289         try {
 290             member = MEMBERNAME_FACTORY.resolveOrFail(REF_invokeStatic, member, HOST_CLASS, ReflectiveOperationException.class);
 291         } catch (ReflectiveOperationException e) {
 292             throw newInternalError(e);
 293         }

 294         return member;
 295     }
 296 
 297     /**
 298      * Set up class file generation.
 299      */
 300     private void classFilePrologue() {
 301         final int NOT_ACC_PUBLIC = 0;  // not ACC_PUBLIC
 302         cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
 303         cw.visit(Opcodes.V1_8, NOT_ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER, className, null, superName, null);
 304         cw.visitSource(sourceFile, null);
 305 
 306         String invokerDesc = invokerType.toMethodDescriptorString();
 307         mv = cw.visitMethod(Opcodes.ACC_STATIC, invokerName, invokerDesc, null, null);
 308     }
 309 
 310     /**
 311      * Tear down class file generation.
 312      */
 313     private void classFileEpilogue() {


src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File