jdk/test/com/sun/jdi/sde/InstallSDE.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 35388 a33a232cf7b7
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
class InstallSDE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
    static final boolean verbose = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
    static final String nameSDE = "SourceDebugExtension";
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
    byte[] orig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
    byte[] sdeAttr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
    byte[] gen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
    int origPos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
    int genPos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
    int sdeIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
    public static void main(String[] args) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
        if (args.length == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
            install(new File(args[0]), new File(args[1]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
        } else if (args.length == 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
            install(new File(args[0]), new File(args[1]), new File(args[2]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
            abort("Usage: <command> <input class file> " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
                               "<attribute file> <output class file name>\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
                  "<command> <input/output class file> <attribute file>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
    static void install(File inClassFile, File attrFile, File outClassFile)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
                                                            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
        new InstallSDE(inClassFile, attrFile, outClassFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
    static void install(File inOutClassFile, File attrFile) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
        File tmpFile = new File(inOutClassFile.getPath() + "tmp");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
        new InstallSDE(inOutClassFile, attrFile, tmpFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
        if (!inOutClassFile.delete()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
            throw new IOException("inOutClassFile.delete() failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        if (!tmpFile.renameTo(inOutClassFile)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
            throw new IOException("tmpFile.renameTo(inOutClassFile) failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    static void abort(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        System.err.println(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    InstallSDE(File inClassFile, File attrFile, File outClassFile) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        if (!inClassFile.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
            abort("no such file: " + inClassFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        if (!attrFile.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            abort("no such file: " + attrFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        // get the bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        orig = readWhole(inClassFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        sdeAttr = readWhole(attrFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        gen = new byte[orig.length + sdeAttr.length + 100];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        // do it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        addSDE();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        // write result
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        FileOutputStream outStream = new FileOutputStream(outClassFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        outStream.write(gen, 0, genPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        outStream.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    byte[] readWhole(File input) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        FileInputStream inStream = new FileInputStream(input);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        int len = (int)input.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        byte[] bytes = new byte[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        if (inStream.read(bytes, 0, len) != len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            abort("expected size: " + len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        inStream.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        return bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    void addSDE() throws UnsupportedEncodingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        copy(4 + 2 + 2); // magic min/maj version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        int constantPoolCountPos = genPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        int constantPoolCount = readU2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        writeU2(constantPoolCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        // copy old constant pool return index of SDE symbol, if found
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        sdeIndex = copyConstantPool(constantPoolCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        if (sdeIndex < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            // if "SourceDebugExtension" symbol not there add it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            writeUtf8ForSDE();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            // increment the countantPoolCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            sdeIndex = constantPoolCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            ++constantPoolCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            randomAccessWriteU2(constantPoolCountPos, constantPoolCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                System.out.println("SourceDebugExtension not found, installed at: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                                   sdeIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                System.out.println("SourceDebugExtension found at: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                                   sdeIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        copy(2 + 2 + 2);  // access, this, super
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        int interfaceCount = readU2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        writeU2(interfaceCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            System.out.println("interfaceCount: " + interfaceCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        copy(interfaceCount * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        copyMembers(); // fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        copyMembers(); // methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        int attrCountPos = genPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        int attrCount = readU2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        writeU2(attrCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            System.out.println("class attrCount: " + attrCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        // copy the class attributes, return true if SDE attr found (not copied)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        if (!copyAttrs(attrCount)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            // we will be adding SDE and it isn't already counted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            ++attrCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            randomAccessWriteU2(attrCountPos, attrCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                System.out.println("class attrCount incremented");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        writeAttrForSDE(sdeIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    void copyMembers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        int count = readU2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        writeU2(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            System.out.println("members count: " + count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        for (int i = 0; i < count; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            copy(6); // access, name, descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            int attrCount = readU2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            writeU2(attrCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                System.out.println("member attr count: " + attrCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            copyAttrs(attrCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    boolean copyAttrs(int attrCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        boolean sdeFound = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        for (int i = 0; i < attrCount; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            int nameIndex = readU2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            // don't write old SDE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            if (nameIndex == sdeIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                sdeFound = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                    System.out.println("SDE attr found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                writeU2(nameIndex);  // name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                int len = readU4();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                writeU4(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                copy(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                    System.out.println("attr len: " + len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        return sdeFound;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    void writeAttrForSDE(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        writeU2(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        writeU4(sdeAttr.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        for (int i = 0; i < sdeAttr.length; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            writeU1(sdeAttr[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    void randomAccessWriteU2(int pos, int val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        int savePos = genPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        genPos = pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        writeU2(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        genPos = savePos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    int readU1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return ((int)orig[origPos++]) & 0xFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    int readU2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
         int res = readU1();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        return (res << 8) + readU1();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    int readU4() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        int res = readU2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        return (res << 16) + readU2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    void writeU1(int val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        gen[genPos++] = (byte)val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    void writeU2(int val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        writeU1(val >> 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        writeU1(val & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    void writeU4(int val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        writeU2(val >> 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        writeU2(val & 0xFFFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    void copy(int count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        for (int i = 0; i < count; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            gen[genPos++] = orig[origPos++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    byte[] readBytes(int count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        byte[] bytes = new byte[count];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        for (int i = 0; i < count; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            bytes[i] = orig[origPos++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        return bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    void writeBytes(byte[] bytes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        for (int i = 0; i < bytes.length; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            gen[genPos++] = bytes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    int copyConstantPool(int constantPoolCount) throws UnsupportedEncodingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        int sdeIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        // copy const pool index zero not in class file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        for (int i = 1; i < constantPoolCount; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            int tag = readU1();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            writeU1(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                case 7:  // Class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                case 8:  // String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                    copy(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                case 9:  // Field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                case 10: // Method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                case 11: // InterfaceMethod
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                case 3:  // Integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                case 4:  // Float
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                case 12: // NameAndType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                    copy(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                case 5:  // Long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                case 6:  // Double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                    copy(8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                case 1:  // Utf8
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                    int len = readU2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                    writeU2(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                    byte[] utf8 = readBytes(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    String str = new String(utf8, "UTF-8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                    if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                        System.out.println(i + " read class attr -- '" + str + "'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                    if (str.equals(nameSDE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                        sdeIndex = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                    writeBytes(utf8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                    abort("unexpected tag: " + tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        return sdeIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    void writeUtf8ForSDE() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        int len = nameSDE.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        writeU1(1); // Utf8 tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        writeU2(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        for (int i = 0; i < len; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            writeU1(nameSDE.charAt(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
}