jdk/src/share/classes/com/sun/java/util/jar/pack/ClassWriter.java
author never
Mon, 12 Jul 2010 22:27:18 -0700
changeset 5926 a36f90d986b6
parent 5506 202f599c92aa
child 7192 445c518364c4
permissions -rw-r--r--
6968385: malformed xml in sweeper logging Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2001, 2003, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.java.util.jar.pack;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import com.sun.java.util.jar.pack.Package.Class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import com.sun.java.util.jar.pack.Package.InnerClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import com.sun.java.util.jar.pack.ConstantPool.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Writer for a class file that is incorporated into a package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * @author John Rose
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
class ClassWriter implements Constants {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    int verbose;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    Package pkg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    Class cls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    DataOutputStream out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    Index cpIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    ClassWriter(Class cls, OutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        this.pkg = cls.getPackage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        this.cls = cls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        this.verbose = pkg.verbose;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        this.out = new DataOutputStream(new BufferedOutputStream(out));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        this.cpIndex = ConstantPool.makeIndex(cls.toString(), cls.getCPMap());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        this.cpIndex.flattenSigs = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        if (verbose > 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            Utils.log.fine("local CP="+(verbose > 2 ? cpIndex.dumpString() : cpIndex.toString()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private void writeShort(int x) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        out.writeShort(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private void writeInt(int x) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        out.writeInt(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /** Write a 2-byte int representing a CP entry, using the local cpIndex. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private void writeRef(Entry e) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        int i = (e == null) ? 0 : cpIndex.indexOf(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        writeShort(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    void write() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        boolean ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            if (verbose > 1)  Utils.log.fine("...writing "+cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            writeMagicNumbers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            writeConstantPool();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            writeHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            writeMembers(false);  // fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            writeMembers(true);   // methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            writeAttributes(ATTR_CONTEXT_CLASS, cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            /* Closing here will cause all the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
               streams to close, Causing the jar stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
               to close prematurely, instead we just flush.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
               out.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            ok = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            if (!ok) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                Utils.log.warning("Error on output of "+cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    void writeMagicNumbers() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        writeInt(cls.magic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        writeShort(cls.minver);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        writeShort(cls.majver);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    void writeConstantPool() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        Entry[] cpMap = cls.cpMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        writeShort(cpMap.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        for (int i = 0; i < cpMap.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            Entry e = cpMap[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            assert((e == null) == (i == 0 || cpMap[i-1] != null && cpMap[i-1].isDoubleWord()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            if (e == null)  continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            byte tag = e.getTag();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            if (verbose > 2)  Utils.log.fine("   CP["+i+"] = "+e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            out.write(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                case CONSTANT_Signature:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                    assert(false);  // should not reach here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                case CONSTANT_Utf8:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                    out.writeUTF(e.stringValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                case CONSTANT_Integer:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                    out.writeInt(((NumberEntry)e).numberValue().intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                case CONSTANT_Float:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                    float fval = ((NumberEntry)e).numberValue().floatValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                    out.writeInt(Float.floatToRawIntBits(fval));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                case CONSTANT_Long:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    out.writeLong(((NumberEntry)e).numberValue().longValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                case CONSTANT_Double:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                    double dval = ((NumberEntry)e).numberValue().doubleValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                    out.writeLong(Double.doubleToRawLongBits(dval));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                case CONSTANT_Class:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                case CONSTANT_String:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    writeRef(e.getRef(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                case CONSTANT_Fieldref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                case CONSTANT_Methodref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                case CONSTANT_InterfaceMethodref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                case CONSTANT_NameandType:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                    writeRef(e.getRef(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                    writeRef(e.getRef(1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                    throw new IOException("Bad constant pool tag "+tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    void writeHeader() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        writeShort(cls.flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        writeRef(cls.thisClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        writeRef(cls.superClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        writeShort(cls.interfaces.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        for (int i = 0; i < cls.interfaces.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            writeRef(cls.interfaces[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    void writeMembers(boolean doMethods) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        List mems;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        if (!doMethods)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            mems = cls.getFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            mems = cls.getMethods();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        writeShort(mems.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        for (Iterator i = mems.iterator(); i.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            Class.Member m = (Class.Member) i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            writeMember(m, doMethods);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    void writeMember(Class.Member m, boolean doMethod) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        if (verbose > 2)  Utils.log.fine("writeMember "+m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        writeShort(m.flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        writeRef(m.getDescriptor().nameRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        writeRef(m.getDescriptor().typeRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        writeAttributes(!doMethod ? ATTR_CONTEXT_FIELD : ATTR_CONTEXT_METHOD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                        m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    // handy buffer for collecting attrs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    ByteArrayOutputStream buf    = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    DataOutputStream      bufOut = new DataOutputStream(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    void writeAttributes(int ctype, Attribute.Holder h) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        if (h.attributes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            writeShort(0);  // attribute size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        writeShort(h.attributes.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        for (Iterator i = h.attributes.iterator(); i.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            Attribute a = (Attribute) i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            a.finishRefs(cpIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            writeRef(a.getNameRef());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            if (a.layout() == Package.attrCodeEmpty ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                a.layout() == Package.attrInnerClassesEmpty) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                // These are hardwired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                DataOutputStream savedOut = out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                assert(out != bufOut);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                buf.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                out = bufOut;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                if (a.name() == "Code") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    Class.Method m = (Class.Method) h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    writeCode(m.code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                    assert(h == cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                    writeInnerClasses(cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                out = savedOut;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                if (verbose > 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                    Utils.log.fine("Attribute "+a.name()+" ["+buf.size()+"]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                writeInt(buf.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                buf.writeTo(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                if (verbose > 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                    Utils.log.fine("Attribute "+a.name()+" ["+a.size()+"]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                writeInt(a.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                out.write(a.bytes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    void writeCode(Code code) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        code.finishRefs(cpIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        writeShort(code.max_stack);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        writeShort(code.max_locals);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        writeInt(code.bytes.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        out.write(code.bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        int nh = code.getHandlerCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        writeShort(nh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        for (int i = 0; i < nh; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
             writeShort(code.handler_start[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
             writeShort(code.handler_end[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
             writeShort(code.handler_catch[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
             writeRef(code.handler_class[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        writeAttributes(ATTR_CONTEXT_CODE, code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    void writeInnerClasses(Class cls) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        List ics = cls.getInnerClasses();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        writeShort(ics.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        for (Iterator i = ics.iterator(); i.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            InnerClass ic = (InnerClass) i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            writeRef(ic.thisClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            writeRef(ic.outerClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            writeRef(ic.name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            writeShort(ic.flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
}