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
  23  * questions.
  24  */
  25 
  26 package java.lang.invoke;
  27 
  28 import jdk.internal.misc.Unsafe;
  29 import jdk.internal.org.objectweb.asm.*;
  30 import sun.invoke.util.BytecodeDescriptor;
  31 import sun.security.action.GetPropertyAction;
  32 
  33 import java.io.FilePermission;
  34 import java.io.Serializable;
  35 import java.lang.invoke.MethodHandles.Lookup;
  36 import java.lang.reflect.Constructor;
  37 import java.security.AccessController;
  38 import java.security.PrivilegedAction;
  39 import java.util.LinkedHashSet;
  40 import java.util.concurrent.atomic.AtomicInteger;
  41 import java.util.PropertyPermission;
  42 import java.util.Set;
  43 
  44 import static java.lang.invoke.MethodHandles.Lookup.*;
  45 import static jdk.internal.org.objectweb.asm.Opcodes.*;
  46 
  47 /**
  48  * Lambda metafactory implementation which dynamically creates an
  49  * inner-class-like class per lambda callsite.
  50  *
  51  * @see LambdaMetafactory
  52  */
  53 /* package */ final class InnerClassLambdaMetafactory extends AbstractValidatingLambdaMetafactory {
  54     private static final Unsafe UNSAFE = Unsafe.getUnsafe();
  55 
  56     private static final int CLASSFILE_VERSION = 52;
  57     private static final String METHOD_DESCRIPTOR_VOID = Type.getMethodDescriptor(Type.VOID_TYPE);
  58     private static final String JAVA_LANG_OBJECT = "java/lang/Object";
  59     private static final String NAME_CTOR = "<init>";
  60 
  61     //Serialization support
  62     private static final String NAME_SERIALIZED_LAMBDA = "java/lang/invoke/SerializedLambda";
  63     private static final String NAME_NOT_SERIALIZABLE_EXCEPTION = "java/io/NotSerializableException";
  64     private static final String DESCR_METHOD_WRITE_REPLACE = "()Ljava/lang/Object;";
  65     private static final String DESCR_METHOD_WRITE_OBJECT = "(Ljava/io/ObjectOutputStream;)V";
  66     private static final String DESCR_METHOD_READ_OBJECT = "(Ljava/io/ObjectInputStream;)V";
  67     private static final String NAME_METHOD_WRITE_REPLACE = "writeReplace";
  68     private static final String NAME_METHOD_READ_OBJECT = "readObject";
  69     private static final String NAME_METHOD_WRITE_OBJECT = "writeObject";
  70 
  71     private static final String DESCR_CLASS = "Ljava/lang/Class;";
  72     private static final String DESCR_STRING = "Ljava/lang/String;";
  73     private static final String DESCR_OBJECT = "Ljava/lang/Object;";
  74     private static final String DESCR_CTOR_SERIALIZED_LAMBDA
  75             = "(" + DESCR_CLASS + DESCR_STRING + DESCR_STRING + DESCR_STRING + "I"
  76             + DESCR_STRING + DESCR_STRING + DESCR_STRING + DESCR_STRING + "[" + DESCR_OBJECT + ")V";
  77 
  78     private static final String DESCR_CTOR_NOT_SERIALIZABLE_EXCEPTION = "(Ljava/lang/String;)V";
  79     private static final String[] SER_HOSTILE_EXCEPTIONS = new String[] {NAME_NOT_SERIALIZABLE_EXCEPTION};
  80 
  81     private static final String DESCR_HIDDEN = "Ljdk/internal/vm/annotation/Hidden;";
  82 
  83     private static final String[] EMPTY_STRING_ARRAY = new String[0];
  84 
  85     // Used to ensure that each spun class name is unique
  86     private static final AtomicInteger counter = new AtomicInteger(0);
  87 
  88     // For dumping generated classes to disk, for debugging purposes
  89     private static final ProxyClassesDumper dumper;
  90 
  91     static {
  92         final String key = "jdk.internal.lambda.dumpProxyClasses";
  93         String path = GetPropertyAction.privilegedGetProperty(key);
  94         dumper = (null == path) ? null : ProxyClassesDumper.getInstance(path);
  95     }
  96 
  97     // See context values in AbstractValidatingLambdaMetafactory
  98     private final String implMethodClassName;        // Name of type containing implementation "CC"
  99     private final String implMethodName;             // Name of implementation method "impl"
 100     private final String implMethodDesc;             // Type descriptor for implementation methods "(I)Ljava/lang/String;"
 101     private final MethodType constructorType;        // Generated class constructor type "(CC)void"
 102     private final ClassWriter cw;                    // ASM class writer
 103     private final String[] argNames;                 // Generated names for the constructor arguments
 104     private final String[] argDescs;                 // Type descriptors for the constructor arguments
 105     private final String lambdaClassName;            // Generated name for the generated class "X$$Lambda$1"
 106 
 107     /**
 108      * General meta-factory constructor, supporting both standard cases and
 109      * allowing for uncommon options such as serialization or bridging.
 110      *
 111      * @param caller Stacked automatically by VM; represents a lookup context
 112      *               with the accessibility privileges of the caller.
 113      * @param invokedType Stacked automatically by VM; the signature of the
 114      *                    invoked method, which includes the expected static
 115      *                    type of the returned lambda object, and the static
 116      *                    types of the captured arguments for the lambda.  In
 117      *                    the event that the implementation method is an
 118      *                    instance method, the first argument in the invocation
 119      *                    signature will correspond to the receiver.
 120      * @param samMethodName Name of the method in the functional interface to
 121      *                      which the lambda or method reference is being
 122      *                      converted, represented as a String.
 123      * @param samMethodType Type of the method in the functional interface to
 124      *                      which the lambda or method reference is being
 125      *                      converted, represented as a MethodType.
 126      * @param implMethod The implementation method which should be called (with
 127      *                   suitable adaptation of argument types, return types,
 128      *                   and adjustment for captured arguments) when methods of
 129      *                   the resulting functional interface instance are invoked.
 130      * @param instantiatedMethodType The signature of the primary functional
 131      *                               interface method after type variables are
 132      *                               substituted with their instantiation from
 133      *                               the capture site
 134      * @param isSerializable Should the lambda be made serializable?  If set,
 135      *                       either the target type or one of the additional SAM
 136      *                       types must extend {@code Serializable}.
 137      * @param markerInterfaces Additional interfaces which the lambda object
 138      *                       should implement.
 139      * @param additionalBridges Method types for additional signatures to be
 140      *                          bridged to the implementation method
 141      * @throws LambdaConversionException If any of the meta-factory protocol
 142      * invariants are violated
 143      */
 144     public InnerClassLambdaMetafactory(MethodHandles.Lookup caller,
 145                                        MethodType invokedType,
 146                                        String samMethodName,
 147                                        MethodType samMethodType,
 148                                        MethodHandle implMethod,
 149                                        MethodType instantiatedMethodType,
 150                                        boolean isSerializable,
 151                                        Class<?>[] markerInterfaces,
 152                                        MethodType[] additionalBridges)
 153             throws LambdaConversionException {
 154         super(caller, invokedType, samMethodName, samMethodType,
 155               implMethod, instantiatedMethodType,
 156               isSerializable, markerInterfaces, additionalBridges);
 157         implMethodClassName = implClass.getName().replace('.', '/');
 158         implMethodName = implInfo.getName();
 159         implMethodDesc = implInfo.getMethodType().toMethodDescriptorString();
 160         constructorType = invokedType.changeReturnType(Void.TYPE);
 161         lambdaClassName = targetClass.getName().replace('.', '/') + "$$Lambda$" + counter.incrementAndGet();
 162         cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
 163         int parameterCount = invokedType.parameterCount();
 164         if (parameterCount > 0) {
 165             argNames = new String[parameterCount];
 166             argDescs = new String[parameterCount];
 167             for (int i = 0; i < parameterCount; i++) {
 168                 argNames[i] = "arg$" + (i + 1);
 169                 argDescs[i] = BytecodeDescriptor.unparse(invokedType.parameterType(i));
 170             }
 171         } else {
 172             argNames = argDescs = EMPTY_STRING_ARRAY;
 173         }
 174     }
 175 
 176     /**
 177      * Build the CallSite. Generate a class file which implements the functional
 178      * interface, define the class, if there are no parameters create an instance
 179      * of the class which the CallSite will return, otherwise, generate handles
 180      * which will call the class' constructor.
 181      *
 182      * @return a CallSite, which, when invoked, will return an instance of the
 183      * functional interface
 184      * @throws ReflectiveOperationException
 185      * @throws LambdaConversionException If properly formed functional interface
 186      * is not found
 187      */
 188     @Override
 189     CallSite buildCallSite() throws LambdaConversionException {
 190         final Class<?> innerClass = spinInnerClass();
 191         if (invokedType.parameterCount() == 0) {
 192             final Constructor<?>[] ctrs = AccessController.doPrivileged(
 193                     new PrivilegedAction<>() {
 194                 @Override
 195                 public Constructor<?>[] run() {
 196                     Constructor<?>[] ctrs = innerClass.getDeclaredConstructors();
 197                     if (ctrs.length == 1) {
 198                         // The lambda implementing inner class constructor is private, set
 199                         // it accessible (by us) before creating the constant sole instance
 200                         ctrs[0].setAccessible(true);
 201                     }
 202                     return ctrs;
 203                 }
 204                     });
 205             if (ctrs.length != 1) {
 206                 throw new LambdaConversionException("Expected one lambda constructor for "
 207                         + innerClass.getCanonicalName() + ", got " + ctrs.length);
 208             }
 209 
 210             try {
 211                 Object inst = ctrs[0].newInstance();
 212                 return new ConstantCallSite(MethodHandles.constant(samBase, inst));
 213             }
 214             catch (ReflectiveOperationException e) {
 215                 throw new LambdaConversionException("Exception instantiating lambda object", e);
 216             }
 217         } else {
 218             try {
 219                 UNSAFE.ensureClassInitialized(innerClass);
 220                 Lookup lookup = MethodHandles.privateLookupIn(innerClass, Lookup.IMPL_LOOKUP);
 221                 MethodHandle mh = lookup.findConstructor(innerClass, invokedType.changeReturnType(void.class));
 222                 return new ConstantCallSite(mh.asType(invokedType));
 223             } catch (ReflectiveOperationException e) {
 224                 throw new LambdaConversionException("Exception finding constructor", e);
 225             }
 226         }
 227     }
 228 
 229     /**
 230      * Generate a class file which implements the functional
 231      * interface, define and return the class.
 232      *
 233      * @implNote The class that is generated does not include signature
 234      * information for exceptions that may be present on the SAM method.
 235      * This is to reduce classfile size, and is harmless as checked exceptions
 236      * are erased anyway, no one will ever compile against this classfile,
 237      * and we make no guarantees about the reflective properties of lambda
 238      * objects.
 239      *
 240      * @return a Class which implements the functional interface
 241      * @throws LambdaConversionException If properly formed functional interface
 242      * is not found
 243      */
 244     private Class<?> spinInnerClass() throws LambdaConversionException {
 245         String[] interfaces;
 246         String samIntf = samBase.getName().replace('.', '/');
 247         boolean accidentallySerializable = !isSerializable && Serializable.class.isAssignableFrom(samBase);
 248         if (markerInterfaces.length == 0) {
 249             interfaces = new String[]{samIntf};
 250         } else {
 251             // Assure no duplicate interfaces (ClassFormatError)
 252             Set<String> itfs = new LinkedHashSet<>(markerInterfaces.length + 1);
 253             itfs.add(samIntf);
 254             for (Class<?> markerInterface : markerInterfaces) {
 255                 itfs.add(markerInterface.getName().replace('.', '/'));
 256                 accidentallySerializable |= !isSerializable && Serializable.class.isAssignableFrom(markerInterface);
 257             }
 258             interfaces = itfs.toArray(new String[itfs.size()]);
 259         }
 260 
 261         cw.visit(CLASSFILE_VERSION, ACC_SUPER + ACC_FINAL + ACC_SYNTHETIC,
 262                  lambdaClassName, null,
 263                  JAVA_LANG_OBJECT, interfaces);
 264 
 265         // Generate final fields to be filled in by constructor
 266         for (int i = 0; i < argDescs.length; i++) {
 267             FieldVisitor fv = cw.visitField(ACC_PRIVATE + ACC_FINAL,
 268                                             argNames[i],
 269                                             argDescs[i],
 270                                             null, null);
 271             fv.visitEnd();
 272         }
 273 
 274         generateConstructor();
 275 
 276         // Forward the SAM method
 277         MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, samMethodName,
 278                                           samMethodType.toMethodDescriptorString(), null, null);
 279         mv.visitAnnotation(DESCR_HIDDEN, true);
 280         new ForwardingMethodGenerator(mv).generate(samMethodType);
 281 
 282         // Forward the bridges
 283         if (additionalBridges != null) {
 284             for (MethodType mt : additionalBridges) {
 285                 mv = cw.visitMethod(ACC_PUBLIC|ACC_BRIDGE, samMethodName,
 286                                     mt.toMethodDescriptorString(), null, null);
 287                 mv.visitAnnotation(DESCR_HIDDEN, true);
 288                 new ForwardingMethodGenerator(mv).generate(mt);
 289             }
 290         }
 291 
 292         if (isSerializable)
 293             generateSerializationFriendlyMethods();
 294         else if (accidentallySerializable)
 295             generateSerializationHostileMethods();
 296 
 297         cw.visitEnd();
 298 
 299         // Define the generated class in this VM.
 300 
 301         final byte[] classBytes = cw.toByteArray();
 302 
 303         // If requested, dump out to a file for debugging purposes
 304         if (dumper != null) {
 305             AccessController.doPrivileged(new PrivilegedAction<>() {
 306                 @Override
 307                 public Void run() {
 308                     dumper.dumpClass(lambdaClassName, classBytes);
 309                     return null;
 310                 }
 311             }, null,
 312             new FilePermission("<<ALL FILES>>", "read, write"),
 313             // createDirectories may need it
 314             new PropertyPermission("user.dir", "read"));
 315         }
 316         try {
 317             Lookup lookup = MethodHandles.privateLookupIn(targetClass, IMPL_LOOKUP);
 318             // this class is linked at the indy callsite.  No need to be weak class
 319             return lookup.defineClassWithNoCheck(classBytes, HIDDEN_NESTMATE);
 320         } catch (ReflectiveOperationException e) {
 321             throw new LambdaConversionException(e);
 322         }
 323     }
 324 
 325     /**
 326      * Generate the constructor for the class
 327      */
 328     private void generateConstructor() {
 329         // Generate constructor
 330         MethodVisitor ctor = cw.visitMethod(ACC_PRIVATE, NAME_CTOR,
 331                                             constructorType.toMethodDescriptorString(), null, null);
 332         ctor.visitCode();
 333         ctor.visitVarInsn(ALOAD, 0);
 334         ctor.visitMethodInsn(INVOKESPECIAL, JAVA_LANG_OBJECT, NAME_CTOR,
 335                              METHOD_DESCRIPTOR_VOID, false);
 336         int parameterCount = invokedType.parameterCount();
 337         for (int i = 0, lvIndex = 0; i < parameterCount; i++) {
 338             ctor.visitVarInsn(ALOAD, 0);
 339             Class<?> argType = invokedType.parameterType(i);
 340             ctor.visitVarInsn(getLoadOpcode(argType), lvIndex + 1);
 341             lvIndex += getParameterSize(argType);
 342             ctor.visitFieldInsn(PUTFIELD, lambdaClassName, argNames[i], argDescs[i]);
 343         }
 344         ctor.visitInsn(RETURN);
 345         // Maxs computed by ClassWriter.COMPUTE_MAXS, these arguments ignored
 346         ctor.visitMaxs(-1, -1);
 347         ctor.visitEnd();
 348     }
 349 
 350     /**
 351      * Generate a writeReplace method that supports serialization
 352      */
 353     private void generateSerializationFriendlyMethods() {
 354         TypeConvertingMethodAdapter mv
 355                 = new TypeConvertingMethodAdapter(
 356                     cw.visitMethod(ACC_PRIVATE + ACC_FINAL,
 357                     NAME_METHOD_WRITE_REPLACE, DESCR_METHOD_WRITE_REPLACE,
 358                     null, null));
 359 
 360         mv.visitCode();
 361         mv.visitTypeInsn(NEW, NAME_SERIALIZED_LAMBDA);
 362         mv.visitInsn(DUP);
 363         mv.visitLdcInsn(Type.getType(targetClass));
 364         mv.visitLdcInsn(invokedType.returnType().getName().replace('.', '/'));
 365         mv.visitLdcInsn(samMethodName);
 366         mv.visitLdcInsn(samMethodType.toMethodDescriptorString());
 367         mv.visitLdcInsn(implInfo.getReferenceKind());
 368         mv.visitLdcInsn(implInfo.getDeclaringClass().getName().replace('.', '/'));
 369         mv.visitLdcInsn(implInfo.getName());
 370         mv.visitLdcInsn(implInfo.getMethodType().toMethodDescriptorString());
 371         mv.visitLdcInsn(instantiatedMethodType.toMethodDescriptorString());
 372         mv.iconst(argDescs.length);
 373         mv.visitTypeInsn(ANEWARRAY, JAVA_LANG_OBJECT);
 374         for (int i = 0; i < argDescs.length; i++) {
 375             mv.visitInsn(DUP);
 376             mv.iconst(i);
 377             mv.visitVarInsn(ALOAD, 0);
 378             mv.visitFieldInsn(GETFIELD, lambdaClassName, argNames[i], argDescs[i]);
 379             mv.boxIfTypePrimitive(Type.getType(argDescs[i]));
 380             mv.visitInsn(AASTORE);
 381         }
 382         mv.visitMethodInsn(INVOKESPECIAL, NAME_SERIALIZED_LAMBDA, NAME_CTOR,
 383                 DESCR_CTOR_SERIALIZED_LAMBDA, false);
 384         mv.visitInsn(ARETURN);
 385         // Maxs computed by ClassWriter.COMPUTE_MAXS, these arguments ignored
 386         mv.visitMaxs(-1, -1);
 387         mv.visitEnd();
 388     }
 389 
 390     /**
 391      * Generate a readObject/writeObject method that is hostile to serialization
 392      */
 393     private void generateSerializationHostileMethods() {
 394         MethodVisitor mv = cw.visitMethod(ACC_PRIVATE + ACC_FINAL,
 395                                           NAME_METHOD_WRITE_OBJECT, DESCR_METHOD_WRITE_OBJECT,
 396                                           null, SER_HOSTILE_EXCEPTIONS);
 397         mv.visitCode();
 398         mv.visitTypeInsn(NEW, NAME_NOT_SERIALIZABLE_EXCEPTION);
 399         mv.visitInsn(DUP);
 400         mv.visitLdcInsn("Non-serializable lambda");
 401         mv.visitMethodInsn(INVOKESPECIAL, NAME_NOT_SERIALIZABLE_EXCEPTION, NAME_CTOR,
 402                            DESCR_CTOR_NOT_SERIALIZABLE_EXCEPTION, false);
 403         mv.visitInsn(ATHROW);
 404         mv.visitMaxs(-1, -1);
 405         mv.visitEnd();
 406 
 407         mv = cw.visitMethod(ACC_PRIVATE + ACC_FINAL,
 408                             NAME_METHOD_READ_OBJECT, DESCR_METHOD_READ_OBJECT,
 409                             null, SER_HOSTILE_EXCEPTIONS);
 410         mv.visitCode();
 411         mv.visitTypeInsn(NEW, NAME_NOT_SERIALIZABLE_EXCEPTION);
 412         mv.visitInsn(DUP);
 413         mv.visitLdcInsn("Non-serializable lambda");
 414         mv.visitMethodInsn(INVOKESPECIAL, NAME_NOT_SERIALIZABLE_EXCEPTION, NAME_CTOR,
 415                            DESCR_CTOR_NOT_SERIALIZABLE_EXCEPTION, false);
 416         mv.visitInsn(ATHROW);
 417         mv.visitMaxs(-1, -1);
 418         mv.visitEnd();
 419     }
 420 
 421     /**
 422      * This class generates a method body which calls the lambda implementation
 423      * method, converting arguments, as needed.
 424      */
 425     private class ForwardingMethodGenerator extends TypeConvertingMethodAdapter {
 426 
 427         ForwardingMethodGenerator(MethodVisitor mv) {
 428             super(mv);
 429         }
 430 
 431         void generate(MethodType methodType) {
 432             visitCode();
 433 
 434             if (implKind == MethodHandleInfo.REF_newInvokeSpecial) {
 435                 visitTypeInsn(NEW, implMethodClassName);
 436                 visitInsn(DUP);
 437             }
 438             for (int i = 0; i < argNames.length; i++) {
 439                 visitVarInsn(ALOAD, 0);
 440                 visitFieldInsn(GETFIELD, lambdaClassName, argNames[i], argDescs[i]);
 441             }
 442 
 443             convertArgumentTypes(methodType);
 444 
 445             // Invoke the method we want to forward to
 446             visitMethodInsn(invocationOpcode(), implMethodClassName,
 447                             implMethodName, implMethodDesc,
 448                             implClass.isInterface());
 449 
 450             // Convert the return value (if any) and return it
 451             // Note: if adapting from non-void to void, the 'return'
 452             // instruction will pop the unneeded result
 453             Class<?> implReturnClass = implMethodType.returnType();
 454             Class<?> samReturnClass = methodType.returnType();
 455             convertType(implReturnClass, samReturnClass, samReturnClass);
 456             visitInsn(getReturnOpcode(samReturnClass));
 457             // Maxs computed by ClassWriter.COMPUTE_MAXS,these arguments ignored
 458             visitMaxs(-1, -1);
 459             visitEnd();
 460         }
 461 
 462         private void convertArgumentTypes(MethodType samType) {
 463             int lvIndex = 0;
 464             int samParametersLength = samType.parameterCount();
 465             int captureArity = invokedType.parameterCount();
 466             for (int i = 0; i < samParametersLength; i++) {
 467                 Class<?> argType = samType.parameterType(i);
 468                 visitVarInsn(getLoadOpcode(argType), lvIndex + 1);
 469                 lvIndex += getParameterSize(argType);
 470                 convertType(argType, implMethodType.parameterType(captureArity + i), instantiatedMethodType.parameterType(i));
 471             }
 472         }
 473 
 474         private int invocationOpcode() throws InternalError {
 475             switch (implKind) {
 476                 case MethodHandleInfo.REF_invokeStatic:
 477                     return INVOKESTATIC;
 478                 case MethodHandleInfo.REF_newInvokeSpecial:
 479                     return INVOKESPECIAL;
 480                  case MethodHandleInfo.REF_invokeVirtual:
 481                     return INVOKEVIRTUAL;
 482                 case MethodHandleInfo.REF_invokeInterface:
 483                     return INVOKEINTERFACE;
 484                 case MethodHandleInfo.REF_invokeSpecial:
 485                     return INVOKESPECIAL;
 486                 default:
 487                     throw new InternalError("Unexpected invocation kind: " + implKind);
 488             }
 489         }
 490     }
 491 
 492     static int getParameterSize(Class<?> c) {
 493         if (c == Void.TYPE) {
 494             return 0;
 495         } else if (c == Long.TYPE || c == Double.TYPE) {
 496             return 2;
 497         }
 498         return 1;
 499     }
 500 
 501     static int getLoadOpcode(Class<?> c) {
 502         if(c == Void.TYPE) {
 503             throw new InternalError("Unexpected void type of load opcode");
 504         }
 505         return ILOAD + getOpcodeOffset(c);
 506     }
 507 
 508     static int getReturnOpcode(Class<?> c) {
 509         if(c == Void.TYPE) {
 510             return RETURN;
 511         }
 512         return IRETURN + getOpcodeOffset(c);
 513     }
 514 
 515     private static int getOpcodeOffset(Class<?> c) {
 516         if (c.isPrimitive()) {
 517             if (c == Long.TYPE) {
 518                 return 1;
 519             } else if (c == Float.TYPE) {
 520                 return 2;
 521             } else if (c == Double.TYPE) {
 522                 return 3;
 523             }
 524             return 0;
 525         } else {
 526             return 4;
 527         }
 528     }
 529 
 530 }