jdk/src/share/classes/sun/reflect/AccessorGenerator.java
author alanb
Fri, 02 Nov 2012 15:50:11 +0000
changeset 14342 8435a30053c1
parent 10342 ca0984bc9d32
child 20780 d4ead406572e
permissions -rw-r--r--
7197491: update copyright year to match last edit in jdk8 jdk repository Reviewed-by: chegar, ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 10342
diff changeset
     2
 * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.reflect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.lang.reflect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import sun.misc.Unsafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/** Shared functionality for all accessor generators */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
class AccessorGenerator implements ClassFileConstants {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    static final Unsafe unsafe = Unsafe.getUnsafe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    // Constants because there's no way to say "short integer constant",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    // i.e., "1S"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    protected static final short S0 = (short) 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    protected static final short S1 = (short) 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    protected static final short S2 = (short) 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    protected static final short S3 = (short) 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    protected static final short S4 = (short) 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    protected static final short S5 = (short) 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    protected static final short S6 = (short) 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    // Instance variables for shared functionality between
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    // FieldAccessorGenerator and MethodAccessorGenerator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    protected ClassFileAssembler asm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    protected int   modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    protected short thisClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    protected short superClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    protected short targetClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    // Common constant pool entries to FieldAccessor and MethodAccessor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    protected short throwableClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    protected short classCastClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    protected short nullPointerClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    protected short illegalArgumentClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    protected short invocationTargetClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    protected short initIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    protected short initNameAndTypeIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    protected short initStringNameAndTypeIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    protected short nullPointerCtorIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    protected short illegalArgumentCtorIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    protected short illegalArgumentStringCtorIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    protected short invocationTargetCtorIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    protected short superCtorIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    protected short objectClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    protected short toStringIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    protected short codeIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    protected short exceptionsIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    // Boxing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    protected short booleanIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    protected short booleanCtorIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    protected short booleanUnboxIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    protected short byteIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    protected short byteCtorIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    protected short byteUnboxIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    protected short characterIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    protected short characterCtorIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    protected short characterUnboxIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    protected short doubleIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    protected short doubleCtorIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    protected short doubleUnboxIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    protected short floatIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    protected short floatCtorIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    protected short floatUnboxIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    protected short integerIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    protected short integerCtorIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    protected short integerUnboxIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    protected short longIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    protected short longCtorIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    protected short longUnboxIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    protected short shortIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    protected short shortCtorIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    protected short shortUnboxIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    protected final short NUM_COMMON_CPOOL_ENTRIES = (short) 30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    protected final short NUM_BOXING_CPOOL_ENTRIES = (short) 72;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    // Requires that superClass has been set up
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    protected void emitCommonConstantPoolEntries() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        // +   [UTF-8] "java/lang/Throwable"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        // +   [CONSTANT_Class_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        // +   [UTF-8] "java/lang/ClassCastException"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        // +   [CONSTANT_Class_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        // +   [UTF-8] "java/lang/NullPointerException"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        // +   [CONSTANT_Class_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        // +   [UTF-8] "java/lang/IllegalArgumentException"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        // +   [CONSTANT_Class_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        // +   [UTF-8] "java/lang/InvocationTargetException"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        // +   [CONSTANT_Class_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        // +   [UTF-8] "<init>"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        // +   [UTF-8] "()V"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        // +   [CONSTANT_NameAndType_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        // +   [CONSTANT_Methodref_info] for NullPointerException's constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        // +   [CONSTANT_Methodref_info] for IllegalArgumentException's constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        // +   [UTF-8] "(Ljava/lang/String;)V"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        // +   [CONSTANT_NameAndType_info] for "<init>(Ljava/lang/String;)V"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        // +   [CONSTANT_Methodref_info] for IllegalArgumentException's constructor taking a String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        // +   [UTF-8] "(Ljava/lang/Throwable;)V"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        // +   [CONSTANT_NameAndType_info] for "<init>(Ljava/lang/Throwable;)V"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        // +   [CONSTANT_Methodref_info] for InvocationTargetException's constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        // +   [CONSTANT_Methodref_info] for "super()"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        // +   [UTF-8] "java/lang/Object"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        // +   [CONSTANT_Class_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        // +   [UTF-8] "toString"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        // +   [UTF-8] "()Ljava/lang/String;"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        // +   [CONSTANT_NameAndType_info] for "toString()Ljava/lang/String;"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        // +   [CONSTANT_Methodref_info] for Object's toString method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        // +   [UTF-8] "Code"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        // +   [UTF-8] "Exceptions"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        asm.emitConstantPoolUTF8("java/lang/Throwable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        asm.emitConstantPoolClass(asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        throwableClass = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        asm.emitConstantPoolUTF8("java/lang/ClassCastException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        asm.emitConstantPoolClass(asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        classCastClass = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        asm.emitConstantPoolUTF8("java/lang/NullPointerException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        asm.emitConstantPoolClass(asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        nullPointerClass = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        asm.emitConstantPoolUTF8("java/lang/IllegalArgumentException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        asm.emitConstantPoolClass(asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        illegalArgumentClass = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        asm.emitConstantPoolUTF8("java/lang/reflect/InvocationTargetException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        asm.emitConstantPoolClass(asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        invocationTargetClass = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        asm.emitConstantPoolUTF8("<init>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        initIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        asm.emitConstantPoolUTF8("()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        asm.emitConstantPoolNameAndType(initIdx, asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        initNameAndTypeIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        asm.emitConstantPoolMethodref(nullPointerClass, initNameAndTypeIdx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        nullPointerCtorIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        asm.emitConstantPoolMethodref(illegalArgumentClass, initNameAndTypeIdx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        illegalArgumentCtorIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        asm.emitConstantPoolUTF8("(Ljava/lang/String;)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        asm.emitConstantPoolNameAndType(initIdx, asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        initStringNameAndTypeIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        asm.emitConstantPoolMethodref(illegalArgumentClass, initStringNameAndTypeIdx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        illegalArgumentStringCtorIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        asm.emitConstantPoolUTF8("(Ljava/lang/Throwable;)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        asm.emitConstantPoolNameAndType(initIdx, asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        asm.emitConstantPoolMethodref(invocationTargetClass, asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        invocationTargetCtorIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        asm.emitConstantPoolMethodref(superClass, initNameAndTypeIdx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        superCtorIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        asm.emitConstantPoolUTF8("java/lang/Object");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        asm.emitConstantPoolClass(asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        objectClass = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        asm.emitConstantPoolUTF8("toString");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        asm.emitConstantPoolUTF8("()Ljava/lang/String;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        asm.emitConstantPoolMethodref(objectClass, asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        toStringIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        asm.emitConstantPoolUTF8("Code");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        codeIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        asm.emitConstantPoolUTF8("Exceptions");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        exceptionsIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /** Constant pool entries required to be able to box/unbox primitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        types. Note that we don't emit these if we don't need them. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    protected void emitBoxingContantPoolEntries() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        //  *  [UTF-8] "java/lang/Boolean"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        //  *  [CONSTANT_Class_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        //  *  [UTF-8] "(Z)V"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        //  *  [CONSTANT_NameAndType_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        //  *  [CONSTANT_Methodref_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        //  *  [UTF-8] "booleanValue"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        //  *  [UTF-8] "()Z"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        //  *  [CONSTANT_NameAndType_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        //  *  [CONSTANT_Methodref_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        //  *  [UTF-8] "java/lang/Byte"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        //  *  [CONSTANT_Class_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        //  *  [UTF-8] "(B)V"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        //  *  [CONSTANT_NameAndType_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        //  *  [CONSTANT_Methodref_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        //  *  [UTF-8] "byteValue"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        //  *  [UTF-8] "()B"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        //  *  [CONSTANT_NameAndType_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        //  *  [CONSTANT_Methodref_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        //  *  [UTF-8] "java/lang/Character"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        //  *  [CONSTANT_Class_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        //  *  [UTF-8] "(C)V"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        //  *  [CONSTANT_NameAndType_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        //  *  [CONSTANT_Methodref_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        //  *  [UTF-8] "charValue"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        //  *  [UTF-8] "()C"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        //  *  [CONSTANT_NameAndType_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        //  *  [CONSTANT_Methodref_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        //  *  [UTF-8] "java/lang/Double"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        //  *  [CONSTANT_Class_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        //  *  [UTF-8] "(D)V"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        //  *  [CONSTANT_NameAndType_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        //  *  [CONSTANT_Methodref_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        //  *  [UTF-8] "doubleValue"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        //  *  [UTF-8] "()D"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        //  *  [CONSTANT_NameAndType_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        //  *  [CONSTANT_Methodref_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        //  *  [UTF-8] "java/lang/Float"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        //  *  [CONSTANT_Class_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        //  *  [UTF-8] "(F)V"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        //  *  [CONSTANT_NameAndType_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        //  *  [CONSTANT_Methodref_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        //  *  [UTF-8] "floatValue"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        //  *  [UTF-8] "()F"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        //  *  [CONSTANT_NameAndType_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        //  *  [CONSTANT_Methodref_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        //  *  [UTF-8] "java/lang/Integer"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        //  *  [CONSTANT_Class_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        //  *  [UTF-8] "(I)V"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        //  *  [CONSTANT_NameAndType_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        //  *  [CONSTANT_Methodref_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        //  *  [UTF-8] "intValue"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        //  *  [UTF-8] "()I"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        //  *  [CONSTANT_NameAndType_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        //  *  [CONSTANT_Methodref_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        //  *  [UTF-8] "java/lang/Long"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        //  *  [CONSTANT_Class_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        //  *  [UTF-8] "(J)V"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        //  *  [CONSTANT_NameAndType_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        //  *  [CONSTANT_Methodref_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        //  *  [UTF-8] "longValue"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        //  *  [UTF-8] "()J"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        //  *  [CONSTANT_NameAndType_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        //  *  [CONSTANT_Methodref_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        //  *  [UTF-8] "java/lang/Short"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        //  *  [CONSTANT_Class_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        //  *  [UTF-8] "(S)V"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        //  *  [CONSTANT_NameAndType_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        //  *  [CONSTANT_Methodref_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        //  *  [UTF-8] "shortValue"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        //  *  [UTF-8] "()S"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        //  *  [CONSTANT_NameAndType_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        //  *  [CONSTANT_Methodref_info] for above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        // Boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        asm.emitConstantPoolUTF8("java/lang/Boolean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        asm.emitConstantPoolClass(asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        booleanIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        asm.emitConstantPoolUTF8("(Z)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        asm.emitConstantPoolNameAndType(initIdx, asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        asm.emitConstantPoolMethodref(sub(asm.cpi(), S2), asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        booleanCtorIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        asm.emitConstantPoolUTF8("booleanValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        asm.emitConstantPoolUTF8("()Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        asm.emitConstantPoolMethodref(sub(asm.cpi(), S6), asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        booleanUnboxIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        // Byte
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        asm.emitConstantPoolUTF8("java/lang/Byte");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        asm.emitConstantPoolClass(asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        byteIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        asm.emitConstantPoolUTF8("(B)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        asm.emitConstantPoolNameAndType(initIdx, asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        asm.emitConstantPoolMethodref(sub(asm.cpi(), S2), asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        byteCtorIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        asm.emitConstantPoolUTF8("byteValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        asm.emitConstantPoolUTF8("()B");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        asm.emitConstantPoolMethodref(sub(asm.cpi(), S6), asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        byteUnboxIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        // Character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        asm.emitConstantPoolUTF8("java/lang/Character");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        asm.emitConstantPoolClass(asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        characterIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        asm.emitConstantPoolUTF8("(C)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        asm.emitConstantPoolNameAndType(initIdx, asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        asm.emitConstantPoolMethodref(sub(asm.cpi(), S2), asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        characterCtorIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        asm.emitConstantPoolUTF8("charValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        asm.emitConstantPoolUTF8("()C");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        asm.emitConstantPoolMethodref(sub(asm.cpi(), S6), asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        characterUnboxIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        // Double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        asm.emitConstantPoolUTF8("java/lang/Double");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        asm.emitConstantPoolClass(asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        doubleIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        asm.emitConstantPoolUTF8("(D)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        asm.emitConstantPoolNameAndType(initIdx, asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        asm.emitConstantPoolMethodref(sub(asm.cpi(), S2), asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        doubleCtorIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        asm.emitConstantPoolUTF8("doubleValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        asm.emitConstantPoolUTF8("()D");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        asm.emitConstantPoolMethodref(sub(asm.cpi(), S6), asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        doubleUnboxIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        // Float
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        asm.emitConstantPoolUTF8("java/lang/Float");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        asm.emitConstantPoolClass(asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        floatIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        asm.emitConstantPoolUTF8("(F)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        asm.emitConstantPoolNameAndType(initIdx, asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        asm.emitConstantPoolMethodref(sub(asm.cpi(), S2), asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        floatCtorIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        asm.emitConstantPoolUTF8("floatValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        asm.emitConstantPoolUTF8("()F");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        asm.emitConstantPoolMethodref(sub(asm.cpi(), S6), asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        floatUnboxIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        // Integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        asm.emitConstantPoolUTF8("java/lang/Integer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        asm.emitConstantPoolClass(asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        integerIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        asm.emitConstantPoolUTF8("(I)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        asm.emitConstantPoolNameAndType(initIdx, asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        asm.emitConstantPoolMethodref(sub(asm.cpi(), S2), asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        integerCtorIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        asm.emitConstantPoolUTF8("intValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        asm.emitConstantPoolUTF8("()I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        asm.emitConstantPoolMethodref(sub(asm.cpi(), S6), asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        integerUnboxIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        // Long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        asm.emitConstantPoolUTF8("java/lang/Long");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        asm.emitConstantPoolClass(asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        longIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        asm.emitConstantPoolUTF8("(J)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        asm.emitConstantPoolNameAndType(initIdx, asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        asm.emitConstantPoolMethodref(sub(asm.cpi(), S2), asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        longCtorIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        asm.emitConstantPoolUTF8("longValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        asm.emitConstantPoolUTF8("()J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        asm.emitConstantPoolMethodref(sub(asm.cpi(), S6), asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        longUnboxIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        // Short
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        asm.emitConstantPoolUTF8("java/lang/Short");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        asm.emitConstantPoolClass(asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        shortIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        asm.emitConstantPoolUTF8("(S)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        asm.emitConstantPoolNameAndType(initIdx, asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        asm.emitConstantPoolMethodref(sub(asm.cpi(), S2), asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        shortCtorIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        asm.emitConstantPoolUTF8("shortValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        asm.emitConstantPoolUTF8("()S");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        asm.emitConstantPoolNameAndType(sub(asm.cpi(), S1), asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        asm.emitConstantPoolMethodref(sub(asm.cpi(), S6), asm.cpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        shortUnboxIdx = asm.cpi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    // Necessary because of Java's annoying promotion rules
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    protected static short add(short s1, short s2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        return (short) (s1 + s2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    protected static short sub(short s1, short s2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        return (short) (s1 - s2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    protected boolean isStatic() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        return Modifier.isStatic(modifiers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    /** Returns class name in "internal" form (i.e., '/' separators
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        instead of '.') */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    protected static String getClassName
10342
ca0984bc9d32 7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   385
        (Class<?> c, boolean addPrefixAndSuffixForNonPrimitiveTypes)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        if (c.isPrimitive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            if (c == Boolean.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                return "Z";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            } else if (c == Byte.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                return "B";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            } else if (c == Character.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                return "C";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            } else if (c == Double.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                return "D";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            } else if (c == Float.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                return "F";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            } else if (c == Integer.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                return "I";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            } else if (c == Long.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                return "J";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            } else if (c == Short.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                return "S";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            } else if (c == Void.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                return "V";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            throw new InternalError("Should have found primitive type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        } else if (c.isArray()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            return "[" + getClassName(c.getComponentType(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            if (addPrefixAndSuffixForNonPrimitiveTypes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                return internalize("L" + c.getName() + ";");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                return internalize(c.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    private static String internalize(String className) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        return className.replace('.', '/');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    protected void emitConstructor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        // Generate code into fresh code buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        ClassFileAssembler cb = new ClassFileAssembler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        // 0 incoming arguments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        cb.setMaxLocals(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        cb.opc_aload_0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        cb.opc_invokespecial(superCtorIdx, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        cb.opc_return();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        // Emit method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        emitMethod(initIdx, cb.getMaxLocals(), cb, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    // The descriptor's index in the constant pool must be (1 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    // nameIdx). "numArgs" must indicate ALL arguments, including the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    // implicit "this" argument; double and long arguments each count
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    // as 2 in this count. The code buffer must NOT contain the code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    // length. The exception table may be null, but if non-null must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    // NOT contain the exception table's length. The checked exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    // indices may be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    protected void emitMethod(short nameIdx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                              int numArgs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                              ClassFileAssembler code,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                              ClassFileAssembler exceptionTable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                              short[] checkedExceptionIndices)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        int codeLen = code.getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        int excLen  = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        if (exceptionTable != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            excLen = exceptionTable.getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            if ((excLen % 8) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                throw new IllegalArgumentException("Illegal exception table");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        int attrLen = 12 + codeLen + excLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        excLen = excLen / 8; // No-op if no exception table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        asm.emitShort(ACC_PUBLIC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        asm.emitShort(nameIdx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        asm.emitShort(add(nameIdx, S1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        if (checkedExceptionIndices == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            // Code attribute only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            asm.emitShort(S1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            // Code and Exceptions attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            asm.emitShort(S2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        // Code attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        asm.emitShort(codeIdx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        asm.emitInt(attrLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        asm.emitShort(code.getMaxStack());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        asm.emitShort((short) Math.max(numArgs, code.getMaxLocals()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        asm.emitInt(codeLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        asm.append(code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        asm.emitShort((short) excLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        if (exceptionTable != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            asm.append(exceptionTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        asm.emitShort(S0); // No additional attributes for Code attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        if (checkedExceptionIndices != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            // Exceptions attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            asm.emitShort(exceptionsIdx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            asm.emitInt(2 + 2 * checkedExceptionIndices.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            asm.emitShort((short) checkedExceptionIndices.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            for (int i = 0; i < checkedExceptionIndices.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                asm.emitShort(checkedExceptionIndices[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
10342
ca0984bc9d32 7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   493
    protected short indexForPrimitiveType(Class<?> type) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        if (type == Boolean.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            return booleanIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        } else if (type == Byte.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            return byteIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        } else if (type == Character.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            return characterIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        } else if (type == Double.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            return doubleIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        } else if (type == Float.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            return floatIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        } else if (type == Integer.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            return integerIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        } else if (type == Long.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            return longIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        } else if (type == Short.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            return shortIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        throw new InternalError("Should have found primitive type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
10342
ca0984bc9d32 7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   514
    protected short ctorIndexForPrimitiveType(Class<?> type) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        if (type == Boolean.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            return booleanCtorIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        } else if (type == Byte.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            return byteCtorIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        } else if (type == Character.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            return characterCtorIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        } else if (type == Double.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            return doubleCtorIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        } else if (type == Float.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            return floatCtorIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        } else if (type == Integer.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            return integerCtorIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        } else if (type == Long.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            return longCtorIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        } else if (type == Short.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            return shortCtorIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        throw new InternalError("Should have found primitive type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    /** Returns true for widening or identity conversions for primitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        types only */
10342
ca0984bc9d32 7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   537
    protected static boolean canWidenTo(Class<?> type, Class<?> otherType) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        if (!type.isPrimitive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        // Widening conversions (from JVM spec):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        //  byte to short, int, long, float, or double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        //  short to int, long, float, or double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        //  char to int, long, float, or double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        //  int to long, float, or double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        //  long to float or double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        //  float to double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        if (type == Boolean.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            if (otherType == Boolean.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        } else if (type == Byte.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            if (   otherType == Byte.TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                   || otherType == Short.TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                   || otherType == Integer.TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                   || otherType == Long.TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                   || otherType == Float.TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                   || otherType == Double.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        } else if (type == Short.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            if (   otherType == Short.TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                   || otherType == Integer.TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                   || otherType == Long.TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                   || otherType == Float.TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                   || otherType == Double.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        } else if (type == Character.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            if (   otherType == Character.TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                   || otherType == Integer.TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                   || otherType == Long.TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                   || otherType == Float.TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                   || otherType == Double.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        } else if (type == Integer.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            if (   otherType == Integer.TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                   || otherType == Long.TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                   || otherType == Float.TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                   || otherType == Double.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        } else if (type == Long.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            if (   otherType == Long.TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                   || otherType == Float.TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                   || otherType == Double.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        } else if (type == Float.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            if (   otherType == Float.TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                   || otherType == Double.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        } else if (type == Double.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            if (otherType == Double.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    /** Emits the widening bytecode for the given primitive conversion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        (or none if the identity conversion). Requires that a primitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        conversion exists; i.e., canWidenTo must have already been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        called and returned true. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    protected static void emitWideningBytecodeForPrimitiveConversion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        (ClassFileAssembler cb,
10342
ca0984bc9d32 7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   612
         Class<?> fromType,
ca0984bc9d32 7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   613
         Class<?> toType)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        // Note that widening conversions for integral types (i.e., "b2s",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        // "s2i") are no-ops since values on the Java stack are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        // sign-extended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        // Widening conversions (from JVM spec):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        //  byte to short, int, long, float, or double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        //  short to int, long, float, or double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        //  char to int, long, float, or double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        //  int to long, float, or double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        //  long to float or double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        //  float to double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        if (   fromType == Byte.TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
               || fromType == Short.TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
               || fromType == Character.TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
               || fromType == Integer.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            if (toType == Long.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                cb.opc_i2l();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            } else if (toType == Float.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                cb.opc_i2f();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            } else if (toType == Double.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                cb.opc_i2d();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        } else if (fromType == Long.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            if (toType == Float.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                cb.opc_l2f();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            } else if (toType == Double.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                cb.opc_l2d();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        } else if (fromType == Float.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            if (toType == Double.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                cb.opc_f2d();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        // Otherwise, was identity or no-op conversion. Fall through.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
10342
ca0984bc9d32 7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   653
    protected short unboxingMethodForPrimitiveType(Class<?> primType) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        if (primType == Boolean.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            return booleanUnboxIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        } else if (primType == Byte.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            return byteUnboxIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        } else if (primType == Character.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            return characterUnboxIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        } else if (primType == Short.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            return shortUnboxIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        } else if (primType == Integer.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            return integerUnboxIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        } else if (primType == Long.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            return longUnboxIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        } else if (primType == Float.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            return floatUnboxIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        } else if (primType == Double.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            return doubleUnboxIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        throw new InternalError("Illegal primitive type " + primType.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
10342
ca0984bc9d32 7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   674
    protected static final Class<?>[] primitiveTypes = new Class<?>[] {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        Boolean.TYPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        Byte.TYPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        Character.TYPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        Short.TYPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        Integer.TYPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        Long.TYPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        Float.TYPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        Double.TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    /** We don't consider "Void" to be a primitive type */
10342
ca0984bc9d32 7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   686
    protected static boolean isPrimitive(Class<?> c) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        return (c.isPrimitive() && c != Void.TYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
10342
ca0984bc9d32 7077389: Reflection classes do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   690
    protected int typeSizeInStackSlots(Class<?> c) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        if (c == Void.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        if (c == Long.TYPE || c == Double.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            return 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    private ClassFileAssembler illegalArgumentCodeBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    protected ClassFileAssembler illegalArgumentCodeBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        if (illegalArgumentCodeBuffer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            illegalArgumentCodeBuffer = new ClassFileAssembler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            illegalArgumentCodeBuffer.opc_new(illegalArgumentClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            illegalArgumentCodeBuffer.opc_dup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            illegalArgumentCodeBuffer.opc_invokespecial(illegalArgumentCtorIdx, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            illegalArgumentCodeBuffer.opc_athrow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        return illegalArgumentCodeBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
}