src/java.base/share/classes/java/lang/reflect/ProxyGenerator.java
author redestad
Wed, 21 Mar 2018 10:13:14 +0100
changeset 49272 e137b71166c4
parent 49250 7443b946694a
child 49285 4d2e3f5abb48
permissions -rw-r--r--
8199865: Avoid initializing ShortCache in ProxyGenerator Reviewed-by: mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
21655
55f32ae4f920 8028229: Fix more raw types lint warning in core libraries
darcy
parents: 16923
diff changeset
     2
 * Copyright (c) 1999, 2013, 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: 715
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: 715
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: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
34704
df7aeb5037a1 8145416: Move sun.misc.ProxyGenerator to java.lang.reflect
chegar
parents: 32649
diff changeset
    26
package java.lang.reflect;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.ByteArrayOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.DataOutputStream;
16923
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
    30
import java.io.File;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.lang.reflect.Array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.lang.reflect.Method;
16923
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
    35
import java.nio.file.Files;
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
    36
import java.nio.file.Path;
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
    37
import java.nio.file.Paths;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.LinkedList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.ListIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import sun.security.action.GetBooleanAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * ProxyGenerator contains the code to generate a dynamic proxy class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * for the java.lang.reflect.Proxy API.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * The external interfaces to ProxyGenerator is the static
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * "generateProxyClass" method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @author      Peter Jones
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @since       1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 */
34704
df7aeb5037a1 8145416: Move sun.misc.ProxyGenerator to java.lang.reflect
chegar
parents: 32649
diff changeset
    56
class ProxyGenerator {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * In the comments below, "JVMS" refers to The Java Virtual Machine
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * Specification Second Edition and "JLS" refers to the original
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * version of The Java Language Specification, unless otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /* generate 1.5-era class file version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private static final int CLASSFILE_MAJOR_VERSION = 49;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private static final int CLASSFILE_MINOR_VERSION = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * beginning of constants copied from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * sun.tools.java.RuntimeConstants (which no longer exists):
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /* constant pool tags */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private static final int CONSTANT_UTF8              = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private static final int CONSTANT_UNICODE           = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private static final int CONSTANT_INTEGER           = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private static final int CONSTANT_FLOAT             = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private static final int CONSTANT_LONG              = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private static final int CONSTANT_DOUBLE            = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private static final int CONSTANT_CLASS             = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private static final int CONSTANT_STRING            = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private static final int CONSTANT_FIELD             = 9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private static final int CONSTANT_METHOD            = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private static final int CONSTANT_INTERFACEMETHOD   = 11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private static final int CONSTANT_NAMEANDTYPE       = 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /* access and modifier flags */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private static final int ACC_PUBLIC                 = 0x00000001;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private static final int ACC_PRIVATE                = 0x00000002;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
//  private static final int ACC_PROTECTED              = 0x00000004;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private static final int ACC_STATIC                 = 0x00000008;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private static final int ACC_FINAL                  = 0x00000010;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
//  private static final int ACC_SYNCHRONIZED           = 0x00000020;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
//  private static final int ACC_VOLATILE               = 0x00000040;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
//  private static final int ACC_TRANSIENT              = 0x00000080;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
//  private static final int ACC_NATIVE                 = 0x00000100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
//  private static final int ACC_INTERFACE              = 0x00000200;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
//  private static final int ACC_ABSTRACT               = 0x00000400;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private static final int ACC_SUPER                  = 0x00000020;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
//  private static final int ACC_STRICT                 = 0x00000800;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /* opcodes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
//  private static final int opc_nop                    = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private static final int opc_aconst_null            = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
//  private static final int opc_iconst_m1              = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private static final int opc_iconst_0               = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
//  private static final int opc_iconst_1               = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
//  private static final int opc_iconst_2               = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
//  private static final int opc_iconst_3               = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
//  private static final int opc_iconst_4               = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
//  private static final int opc_iconst_5               = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
//  private static final int opc_lconst_0               = 9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
//  private static final int opc_lconst_1               = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
//  private static final int opc_fconst_0               = 11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
//  private static final int opc_fconst_1               = 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
//  private static final int opc_fconst_2               = 13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
//  private static final int opc_dconst_0               = 14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
//  private static final int opc_dconst_1               = 15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    private static final int opc_bipush                 = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    private static final int opc_sipush                 = 17;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private static final int opc_ldc                    = 18;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    private static final int opc_ldc_w                  = 19;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
//  private static final int opc_ldc2_w                 = 20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    private static final int opc_iload                  = 21;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    private static final int opc_lload                  = 22;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    private static final int opc_fload                  = 23;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    private static final int opc_dload                  = 24;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    private static final int opc_aload                  = 25;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private static final int opc_iload_0                = 26;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
//  private static final int opc_iload_1                = 27;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
//  private static final int opc_iload_2                = 28;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
//  private static final int opc_iload_3                = 29;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    private static final int opc_lload_0                = 30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
//  private static final int opc_lload_1                = 31;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
//  private static final int opc_lload_2                = 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
//  private static final int opc_lload_3                = 33;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    private static final int opc_fload_0                = 34;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
//  private static final int opc_fload_1                = 35;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
//  private static final int opc_fload_2                = 36;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
//  private static final int opc_fload_3                = 37;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private static final int opc_dload_0                = 38;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
//  private static final int opc_dload_1                = 39;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
//  private static final int opc_dload_2                = 40;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
//  private static final int opc_dload_3                = 41;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    private static final int opc_aload_0                = 42;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
//  private static final int opc_aload_1                = 43;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
//  private static final int opc_aload_2                = 44;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
//  private static final int opc_aload_3                = 45;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
//  private static final int opc_iaload                 = 46;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
//  private static final int opc_laload                 = 47;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
//  private static final int opc_faload                 = 48;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
//  private static final int opc_daload                 = 49;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
//  private static final int opc_aaload                 = 50;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
//  private static final int opc_baload                 = 51;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
//  private static final int opc_caload                 = 52;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
//  private static final int opc_saload                 = 53;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
//  private static final int opc_istore                 = 54;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
//  private static final int opc_lstore                 = 55;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
//  private static final int opc_fstore                 = 56;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
//  private static final int opc_dstore                 = 57;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    private static final int opc_astore                 = 58;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
//  private static final int opc_istore_0               = 59;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
//  private static final int opc_istore_1               = 60;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
//  private static final int opc_istore_2               = 61;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
//  private static final int opc_istore_3               = 62;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
//  private static final int opc_lstore_0               = 63;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
//  private static final int opc_lstore_1               = 64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
//  private static final int opc_lstore_2               = 65;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
//  private static final int opc_lstore_3               = 66;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
//  private static final int opc_fstore_0               = 67;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
//  private static final int opc_fstore_1               = 68;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
//  private static final int opc_fstore_2               = 69;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
//  private static final int opc_fstore_3               = 70;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
//  private static final int opc_dstore_0               = 71;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
//  private static final int opc_dstore_1               = 72;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
//  private static final int opc_dstore_2               = 73;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
//  private static final int opc_dstore_3               = 74;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    private static final int opc_astore_0               = 75;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
//  private static final int opc_astore_1               = 76;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
//  private static final int opc_astore_2               = 77;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
//  private static final int opc_astore_3               = 78;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
//  private static final int opc_iastore                = 79;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
//  private static final int opc_lastore                = 80;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
//  private static final int opc_fastore                = 81;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
//  private static final int opc_dastore                = 82;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    private static final int opc_aastore                = 83;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
//  private static final int opc_bastore                = 84;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
//  private static final int opc_castore                = 85;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
//  private static final int opc_sastore                = 86;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    private static final int opc_pop                    = 87;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
//  private static final int opc_pop2                   = 88;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    private static final int opc_dup                    = 89;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
//  private static final int opc_dup_x1                 = 90;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
//  private static final int opc_dup_x2                 = 91;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
//  private static final int opc_dup2                   = 92;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
//  private static final int opc_dup2_x1                = 93;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
//  private static final int opc_dup2_x2                = 94;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
//  private static final int opc_swap                   = 95;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
//  private static final int opc_iadd                   = 96;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
//  private static final int opc_ladd                   = 97;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
//  private static final int opc_fadd                   = 98;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
//  private static final int opc_dadd                   = 99;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
//  private static final int opc_isub                   = 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
//  private static final int opc_lsub                   = 101;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
//  private static final int opc_fsub                   = 102;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
//  private static final int opc_dsub                   = 103;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
//  private static final int opc_imul                   = 104;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
//  private static final int opc_lmul                   = 105;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
//  private static final int opc_fmul                   = 106;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
//  private static final int opc_dmul                   = 107;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
//  private static final int opc_idiv                   = 108;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
//  private static final int opc_ldiv                   = 109;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
//  private static final int opc_fdiv                   = 110;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
//  private static final int opc_ddiv                   = 111;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
//  private static final int opc_irem                   = 112;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
//  private static final int opc_lrem                   = 113;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
//  private static final int opc_frem                   = 114;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
//  private static final int opc_drem                   = 115;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
//  private static final int opc_ineg                   = 116;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
//  private static final int opc_lneg                   = 117;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
//  private static final int opc_fneg                   = 118;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
//  private static final int opc_dneg                   = 119;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
//  private static final int opc_ishl                   = 120;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
//  private static final int opc_lshl                   = 121;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
//  private static final int opc_ishr                   = 122;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
//  private static final int opc_lshr                   = 123;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
//  private static final int opc_iushr                  = 124;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
//  private static final int opc_lushr                  = 125;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
//  private static final int opc_iand                   = 126;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
//  private static final int opc_land                   = 127;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
//  private static final int opc_ior                    = 128;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
//  private static final int opc_lor                    = 129;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
//  private static final int opc_ixor                   = 130;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
//  private static final int opc_lxor                   = 131;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
//  private static final int opc_iinc                   = 132;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
//  private static final int opc_i2l                    = 133;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
//  private static final int opc_i2f                    = 134;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
//  private static final int opc_i2d                    = 135;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
//  private static final int opc_l2i                    = 136;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
//  private static final int opc_l2f                    = 137;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
//  private static final int opc_l2d                    = 138;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
//  private static final int opc_f2i                    = 139;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
//  private static final int opc_f2l                    = 140;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
//  private static final int opc_f2d                    = 141;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
//  private static final int opc_d2i                    = 142;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
//  private static final int opc_d2l                    = 143;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
//  private static final int opc_d2f                    = 144;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
//  private static final int opc_i2b                    = 145;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
//  private static final int opc_i2c                    = 146;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
//  private static final int opc_i2s                    = 147;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
//  private static final int opc_lcmp                   = 148;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
//  private static final int opc_fcmpl                  = 149;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
//  private static final int opc_fcmpg                  = 150;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
//  private static final int opc_dcmpl                  = 151;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
//  private static final int opc_dcmpg                  = 152;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
//  private static final int opc_ifeq                   = 153;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
//  private static final int opc_ifne                   = 154;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
//  private static final int opc_iflt                   = 155;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
//  private static final int opc_ifge                   = 156;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
//  private static final int opc_ifgt                   = 157;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
//  private static final int opc_ifle                   = 158;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
//  private static final int opc_if_icmpeq              = 159;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
//  private static final int opc_if_icmpne              = 160;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
//  private static final int opc_if_icmplt              = 161;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
//  private static final int opc_if_icmpge              = 162;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
//  private static final int opc_if_icmpgt              = 163;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
//  private static final int opc_if_icmple              = 164;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
//  private static final int opc_if_acmpeq              = 165;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
//  private static final int opc_if_acmpne              = 166;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
//  private static final int opc_goto                   = 167;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
//  private static final int opc_jsr                    = 168;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
//  private static final int opc_ret                    = 169;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
//  private static final int opc_tableswitch            = 170;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
//  private static final int opc_lookupswitch           = 171;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    private static final int opc_ireturn                = 172;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    private static final int opc_lreturn                = 173;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    private static final int opc_freturn                = 174;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    private static final int opc_dreturn                = 175;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    private static final int opc_areturn                = 176;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    private static final int opc_return                 = 177;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    private static final int opc_getstatic              = 178;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    private static final int opc_putstatic              = 179;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    private static final int opc_getfield               = 180;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
//  private static final int opc_putfield               = 181;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    private static final int opc_invokevirtual          = 182;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    private static final int opc_invokespecial          = 183;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    private static final int opc_invokestatic           = 184;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    private static final int opc_invokeinterface        = 185;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    private static final int opc_new                    = 187;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
//  private static final int opc_newarray               = 188;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    private static final int opc_anewarray              = 189;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
//  private static final int opc_arraylength            = 190;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    private static final int opc_athrow                 = 191;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    private static final int opc_checkcast              = 192;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
//  private static final int opc_instanceof             = 193;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
//  private static final int opc_monitorenter           = 194;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
//  private static final int opc_monitorexit            = 195;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    private static final int opc_wide                   = 196;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
//  private static final int opc_multianewarray         = 197;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
//  private static final int opc_ifnull                 = 198;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
//  private static final int opc_ifnonnull              = 199;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
//  private static final int opc_goto_w                 = 200;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
//  private static final int opc_jsr_w                  = 201;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    // end of constants copied from sun.tools.java.RuntimeConstants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /** name of the superclass of proxy classes */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   308
    private static final String superclassName = "java/lang/reflect/Proxy";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    /** name of field for storing a proxy instance's invocation handler */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   311
    private static final String handlerFieldName = "h";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    /** debugging flag for saving generated class files */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   314
    private static final boolean saveGeneratedFiles =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            new GetBooleanAction(
34704
df7aeb5037a1 8145416: Move sun.misc.ProxyGenerator to java.lang.reflect
chegar
parents: 32649
diff changeset
   317
                "jdk.proxy.ProxyGenerator.saveGeneratedFiles")).booleanValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    /**
16923
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   320
     * Generate a public proxy class given a name and a list of proxy interfaces.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     */
34704
df7aeb5037a1 8145416: Move sun.misc.ProxyGenerator to java.lang.reflect
chegar
parents: 32649
diff changeset
   322
    static byte[] generateProxyClass(final String name,
df7aeb5037a1 8145416: Move sun.misc.ProxyGenerator to java.lang.reflect
chegar
parents: 32649
diff changeset
   323
                                     Class<?>[] interfaces) {
16923
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   324
        return generateProxyClass(name, interfaces, (ACC_PUBLIC | ACC_FINAL | ACC_SUPER));
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   325
    }
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   326
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   327
    /**
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   328
     * Generate a proxy class given a name and a list of proxy interfaces.
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   329
     *
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   330
     * @param name        the class name of the proxy class
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   331
     * @param interfaces  proxy interfaces
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   332
     * @param accessFlags access flags of the proxy class
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   333
    */
34704
df7aeb5037a1 8145416: Move sun.misc.ProxyGenerator to java.lang.reflect
chegar
parents: 32649
diff changeset
   334
    static byte[] generateProxyClass(final String name,
df7aeb5037a1 8145416: Move sun.misc.ProxyGenerator to java.lang.reflect
chegar
parents: 32649
diff changeset
   335
                                     Class<?>[] interfaces,
df7aeb5037a1 8145416: Move sun.misc.ProxyGenerator to java.lang.reflect
chegar
parents: 32649
diff changeset
   336
                                     int accessFlags)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    {
16923
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   338
        ProxyGenerator gen = new ProxyGenerator(name, interfaces, accessFlags);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        final byte[] classFile = gen.generateClassFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        if (saveGeneratedFiles) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            java.security.AccessController.doPrivileged(
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   343
            new java.security.PrivilegedAction<Void>() {
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   344
                public Void run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                    try {
16923
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   346
                        int i = name.lastIndexOf('.');
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   347
                        Path path;
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   348
                        if (i > 0) {
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   349
                            Path dir = Paths.get(name.substring(0, i).replace('.', File.separatorChar));
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   350
                            Files.createDirectories(dir);
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   351
                            path = dir.resolve(name.substring(i+1, name.length()) + ".class");
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   352
                        } else {
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   353
                            path = Paths.get(name + ".class");
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   354
                        }
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   355
                        Files.write(path, classFile);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                    } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                        throw new InternalError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                            "I/O exception saving generated file: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        return classFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    /* preloaded Method objects for methods in java.lang.Object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    private static Method hashCodeMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    private static Method equalsMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    private static Method toStringMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            hashCodeMethod = Object.class.getMethod("hashCode");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            equalsMethod =
11119
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
   376
                Object.class.getMethod("equals", new Class<?>[] { Object.class });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            toStringMethod = Object.class.getMethod("toString");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        } catch (NoSuchMethodException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            throw new NoSuchMethodError(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    /** name of proxy class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    private String className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    /** proxy interfaces */
21655
55f32ae4f920 8028229: Fix more raw types lint warning in core libraries
darcy
parents: 16923
diff changeset
   387
    private Class<?>[] interfaces;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
16923
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   389
    /** proxy class access flags */
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   390
    private int accessFlags;
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   391
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    /** constant pool of class being generated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    private ConstantPool cp = new ConstantPool();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    /** FieldInfo struct for each field of generated class */
16923
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   396
    private List<FieldInfo> fields = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    /** MethodInfo struct for each method of generated class */
16923
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   399
    private List<MethodInfo> methods = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * maps method signature string to list of ProxyMethod objects for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * proxy methods with that signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     */
16923
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   405
    private Map<String, List<ProxyMethod>> proxyMethods = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    /** count of ProxyMethod objects added to proxyMethods */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    private int proxyMethodCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * Construct a ProxyGenerator to generate a proxy class with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * specified name and for the given interfaces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * A ProxyGenerator object contains the state for the ongoing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * generation of a particular proxy class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     */
16923
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   417
    private ProxyGenerator(String className, Class<?>[] interfaces, int accessFlags) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        this.className = className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        this.interfaces = interfaces;
16923
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   420
        this.accessFlags = accessFlags;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * Generate a class file for the proxy class.  This method drives the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * class file generation process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    private byte[] generateClassFile() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        /* ============================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
         * Step 1: Assemble ProxyMethod objects for all methods to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
         * generate proxy dispatching code for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
         * Record that proxy methods are needed for the hashCode, equals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
         * and toString methods of java.lang.Object.  This is done before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
         * the methods from the proxy interfaces so that the methods from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
         * java.lang.Object take precedence over duplicate methods in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
         * proxy interfaces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        addProxyMethod(hashCodeMethod, Object.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        addProxyMethod(equalsMethod, Object.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        addProxyMethod(toStringMethod, Object.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
         * Now record all of the methods from the proxy interfaces, giving
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
         * earlier interfaces precedence over later ones with duplicate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
         * methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
         */
16923
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   450
        for (Class<?> intf : interfaces) {
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   451
            for (Method m : intf.getMethods()) {
49250
7443b946694a 8188240: Reflection Proxy should skip static methods
shade
parents: 47216
diff changeset
   452
                if (!Modifier.isStatic(m.getModifiers())) {
7443b946694a 8188240: Reflection Proxy should skip static methods
shade
parents: 47216
diff changeset
   453
                    addProxyMethod(m, intf);
7443b946694a 8188240: Reflection Proxy should skip static methods
shade
parents: 47216
diff changeset
   454
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
         * For each set of proxy methods with the same signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
         * verify that the methods' return types are compatible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        for (List<ProxyMethod> sigmethods : proxyMethods.values()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            checkReturnTypes(sigmethods);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        /* ============================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
         * Step 2: Assemble FieldInfo and MethodInfo structs for all of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
         * fields and methods in the class we are generating.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            methods.add(generateConstructor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            for (List<ProxyMethod> sigmethods : proxyMethods.values()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                for (ProxyMethod pm : sigmethods) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                    // add static field for method's Method object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                    fields.add(new FieldInfo(pm.methodFieldName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                        "Ljava/lang/reflect/Method;",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                         ACC_PRIVATE | ACC_STATIC));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                    // generate code for proxy method and add it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                    methods.add(pm.generateMethod());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            methods.add(generateStaticInitializer());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        } catch (IOException e) {
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 5506
diff changeset
   489
            throw new InternalError("unexpected I/O Exception", e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        if (methods.size() > 65535) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            throw new IllegalArgumentException("method limit exceeded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        if (fields.size() > 65535) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            throw new IllegalArgumentException("field limit exceeded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        /* ============================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
         * Step 3: Write the final class file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
         * Make sure that constant pool indexes are reserved for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
         * following items before starting to write the final class file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        cp.getClass(dotToSlash(className));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        cp.getClass(superclassName);
16923
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   509
        for (Class<?> intf: interfaces) {
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   510
            cp.getClass(dotToSlash(intf.getName()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
         * Disallow new constant pool additions beyond this point, since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
         * we are about to write the final constant pool table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        cp.setReadOnly();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        DataOutputStream dout = new DataOutputStream(bout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
             * Write all the items of the "ClassFile" structure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
             * See JVMS section 4.1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                                        // u4 magic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            dout.writeInt(0xCAFEBABE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                                        // u2 minor_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            dout.writeShort(CLASSFILE_MINOR_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                                        // u2 major_version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            dout.writeShort(CLASSFILE_MAJOR_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            cp.write(dout);             // (write constant pool)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                                        // u2 access_flags;
16923
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   537
            dout.writeShort(accessFlags);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                                        // u2 this_class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            dout.writeShort(cp.getClass(dotToSlash(className)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                                        // u2 super_class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            dout.writeShort(cp.getClass(superclassName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                                        // u2 interfaces_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            dout.writeShort(interfaces.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                                        // u2 interfaces[interfaces_count];
16923
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   546
            for (Class<?> intf : interfaces) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                dout.writeShort(cp.getClass(
16923
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   548
                    dotToSlash(intf.getName())));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                                        // u2 fields_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            dout.writeShort(fields.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                                        // field_info fields[fields_count];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            for (FieldInfo f : fields) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                f.write(dout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                                        // u2 methods_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            dout.writeShort(methods.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                                        // method_info methods[methods_count];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            for (MethodInfo m : methods) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                m.write(dout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                                         // u2 attributes_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            dout.writeShort(0); // (no ClassFile attributes for proxy classes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        } catch (IOException e) {
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 5506
diff changeset
   569
            throw new InternalError("unexpected I/O Exception", e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        return bout.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * Add another method to be proxied, either by creating a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * ProxyMethod object or augmenting an old one for a duplicate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * "fromClass" indicates the proxy interface that the method was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * found through, which may be different from (a subinterface of)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * the method's "declaring class".  Note that the first Method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * object passed for a given name and descriptor identifies the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * Method object (and thus the declaring class) that will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * passed to the invocation handler's "invoke" method for a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * set of duplicate methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     */
11119
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
   588
    private void addProxyMethod(Method m, Class<?> fromClass) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        String name = m.getName();
11119
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
   590
        Class<?>[] parameterTypes = m.getParameterTypes();
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
   591
        Class<?> returnType = m.getReturnType();
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
   592
        Class<?>[] exceptionTypes = m.getExceptionTypes();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        String sig = name + getParameterDescriptors(parameterTypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        List<ProxyMethod> sigmethods = proxyMethods.get(sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        if (sigmethods != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            for (ProxyMethod pm : sigmethods) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                if (returnType == pm.returnType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                     * Found a match: reduce exception types to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                     * greatest set of exceptions that can thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                     * compatibly with the throws clauses of both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                     * overridden methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                     */
16923
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   605
                    List<Class<?>> legalExceptions = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                    collectCompatibleTypes(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                        exceptionTypes, pm.exceptionTypes, legalExceptions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                    collectCompatibleTypes(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                        pm.exceptionTypes, exceptionTypes, legalExceptions);
11119
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
   610
                    pm.exceptionTypes = new Class<?>[legalExceptions.size()];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                    pm.exceptionTypes =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                        legalExceptions.toArray(pm.exceptionTypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        } else {
16923
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   617
            sigmethods = new ArrayList<>(3);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            proxyMethods.put(sig, sigmethods);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        sigmethods.add(new ProxyMethod(name, parameterTypes, returnType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                                       exceptionTypes, fromClass));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * For a given set of proxy methods with the same signature, check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * that their return types are compatible according to the Proxy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * Specifically, if there is more than one such method, then all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * of the return types must be reference types, and there must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * one return type that is assignable to each of the rest of them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    private static void checkReturnTypes(List<ProxyMethod> methods) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
         * If there is only one method with a given signature, there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
         * cannot be a conflict.  This is the only case in which a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
         * primitive (or void) return type is allowed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        if (methods.size() < 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
         * List of return types that are not yet known to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
         * assignable from ("covered" by) any of the others.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
         */
16923
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   647
        LinkedList<Class<?>> uncoveredReturnTypes = new LinkedList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    nextNewReturnType:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        for (ProxyMethod pm : methods) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   651
            Class<?> newReturnType = pm.returnType;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            if (newReturnType.isPrimitive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                    "methods with same signature " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                    getFriendlyMethodSignature(pm.methodName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                                               pm.parameterTypes) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                    " but incompatible return types: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                    newReturnType.getName() + " and others");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            boolean added = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
             * Compare the new return type to the existing uncovered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
             * return types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
             */
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   666
            ListIterator<Class<?>> liter = uncoveredReturnTypes.listIterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            while (liter.hasNext()) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   668
                Class<?> uncoveredReturnType = liter.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                 * If an existing uncovered return type is assignable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                 * to this new one, then we can forget the new one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                if (newReturnType.isAssignableFrom(uncoveredReturnType)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                    assert !added;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                    continue nextNewReturnType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                 * If the new return type is assignable to an existing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                 * uncovered one, then should replace the existing one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                 * with the new one (or just forget the existing one,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                 * if the new one has already be put in the list).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                if (uncoveredReturnType.isAssignableFrom(newReturnType)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                    // (we can assume that each return type is unique)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                    if (!added) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                        liter.set(newReturnType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                        added = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                        liter.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
             * If we got through the list of existing uncovered return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
             * types without an assignability relationship, then add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
             * the new return type to the list of uncovered ones.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            if (!added) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                uncoveredReturnTypes.add(newReturnType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
         * We shouldn't end up with more than one return type that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
         * not assignable from any of the others.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        if (uncoveredReturnTypes.size() > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            ProxyMethod pm = methods.get(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                "methods with same signature " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                getFriendlyMethodSignature(pm.methodName, pm.parameterTypes) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                " but incompatible return types: " + uncoveredReturnTypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * A FieldInfo object contains information about a particular field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * in the class being generated.  The class mirrors the data items of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * the "field_info" structure of the class file format (see JVMS 4.5).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    private class FieldInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        public int accessFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        public String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        public String descriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        public FieldInfo(String name, String descriptor, int accessFlags) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            this.descriptor = descriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            this.accessFlags = accessFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
             * Make sure that constant pool indexes are reserved for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
             * following items before starting to write the final class file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            cp.getUtf8(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            cp.getUtf8(descriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        public void write(DataOutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
             * Write all the items of the "field_info" structure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
             * See JVMS section 4.5.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                                        // u2 access_flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            out.writeShort(accessFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                                        // u2 name_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            out.writeShort(cp.getUtf8(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                                        // u2 descriptor_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            out.writeShort(cp.getUtf8(descriptor));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                                        // u2 attributes_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            out.writeShort(0);  // (no field_info attributes for proxy classes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * An ExceptionTableEntry object holds values for the data items of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * an entry in the "exception_table" item of the "Code" attribute of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * "method_info" structures (see JVMS 4.7.3).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    private static class ExceptionTableEntry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        public short startPc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        public short endPc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        public short handlerPc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        public short catchType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        public ExceptionTableEntry(short startPc, short endPc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                                   short handlerPc, short catchType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            this.startPc = startPc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            this.endPc = endPc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            this.handlerPc = handlerPc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            this.catchType = catchType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * A MethodInfo object contains information about a particular method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * in the class being generated.  This class mirrors the data items of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * the "method_info" structure of the class file format (see JVMS 4.6).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    private class MethodInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        public int accessFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        public String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        public String descriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        public short maxStack;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        public short maxLocals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        public ByteArrayOutputStream code = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        public List<ExceptionTableEntry> exceptionTable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            new ArrayList<ExceptionTableEntry>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        public short[] declaredExceptions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        public MethodInfo(String name, String descriptor, int accessFlags) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            this.descriptor = descriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            this.accessFlags = accessFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
             * Make sure that constant pool indexes are reserved for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
             * following items before starting to write the final class file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
            cp.getUtf8(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            cp.getUtf8(descriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            cp.getUtf8("Code");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            cp.getUtf8("Exceptions");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        public void write(DataOutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
             * Write all the items of the "method_info" structure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
             * See JVMS section 4.6.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                                        // u2 access_flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            out.writeShort(accessFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                                        // u2 name_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            out.writeShort(cp.getUtf8(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                                        // u2 descriptor_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            out.writeShort(cp.getUtf8(descriptor));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                                        // u2 attributes_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            out.writeShort(2);  // (two method_info attributes:)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
            // Write "Code" attribute. See JVMS section 4.7.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                                        // u2 attribute_name_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            out.writeShort(cp.getUtf8("Code"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                                        // u4 attribute_length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            out.writeInt(12 + code.size() + 8 * exceptionTable.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                                        // u2 max_stack;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            out.writeShort(maxStack);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                                        // u2 max_locals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            out.writeShort(maxLocals);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                                        // u2 code_length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            out.writeInt(code.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                                        // u1 code[code_length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            code.writeTo(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                                        // u2 exception_table_length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            out.writeShort(exceptionTable.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            for (ExceptionTableEntry e : exceptionTable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                                        // u2 start_pc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                out.writeShort(e.startPc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                                        // u2 end_pc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                out.writeShort(e.endPc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                                        // u2 handler_pc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                out.writeShort(e.handlerPc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                                        // u2 catch_type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                out.writeShort(e.catchType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                                        // u2 attributes_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
            out.writeShort(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            // write "Exceptions" attribute.  See JVMS section 4.7.4.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                                        // u2 attribute_name_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            out.writeShort(cp.getUtf8("Exceptions"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                                        // u4 attributes_length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            out.writeInt(2 + 2 * declaredExceptions.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                                        // u2 number_of_exceptions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            out.writeShort(declaredExceptions.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                        // u2 exception_index_table[number_of_exceptions];
16923
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   862
            for (short value : declaredExceptions) {
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
   863
                out.writeShort(value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * A ProxyMethod object represents a proxy method in the proxy class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     * being generated: a method whose implementation will encode and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * dispatch invocations to the proxy instance's invocation handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    private class ProxyMethod {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        public String methodName;
11119
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
   877
        public Class<?>[] parameterTypes;
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
   878
        public Class<?> returnType;
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
   879
        public Class<?>[] exceptionTypes;
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
   880
        public Class<?> fromClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        public String methodFieldName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
11119
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
   883
        private ProxyMethod(String methodName, Class<?>[] parameterTypes,
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
   884
                            Class<?> returnType, Class<?>[] exceptionTypes,
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
   885
                            Class<?> fromClass)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            this.methodName = methodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            this.parameterTypes = parameterTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            this.returnType = returnType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            this.exceptionTypes = exceptionTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            this.fromClass = fromClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            this.methodFieldName = "m" + proxyMethodCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
         * Return a MethodInfo object for this method, including generating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
         * the code and exception table entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        private MethodInfo generateMethod() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            String desc = getMethodDescriptor(parameterTypes, returnType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            MethodInfo minfo = new MethodInfo(methodName, desc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                ACC_PUBLIC | ACC_FINAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            int[] parameterSlot = new int[parameterTypes.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            int nextSlot = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            for (int i = 0; i < parameterSlot.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                parameterSlot[i] = nextSlot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                nextSlot += getWordsPerType(parameterTypes[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            int localSlot0 = nextSlot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            short pc, tryBegin = 0, tryEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            DataOutputStream out = new DataOutputStream(minfo.code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            code_aload(0, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            out.writeByte(opc_getfield);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            out.writeShort(cp.getFieldRef(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                superclassName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                handlerFieldName, "Ljava/lang/reflect/InvocationHandler;"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            code_aload(0, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
            out.writeByte(opc_getstatic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
            out.writeShort(cp.getFieldRef(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                dotToSlash(className),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                methodFieldName, "Ljava/lang/reflect/Method;"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
            if (parameterTypes.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                code_ipush(parameterTypes.length, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                out.writeByte(opc_anewarray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                out.writeShort(cp.getClass("java/lang/Object"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                for (int i = 0; i < parameterTypes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                    out.writeByte(opc_dup);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                    code_ipush(i, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                    codeWrapArgument(parameterTypes[i], parameterSlot[i], out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                    out.writeByte(opc_aastore);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                out.writeByte(opc_aconst_null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            out.writeByte(opc_invokeinterface);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            out.writeShort(cp.getInterfaceMethodRef(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                "java/lang/reflect/InvocationHandler",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                "invoke",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                "(Ljava/lang/Object;Ljava/lang/reflect/Method;" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                    "[Ljava/lang/Object;)Ljava/lang/Object;"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            out.writeByte(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            out.writeByte(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            if (returnType == void.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                out.writeByte(opc_pop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                out.writeByte(opc_return);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                codeUnwrapReturnValue(returnType, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            tryEnd = pc = (short) minfo.code.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   973
            List<Class<?>> catchList = computeUniqueCatchList(exceptionTypes);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
            if (catchList.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   976
                for (Class<?> ex : catchList) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                    minfo.exceptionTable.add(new ExceptionTableEntry(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
                        tryBegin, tryEnd, pc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                        cp.getClass(dotToSlash(ex.getName()))));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                out.writeByte(opc_athrow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                pc = (short) minfo.code.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                minfo.exceptionTable.add(new ExceptionTableEntry(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                    tryBegin, tryEnd, pc, cp.getClass("java/lang/Throwable")));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                code_astore(localSlot0, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                out.writeByte(opc_new);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                out.writeShort(cp.getClass(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
                    "java/lang/reflect/UndeclaredThrowableException"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                out.writeByte(opc_dup);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
                code_aload(localSlot0, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                out.writeByte(opc_invokespecial);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                out.writeShort(cp.getMethodRef(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                    "java/lang/reflect/UndeclaredThrowableException",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                    "<init>", "(Ljava/lang/Throwable;)V"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                out.writeByte(opc_athrow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            if (minfo.code.size() > 65535) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                throw new IllegalArgumentException("code size limit exceeded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
            minfo.maxStack = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
            minfo.maxLocals = (short) (localSlot0 + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
            minfo.declaredExceptions = new short[exceptionTypes.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
            for (int i = 0; i < exceptionTypes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                minfo.declaredExceptions[i] = cp.getClass(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                    dotToSlash(exceptionTypes[i].getName()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            return minfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
         * Generate code for wrapping an argument of the given type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
         * whose value can be found at the specified local variable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
         * index, in order for it to be passed (as an Object) to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
         * invocation handler's "invoke" method.  The code is written
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
         * to the supplied stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
         */
11119
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
  1030
        private void codeWrapArgument(Class<?> type, int slot,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                                      DataOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            if (type.isPrimitive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                PrimitiveTypeInfo prim = PrimitiveTypeInfo.get(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                if (type == int.class ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                    type == boolean.class ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                    type == byte.class ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                    type == char.class ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                    type == short.class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
                    code_iload(slot, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                } else if (type == long.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                    code_lload(slot, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                } else if (type == float.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                    code_fload(slot, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                } else if (type == double.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                    code_dload(slot, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                    throw new AssertionError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                out.writeByte(opc_invokestatic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                out.writeShort(cp.getMethodRef(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                    prim.wrapperClassName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                    "valueOf", prim.wrapperValueOfDesc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                code_aload(slot, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
         * Generate code for unwrapping a return value of the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
         * type from the invocation handler's "invoke" method (as type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
         * Object) to its correct type.  The code is written to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
         * supplied stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
         */
11119
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
  1071
        private void codeUnwrapReturnValue(Class<?> type, DataOutputStream out)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
            throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
            if (type.isPrimitive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                PrimitiveTypeInfo prim = PrimitiveTypeInfo.get(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                out.writeByte(opc_checkcast);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                out.writeShort(cp.getClass(prim.wrapperClassName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                out.writeByte(opc_invokevirtual);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                out.writeShort(cp.getMethodRef(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                    prim.wrapperClassName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                    prim.unwrapMethodName, prim.unwrapMethodDesc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                if (type == int.class ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                    type == boolean.class ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                    type == byte.class ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                    type == char.class ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                    type == short.class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                    out.writeByte(opc_ireturn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
                } else if (type == long.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                    out.writeByte(opc_lreturn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                } else if (type == float.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                    out.writeByte(opc_freturn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                } else if (type == double.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                    out.writeByte(opc_dreturn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                    throw new AssertionError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                out.writeByte(opc_checkcast);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                out.writeShort(cp.getClass(dotToSlash(type.getName())));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                out.writeByte(opc_areturn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
         * Generate code for initializing the static field that stores
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
         * the Method object for this proxy method.  The code is written
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
         * to the supplied stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        private void codeFieldInitialization(DataOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
            throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
            codeClassForName(fromClass, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            code_ldc(cp.getString(methodName), out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
            code_ipush(parameterTypes.length, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
            out.writeByte(opc_anewarray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
            out.writeShort(cp.getClass("java/lang/Class"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
            for (int i = 0; i < parameterTypes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                out.writeByte(opc_dup);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
                code_ipush(i, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                if (parameterTypes[i].isPrimitive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
                    PrimitiveTypeInfo prim =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
                        PrimitiveTypeInfo.get(parameterTypes[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
                    out.writeByte(opc_getstatic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
                    out.writeShort(cp.getFieldRef(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                        prim.wrapperClassName, "TYPE", "Ljava/lang/Class;"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
                    codeClassForName(parameterTypes[i], out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
                out.writeByte(opc_aastore);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
            out.writeByte(opc_invokevirtual);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
            out.writeShort(cp.getMethodRef(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
                "java/lang/Class",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                "getMethod",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                "(Ljava/lang/String;[Ljava/lang/Class;)" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
                "Ljava/lang/reflect/Method;"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
            out.writeByte(opc_putstatic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            out.writeShort(cp.getFieldRef(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                dotToSlash(className),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
                methodFieldName, "Ljava/lang/reflect/Method;"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     * Generate the constructor method for the proxy class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
    private MethodInfo generateConstructor() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
        MethodInfo minfo = new MethodInfo(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            "<init>", "(Ljava/lang/reflect/InvocationHandler;)V",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
            ACC_PUBLIC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        DataOutputStream out = new DataOutputStream(minfo.code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        code_aload(0, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        code_aload(1, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
        out.writeByte(opc_invokespecial);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
        out.writeShort(cp.getMethodRef(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
            superclassName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
            "<init>", "(Ljava/lang/reflect/InvocationHandler;)V"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        out.writeByte(opc_return);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        minfo.maxStack = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        minfo.maxLocals = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        minfo.declaredExceptions = new short[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        return minfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     * Generate the static initializer method for the proxy class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
    private MethodInfo generateStaticInitializer() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        MethodInfo minfo = new MethodInfo(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
            "<clinit>", "()V", ACC_STATIC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        int localSlot0 = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        short pc, tryBegin = 0, tryEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        DataOutputStream out = new DataOutputStream(minfo.code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
        for (List<ProxyMethod> sigmethods : proxyMethods.values()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
            for (ProxyMethod pm : sigmethods) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
                pm.codeFieldInitialization(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        out.writeByte(opc_return);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
        tryEnd = pc = (short) minfo.code.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        minfo.exceptionTable.add(new ExceptionTableEntry(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            tryBegin, tryEnd, pc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
            cp.getClass("java/lang/NoSuchMethodException")));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        code_astore(localSlot0, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        out.writeByte(opc_new);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        out.writeShort(cp.getClass("java/lang/NoSuchMethodError"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        out.writeByte(opc_dup);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        code_aload(localSlot0, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        out.writeByte(opc_invokevirtual);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        out.writeShort(cp.getMethodRef(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
            "java/lang/Throwable", "getMessage", "()Ljava/lang/String;"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        out.writeByte(opc_invokespecial);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
        out.writeShort(cp.getMethodRef(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
            "java/lang/NoSuchMethodError", "<init>", "(Ljava/lang/String;)V"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        out.writeByte(opc_athrow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        pc = (short) minfo.code.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        minfo.exceptionTable.add(new ExceptionTableEntry(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
            tryBegin, tryEnd, pc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
            cp.getClass("java/lang/ClassNotFoundException")));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        code_astore(localSlot0, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
        out.writeByte(opc_new);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        out.writeShort(cp.getClass("java/lang/NoClassDefFoundError"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        out.writeByte(opc_dup);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        code_aload(localSlot0, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
        out.writeByte(opc_invokevirtual);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        out.writeShort(cp.getMethodRef(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
            "java/lang/Throwable", "getMessage", "()Ljava/lang/String;"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
        out.writeByte(opc_invokespecial);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        out.writeShort(cp.getMethodRef(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
            "java/lang/NoClassDefFoundError",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
            "<init>", "(Ljava/lang/String;)V"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        out.writeByte(opc_athrow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
        if (minfo.code.size() > 65535) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
            throw new IllegalArgumentException("code size limit exceeded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
        minfo.maxStack = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
        minfo.maxLocals = (short) (localSlot0 + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        minfo.declaredExceptions = new short[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        return minfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
     * =============== Code Generation Utility Methods ===============
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
     * The following methods generate code for the load or store operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
     * indicated by their name for the given local variable.  The code is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
     * written to the supplied stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
    private void code_iload(int lvar, DataOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        codeLocalLoadStore(lvar, opc_iload, opc_iload_0, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
    private void code_lload(int lvar, DataOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
        codeLocalLoadStore(lvar, opc_lload, opc_lload_0, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
    private void code_fload(int lvar, DataOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
        codeLocalLoadStore(lvar, opc_fload, opc_fload_0, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
    private void code_dload(int lvar, DataOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
        codeLocalLoadStore(lvar, opc_dload, opc_dload_0, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
    private void code_aload(int lvar, DataOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
        codeLocalLoadStore(lvar, opc_aload, opc_aload_0, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
//  private void code_istore(int lvar, DataOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
//      throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
//  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
//      codeLocalLoadStore(lvar, opc_istore, opc_istore_0, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
//  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
//  private void code_lstore(int lvar, DataOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
//      throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
//  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
//      codeLocalLoadStore(lvar, opc_lstore, opc_lstore_0, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
//  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
//  private void code_fstore(int lvar, DataOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
//      throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
//  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
//      codeLocalLoadStore(lvar, opc_fstore, opc_fstore_0, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
//  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
//  private void code_dstore(int lvar, DataOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
//      throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
//  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
//      codeLocalLoadStore(lvar, opc_dstore, opc_dstore_0, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
//  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
    private void code_astore(int lvar, DataOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
        codeLocalLoadStore(lvar, opc_astore, opc_astore_0, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
     * Generate code for a load or store instruction for the given local
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
     * variable.  The code is written to the supplied stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
     * "opcode" indicates the opcode form of the desired load or store
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
     * instruction that takes an explicit local variable index, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
     * "opcode_0" indicates the corresponding form of the instruction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
     * with the implicit index 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
    private void codeLocalLoadStore(int lvar, int opcode, int opcode_0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
                                    DataOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
        assert lvar >= 0 && lvar <= 0xFFFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
        if (lvar <= 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
            out.writeByte(opcode_0 + lvar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
        } else if (lvar <= 0xFF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
            out.writeByte(opcode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
            out.writeByte(lvar & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
             * Use the "wide" instruction modifier for local variable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
             * indexes that do not fit into an unsigned byte.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
            out.writeByte(opc_wide);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
            out.writeByte(opcode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
            out.writeShort(lvar & 0xFFFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
     * Generate code for an "ldc" instruction for the given constant pool
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
     * index (the "ldc_w" instruction is used if the index does not fit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
     * into an unsigned byte).  The code is written to the supplied stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
    private void code_ldc(int index, DataOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
        assert index >= 0 && index <= 0xFFFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
        if (index <= 0xFF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
            out.writeByte(opc_ldc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
            out.writeByte(index & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
            out.writeByte(opc_ldc_w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
            out.writeShort(index & 0xFFFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
     * Generate code to push a constant integer value on to the operand
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
     * stack, using the "iconst_<i>", "bipush", or "sipush" instructions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
     * depending on the size of the value.  The code is written to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
     * supplied stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
    private void code_ipush(int value, DataOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
        if (value >= -1 && value <= 5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
            out.writeByte(opc_iconst_0 + value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
        } else if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
            out.writeByte(opc_bipush);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
            out.writeByte(value & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
        } else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
            out.writeByte(opc_sipush);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
            out.writeShort(value & 0xFFFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
            throw new AssertionError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
     * Generate code to invoke the Class.forName with the name of the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
     * class to get its Class object at runtime.  The code is written to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
     * the supplied stream.  Note that the code generated by this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
     * may caused the checked ClassNotFoundException to be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
     */
11119
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
  1420
    private void codeClassForName(Class<?> cl, DataOutputStream out)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
        code_ldc(cp.getString(cl.getName()), out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
        out.writeByte(opc_invokestatic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
        out.writeShort(cp.getMethodRef(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
            "java/lang/Class",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
            "forName", "(Ljava/lang/String;)Ljava/lang/Class;"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
     * ==================== General Utility Methods ====================
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
     * Convert a fully qualified class name that uses '.' as the package
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
     * separator, the external representation used by the Java language
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
     * and APIs, to a fully qualified class name that uses '/' as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
     * package separator, the representation used in the class file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
     * format (see JVMS section 4.2).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
    private static String dotToSlash(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
        return name.replace('.', '/');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
     * Return the "method descriptor" string for a method with the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
     * parameter types and return type.  See JVMS section 4.3.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
     */
11119
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
  1451
    private static String getMethodDescriptor(Class<?>[] parameterTypes,
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
  1452
                                              Class<?> returnType)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
        return getParameterDescriptors(parameterTypes) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
            ((returnType == void.class) ? "V" : getFieldType(returnType));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
     * Return the list of "parameter descriptor" strings enclosed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
     * parentheses corresponding to the given parameter types (in other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
     * words, a method descriptor without a return descriptor).  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
     * string is useful for constructing string keys for methods without
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
     * regard to their return type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
     */
11119
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
  1465
    private static String getParameterDescriptors(Class<?>[] parameterTypes) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
        StringBuilder desc = new StringBuilder("(");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
        for (int i = 0; i < parameterTypes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
            desc.append(getFieldType(parameterTypes[i]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
        desc.append(')');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
        return desc.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
     * Return the "field type" string for the given type, appropriate for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
     * a field descriptor, a parameter descriptor, or a return descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
     * other than "void".  See JVMS section 4.3.2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
     */
11119
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
  1479
    private static String getFieldType(Class<?> type) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
        if (type.isPrimitive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
            return PrimitiveTypeInfo.get(type).baseTypeString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
        } else if (type.isArray()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
             * According to JLS 20.3.2, the getName() method on Class does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
             * return the VM type descriptor format for array classes (only);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
             * using that should be quicker than the otherwise obvious code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
             *     return "[" + getTypeDescriptor(type.getComponentType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
            return type.getName().replace('.', '/');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
            return "L" + dotToSlash(type.getName()) + ";";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
     * Returns a human-readable string representing the signature of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
     * method with the given name and parameter types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
    private static String getFriendlyMethodSignature(String name,
11119
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
  1501
                                                     Class<?>[] parameterTypes)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
        StringBuilder sig = new StringBuilder(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
        sig.append('(');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
        for (int i = 0; i < parameterTypes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
            if (i > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
                sig.append(',');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
            }
11119
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
  1509
            Class<?> parameterType = parameterTypes[i];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
            int dimensions = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
            while (parameterType.isArray()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
                parameterType = parameterType.getComponentType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
                dimensions++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
            sig.append(parameterType.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
            while (dimensions-- > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
                sig.append("[]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
        sig.append(')');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
        return sig.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
     * Return the number of abstract "words", or consecutive local variable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
     * indexes, required to contain a value of the given type.  See JVMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
     * section 3.6.1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
     * Note that the original version of the JVMS contained a definition of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
     * this abstract notion of a "word" in section 3.4, but that definition
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
     * was removed for the second edition.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
     */
11119
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
  1533
    private static int getWordsPerType(Class<?> type) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
        if (type == long.class || type == double.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
            return 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
     * Add to the given list all of the types in the "from" array that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
     * are not already contained in the list and are assignable to at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
     * least one of the types in the "with" array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
     * This method is useful for computing the greatest common set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
     * declared exceptions from duplicate methods inherited from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
     * different interfaces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
     */
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
  1550
    private static void collectCompatibleTypes(Class<?>[] from,
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
  1551
                                               Class<?>[] with,
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
  1552
                                               List<Class<?>> list)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
    {
16923
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
  1554
        for (Class<?> fc: from) {
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
  1555
            if (!list.contains(fc)) {
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
  1556
                for (Class<?> wc: with) {
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
  1557
                    if (wc.isAssignableFrom(fc)) {
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
  1558
                        list.add(fc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
     * Given the exceptions declared in the throws clause of a proxy method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
     * compute the exceptions that need to be caught from the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
     * handler's invoke method and rethrown intact in the method's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
     * implementation before catching other Throwables and wrapping them
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
     * in UndeclaredThrowableExceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
     * The exceptions to be caught are returned in a List object.  Each
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
     * exception in the returned list is guaranteed to not be a subclass of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
     * any of the other exceptions in the list, so the catch blocks for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
     * these exceptions may be generated in any order relative to each other.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
     * Error and RuntimeException are each always contained by the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
     * list (if none of their superclasses are contained), since those
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
     * unchecked exceptions should always be rethrown intact, and thus their
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
     * subclasses will never appear in the returned list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
     * The returned List will be empty if java.lang.Throwable is in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
     * given list of declared exceptions, indicating that no exceptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
     * need to be caught.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
     */
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
  1587
    private static List<Class<?>> computeUniqueCatchList(Class<?>[] exceptions) {
16923
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
  1588
        List<Class<?>> uniqueList = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
                                                // unique exceptions to catch
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
        uniqueList.add(Error.class);            // always catch/rethrow these
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
        uniqueList.add(RuntimeException.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
    nextException:
16923
50bfa0defec2 8004260: dynamic proxy class should have the same Java language access as the proxy interfaces
mchung
parents: 14342
diff changeset
  1595
        for (Class<?> ex: exceptions) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
            if (ex.isAssignableFrom(Throwable.class)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
                 * If Throwable is declared to be thrown by the proxy method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
                 * then no catch blocks are necessary, because the invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
                 * can, at most, throw Throwable anyway.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
                uniqueList.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
            } else if (!Throwable.class.isAssignableFrom(ex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
                 * Ignore types that cannot be thrown by the invoke method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
             * Compare this exception against the current list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
             * exceptions that need to be caught:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
            for (int j = 0; j < uniqueList.size();) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
  1615
                Class<?> ex2 = uniqueList.get(j);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
                if (ex2.isAssignableFrom(ex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
                    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
                     * if a superclass of this exception is already on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
                     * the list to catch, then ignore this one and continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
                    continue nextException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
                } else if (ex.isAssignableFrom(ex2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
                    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
                     * if a subclass of this exception is on the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
                     * to catch, then remove it;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
                    uniqueList.remove(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
                    j++;        // else continue comparing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
            // This exception is unique (so far): add it to the list to catch.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
            uniqueList.add(ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
        return uniqueList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
     * A PrimitiveTypeInfo object contains assorted information about
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
     * a primitive type in its public fields.  The struct for a particular
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
     * primitive type can be obtained using the static "get" method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
    private static class PrimitiveTypeInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
        /** "base type" used in various descriptors (see JVMS section 4.3.2) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
        public String baseTypeString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
        /** name of corresponding wrapper class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
        public String wrapperClassName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
        /** method descriptor for wrapper class "valueOf" factory method */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
        public String wrapperValueOfDesc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
        /** name of wrapper class method for retrieving primitive value */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
        public String unwrapMethodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
        /** descriptor of same method */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
        public String unwrapMethodDesc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
11119
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
  1660
        private static Map<Class<?>,PrimitiveTypeInfo> table = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
        static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
            add(byte.class, Byte.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
            add(char.class, Character.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
            add(double.class, Double.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
            add(float.class, Float.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
            add(int.class, Integer.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
            add(long.class, Long.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
            add(short.class, Short.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
            add(boolean.class, Boolean.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
11119
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
  1672
        private static void add(Class<?> primitiveClass, Class<?> wrapperClass) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
            table.put(primitiveClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
                      new PrimitiveTypeInfo(primitiveClass, wrapperClass));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
11119
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
  1677
        private PrimitiveTypeInfo(Class<?> primitiveClass, Class<?> wrapperClass) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
            assert primitiveClass.isPrimitive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
            baseTypeString =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
                Array.newInstance(primitiveClass, 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
                .getClass().getName().substring(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
            wrapperClassName = dotToSlash(wrapperClass.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
            wrapperValueOfDesc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
                "(" + baseTypeString + ")L" + wrapperClassName + ";";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
            unwrapMethodName = primitiveClass.getName() + "Value";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
            unwrapMethodDesc = "()" + baseTypeString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
11119
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
  1690
        public static PrimitiveTypeInfo get(Class<?> cl) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
            return table.get(cl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
     * A ConstantPool object represents the constant pool of a class file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
     * being generated.  This representation of a constant pool is designed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
     * specifically for use by ProxyGenerator; in particular, it assumes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
     * that constant pool entries will not need to be resorted (for example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
     * by their type, as the Java compiler does), so that the final index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
     * value can be assigned and used when an entry is first created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
     * Note that new entries cannot be created after the constant pool has
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
     * been written to a class file.  To prevent such logic errors, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
     * ConstantPool instance can be marked "read only", so that further
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
     * attempts to add new entries will fail with a runtime exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
     * See JVMS section 4.4 for more information about the constant pool
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
     * of a class file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
    private static class ConstantPool {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
         * list of constant pool entries, in constant pool index order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
         * This list is used when writing the constant pool to a stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
         * and for assigning the next index value.  Note that element 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
         * of this list corresponds to constant pool index 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
         */
11119
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 10419
diff changeset
  1721
        private List<Entry> pool = new ArrayList<>(32);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
         * maps constant pool data of all types to constant pool indexes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
         * This map is used to look up the index of an existing entry for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
         * values of all types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
         */
49272
e137b71166c4 8199865: Avoid initializing ShortCache in ProxyGenerator
redestad
parents: 49250
diff changeset
  1729
        private Map<Object,Integer> map = new HashMap<>(16);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
        /** true if no new constant pool entries may be added */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
        private boolean readOnly = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
         * Get or assign the index for a CONSTANT_Utf8 entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
        public short getUtf8(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
            if (s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
                throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
            return getValue(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
         * Get or assign the index for a CONSTANT_Integer entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
        public short getInteger(int i) {
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 25187
diff changeset
  1748
            return getValue(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
         * Get or assign the index for a CONSTANT_Float entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
        public short getFloat(float f) {
37521
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 34704
diff changeset
  1755
            return getValue(f);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
         * Get or assign the index for a CONSTANT_Class entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
        public short getClass(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
            short utf8Index = getUtf8(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
            return getIndirect(new IndirectEntry(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
                CONSTANT_CLASS, utf8Index));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
         * Get or assign the index for a CONSTANT_String entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
        public short getString(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
            short utf8Index = getUtf8(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
            return getIndirect(new IndirectEntry(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
                CONSTANT_STRING, utf8Index));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
         * Get or assign the index for a CONSTANT_FieldRef entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
        public short getFieldRef(String className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
                                 String name, String descriptor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
            short classIndex = getClass(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
            short nameAndTypeIndex = getNameAndType(name, descriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
            return getIndirect(new IndirectEntry(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
                CONSTANT_FIELD, classIndex, nameAndTypeIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
         * Get or assign the index for a CONSTANT_MethodRef entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
        public short getMethodRef(String className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
                                  String name, String descriptor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
            short classIndex = getClass(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
            short nameAndTypeIndex = getNameAndType(name, descriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
            return getIndirect(new IndirectEntry(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
                CONSTANT_METHOD, classIndex, nameAndTypeIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
         * Get or assign the index for a CONSTANT_InterfaceMethodRef entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
        public short getInterfaceMethodRef(String className, String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
                                           String descriptor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
            short classIndex = getClass(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
            short nameAndTypeIndex = getNameAndType(name, descriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
            return getIndirect(new IndirectEntry(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
                CONSTANT_INTERFACEMETHOD, classIndex, nameAndTypeIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
         * Get or assign the index for a CONSTANT_NameAndType entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
        public short getNameAndType(String name, String descriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
            short nameIndex = getUtf8(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
            short descriptorIndex = getUtf8(descriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
            return getIndirect(new IndirectEntry(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
                CONSTANT_NAMEANDTYPE, nameIndex, descriptorIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
         * Set this ConstantPool instance to be "read only".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
         * After this method has been called, further requests to get
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
         * an index for a non-existent entry will cause an InternalError
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
         * to be thrown instead of creating of the entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
        public void setReadOnly() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
            readOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
         * Write this constant pool to a stream as part of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
         * the class file format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
         * This consists of writing the "constant_pool_count" and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
         * "constant_pool[]" items of the "ClassFile" structure, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
         * described in JVMS section 4.1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
        public void write(OutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
            DataOutputStream dataOut = new DataOutputStream(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
            // constant_pool_count: number of entries plus one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
            dataOut.writeShort(pool.size() + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
            for (Entry e : pool) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
                e.write(dataOut);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
         * Add a new constant pool entry and return its index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
        private short addEntry(Entry entry) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
            pool.add(entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
             * Note that this way of determining the index of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
             * added entry is wrong if this pool supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
             * CONSTANT_Long or CONSTANT_Double entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
            if (pool.size() >= 65535) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
                throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
                    "constant pool size limit exceeded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
            return (short) pool.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
         * Get or assign the index for an entry of a type that contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
         * a direct value.  The type of the given object determines the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
         * type of the desired entry as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
         *      java.lang.String        CONSTANT_Utf8
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
         *      java.lang.Integer       CONSTANT_Integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
         *      java.lang.Float         CONSTANT_Float
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
         *      java.lang.Long          CONSTANT_Long
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
         *      java.lang.Double        CONSTANT_DOUBLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
        private short getValue(Object key) {
49272
e137b71166c4 8199865: Avoid initializing ShortCache in ProxyGenerator
redestad
parents: 49250
diff changeset
  1881
            Integer index = map.get(key);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
            if (index != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
                return index.shortValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
                if (readOnly) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
                    throw new InternalError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
                        "late constant pool addition: " + key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
                short i = addEntry(new ValueEntry(key));
49272
e137b71166c4 8199865: Avoid initializing ShortCache in ProxyGenerator
redestad
parents: 49250
diff changeset
  1890
                map.put(key, (int)i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
         * Get or assign the index for an entry of a type that contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
         * references to other constant pool entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
        private short getIndirect(IndirectEntry e) {
49272
e137b71166c4 8199865: Avoid initializing ShortCache in ProxyGenerator
redestad
parents: 49250
diff changeset
  1900
            Integer index = map.get(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
            if (index != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
                return index.shortValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
                if (readOnly) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
                    throw new InternalError("late constant pool addition");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
                short i = addEntry(e);
49272
e137b71166c4 8199865: Avoid initializing ShortCache in ProxyGenerator
redestad
parents: 49250
diff changeset
  1908
                map.put(e, (int)i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
         * Entry is the abstact superclass of all constant pool entry types
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
         * that can be stored in the "pool" list; its purpose is to define a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
         * common method for writing constant pool entries to a class file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
         */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
  1918
        private abstract static class Entry {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
            public abstract void write(DataOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
                throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
         * ValueEntry represents a constant pool entry of a type that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
         * contains a direct value (see the comments for the "getValue"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
         * method for a list of such types).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
         * ValueEntry objects are not used as keys for their entries in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
         * Map "map", so no useful hashCode or equals methods are defined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
        private static class ValueEntry extends Entry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
            private Object value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
            public ValueEntry(Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
                this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
            public void write(DataOutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
                if (value instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
                    out.writeByte(CONSTANT_UTF8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
                    out.writeUTF((String) value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
                } else if (value instanceof Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
                    out.writeByte(CONSTANT_INTEGER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
                    out.writeInt(((Integer) value).intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
                } else if (value instanceof Float) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
                    out.writeByte(CONSTANT_FLOAT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
                    out.writeFloat(((Float) value).floatValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
                } else if (value instanceof Long) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
                    out.writeByte(CONSTANT_LONG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
                    out.writeLong(((Long) value).longValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
                } else if (value instanceof Double) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
                    out.writeDouble(CONSTANT_DOUBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
                    out.writeDouble(((Double) value).doubleValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
                    throw new InternalError("bogus value entry: " + value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
         * IndirectEntry represents a constant pool entry of a type that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
         * references other constant pool entries, i.e., the following types:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
         *      CONSTANT_Class, CONSTANT_String, CONSTANT_Fieldref,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
         *      CONSTANT_Methodref, CONSTANT_InterfaceMethodref, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
         *      CONSTANT_NameAndType.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
         * Each of these entry types contains either one or two indexes of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
         * other constant pool entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
         * IndirectEntry objects are used as the keys for their entries in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
         * the Map "map", so the hashCode and equals methods are overridden
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
         * to allow matching.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
        private static class IndirectEntry extends Entry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
            private int tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
            private short index0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
            private short index1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
             * Construct an IndirectEntry for a constant pool entry type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
             * that contains one index of another entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
            public IndirectEntry(int tag, short index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
                this.tag = tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
                this.index0 = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
                this.index1 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
             * Construct an IndirectEntry for a constant pool entry type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
             * that contains two indexes for other entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
            public IndirectEntry(int tag, short index0, short index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
                this.tag = tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
                this.index0 = index0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
                this.index1 = index1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
            public void write(DataOutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
                out.writeByte(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
                out.writeShort(index0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
                 * If this entry type contains two indexes, write
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
                 * out the second, too.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
                if (tag == CONSTANT_FIELD ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
                    tag == CONSTANT_METHOD ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
                    tag == CONSTANT_INTERFACEMETHOD ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
                    tag == CONSTANT_NAMEANDTYPE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
                    out.writeShort(index1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
            public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
                return tag + index0 + index1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
            public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
                if (obj instanceof IndirectEntry) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
                    IndirectEntry other = (IndirectEntry) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
                    if (tag == other.tag &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
                        index0 == other.index0 && index1 == other.index1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
                        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
}