langtools/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java
author mcimadamore
Wed, 13 Feb 2013 17:04:21 +0000
changeset 15720 e61b2f7a5148
parent 15718 8e54c8e43d38
child 16300 7cf27559c8df
permissions -rw-r--r--
8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API 8006896: ClassReader doesn't see MethodParameters attr for method of anon inner class 8007098: Output Synthesized Parameters to MethodParameters Attributes Summary: Correctly report synthesized and mandated parameters Reviewed-by: mcimadamore, jjg Contributed-by: eric.mccorkle@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
     2
 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4872
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4872
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4872
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4872
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4872
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.jvm;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.io.*;
14046
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
    29
import java.util.LinkedHashMap;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
    30
import java.util.Map;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import java.util.Set;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import java.util.HashSet;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
    34
import javax.lang.model.type.TypeKind;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import javax.tools.JavaFileManager;
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
import javax.tools.FileObject;
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import javax.tools.JavaFileObject;
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
import com.sun.tools.javac.code.*;
6575
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents: 6143
diff changeset
    40
import com.sun.tools.javac.code.Attribute.RetentionPolicy;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
    41
import com.sun.tools.javac.code.Attribute.TypeCompound;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
import com.sun.tools.javac.code.Symbol.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
import com.sun.tools.javac.code.Type.*;
14949
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
    44
import com.sun.tools.javac.code.Types.UniqueType;
3995
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3300
diff changeset
    45
import com.sun.tools.javac.file.BaseFileObject;
14949
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
    46
import com.sun.tools.javac.jvm.Pool.DynamicMethod;
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
    47
import com.sun.tools.javac.jvm.Pool.Method;
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
    48
import com.sun.tools.javac.jvm.Pool.MethodHandle;
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
    49
import com.sun.tools.javac.jvm.Pool.Variable;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
import com.sun.tools.javac.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
import static com.sun.tools.javac.code.Flags.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
import static com.sun.tools.javac.code.Kinds.*;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14053
diff changeset
    54
import static com.sun.tools.javac.code.TypeTag.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
import static com.sun.tools.javac.jvm.UninitializedType.*;
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 11052
diff changeset
    56
import static com.sun.tools.javac.main.Option.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
import static javax.tools.StandardLocation.CLASS_OUTPUT;
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6592
diff changeset
    59
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
/** This class provides operations to map an internal symbol table graph
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
 *  rooted in a ClassSymbol into a classfile.
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    63
 *  <p><b>This is NOT part of any supported API.
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    64
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
public class ClassWriter extends ClassFile {
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    protected static final Context.Key<ClassWriter> classWriterKey =
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
        new Context.Key<ClassWriter>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
    private final Options options;
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    /** Switch: verbose output.
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
    private boolean verbose;
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
    78
    /** Switch: scramble private field names.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    private boolean scramble;
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
    82
    /** Switch: scramble all field names.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    private boolean scrambleAll;
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    /** Switch: retrofit mode.
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    private boolean retrofit;
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    /** Switch: emit source file attribute.
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    private boolean emitSourceFile;
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
    /** Switch: generate CharacterRangeTable attribute.
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
    private boolean genCrt;
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
    98
    /** Switch: describe the generated stackmap.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    boolean debugstackmap;
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
     * Target class version.
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
    private Target target;
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
     * Source language version.
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
    private Source source;
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
    /** Type utilities. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
    private Types types;
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    /** The initial sizes of the data and constant pool buffers.
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   116
     *  Sizes are increased when buffers get full.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
    static final int DATA_BUF_SIZE = 0x0fff0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
    static final int POOL_BUF_SIZE = 0x1fff0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
    /** An output buffer for member info.
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    ByteBuffer databuf = new ByteBuffer(DATA_BUF_SIZE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    /** An output buffer for the constant pool.
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
    ByteBuffer poolbuf = new ByteBuffer(POOL_BUF_SIZE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
    /** An output buffer for type signatures.
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
    ByteBuffer sigbuf = new ByteBuffer();
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    /** The constant pool.
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
    Pool pool;
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
    /** The inner classes to be written, as a set.
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
    Set<ClassSymbol> innerClasses;
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
    /** The inner classes to be written, as a queue where
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
     *  enclosing classes come first.
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
    ListBuffer<ClassSymbol> innerClassesQueue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
14046
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
   146
    /** The bootstrap methods to be written in the corresponding class attribute
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
   147
     *  (one for each invokedynamic)
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
   148
     */
14949
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
   149
    Map<DynamicMethod, MethodHandle> bootstrapMethods;
14046
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
   150
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
    /** The log to use for verbose output.
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
    private final Log log;
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
    /** The name table. */
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
   156
    private final Names names;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
    /** Access to files. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
    private final JavaFileManager fileManager;
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
    /** The tags and constants used in compressed stackmap. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
    static final int SAME_FRAME_SIZE = 64;
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    static final int SAME_LOCALS_1_STACK_ITEM_EXTENDED = 247;
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
    static final int SAME_FRAME_EXTENDED = 251;
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
    static final int FULL_FRAME = 255;
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    static final int MAX_LOCAL_LENGTH_DIFF = 4;
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
    /** Get the ClassWriter instance for this context. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
    public static ClassWriter instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
        ClassWriter instance = context.get(classWriterKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
        if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
            instance = new ClassWriter(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
    /** Construct a class writer, given an options table.
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
     */
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12213
diff changeset
   178
    protected ClassWriter(Context context) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
        context.put(classWriterKey, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
        log = Log.instance(context);
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
   182
        names = Names.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
        options = Options.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
        target = Target.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
        source = Source.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
        types = Types.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
        fileManager = context.get(JavaFileManager.class);
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6592
diff changeset
   189
        verbose        = options.isSet(VERBOSE);
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6592
diff changeset
   190
        scramble       = options.isSet("-scramble");
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6592
diff changeset
   191
        scrambleAll    = options.isSet("-scrambleAll");
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6592
diff changeset
   192
        retrofit       = options.isSet("-retrofit");
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6592
diff changeset
   193
        genCrt         = options.isSet(XJCOV);
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6592
diff changeset
   194
        debugstackmap  = options.isSet("debugstackmap");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6592
diff changeset
   196
        emitSourceFile = options.isUnset(G_CUSTOM) ||
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6592
diff changeset
   197
                            options.isSet(G_CUSTOM, "source");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
        String dumpModFlags = options.get("dumpmodifiers");
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
        dumpClassModifiers =
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
            (dumpModFlags != null && dumpModFlags.indexOf('c') != -1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
        dumpFieldModifiers =
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
            (dumpModFlags != null && dumpModFlags.indexOf('f') != -1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
        dumpInnerClassModifiers =
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
            (dumpModFlags != null && dumpModFlags.indexOf('i') != -1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
        dumpMethodModifiers =
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
            (dumpModFlags != null && dumpModFlags.indexOf('m') != -1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
/******************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
 * Diagnostics: dump generated class names and modifiers
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
 ******************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
    /** Value of option 'dumpmodifiers' is a string
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
     *  indicating which modifiers should be dumped for debugging:
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
     *    'c' -- classes
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
     *    'f' -- fields
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
     *    'i' -- innerclass attributes
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
     *    'm' -- methods
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
     *  For example, to dump everything:
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
     *    javac -XDdumpmodifiers=cifm MyProg.java
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
    private final boolean dumpClassModifiers; // -XDdumpmodifiers=c
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
    private final boolean dumpFieldModifiers; // -XDdumpmodifiers=f
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
    private final boolean dumpInnerClassModifiers; // -XDdumpmodifiers=i
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
    private final boolean dumpMethodModifiers; // -XDdumpmodifiers=m
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
    /** Return flags as a string, separated by " ".
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
    public static String flagNames(long flags) {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
   232
        StringBuilder sbuf = new StringBuilder();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
        int i = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
        long f = flags & StandardFlags;
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
        while (f != 0) {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
   236
            if ((f & 1) != 0) {
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
   237
                sbuf.append(" ");
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
   238
                sbuf.append(flagName[i]);
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
   239
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
            f = f >> 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
            i++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
        return sbuf.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
    //where
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
        private final static String[] flagName = {
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
            "PUBLIC", "PRIVATE", "PROTECTED", "STATIC", "FINAL",
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
            "SUPER", "VOLATILE", "TRANSIENT", "NATIVE", "INTERFACE",
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
            "ABSTRACT", "STRICTFP"};
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
/******************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
 * Output routines
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
 ******************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
    /** Write a character into given byte buffer;
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
     *  byte buffer will not be grown.
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
    void putChar(ByteBuffer buf, int op, int x) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
        buf.elems[op  ] = (byte)((x >>  8) & 0xFF);
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
        buf.elems[op+1] = (byte)((x      ) & 0xFF);
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
    /** Write an integer into given byte buffer;
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
     *  byte buffer will not be grown.
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
    void putInt(ByteBuffer buf, int adr, int x) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
        buf.elems[adr  ] = (byte)((x >> 24) & 0xFF);
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
        buf.elems[adr+1] = (byte)((x >> 16) & 0xFF);
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
        buf.elems[adr+2] = (byte)((x >>  8) & 0xFF);
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
        buf.elems[adr+3] = (byte)((x      ) & 0xFF);
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
/******************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
 * Signature Generation
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
 ******************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
    /** Assemble signature of given type in string buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
    void assembleSig(Type type) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   280
        type = type.unannotatedType();
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14053
diff changeset
   281
        switch (type.getTag()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
        case BYTE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
            sigbuf.appendByte('B');
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
        case SHORT:
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
            sigbuf.appendByte('S');
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
        case CHAR:
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
            sigbuf.appendByte('C');
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
        case INT:
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
            sigbuf.appendByte('I');
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
        case LONG:
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
            sigbuf.appendByte('J');
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
        case FLOAT:
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
            sigbuf.appendByte('F');
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
        case DOUBLE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
            sigbuf.appendByte('D');
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
        case BOOLEAN:
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
            sigbuf.appendByte('Z');
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
        case VOID:
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
            sigbuf.appendByte('V');
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
        case CLASS:
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
            sigbuf.appendByte('L');
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
            assembleClassSig(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
            sigbuf.appendByte(';');
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
        case ARRAY:
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
            ArrayType at = (ArrayType)type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
            sigbuf.appendByte('[');
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
            assembleSig(at.elemtype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
        case METHOD:
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
            MethodType mt = (MethodType)type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
            sigbuf.appendByte('(');
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
            assembleSig(mt.argtypes);
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
            sigbuf.appendByte(')');
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
            assembleSig(mt.restype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
            if (hasTypeVar(mt.thrown)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
                for (List<Type> l = mt.thrown; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
                    sigbuf.appendByte('^');
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
                    assembleSig(l.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
        case WILDCARD: {
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
            WildcardType ta = (WildcardType) type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
            switch (ta.kind) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
            case SUPER:
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
                sigbuf.appendByte('-');
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
                assembleSig(ta.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
            case EXTENDS:
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
                sigbuf.appendByte('+');
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
                assembleSig(ta.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
            case UNBOUND:
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
                sigbuf.appendByte('*');
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
            default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
                throw new AssertionError(ta.kind);
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
        case TYPEVAR:
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
            sigbuf.appendByte('T');
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
            sigbuf.appendName(type.tsym.name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
            sigbuf.appendByte(';');
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
        case FORALL:
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
            ForAll ft = (ForAll)type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
            assembleParamsSig(ft.tvars);
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
            assembleSig(ft.qtype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
        case UNINITIALIZED_THIS:
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
        case UNINITIALIZED_OBJECT:
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
            // we don't yet have a spec for uninitialized types in the
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
            // local variable table
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
            assembleSig(types.erasure(((UninitializedType)type).qtype));
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
        default:
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14053
diff changeset
   368
            throw new AssertionError("typeSig " + type.getTag());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
    boolean hasTypeVar(List<Type> l) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
        while (l.nonEmpty()) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14053
diff changeset
   374
            if (l.head.hasTag(TYPEVAR)) return true;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
            l = l.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
    void assembleClassSig(Type type) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   381
        type = type.unannotatedType();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
        ClassType ct = (ClassType)type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
        ClassSymbol c = (ClassSymbol)ct.tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
        enterInner(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
        Type outer = ct.getEnclosingType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
        if (outer.allparams().nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
            boolean rawOuter =
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
                c.owner.kind == MTH || // either a local class
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
                c.name == names.empty; // or anonymous
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
            assembleClassSig(rawOuter
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
                             ? types.erasure(outer)
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
                             : outer);
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
            sigbuf.appendByte('.');
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
   394
            Assert.check(c.flatname.startsWith(c.owner.enclClass().flatname));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
            sigbuf.appendName(rawOuter
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
   396
                              ? c.flatname.subName(c.owner.enclClass().flatname.getByteLength()+1,c.flatname.getByteLength())
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
                              : c.name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
            sigbuf.appendBytes(externalize(c.flatname));
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
        if (ct.getTypeArguments().nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
            sigbuf.appendByte('<');
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
            assembleSig(ct.getTypeArguments());
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
            sigbuf.appendByte('>');
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
    void assembleSig(List<Type> types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
        for (List<Type> ts = types; ts.nonEmpty(); ts = ts.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
            assembleSig(ts.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
    void assembleParamsSig(List<Type> typarams) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
        sigbuf.appendByte('<');
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
        for (List<Type> ts = typarams; ts.nonEmpty(); ts = ts.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
            TypeVar tvar = (TypeVar)ts.head;
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
            sigbuf.appendName(tvar.tsym.name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
            List<Type> bounds = types.getBounds(tvar);
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
            if ((bounds.head.tsym.flags() & INTERFACE) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
                sigbuf.appendByte(':');
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
            for (List<Type> l = bounds; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
                sigbuf.appendByte(':');
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
                assembleSig(l.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
        sigbuf.appendByte('>');
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
    /** Return signature of given type
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
    Name typeSig(Type type) {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
   434
        Assert.check(sigbuf.length == 0);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
        //- System.out.println(" ? " + type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
        assembleSig(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
        Name n = sigbuf.toName(names);
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
        sigbuf.reset();
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
        //- System.out.println("   " + n);
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
        return n;
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
    /** Given a type t, return the extended class name of its erasure in
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
     *  external representation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
    public Name xClassName(Type t) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14053
diff changeset
   447
        if (t.hasTag(CLASS)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
            return names.fromUtf(externalize(t.tsym.flatName()));
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14053
diff changeset
   449
        } else if (t.hasTag(ARRAY)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
            return typeSig(types.erasure(t));
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
            throw new AssertionError("xClassName");
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
/******************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
 * Writing the Constant Pool
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
 ******************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
    /** Thrown when the constant pool is over full.
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
    public static class PoolOverflow extends Exception {
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
        private static final long serialVersionUID = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
        public PoolOverflow() {}
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
    public static class StringOverflow extends Exception {
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
        private static final long serialVersionUID = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
        public final String value;
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
        public StringOverflow(String s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
            value = s;
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
    /** Write constant pool to pool buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
     *  Note: during writing, constant pool
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
     *  might grow since some parts of constants still need to be entered.
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
    void writePool(Pool pool) throws PoolOverflow, StringOverflow {
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
        int poolCountIdx = poolbuf.length;
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
        poolbuf.appendChar(0);
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
        int i = 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
        while (i < pool.pp) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
            Object value = pool.pool[i];
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
   484
            Assert.checkNonNull(value);
15564
6d8db91563a7 8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents: 15385
diff changeset
   485
            if (value instanceof Method || value instanceof Variable)
6d8db91563a7 8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed
vromero
parents: 15385
diff changeset
   486
                value = ((DelegatedSymbol)value).getUnderlyingSymbol();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
            if (value instanceof MethodSymbol) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
                MethodSymbol m = (MethodSymbol)value;
14046
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
   490
                if (!m.isDynamic()) {
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
   491
                    poolbuf.appendByte((m.owner.flags() & INTERFACE) != 0
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
   492
                              ? CONSTANT_InterfaceMethodref
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
   493
                              : CONSTANT_Methodref);
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
   494
                    poolbuf.appendChar(pool.put(m.owner));
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
   495
                    poolbuf.appendChar(pool.put(nameType(m)));
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
   496
                } else {
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
   497
                    //invokedynamic
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
   498
                    DynamicMethodSymbol dynSym = (DynamicMethodSymbol)m;
14949
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
   499
                    MethodHandle handle = new MethodHandle(dynSym.bsmKind, dynSym.bsm, types);
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
   500
                    DynamicMethod dynMeth = new DynamicMethod(dynSym, types);
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
   501
                    bootstrapMethods.put(dynMeth, handle);
14046
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
   502
                    //init cp entries
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
   503
                    pool.put(names.BootstrapMethods);
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
   504
                    pool.put(handle);
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
   505
                    for (Object staticArg : dynSym.staticArgs) {
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
   506
                        pool.put(staticArg);
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
   507
                    }
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
   508
                    poolbuf.appendByte(CONSTANT_InvokeDynamic);
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
   509
                    poolbuf.appendChar(bootstrapMethods.size() - 1);
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
   510
                    poolbuf.appendChar(pool.put(nameType(dynSym)));
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
   511
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
            } else if (value instanceof VarSymbol) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
                VarSymbol v = (VarSymbol)value;
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
                poolbuf.appendByte(CONSTANT_Fieldref);
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
                poolbuf.appendChar(pool.put(v.owner));
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
                poolbuf.appendChar(pool.put(nameType(v)));
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
            } else if (value instanceof Name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
                poolbuf.appendByte(CONSTANT_Utf8);
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
                byte[] bs = ((Name)value).toUtf();
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
                poolbuf.appendChar(bs.length);
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
                poolbuf.appendBytes(bs, 0, bs.length);
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
                if (bs.length > Pool.MAX_STRING_LENGTH)
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
                    throw new StringOverflow(value.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
            } else if (value instanceof ClassSymbol) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
                ClassSymbol c = (ClassSymbol)value;
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
                if (c.owner.kind == TYP) pool.put(c.owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
                poolbuf.appendByte(CONSTANT_Class);
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14053
diff changeset
   528
                if (c.type.hasTag(ARRAY)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
                    poolbuf.appendChar(pool.put(typeSig(c.type)));
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
                    poolbuf.appendChar(pool.put(names.fromUtf(externalize(c.flatname))));
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
                    enterInner(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
            } else if (value instanceof NameAndType) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
                NameAndType nt = (NameAndType)value;
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
                poolbuf.appendByte(CONSTANT_NameandType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
                poolbuf.appendChar(pool.put(nt.name));
14949
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
   538
                poolbuf.appendChar(pool.put(typeSig(nt.uniqueType.type)));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
            } else if (value instanceof Integer) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
                poolbuf.appendByte(CONSTANT_Integer);
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
                poolbuf.appendInt(((Integer)value).intValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
            } else if (value instanceof Long) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
                poolbuf.appendByte(CONSTANT_Long);
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
                poolbuf.appendLong(((Long)value).longValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
                i++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
            } else if (value instanceof Float) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
                poolbuf.appendByte(CONSTANT_Float);
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
                poolbuf.appendFloat(((Float)value).floatValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
            } else if (value instanceof Double) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
                poolbuf.appendByte(CONSTANT_Double);
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
                poolbuf.appendDouble(((Double)value).doubleValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
                i++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
            } else if (value instanceof String) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
                poolbuf.appendByte(CONSTANT_String);
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
                poolbuf.appendChar(pool.put(names.fromString((String)value)));
14949
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
   556
            } else if (value instanceof UniqueType) {
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
   557
                Type type = ((UniqueType)value).type;
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
   558
                if (type instanceof MethodType) {
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
   559
                    poolbuf.appendByte(CONSTANT_MethodType);
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
   560
                    poolbuf.appendChar(pool.put(typeSig((MethodType)type)));
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
   561
                } else {
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
   562
                    if (type.hasTag(CLASS)) enterInner((ClassSymbol)type.tsym);
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
   563
                    poolbuf.appendByte(CONSTANT_Class);
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
   564
                    poolbuf.appendChar(pool.put(xClassName(type)));
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
   565
                }
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
   566
            } else if (value instanceof MethodHandle) {
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
   567
                MethodHandle ref = (MethodHandle)value;
14046
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
   568
                poolbuf.appendByte(CONSTANT_MethodHandle);
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
   569
                poolbuf.appendByte(ref.refKind);
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
   570
                poolbuf.appendChar(pool.put(ref.refSym));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   571
            } else {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
   572
                Assert.error("writePool " + value);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   573
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
            i++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
        if (pool.pp > Pool.MAX_ENTRIES)
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
            throw new PoolOverflow();
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
        putChar(poolbuf, poolCountIdx, pool.pp);
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
    /** Given a field, return its name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
    Name fieldName(Symbol sym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
        if (scramble && (sym.flags() & PRIVATE) != 0 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
            scrambleAll && (sym.flags() & (PROTECTED | PUBLIC)) == 0)
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
   586
            return names.fromString("_$" + sym.name.getIndex());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
            return sym.name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
    /** Given a symbol, return its name-and-type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
    NameAndType nameType(Symbol sym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
        return new NameAndType(fieldName(sym),
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
                               retrofit
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
                               ? sym.erasure(types)
14949
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
   597
                               : sym.externalType(types), types);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
        // if we retrofit, then the NameAndType has been read in as is
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
        // and no change is necessary. If we compile normally, the
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
        // NameAndType is generated from a symbol reference, and the
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
        // adjustment of adding an additional this$n parameter needs to be made.
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
/******************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
 * Writing Attributes
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
 ******************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
    /** Write header for an attribute to data buffer and return
06bc494ca11e Initial load
duke
parents:
diff changeset
   609
     *  position past attribute length index.
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   611
    int writeAttr(Name attrName) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
        databuf.appendChar(pool.put(attrName));
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
        databuf.appendInt(0);
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
        return databuf.length;
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
06bc494ca11e Initial load
duke
parents:
diff changeset
   617
    /** Fill in attribute length.
06bc494ca11e Initial load
duke
parents:
diff changeset
   618
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   619
    void endAttr(int index) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   620
        putInt(databuf, index - 4, databuf.length - index);
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   622
06bc494ca11e Initial load
duke
parents:
diff changeset
   623
    /** Leave space for attribute count and return index for
06bc494ca11e Initial load
duke
parents:
diff changeset
   624
     *  number of attributes field.
06bc494ca11e Initial load
duke
parents:
diff changeset
   625
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   626
    int beginAttrs() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   627
        databuf.appendChar(0);
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
        return databuf.length;
06bc494ca11e Initial load
duke
parents:
diff changeset
   629
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   630
06bc494ca11e Initial load
duke
parents:
diff changeset
   631
    /** Fill in number of attributes.
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   633
    void endAttrs(int index, int count) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   634
        putChar(databuf, index - 2, count);
06bc494ca11e Initial load
duke
parents:
diff changeset
   635
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   636
06bc494ca11e Initial load
duke
parents:
diff changeset
   637
    /** Write the EnclosingMethod attribute if needed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   638
     *  Returns the number of attributes written (0 or 1).
06bc494ca11e Initial load
duke
parents:
diff changeset
   639
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   640
    int writeEnclosingMethodAttribute(ClassSymbol c) {
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12213
diff changeset
   641
        if (!target.hasEnclosingMethodAttribute())
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12213
diff changeset
   642
            return 0;
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12213
diff changeset
   643
        return writeEnclosingMethodAttribute(names.EnclosingMethod, c);
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12213
diff changeset
   644
    }
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12213
diff changeset
   645
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12213
diff changeset
   646
    /** Write the EnclosingMethod attribute with a specified name.
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12213
diff changeset
   647
     *  Returns the number of attributes written (0 or 1).
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12213
diff changeset
   648
     */
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12213
diff changeset
   649
    protected int writeEnclosingMethodAttribute(Name attributeName, ClassSymbol c) {
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12213
diff changeset
   650
        if (c.owner.kind != MTH && // neither a local class
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   651
            c.name != names.empty) // nor anonymous
06bc494ca11e Initial load
duke
parents:
diff changeset
   652
            return 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   653
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12213
diff changeset
   654
        int alenIdx = writeAttr(attributeName);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
        ClassSymbol enclClass = c.owner.enclClass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   656
        MethodSymbol enclMethod =
06bc494ca11e Initial load
duke
parents:
diff changeset
   657
            (c.owner.type == null // local to init block
06bc494ca11e Initial load
duke
parents:
diff changeset
   658
             || c.owner.kind != MTH) // or member init
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
            ? null
06bc494ca11e Initial load
duke
parents:
diff changeset
   660
            : (MethodSymbol)c.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
        databuf.appendChar(pool.put(enclClass));
06bc494ca11e Initial load
duke
parents:
diff changeset
   662
        databuf.appendChar(enclMethod == null ? 0 : pool.put(nameType(c.owner)));
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
        endAttr(alenIdx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
        return 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   665
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   666
06bc494ca11e Initial load
duke
parents:
diff changeset
   667
    /** Write flag attributes; return number of attributes written.
06bc494ca11e Initial load
duke
parents:
diff changeset
   668
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   669
    int writeFlagAttrs(long flags) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   670
        int acount = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
        if ((flags & DEPRECATED) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   672
            int alenIdx = writeAttr(names.Deprecated);
06bc494ca11e Initial load
duke
parents:
diff changeset
   673
            endAttr(alenIdx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   674
            acount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   675
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   676
        if ((flags & ENUM) != 0 && !target.useEnumFlag()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   677
            int alenIdx = writeAttr(names.Enum);
06bc494ca11e Initial load
duke
parents:
diff changeset
   678
            endAttr(alenIdx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
            acount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   681
        if ((flags & SYNTHETIC) != 0 && !target.useSyntheticFlag()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   682
            int alenIdx = writeAttr(names.Synthetic);
06bc494ca11e Initial load
duke
parents:
diff changeset
   683
            endAttr(alenIdx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   684
            acount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   685
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   686
        if ((flags & BRIDGE) != 0 && !target.useBridgeFlag()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   687
            int alenIdx = writeAttr(names.Bridge);
06bc494ca11e Initial load
duke
parents:
diff changeset
   688
            endAttr(alenIdx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   689
            acount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   690
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   691
        if ((flags & VARARGS) != 0 && !target.useVarargsFlag()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   692
            int alenIdx = writeAttr(names.Varargs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   693
            endAttr(alenIdx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   694
            acount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   695
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   696
        if ((flags & ANNOTATION) != 0 && !target.useAnnotationFlag()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   697
            int alenIdx = writeAttr(names.Annotation);
06bc494ca11e Initial load
duke
parents:
diff changeset
   698
            endAttr(alenIdx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   699
            acount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   700
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   701
        return acount;
06bc494ca11e Initial load
duke
parents:
diff changeset
   702
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   703
06bc494ca11e Initial load
duke
parents:
diff changeset
   704
    /** Write member (field or method) attributes;
06bc494ca11e Initial load
duke
parents:
diff changeset
   705
     *  return number of attributes written.
06bc494ca11e Initial load
duke
parents:
diff changeset
   706
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   707
    int writeMemberAttrs(Symbol sym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   708
        int acount = writeFlagAttrs(sym.flags());
06bc494ca11e Initial load
duke
parents:
diff changeset
   709
        long flags = sym.flags();
06bc494ca11e Initial load
duke
parents:
diff changeset
   710
        if (source.allowGenerics() &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   711
            (flags & (SYNTHETIC|BRIDGE)) != SYNTHETIC &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   712
            (flags & ANONCONSTR) == 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   713
            (!types.isSameType(sym.type, sym.erasure(types)) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   714
             hasTypeVar(sym.type.getThrownTypes()))) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   715
            // note that a local class with captured variables
06bc494ca11e Initial load
duke
parents:
diff changeset
   716
            // will get a signature attribute
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
            int alenIdx = writeAttr(names.Signature);
06bc494ca11e Initial load
duke
parents:
diff changeset
   718
            databuf.appendChar(pool.put(typeSig(sym.type)));
06bc494ca11e Initial load
duke
parents:
diff changeset
   719
            endAttr(alenIdx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   720
            acount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   721
        }
14961
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14949
diff changeset
   722
        acount += writeJavaAnnotations(sym.getRawAttributes());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   723
        acount += writeTypeAnnotations(sym.getRawTypeAttributes());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   724
        return acount;
06bc494ca11e Initial load
duke
parents:
diff changeset
   725
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   726
15031
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14961
diff changeset
   727
    /**
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14961
diff changeset
   728
     * Write method parameter names attribute.
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14961
diff changeset
   729
     */
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14961
diff changeset
   730
    int writeMethodParametersAttr(MethodSymbol m) {
15720
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15718
diff changeset
   731
        MethodType ty = m.externalType(types).asMethodType();
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15718
diff changeset
   732
        final int allparams = ty.argtypes.size();
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15718
diff changeset
   733
        if (m.params != null && allparams != 0) {
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15718
diff changeset
   734
            final int attrIndex = writeAttr(names.MethodParameters);
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15718
diff changeset
   735
            databuf.appendByte(allparams);
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15718
diff changeset
   736
            // Write extra parameters first
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15718
diff changeset
   737
            for (VarSymbol s : m.extraParams) {
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15718
diff changeset
   738
                final int flags =
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15718
diff changeset
   739
                    ((int) s.flags() & (FINAL | SYNTHETIC | MANDATED)) |
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15718
diff changeset
   740
                    ((int) m.flags() & SYNTHETIC);
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15718
diff changeset
   741
                databuf.appendChar(pool.put(s.name));
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15718
diff changeset
   742
                databuf.appendInt(flags);
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15718
diff changeset
   743
            }
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15718
diff changeset
   744
            // Now write the real parameters
15031
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14961
diff changeset
   745
            for (VarSymbol s : m.params) {
15720
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15718
diff changeset
   746
                final int flags =
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15718
diff changeset
   747
                    ((int) s.flags() & (FINAL | SYNTHETIC | MANDATED)) |
e61b2f7a5148 8006345: Report Synthesized Parameters in java.lang.reflect.Parameter API
mcimadamore
parents: 15718
diff changeset
   748
                    ((int) m.flags() & SYNTHETIC);
15031
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14961
diff changeset
   749
                databuf.appendChar(pool.put(s.name));
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14961
diff changeset
   750
                databuf.appendInt(flags);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14961
diff changeset
   751
            }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14961
diff changeset
   752
            endAttr(attrIndex);
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14961
diff changeset
   753
            return 1;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14961
diff changeset
   754
        } else
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14961
diff changeset
   755
            return 0;
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14961
diff changeset
   756
    }
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14961
diff changeset
   757
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14961
diff changeset
   758
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   759
    /** Write method parameter annotations;
06bc494ca11e Initial load
duke
parents:
diff changeset
   760
     *  return number of attributes written.
06bc494ca11e Initial load
duke
parents:
diff changeset
   761
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   762
    int writeParameterAttrs(MethodSymbol m) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   763
        boolean hasVisible = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   764
        boolean hasInvisible = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   765
        if (m.params != null) for (VarSymbol s : m.params) {
14961
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14949
diff changeset
   766
            for (Attribute.Compound a : s.getRawAttributes()) {
6575
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents: 6143
diff changeset
   767
                switch (types.getRetention(a)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   768
                case SOURCE: break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   769
                case CLASS: hasInvisible = true; break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   770
                case RUNTIME: hasVisible = true; break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   771
                default: ;// /* fail soft */ throw new AssertionError(vis);
06bc494ca11e Initial load
duke
parents:
diff changeset
   772
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   773
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   774
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   775
06bc494ca11e Initial load
duke
parents:
diff changeset
   776
        int attrCount = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   777
        if (hasVisible) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   778
            int attrIndex = writeAttr(names.RuntimeVisibleParameterAnnotations);
06bc494ca11e Initial load
duke
parents:
diff changeset
   779
            databuf.appendByte(m.params.length());
06bc494ca11e Initial load
duke
parents:
diff changeset
   780
            for (VarSymbol s : m.params) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   781
                ListBuffer<Attribute.Compound> buf = new ListBuffer<Attribute.Compound>();
14961
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14949
diff changeset
   782
                for (Attribute.Compound a : s.getRawAttributes())
6575
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents: 6143
diff changeset
   783
                    if (types.getRetention(a) == RetentionPolicy.RUNTIME)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   784
                        buf.append(a);
06bc494ca11e Initial load
duke
parents:
diff changeset
   785
                databuf.appendChar(buf.length());
06bc494ca11e Initial load
duke
parents:
diff changeset
   786
                for (Attribute.Compound a : buf)
06bc494ca11e Initial load
duke
parents:
diff changeset
   787
                    writeCompoundAttribute(a);
06bc494ca11e Initial load
duke
parents:
diff changeset
   788
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   789
            endAttr(attrIndex);
06bc494ca11e Initial load
duke
parents:
diff changeset
   790
            attrCount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   791
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   792
        if (hasInvisible) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   793
            int attrIndex = writeAttr(names.RuntimeInvisibleParameterAnnotations);
06bc494ca11e Initial load
duke
parents:
diff changeset
   794
            databuf.appendByte(m.params.length());
06bc494ca11e Initial load
duke
parents:
diff changeset
   795
            for (VarSymbol s : m.params) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   796
                ListBuffer<Attribute.Compound> buf = new ListBuffer<Attribute.Compound>();
14961
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14949
diff changeset
   797
                for (Attribute.Compound a : s.getRawAttributes())
6575
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents: 6143
diff changeset
   798
                    if (types.getRetention(a) == RetentionPolicy.CLASS)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   799
                        buf.append(a);
06bc494ca11e Initial load
duke
parents:
diff changeset
   800
                databuf.appendChar(buf.length());
06bc494ca11e Initial load
duke
parents:
diff changeset
   801
                for (Attribute.Compound a : buf)
06bc494ca11e Initial load
duke
parents:
diff changeset
   802
                    writeCompoundAttribute(a);
06bc494ca11e Initial load
duke
parents:
diff changeset
   803
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   804
            endAttr(attrIndex);
06bc494ca11e Initial load
duke
parents:
diff changeset
   805
            attrCount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   806
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   807
        return attrCount;
06bc494ca11e Initial load
duke
parents:
diff changeset
   808
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   809
06bc494ca11e Initial load
duke
parents:
diff changeset
   810
/**********************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
   811
 * Writing Java-language annotations (aka metadata, attributes)
06bc494ca11e Initial load
duke
parents:
diff changeset
   812
 **********************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
   813
06bc494ca11e Initial load
duke
parents:
diff changeset
   814
    /** Write Java-language annotations; return number of JVM
06bc494ca11e Initial load
duke
parents:
diff changeset
   815
     *  attributes written (zero or one).
06bc494ca11e Initial load
duke
parents:
diff changeset
   816
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   817
    int writeJavaAnnotations(List<Attribute.Compound> attrs) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   818
        if (attrs.isEmpty()) return 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   819
        ListBuffer<Attribute.Compound> visibles = new ListBuffer<Attribute.Compound>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   820
        ListBuffer<Attribute.Compound> invisibles = new ListBuffer<Attribute.Compound>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   821
        for (Attribute.Compound a : attrs) {
6575
ae1798028008 6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents: 6143
diff changeset
   822
            switch (types.getRetention(a)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   823
            case SOURCE: break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   824
            case CLASS: invisibles.append(a); break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   825
            case RUNTIME: visibles.append(a); break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   826
            default: ;// /* fail soft */ throw new AssertionError(vis);
06bc494ca11e Initial load
duke
parents:
diff changeset
   827
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   828
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   829
06bc494ca11e Initial load
duke
parents:
diff changeset
   830
        int attrCount = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   831
        if (visibles.length() != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   832
            int attrIndex = writeAttr(names.RuntimeVisibleAnnotations);
06bc494ca11e Initial load
duke
parents:
diff changeset
   833
            databuf.appendChar(visibles.length());
06bc494ca11e Initial load
duke
parents:
diff changeset
   834
            for (Attribute.Compound a : visibles)
06bc494ca11e Initial load
duke
parents:
diff changeset
   835
                writeCompoundAttribute(a);
06bc494ca11e Initial load
duke
parents:
diff changeset
   836
            endAttr(attrIndex);
06bc494ca11e Initial load
duke
parents:
diff changeset
   837
            attrCount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   838
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   839
        if (invisibles.length() != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   840
            int attrIndex = writeAttr(names.RuntimeInvisibleAnnotations);
06bc494ca11e Initial load
duke
parents:
diff changeset
   841
            databuf.appendChar(invisibles.length());
06bc494ca11e Initial load
duke
parents:
diff changeset
   842
            for (Attribute.Compound a : invisibles)
06bc494ca11e Initial load
duke
parents:
diff changeset
   843
                writeCompoundAttribute(a);
06bc494ca11e Initial load
duke
parents:
diff changeset
   844
            endAttr(attrIndex);
06bc494ca11e Initial load
duke
parents:
diff changeset
   845
            attrCount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   846
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   847
        return attrCount;
06bc494ca11e Initial load
duke
parents:
diff changeset
   848
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   849
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   850
    int writeTypeAnnotations(List<Attribute.TypeCompound> typeAnnos) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   851
        if (typeAnnos.isEmpty()) return 0;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   852
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   853
        ListBuffer<Attribute.TypeCompound> visibles = ListBuffer.lb();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   854
        ListBuffer<Attribute.TypeCompound> invisibles = ListBuffer.lb();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   855
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   856
        for (Attribute.TypeCompound tc : typeAnnos) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   857
            if (tc.position == null || tc.position.type == TargetType.UNKNOWN) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   858
                boolean found = false;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   859
                // TODO: the position for the container annotation of a
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   860
                // repeating type annotation has to be set.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   861
                // This cannot be done when the container is created, because
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   862
                // then the position is not determined yet.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   863
                // How can we link these pieces better together?
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   864
                if (tc.values.size() == 1) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   865
                    Pair<MethodSymbol, Attribute> val = tc.values.get(0);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   866
                    if (val.fst.getSimpleName().contentEquals("value") &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   867
                            val.snd instanceof Attribute.Array) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   868
                        Attribute.Array arr = (Attribute.Array) val.snd;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   869
                        if (arr.values.length != 0 &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   870
                                arr.values[0] instanceof Attribute.TypeCompound) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   871
                            TypeCompound atycomp = (Attribute.TypeCompound) arr.values[0];
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   872
                            if (atycomp.position.type != TargetType.UNKNOWN) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   873
                                tc.position = atycomp.position;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   874
                                found = true;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   875
                            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   876
                        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   877
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   878
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   879
                if (!found) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   880
                    // This happens for nested types like @A Outer. @B Inner.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   881
                    // For method parameters we get the annotation twice! Once with
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   882
                    // a valid position, once unknown.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   883
                    // TODO: find a cleaner solution.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   884
                    // System.err.println("ClassWriter: Position UNKNOWN in type annotation: " + tc);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   885
                    continue;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   886
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   887
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   888
            if (!tc.position.emitToClassfile())
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   889
                continue;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   890
            switch (types.getRetention(tc)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   891
            case SOURCE: break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   892
            case CLASS: invisibles.append(tc); break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   893
            case RUNTIME: visibles.append(tc); break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   894
            default: ;// /* fail soft */ throw new AssertionError(vis);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   895
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   896
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   897
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   898
        int attrCount = 0;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   899
        if (visibles.length() != 0) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   900
            int attrIndex = writeAttr(names.RuntimeVisibleTypeAnnotations);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   901
            databuf.appendChar(visibles.length());
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   902
            for (Attribute.TypeCompound p : visibles)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   903
                writeTypeAnnotation(p);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   904
            endAttr(attrIndex);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   905
            attrCount++;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   906
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   907
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   908
        if (invisibles.length() != 0) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   909
            int attrIndex = writeAttr(names.RuntimeInvisibleTypeAnnotations);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   910
            databuf.appendChar(invisibles.length());
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   911
            for (Attribute.TypeCompound p : invisibles)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   912
                writeTypeAnnotation(p);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   913
            endAttr(attrIndex);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   914
            attrCount++;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   915
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   916
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   917
        return attrCount;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   918
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   919
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   920
    /** A visitor to write an attribute including its leading
06bc494ca11e Initial load
duke
parents:
diff changeset
   921
     *  single-character marker.
06bc494ca11e Initial load
duke
parents:
diff changeset
   922
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   923
    class AttributeWriter implements Attribute.Visitor {
06bc494ca11e Initial load
duke
parents:
diff changeset
   924
        public void visitConstant(Attribute.Constant _value) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   925
            Object value = _value.value;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14053
diff changeset
   926
            switch (_value.type.getTag()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   927
            case BYTE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   928
                databuf.appendByte('B');
06bc494ca11e Initial load
duke
parents:
diff changeset
   929
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   930
            case CHAR:
06bc494ca11e Initial load
duke
parents:
diff changeset
   931
                databuf.appendByte('C');
06bc494ca11e Initial load
duke
parents:
diff changeset
   932
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   933
            case SHORT:
06bc494ca11e Initial load
duke
parents:
diff changeset
   934
                databuf.appendByte('S');
06bc494ca11e Initial load
duke
parents:
diff changeset
   935
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   936
            case INT:
06bc494ca11e Initial load
duke
parents:
diff changeset
   937
                databuf.appendByte('I');
06bc494ca11e Initial load
duke
parents:
diff changeset
   938
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   939
            case LONG:
06bc494ca11e Initial load
duke
parents:
diff changeset
   940
                databuf.appendByte('J');
06bc494ca11e Initial load
duke
parents:
diff changeset
   941
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   942
            case FLOAT:
06bc494ca11e Initial load
duke
parents:
diff changeset
   943
                databuf.appendByte('F');
06bc494ca11e Initial load
duke
parents:
diff changeset
   944
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   945
            case DOUBLE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   946
                databuf.appendByte('D');
06bc494ca11e Initial load
duke
parents:
diff changeset
   947
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   948
            case BOOLEAN:
06bc494ca11e Initial load
duke
parents:
diff changeset
   949
                databuf.appendByte('Z');
06bc494ca11e Initial load
duke
parents:
diff changeset
   950
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   951
            case CLASS:
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
   952
                Assert.check(value instanceof String);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   953
                databuf.appendByte('s');
06bc494ca11e Initial load
duke
parents:
diff changeset
   954
                value = names.fromString(value.toString()); // CONSTANT_Utf8
06bc494ca11e Initial load
duke
parents:
diff changeset
   955
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   956
            default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   957
                throw new AssertionError(_value.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   958
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   959
            databuf.appendChar(pool.put(value));
06bc494ca11e Initial load
duke
parents:
diff changeset
   960
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   961
        public void visitEnum(Attribute.Enum e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   962
            databuf.appendByte('e');
06bc494ca11e Initial load
duke
parents:
diff changeset
   963
            databuf.appendChar(pool.put(typeSig(e.value.type)));
06bc494ca11e Initial load
duke
parents:
diff changeset
   964
            databuf.appendChar(pool.put(e.value.name));
06bc494ca11e Initial load
duke
parents:
diff changeset
   965
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   966
        public void visitClass(Attribute.Class clazz) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   967
            databuf.appendByte('c');
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 13635
diff changeset
   968
            databuf.appendChar(pool.put(typeSig(clazz.classType)));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   969
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   970
        public void visitCompound(Attribute.Compound compound) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   971
            databuf.appendByte('@');
06bc494ca11e Initial load
duke
parents:
diff changeset
   972
            writeCompoundAttribute(compound);
06bc494ca11e Initial load
duke
parents:
diff changeset
   973
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   974
        public void visitError(Attribute.Error x) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   975
            throw new AssertionError(x);
06bc494ca11e Initial load
duke
parents:
diff changeset
   976
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   977
        public void visitArray(Attribute.Array array) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   978
            databuf.appendByte('[');
06bc494ca11e Initial load
duke
parents:
diff changeset
   979
            databuf.appendChar(array.values.length);
06bc494ca11e Initial load
duke
parents:
diff changeset
   980
            for (Attribute a : array.values) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   981
                a.accept(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   982
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   983
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   984
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   985
    AttributeWriter awriter = new AttributeWriter();
06bc494ca11e Initial load
duke
parents:
diff changeset
   986
06bc494ca11e Initial load
duke
parents:
diff changeset
   987
    /** Write a compound attribute excluding the '@' marker. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   988
    void writeCompoundAttribute(Attribute.Compound c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   989
        databuf.appendChar(pool.put(typeSig(c.type)));
06bc494ca11e Initial load
duke
parents:
diff changeset
   990
        databuf.appendChar(c.values.length());
06bc494ca11e Initial load
duke
parents:
diff changeset
   991
        for (Pair<Symbol.MethodSymbol,Attribute> p : c.values) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   992
            databuf.appendChar(pool.put(p.fst.name));
06bc494ca11e Initial load
duke
parents:
diff changeset
   993
            p.snd.accept(awriter);
06bc494ca11e Initial load
duke
parents:
diff changeset
   994
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   995
    }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   996
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   997
    void writeTypeAnnotation(Attribute.TypeCompound c) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   998
        writePosition(c.position);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
   999
        writeCompoundAttribute(c);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1000
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1001
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1002
    void writePosition(TypeAnnotationPosition p) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1003
        databuf.appendByte(p.type.targetTypeValue()); // TargetType tag is a byte
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1004
        switch (p.type) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1005
        // instanceof
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1006
        case INSTANCEOF:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1007
        // new expression
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1008
        case NEW:
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15564
diff changeset
  1009
        // constructor/method reference receiver
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15564
diff changeset
  1010
        case CONSTRUCTOR_REFERENCE:
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15564
diff changeset
  1011
        case METHOD_REFERENCE:
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1012
            databuf.appendChar(p.offset);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1013
            break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1014
        // local variable
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1015
        case LOCAL_VARIABLE:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1016
        // resource variable
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1017
        case RESOURCE_VARIABLE:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1018
            databuf.appendChar(p.lvarOffset.length);  // for table length
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1019
            for (int i = 0; i < p.lvarOffset.length; ++i) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1020
                databuf.appendChar(p.lvarOffset[i]);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1021
                databuf.appendChar(p.lvarLength[i]);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1022
                databuf.appendChar(p.lvarIndex[i]);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1023
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1024
            break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1025
        // exception parameter
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1026
        case EXCEPTION_PARAMETER:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1027
            databuf.appendByte(p.exception_index);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1028
            break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1029
        // method receiver
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1030
        case METHOD_RECEIVER:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1031
            // Do nothing
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1032
            break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1033
        // type parameter
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1034
        case CLASS_TYPE_PARAMETER:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1035
        case METHOD_TYPE_PARAMETER:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1036
            databuf.appendByte(p.parameter_index);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1037
            break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1038
        // type parameter bound
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1039
        case CLASS_TYPE_PARAMETER_BOUND:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1040
        case METHOD_TYPE_PARAMETER_BOUND:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1041
            databuf.appendByte(p.parameter_index);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1042
            databuf.appendByte(p.bound_index);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1043
            break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1044
        // class extends or implements clause
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1045
        case CLASS_EXTENDS:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1046
            databuf.appendChar(p.type_index);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1047
            break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1048
        // throws
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1049
        case THROWS:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1050
            databuf.appendChar(p.type_index);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1051
            break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1052
        // method parameter
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1053
        case METHOD_FORMAL_PARAMETER:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1054
            databuf.appendByte(p.parameter_index);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1055
            break;
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15564
diff changeset
  1056
        // type cast
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15564
diff changeset
  1057
        case CAST:
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1058
        // method/constructor/reference type argument
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1059
        case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1060
        case METHOD_INVOCATION_TYPE_ARGUMENT:
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15564
diff changeset
  1061
        case CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT:
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1062
        case METHOD_REFERENCE_TYPE_ARGUMENT:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1063
            databuf.appendChar(p.offset);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1064
            databuf.appendByte(p.type_index);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1065
            break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1066
        // We don't need to worry about these
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1067
        case METHOD_RETURN:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1068
        case FIELD:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1069
            break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1070
        case UNKNOWN:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1071
            throw new AssertionError("jvm.ClassWriter: UNKNOWN target type should never occur!");
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1072
        default:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1073
            throw new AssertionError("jvm.ClassWriter: Unknown target type for position: " + p);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1074
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1075
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1076
        { // Append location data for generics/arrays.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1077
            databuf.appendByte(p.location.size());
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1078
            java.util.List<Integer> loc = TypeAnnotationPosition.getBinaryFromTypePath(p.location);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1079
            for (int i : loc)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1080
                databuf.appendByte((byte)i);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1081
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1082
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1083
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1084
/**********************************************************************
06bc494ca11e Initial load
duke
parents:
diff changeset
  1085
 * Writing Objects
06bc494ca11e Initial load
duke
parents:
diff changeset
  1086
 **********************************************************************/
06bc494ca11e Initial load
duke
parents:
diff changeset
  1087
06bc494ca11e Initial load
duke
parents:
diff changeset
  1088
    /** Enter an inner class into the `innerClasses' set/queue.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1089
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1090
    void enterInner(ClassSymbol c) {
7215
49e5caf5b854 6999635: Multicatch: crash while compiling simple code with a multicatch parameter
mcimadamore
parents: 6721
diff changeset
  1091
        if (c.type.isCompound()) {
49e5caf5b854 6999635: Multicatch: crash while compiling simple code with a multicatch parameter
mcimadamore
parents: 6721
diff changeset
  1092
            throw new AssertionError("Unexpected intersection type: " + c.type);
49e5caf5b854 6999635: Multicatch: crash while compiling simple code with a multicatch parameter
mcimadamore
parents: 6721
diff changeset
  1093
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1094
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1095
            c.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1096
        } catch (CompletionFailure ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1097
            System.err.println("error: " + c + ": " + ex.getMessage());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1098
            throw ex;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1099
        }
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14053
diff changeset
  1100
        if (!c.type.hasTag(CLASS)) return; // arrays
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1101
        if (pool != null && // pool might be null if called from xClassName
10627
d8e900b62e02 7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents: 8630
diff changeset
  1102
            c.owner.enclClass() != null &&
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1103
            (innerClasses == null || !innerClasses.contains(c))) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1104
//          log.errWriter.println("enter inner " + c);//DEBUG
10627
d8e900b62e02 7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents: 8630
diff changeset
  1105
            enterInner(c.owner.enclClass());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1106
            pool.put(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1107
            pool.put(c.name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1108
            if (innerClasses == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1109
                innerClasses = new HashSet<ClassSymbol>();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1110
                innerClassesQueue = new ListBuffer<ClassSymbol>();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1111
                pool.put(names.InnerClasses);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1112
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1113
            innerClasses.add(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1114
            innerClassesQueue.append(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1115
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1116
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1117
06bc494ca11e Initial load
duke
parents:
diff changeset
  1118
    /** Write "inner classes" attribute.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1119
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1120
    void writeInnerClasses() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1121
        int alenIdx = writeAttr(names.InnerClasses);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1122
        databuf.appendChar(innerClassesQueue.length());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1123
        for (List<ClassSymbol> l = innerClassesQueue.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1124
             l.nonEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1125
             l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1126
            ClassSymbol inner = l.head;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1127
            char flags = (char) adjustFlags(inner.flags_field);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1128
            if ((flags & INTERFACE) != 0) flags |= ABSTRACT; // Interfaces are always ABSTRACT
06bc494ca11e Initial load
duke
parents:
diff changeset
  1129
            if (inner.name.isEmpty()) flags &= ~FINAL; // Anonymous class: unset FINAL flag
06bc494ca11e Initial load
duke
parents:
diff changeset
  1130
            if (dumpInnerClassModifiers) {
11052
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 10627
diff changeset
  1131
                PrintWriter pw = log.getWriter(Log.WriterKind.ERROR);
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 10627
diff changeset
  1132
                pw.println("INNERCLASS  " + inner.name);
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 10627
diff changeset
  1133
                pw.println("---" + flagNames(flags));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1134
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1135
            databuf.appendChar(pool.get(inner));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1136
            databuf.appendChar(
06bc494ca11e Initial load
duke
parents:
diff changeset
  1137
                inner.owner.kind == TYP ? pool.get(inner.owner) : 0);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1138
            databuf.appendChar(
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
  1139
                !inner.name.isEmpty() ? pool.get(inner.name) : 0);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1140
            databuf.appendChar(flags);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1141
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1142
        endAttr(alenIdx);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1143
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1144
14046
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1145
    /** Write "bootstrapMethods" attribute.
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1146
     */
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1147
    void writeBootstrapMethods() {
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1148
        int alenIdx = writeAttr(names.BootstrapMethods);
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1149
        databuf.appendChar(bootstrapMethods.size());
14949
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
  1150
        for (Map.Entry<DynamicMethod, MethodHandle> entry : bootstrapMethods.entrySet()) {
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
  1151
            DynamicMethod dmeth = entry.getKey();
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
  1152
            DynamicMethodSymbol dsym = (DynamicMethodSymbol)dmeth.baseSymbol();
14046
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1153
            //write BSM handle
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1154
            databuf.appendChar(pool.get(entry.getValue()));
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1155
            //write static args length
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1156
            databuf.appendChar(dsym.staticArgs.length);
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1157
            //write static args array
14949
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
  1158
            Object[] uniqueArgs = dmeth.uniqueStaticArgs;
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
  1159
            for (Object o : uniqueArgs) {
14046
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1160
                databuf.appendChar(pool.get(o));
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1161
            }
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1162
        }
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1163
        endAttr(alenIdx);
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1164
    }
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1165
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1166
    /** Write field symbol, entering all references into constant pool.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1167
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1168
    void writeField(VarSymbol v) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1169
        int flags = adjustFlags(v.flags());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1170
        databuf.appendChar(flags);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1171
        if (dumpFieldModifiers) {
11052
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 10627
diff changeset
  1172
            PrintWriter pw = log.getWriter(Log.WriterKind.ERROR);
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 10627
diff changeset
  1173
            pw.println("FIELD  " + fieldName(v));
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 10627
diff changeset
  1174
            pw.println("---" + flagNames(v.flags()));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1175
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1176
        databuf.appendChar(pool.put(fieldName(v)));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1177
        databuf.appendChar(pool.put(typeSig(v.erasure(types))));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1178
        int acountIdx = beginAttrs();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1179
        int acount = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1180
        if (v.getConstValue() != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1181
            int alenIdx = writeAttr(names.ConstantValue);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1182
            databuf.appendChar(pool.put(v.getConstValue()));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1183
            endAttr(alenIdx);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1184
            acount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1185
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1186
        acount += writeMemberAttrs(v);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1187
        endAttrs(acountIdx, acount);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1188
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1189
06bc494ca11e Initial load
duke
parents:
diff changeset
  1190
    /** Write method symbol, entering all references into constant pool.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1191
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1192
    void writeMethod(MethodSymbol m) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1193
        int flags = adjustFlags(m.flags());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1194
        databuf.appendChar(flags);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1195
        if (dumpMethodModifiers) {
11052
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 10627
diff changeset
  1196
            PrintWriter pw = log.getWriter(Log.WriterKind.ERROR);
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 10627
diff changeset
  1197
            pw.println("METHOD  " + fieldName(m));
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 10627
diff changeset
  1198
            pw.println("---" + flagNames(m.flags()));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1199
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1200
        databuf.appendChar(pool.put(fieldName(m)));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1201
        databuf.appendChar(pool.put(typeSig(m.externalType(types))));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1202
        int acountIdx = beginAttrs();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1203
        int acount = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1204
        if (m.code != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1205
            int alenIdx = writeAttr(names.Code);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1206
            writeCode(m.code);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1207
            m.code = null; // to conserve space
06bc494ca11e Initial load
duke
parents:
diff changeset
  1208
            endAttr(alenIdx);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1209
            acount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1210
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1211
        List<Type> thrown = m.erasure(types).getThrownTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1212
        if (thrown.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1213
            int alenIdx = writeAttr(names.Exceptions);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1214
            databuf.appendChar(thrown.length());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1215
            for (List<Type> l = thrown; l.nonEmpty(); l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1216
                databuf.appendChar(pool.put(l.head.tsym));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1217
            endAttr(alenIdx);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1218
            acount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1219
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1220
        if (m.defaultValue != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1221
            int alenIdx = writeAttr(names.AnnotationDefault);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1222
            m.defaultValue.accept(awriter);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1223
            endAttr(alenIdx);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1224
            acount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1225
        }
15031
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14961
diff changeset
  1226
        if (options.isSet(PARAMETERS))
c4fad55a5681 8004727: Add compiler support for parameter reflection
jjg
parents: 14961
diff changeset
  1227
            acount += writeMethodParametersAttr(m);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1228
        acount += writeMemberAttrs(m);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1229
        acount += writeParameterAttrs(m);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1230
        endAttrs(acountIdx, acount);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1231
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1232
06bc494ca11e Initial load
duke
parents:
diff changeset
  1233
    /** Write code attribute of method.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1234
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1235
    void writeCode(Code code) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1236
        databuf.appendChar(code.max_stack);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1237
        databuf.appendChar(code.max_locals);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1238
        databuf.appendInt(code.cp);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1239
        databuf.appendBytes(code.code, 0, code.cp);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1240
        databuf.appendChar(code.catchInfo.length());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1241
        for (List<char[]> l = code.catchInfo.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1242
             l.nonEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1243
             l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1244
            for (int i = 0; i < l.head.length; i++)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1245
                databuf.appendChar(l.head[i]);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1246
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1247
        int acountIdx = beginAttrs();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1248
        int acount = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1249
06bc494ca11e Initial load
duke
parents:
diff changeset
  1250
        if (code.lineInfo.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1251
            int alenIdx = writeAttr(names.LineNumberTable);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1252
            databuf.appendChar(code.lineInfo.length());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1253
            for (List<char[]> l = code.lineInfo.reverse();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1254
                 l.nonEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1255
                 l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1256
                for (int i = 0; i < l.head.length; i++)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1257
                    databuf.appendChar(l.head[i]);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1258
            endAttr(alenIdx);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1259
            acount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1260
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1261
06bc494ca11e Initial load
duke
parents:
diff changeset
  1262
        if (genCrt && (code.crt != null)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1263
            CRTable crt = code.crt;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1264
            int alenIdx = writeAttr(names.CharacterRangeTable);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1265
            int crtIdx = beginAttrs();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1266
            int crtEntries = crt.writeCRT(databuf, code.lineMap, log);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1267
            endAttrs(crtIdx, crtEntries);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1268
            endAttr(alenIdx);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1269
            acount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1270
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1271
06bc494ca11e Initial load
duke
parents:
diff changeset
  1272
        // counter for number of generic local variables
06bc494ca11e Initial load
duke
parents:
diff changeset
  1273
        int nGenericVars = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1274
06bc494ca11e Initial load
duke
parents:
diff changeset
  1275
        if (code.varBufferSize > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1276
            int alenIdx = writeAttr(names.LocalVariableTable);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1277
            databuf.appendChar(code.varBufferSize);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1278
06bc494ca11e Initial load
duke
parents:
diff changeset
  1279
            for (int i=0; i<code.varBufferSize; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1280
                Code.LocalVar var = code.varBuffer[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1281
06bc494ca11e Initial load
duke
parents:
diff changeset
  1282
                // write variable info
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
  1283
                Assert.check(var.start_pc >= 0
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
  1284
                        && var.start_pc <= code.cp);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1285
                databuf.appendChar(var.start_pc);
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
  1286
                Assert.check(var.length >= 0
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
  1287
                        && (var.start_pc + var.length) <= code.cp);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1288
                databuf.appendChar(var.length);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1289
                VarSymbol sym = var.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1290
                databuf.appendChar(pool.put(sym.name));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1291
                Type vartype = sym.erasure(types);
7629
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents: 7215
diff changeset
  1292
                if (needsLocalVariableTypeEntry(sym.type))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1293
                    nGenericVars++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1294
                databuf.appendChar(pool.put(typeSig(vartype)));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1295
                databuf.appendChar(var.reg);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1296
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1297
            endAttr(alenIdx);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1298
            acount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1299
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1300
06bc494ca11e Initial load
duke
parents:
diff changeset
  1301
        if (nGenericVars > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1302
            int alenIdx = writeAttr(names.LocalVariableTypeTable);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1303
            databuf.appendChar(nGenericVars);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1304
            int count = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1305
06bc494ca11e Initial load
duke
parents:
diff changeset
  1306
            for (int i=0; i<code.varBufferSize; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1307
                Code.LocalVar var = code.varBuffer[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1308
                VarSymbol sym = var.sym;
7629
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents: 7215
diff changeset
  1309
                if (!needsLocalVariableTypeEntry(sym.type))
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1310
                    continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1311
                count++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1312
                // write variable info
06bc494ca11e Initial load
duke
parents:
diff changeset
  1313
                databuf.appendChar(var.start_pc);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1314
                databuf.appendChar(var.length);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1315
                databuf.appendChar(pool.put(sym.name));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1316
                databuf.appendChar(pool.put(typeSig(sym.type)));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1317
                databuf.appendChar(var.reg);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1318
            }
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
  1319
            Assert.check(count == nGenericVars);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1320
            endAttr(alenIdx);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1321
            acount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1322
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1323
06bc494ca11e Initial load
duke
parents:
diff changeset
  1324
        if (code.stackMapBufferSize > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1325
            if (debugstackmap) System.out.println("Stack map for " + code.meth);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1326
            int alenIdx = writeAttr(code.stackMap.getAttributeName(names));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1327
            writeStackMap(code);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1328
            endAttr(alenIdx);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1329
            acount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1330
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1331
        endAttrs(acountIdx, acount);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1332
    }
7629
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents: 7215
diff changeset
  1333
    //where
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents: 7215
diff changeset
  1334
    private boolean needsLocalVariableTypeEntry(Type t) {
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents: 7215
diff changeset
  1335
        //a local variable needs a type-entry if its type T is generic
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents: 7215
diff changeset
  1336
        //(i.e. |T| != T) and if it's not an intersection type (not supported
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents: 7215
diff changeset
  1337
        //in signature attribute grammar)
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents: 7215
diff changeset
  1338
        return (!types.isSameType(t, types.erasure(t)) &&
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents: 7215
diff changeset
  1339
                !t.isCompound());
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents: 7215
diff changeset
  1340
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1341
06bc494ca11e Initial load
duke
parents:
diff changeset
  1342
    void writeStackMap(Code code) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1343
        int nframes = code.stackMapBufferSize;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1344
        if (debugstackmap) System.out.println(" nframes = " + nframes);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1345
        databuf.appendChar(nframes);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1346
06bc494ca11e Initial load
duke
parents:
diff changeset
  1347
        switch (code.stackMap) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1348
        case CLDC:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1349
            for (int i=0; i<nframes; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1350
                if (debugstackmap) System.out.print("  " + i + ":");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1351
                Code.StackMapFrame frame = code.stackMapBuffer[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1352
06bc494ca11e Initial load
duke
parents:
diff changeset
  1353
                // output PC
06bc494ca11e Initial load
duke
parents:
diff changeset
  1354
                if (debugstackmap) System.out.print(" pc=" + frame.pc);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1355
                databuf.appendChar(frame.pc);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1356
06bc494ca11e Initial load
duke
parents:
diff changeset
  1357
                // output locals
06bc494ca11e Initial load
duke
parents:
diff changeset
  1358
                int localCount = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1359
                for (int j=0; j<frame.locals.length;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1360
                     j += (target.generateEmptyAfterBig() ? 1 : Code.width(frame.locals[j]))) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1361
                    localCount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1362
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1363
                if (debugstackmap) System.out.print(" nlocals=" +
06bc494ca11e Initial load
duke
parents:
diff changeset
  1364
                                                    localCount);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1365
                databuf.appendChar(localCount);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1366
                for (int j=0; j<frame.locals.length;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1367
                     j += (target.generateEmptyAfterBig() ? 1 : Code.width(frame.locals[j]))) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1368
                    if (debugstackmap) System.out.print(" local[" + j + "]=");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1369
                    writeStackMapType(frame.locals[j]);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1370
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1371
06bc494ca11e Initial load
duke
parents:
diff changeset
  1372
                // output stack
06bc494ca11e Initial load
duke
parents:
diff changeset
  1373
                int stackCount = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1374
                for (int j=0; j<frame.stack.length;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1375
                     j += (target.generateEmptyAfterBig() ? 1 : Code.width(frame.stack[j]))) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1376
                    stackCount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1377
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1378
                if (debugstackmap) System.out.print(" nstack=" +
06bc494ca11e Initial load
duke
parents:
diff changeset
  1379
                                                    stackCount);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1380
                databuf.appendChar(stackCount);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1381
                for (int j=0; j<frame.stack.length;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1382
                     j += (target.generateEmptyAfterBig() ? 1 : Code.width(frame.stack[j]))) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1383
                    if (debugstackmap) System.out.print(" stack[" + j + "]=");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1384
                    writeStackMapType(frame.stack[j]);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1385
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1386
                if (debugstackmap) System.out.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1387
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1388
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1389
        case JSR202: {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
  1390
            Assert.checkNull(code.stackMapBuffer);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1391
            for (int i=0; i<nframes; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1392
                if (debugstackmap) System.out.print("  " + i + ":");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1393
                StackMapTableFrame frame = code.stackMapTableBuffer[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1394
                frame.write(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1395
                if (debugstackmap) System.out.println();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1396
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1397
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1398
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1399
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1400
            throw new AssertionError("Unexpected stackmap format value");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1401
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1402
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1403
06bc494ca11e Initial load
duke
parents:
diff changeset
  1404
        //where
06bc494ca11e Initial load
duke
parents:
diff changeset
  1405
        void writeStackMapType(Type t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1406
            if (t == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1407
                if (debugstackmap) System.out.print("empty");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1408
                databuf.appendByte(0);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1409
            }
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14053
diff changeset
  1410
            else switch(t.getTag()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1411
            case BYTE:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1412
            case CHAR:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1413
            case SHORT:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1414
            case INT:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1415
            case BOOLEAN:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1416
                if (debugstackmap) System.out.print("int");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1417
                databuf.appendByte(1);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1418
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1419
            case FLOAT:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1420
                if (debugstackmap) System.out.print("float");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1421
                databuf.appendByte(2);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1422
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1423
            case DOUBLE:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1424
                if (debugstackmap) System.out.print("double");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1425
                databuf.appendByte(3);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1426
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1427
            case LONG:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1428
                if (debugstackmap) System.out.print("long");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1429
                databuf.appendByte(4);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1430
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1431
            case BOT: // null
06bc494ca11e Initial load
duke
parents:
diff changeset
  1432
                if (debugstackmap) System.out.print("null");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1433
                databuf.appendByte(5);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1434
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1435
            case CLASS:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1436
            case ARRAY:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1437
                if (debugstackmap) System.out.print("object(" + t + ")");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1438
                databuf.appendByte(7);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1439
                databuf.appendChar(pool.put(t));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1440
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1441
            case TYPEVAR:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1442
                if (debugstackmap) System.out.print("object(" + types.erasure(t).tsym + ")");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1443
                databuf.appendByte(7);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1444
                databuf.appendChar(pool.put(types.erasure(t).tsym));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1445
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1446
            case UNINITIALIZED_THIS:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1447
                if (debugstackmap) System.out.print("uninit_this");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1448
                databuf.appendByte(6);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1449
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1450
            case UNINITIALIZED_OBJECT:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1451
                { UninitializedType uninitType = (UninitializedType)t;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1452
                databuf.appendByte(8);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1453
                if (debugstackmap) System.out.print("uninit_object@" + uninitType.offset);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1454
                databuf.appendChar(uninitType.offset);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1455
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1456
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1457
            default:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1458
                throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1459
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1460
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1461
06bc494ca11e Initial load
duke
parents:
diff changeset
  1462
    /** An entry in the JSR202 StackMapTable */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1463
    abstract static class StackMapTableFrame {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1464
        abstract int getFrameType();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1465
06bc494ca11e Initial load
duke
parents:
diff changeset
  1466
        void write(ClassWriter writer) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1467
            int frameType = getFrameType();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1468
            writer.databuf.appendByte(frameType);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1469
            if (writer.debugstackmap) System.out.print(" frame_type=" + frameType);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1470
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1471
06bc494ca11e Initial load
duke
parents:
diff changeset
  1472
        static class SameFrame extends StackMapTableFrame {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1473
            final int offsetDelta;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1474
            SameFrame(int offsetDelta) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1475
                this.offsetDelta = offsetDelta;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1476
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1477
            int getFrameType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1478
                return (offsetDelta < SAME_FRAME_SIZE) ? offsetDelta : SAME_FRAME_EXTENDED;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1479
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1480
            @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1481
            void write(ClassWriter writer) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1482
                super.write(writer);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1483
                if (getFrameType() == SAME_FRAME_EXTENDED) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1484
                    writer.databuf.appendChar(offsetDelta);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1485
                    if (writer.debugstackmap){
06bc494ca11e Initial load
duke
parents:
diff changeset
  1486
                        System.out.print(" offset_delta=" + offsetDelta);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1487
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1488
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1489
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1490
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1491
06bc494ca11e Initial load
duke
parents:
diff changeset
  1492
        static class SameLocals1StackItemFrame extends StackMapTableFrame {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1493
            final int offsetDelta;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1494
            final Type stack;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1495
            SameLocals1StackItemFrame(int offsetDelta, Type stack) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1496
                this.offsetDelta = offsetDelta;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1497
                this.stack = stack;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1498
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1499
            int getFrameType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1500
                return (offsetDelta < SAME_FRAME_SIZE) ?
06bc494ca11e Initial load
duke
parents:
diff changeset
  1501
                       (SAME_FRAME_SIZE + offsetDelta) :
06bc494ca11e Initial load
duke
parents:
diff changeset
  1502
                       SAME_LOCALS_1_STACK_ITEM_EXTENDED;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1503
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1504
            @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1505
            void write(ClassWriter writer) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1506
                super.write(writer);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1507
                if (getFrameType() == SAME_LOCALS_1_STACK_ITEM_EXTENDED) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1508
                    writer.databuf.appendChar(offsetDelta);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1509
                    if (writer.debugstackmap) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1510
                        System.out.print(" offset_delta=" + offsetDelta);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1511
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1512
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1513
                if (writer.debugstackmap) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1514
                    System.out.print(" stack[" + 0 + "]=");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1515
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1516
                writer.writeStackMapType(stack);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1517
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1518
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1519
06bc494ca11e Initial load
duke
parents:
diff changeset
  1520
        static class ChopFrame extends StackMapTableFrame {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1521
            final int frameType;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1522
            final int offsetDelta;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1523
            ChopFrame(int frameType, int offsetDelta) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1524
                this.frameType = frameType;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1525
                this.offsetDelta = offsetDelta;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1526
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1527
            int getFrameType() { return frameType; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1528
            @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1529
            void write(ClassWriter writer) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1530
                super.write(writer);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1531
                writer.databuf.appendChar(offsetDelta);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1532
                if (writer.debugstackmap) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1533
                    System.out.print(" offset_delta=" + offsetDelta);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1534
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1535
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1536
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1537
06bc494ca11e Initial load
duke
parents:
diff changeset
  1538
        static class AppendFrame extends StackMapTableFrame {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1539
            final int frameType;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1540
            final int offsetDelta;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1541
            final Type[] locals;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1542
            AppendFrame(int frameType, int offsetDelta, Type[] locals) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1543
                this.frameType = frameType;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1544
                this.offsetDelta = offsetDelta;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1545
                this.locals = locals;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1546
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1547
            int getFrameType() { return frameType; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1548
            @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1549
            void write(ClassWriter writer) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1550
                super.write(writer);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1551
                writer.databuf.appendChar(offsetDelta);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1552
                if (writer.debugstackmap) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1553
                    System.out.print(" offset_delta=" + offsetDelta);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1554
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1555
                for (int i=0; i<locals.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1556
                     if (writer.debugstackmap) System.out.print(" locals[" + i + "]=");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1557
                     writer.writeStackMapType(locals[i]);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1558
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1559
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1560
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1561
06bc494ca11e Initial load
duke
parents:
diff changeset
  1562
        static class FullFrame extends StackMapTableFrame {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1563
            final int offsetDelta;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1564
            final Type[] locals;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1565
            final Type[] stack;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1566
            FullFrame(int offsetDelta, Type[] locals, Type[] stack) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1567
                this.offsetDelta = offsetDelta;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1568
                this.locals = locals;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1569
                this.stack = stack;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1570
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1571
            int getFrameType() { return FULL_FRAME; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1572
            @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1573
            void write(ClassWriter writer) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1574
                super.write(writer);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1575
                writer.databuf.appendChar(offsetDelta);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1576
                writer.databuf.appendChar(locals.length);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1577
                if (writer.debugstackmap) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1578
                    System.out.print(" offset_delta=" + offsetDelta);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1579
                    System.out.print(" nlocals=" + locals.length);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1580
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1581
                for (int i=0; i<locals.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1582
                    if (writer.debugstackmap) System.out.print(" locals[" + i + "]=");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1583
                    writer.writeStackMapType(locals[i]);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1584
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1585
06bc494ca11e Initial load
duke
parents:
diff changeset
  1586
                writer.databuf.appendChar(stack.length);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1587
                if (writer.debugstackmap) { System.out.print(" nstack=" + stack.length); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1588
                for (int i=0; i<stack.length; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1589
                    if (writer.debugstackmap) System.out.print(" stack[" + i + "]=");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1590
                    writer.writeStackMapType(stack[i]);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1591
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1592
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1593
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1594
06bc494ca11e Initial load
duke
parents:
diff changeset
  1595
       /** Compare this frame with the previous frame and produce
06bc494ca11e Initial load
duke
parents:
diff changeset
  1596
        *  an entry of compressed stack map frame. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1597
        static StackMapTableFrame getInstance(Code.StackMapFrame this_frame,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1598
                                              int prev_pc,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1599
                                              Type[] prev_locals,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1600
                                              Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1601
            Type[] locals = this_frame.locals;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1602
            Type[] stack = this_frame.stack;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1603
            int offset_delta = this_frame.pc - prev_pc - 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1604
            if (stack.length == 1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1605
                if (locals.length == prev_locals.length
06bc494ca11e Initial load
duke
parents:
diff changeset
  1606
                    && compare(prev_locals, locals, types) == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1607
                    return new SameLocals1StackItemFrame(offset_delta, stack[0]);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1608
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1609
            } else if (stack.length == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1610
                int diff_length = compare(prev_locals, locals, types);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1611
                if (diff_length == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1612
                    return new SameFrame(offset_delta);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1613
                } else if (-MAX_LOCAL_LENGTH_DIFF < diff_length && diff_length < 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1614
                    // APPEND
06bc494ca11e Initial load
duke
parents:
diff changeset
  1615
                    Type[] local_diff = new Type[-diff_length];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1616
                    for (int i=prev_locals.length, j=0; i<locals.length; i++,j++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1617
                        local_diff[j] = locals[i];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1618
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1619
                    return new AppendFrame(SAME_FRAME_EXTENDED - diff_length,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1620
                                           offset_delta,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1621
                                           local_diff);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1622
                } else if (0 < diff_length && diff_length < MAX_LOCAL_LENGTH_DIFF) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1623
                    // CHOP
06bc494ca11e Initial load
duke
parents:
diff changeset
  1624
                    return new ChopFrame(SAME_FRAME_EXTENDED - diff_length,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1625
                                         offset_delta);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1626
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1627
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1628
            // FULL_FRAME
06bc494ca11e Initial load
duke
parents:
diff changeset
  1629
            return new FullFrame(offset_delta, locals, stack);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1630
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1631
06bc494ca11e Initial load
duke
parents:
diff changeset
  1632
        static boolean isInt(Type t) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14053
diff changeset
  1633
            return (t.getTag().isStrictSubRangeOf(INT)  || t.hasTag(BOOLEAN));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1634
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1635
06bc494ca11e Initial load
duke
parents:
diff changeset
  1636
        static boolean isSameType(Type t1, Type t2, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1637
            if (t1 == null) { return t2 == null; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1638
            if (t2 == null) { return false; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1639
06bc494ca11e Initial load
duke
parents:
diff changeset
  1640
            if (isInt(t1) && isInt(t2)) { return true; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1641
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14053
diff changeset
  1642
            if (t1.hasTag(UNINITIALIZED_THIS)) {
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14053
diff changeset
  1643
                return t2.hasTag(UNINITIALIZED_THIS);
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14053
diff changeset
  1644
            } else if (t1.hasTag(UNINITIALIZED_OBJECT)) {
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14053
diff changeset
  1645
                if (t2.hasTag(UNINITIALIZED_OBJECT)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1646
                    return ((UninitializedType)t1).offset == ((UninitializedType)t2).offset;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1647
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1648
                    return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1649
                }
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14053
diff changeset
  1650
            } else if (t2.hasTag(UNINITIALIZED_THIS) || t2.hasTag(UNINITIALIZED_OBJECT)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1651
                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1652
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1653
06bc494ca11e Initial load
duke
parents:
diff changeset
  1654
            return types.isSameType(t1, t2);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1655
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1656
06bc494ca11e Initial load
duke
parents:
diff changeset
  1657
        static int compare(Type[] arr1, Type[] arr2, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1658
            int diff_length = arr1.length - arr2.length;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1659
            if (diff_length > MAX_LOCAL_LENGTH_DIFF || diff_length < -MAX_LOCAL_LENGTH_DIFF) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1660
                return Integer.MAX_VALUE;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1661
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1662
            int len = (diff_length > 0) ? arr2.length : arr1.length;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1663
            for (int i=0; i<len; i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1664
                if (!isSameType(arr1[i], arr2[i], types)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1665
                    return Integer.MAX_VALUE;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1666
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1667
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1668
            return diff_length;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1669
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1670
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1671
06bc494ca11e Initial load
duke
parents:
diff changeset
  1672
    void writeFields(Scope.Entry e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1673
        // process them in reverse sibling order;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1674
        // i.e., process them in declaration order.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1675
        List<VarSymbol> vars = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1676
        for (Scope.Entry i = e; i != null; i = i.sibling) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1677
            if (i.sym.kind == VAR) vars = vars.prepend((VarSymbol)i.sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1678
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1679
        while (vars.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1680
            writeField(vars.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1681
            vars = vars.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1682
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1683
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1684
06bc494ca11e Initial load
duke
parents:
diff changeset
  1685
    void writeMethods(Scope.Entry e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1686
        List<MethodSymbol> methods = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1687
        for (Scope.Entry i = e; i != null; i = i.sibling) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1688
            if (i.sym.kind == MTH && (i.sym.flags() & HYPOTHETICAL) == 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1689
                methods = methods.prepend((MethodSymbol)i.sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1690
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1691
        while (methods.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1692
            writeMethod(methods.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1693
            methods = methods.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1694
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1695
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1696
06bc494ca11e Initial load
duke
parents:
diff changeset
  1697
    /** Emit a class file for a given class.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1698
     *  @param c      The class from which a class file is generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1699
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1700
    public JavaFileObject writeClass(ClassSymbol c)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1701
        throws IOException, PoolOverflow, StringOverflow
06bc494ca11e Initial load
duke
parents:
diff changeset
  1702
    {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1703
        JavaFileObject outFile
06bc494ca11e Initial load
duke
parents:
diff changeset
  1704
            = fileManager.getJavaFileForOutput(CLASS_OUTPUT,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1705
                                               c.flatname.toString(),
06bc494ca11e Initial load
duke
parents:
diff changeset
  1706
                                               JavaFileObject.Kind.CLASS,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1707
                                               c.sourcefile);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1708
        OutputStream out = outFile.openOutputStream();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1709
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1710
            writeClassFile(out, c);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1711
            if (verbose)
8630
cd9eefe597f6 6966736: javac verbose output is inconsistent
jjg
parents: 8032
diff changeset
  1712
                log.printVerbose("wrote.file", outFile);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1713
            out.close();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1714
            out = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1715
        } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1716
            if (out != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1717
                // if we are propogating an exception, delete the file
06bc494ca11e Initial load
duke
parents:
diff changeset
  1718
                out.close();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1719
                outFile.delete();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1720
                outFile = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1721
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1722
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1723
        return outFile; // may be null if write failed
06bc494ca11e Initial load
duke
parents:
diff changeset
  1724
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1725
06bc494ca11e Initial load
duke
parents:
diff changeset
  1726
    /** Write class `c' to outstream `out'.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1727
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1728
    public void writeClassFile(OutputStream out, ClassSymbol c)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1729
        throws IOException, PoolOverflow, StringOverflow {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
  1730
        Assert.check((c.flags() & COMPOUND) == 0);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1731
        databuf.reset();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1732
        poolbuf.reset();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1733
        sigbuf.reset();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1734
        pool = c.pool;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1735
        innerClasses = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1736
        innerClassesQueue = null;
14949
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14443
diff changeset
  1737
        bootstrapMethods = new LinkedHashMap<DynamicMethod, MethodHandle>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1738
06bc494ca11e Initial load
duke
parents:
diff changeset
  1739
        Type supertype = types.supertype(c.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1740
        List<Type> interfaces = types.interfaces(c.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1741
        List<Type> typarams = c.type.getTypeArguments();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1742
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1743
        int flags = adjustFlags(c.flags() & ~DEFAULT);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1744
        if ((flags & PROTECTED) != 0) flags |= PUBLIC;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1745
        flags = flags & ClassFlags & ~STRICTFP;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1746
        if ((flags & INTERFACE) == 0) flags |= ACC_SUPER;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1747
        if (c.isInner() && c.name.isEmpty()) flags &= ~FINAL;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1748
        if (dumpClassModifiers) {
11052
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 10627
diff changeset
  1749
            PrintWriter pw = log.getWriter(Log.WriterKind.ERROR);
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 10627
diff changeset
  1750
            pw.println();
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 10627
diff changeset
  1751
            pw.println("CLASSFILE  " + c.getQualifiedName());
65b9fa7eaf55 7108668: allow Log to be initialized and used earlier
jjg
parents: 10627
diff changeset
  1752
            pw.println("---" + flagNames(flags));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1753
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1754
        databuf.appendChar(flags);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1755
06bc494ca11e Initial load
duke
parents:
diff changeset
  1756
        databuf.appendChar(pool.put(c));
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14053
diff changeset
  1757
        databuf.appendChar(supertype.hasTag(CLASS) ? pool.put(supertype.tsym) : 0);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1758
        databuf.appendChar(interfaces.length());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1759
        for (List<Type> l = interfaces; l.nonEmpty(); l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1760
            databuf.appendChar(pool.put(l.head.tsym));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1761
        int fieldsCount = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1762
        int methodsCount = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1763
        for (Scope.Entry e = c.members().elems; e != null; e = e.sibling) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1764
            switch (e.sym.kind) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1765
            case VAR: fieldsCount++; break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1766
            case MTH: if ((e.sym.flags() & HYPOTHETICAL) == 0) methodsCount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1767
                      break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1768
            case TYP: enterInner((ClassSymbol)e.sym); break;
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
  1769
            default : Assert.error();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1770
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1771
        }
10627
d8e900b62e02 7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents: 8630
diff changeset
  1772
d8e900b62e02 7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents: 8630
diff changeset
  1773
        if (c.trans_local != null) {
d8e900b62e02 7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents: 8630
diff changeset
  1774
            for (ClassSymbol local : c.trans_local) {
d8e900b62e02 7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents: 8630
diff changeset
  1775
                enterInner(local);
d8e900b62e02 7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents: 8630
diff changeset
  1776
            }
d8e900b62e02 7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents: 8630
diff changeset
  1777
        }
d8e900b62e02 7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents: 8630
diff changeset
  1778
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1779
        databuf.appendChar(fieldsCount);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1780
        writeFields(c.members().elems);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1781
        databuf.appendChar(methodsCount);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1782
        writeMethods(c.members().elems);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1783
06bc494ca11e Initial load
duke
parents:
diff changeset
  1784
        int acountIdx = beginAttrs();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1785
        int acount = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1786
06bc494ca11e Initial load
duke
parents:
diff changeset
  1787
        boolean sigReq =
3138
c9fe0e7472ac 6835430: javac does not generate signature attributes for classes extending parameterized inner classes
mcimadamore
parents: 1264
diff changeset
  1788
            typarams.length() != 0 || supertype.allparams().length() != 0;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1789
        for (List<Type> l = interfaces; !sigReq && l.nonEmpty(); l = l.tail)
3138
c9fe0e7472ac 6835430: javac does not generate signature attributes for classes extending parameterized inner classes
mcimadamore
parents: 1264
diff changeset
  1790
            sigReq = l.head.allparams().length() != 0;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1791
        if (sigReq) {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
  1792
            Assert.check(source.allowGenerics());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1793
            int alenIdx = writeAttr(names.Signature);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1794
            if (typarams.length() != 0) assembleParamsSig(typarams);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1795
            assembleSig(supertype);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1796
            for (List<Type> l = interfaces; l.nonEmpty(); l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1797
                assembleSig(l.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1798
            databuf.appendChar(pool.put(sigbuf.toName(names)));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1799
            sigbuf.reset();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1800
            endAttr(alenIdx);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1801
            acount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1802
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1803
06bc494ca11e Initial load
duke
parents:
diff changeset
  1804
        if (c.sourcefile != null && emitSourceFile) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1805
            int alenIdx = writeAttr(names.SourceFile);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1806
            // WHM 6/29/1999: Strip file path prefix.  We do it here at
06bc494ca11e Initial load
duke
parents:
diff changeset
  1807
            // the last possible moment because the sourcefile may be used
06bc494ca11e Initial load
duke
parents:
diff changeset
  1808
            // elsewhere in error diagnostics. Fixes 4241573.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1809
            //databuf.appendChar(c.pool.put(c.sourcefile));
3995
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3300
diff changeset
  1810
            String simpleName = BaseFileObject.getSimpleName(c.sourcefile);
73af8b6fb8bc 6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents: 3300
diff changeset
  1811
            databuf.appendChar(c.pool.put(names.fromString(simpleName)));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1812
            endAttr(alenIdx);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1813
            acount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1814
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1815
06bc494ca11e Initial load
duke
parents:
diff changeset
  1816
        if (genCrt) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1817
            // Append SourceID attribute
06bc494ca11e Initial load
duke
parents:
diff changeset
  1818
            int alenIdx = writeAttr(names.SourceID);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1819
            databuf.appendChar(c.pool.put(names.fromString(Long.toString(getLastModified(c.sourcefile)))));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1820
            endAttr(alenIdx);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1821
            acount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1822
            // Append CompilationID attribute
06bc494ca11e Initial load
duke
parents:
diff changeset
  1823
            alenIdx = writeAttr(names.CompilationID);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1824
            databuf.appendChar(c.pool.put(names.fromString(Long.toString(System.currentTimeMillis()))));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1825
            endAttr(alenIdx);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1826
            acount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1827
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1828
06bc494ca11e Initial load
duke
parents:
diff changeset
  1829
        acount += writeFlagAttrs(c.flags());
14961
e731935052af 8005098: Provide isSynthesized() information on Attribute.Compound
jfranck
parents: 14949
diff changeset
  1830
        acount += writeJavaAnnotations(c.getRawAttributes());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15031
diff changeset
  1831
        acount += writeTypeAnnotations(c.getRawTypeAttributes());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1832
        acount += writeEnclosingMethodAttribute(c);
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12213
diff changeset
  1833
        acount += writeExtraClassAttributes(c);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1834
06bc494ca11e Initial load
duke
parents:
diff changeset
  1835
        poolbuf.appendInt(JAVA_MAGIC);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1836
        poolbuf.appendChar(target.minorVersion);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1837
        poolbuf.appendChar(target.majorVersion);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1838
06bc494ca11e Initial load
duke
parents:
diff changeset
  1839
        writePool(c.pool);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1840
06bc494ca11e Initial load
duke
parents:
diff changeset
  1841
        if (innerClasses != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1842
            writeInnerClasses();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1843
            acount++;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1844
        }
14046
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1845
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1846
        if (!bootstrapMethods.isEmpty()) {
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1847
            writeBootstrapMethods();
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1848
            acount++;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1849
        }
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1850
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1851
        endAttrs(acountIdx, acount);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1852
06bc494ca11e Initial load
duke
parents:
diff changeset
  1853
        poolbuf.appendBytes(databuf.elems, 0, databuf.length);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1854
        out.write(poolbuf.elems, 0, poolbuf.length);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1855
06bc494ca11e Initial load
duke
parents:
diff changeset
  1856
        pool = c.pool = null; // to conserve space
06bc494ca11e Initial load
duke
parents:
diff changeset
  1857
     }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1858
13635
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12213
diff changeset
  1859
    /**Allows subclasses to write additional class attributes
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12213
diff changeset
  1860
     *
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12213
diff changeset
  1861
     * @return the number of attributes written
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12213
diff changeset
  1862
     */
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12213
diff changeset
  1863
    protected int writeExtraClassAttributes(ClassSymbol c) {
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12213
diff changeset
  1864
        return 0;
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12213
diff changeset
  1865
    }
5c742eabba7c 7192068: (javac) provide a way for IDEs to produce Enclosing Method attributes.
ksrini
parents: 12213
diff changeset
  1866
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1867
    int adjustFlags(final long flags) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1868
        int result = (int)flags;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1869
        if ((flags & SYNTHETIC) != 0  && !target.useSyntheticFlag())
06bc494ca11e Initial load
duke
parents:
diff changeset
  1870
            result &= ~SYNTHETIC;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1871
        if ((flags & ENUM) != 0  && !target.useEnumFlag())
06bc494ca11e Initial load
duke
parents:
diff changeset
  1872
            result &= ~ENUM;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1873
        if ((flags & ANNOTATION) != 0  && !target.useAnnotationFlag())
06bc494ca11e Initial load
duke
parents:
diff changeset
  1874
            result &= ~ANNOTATION;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1875
06bc494ca11e Initial load
duke
parents:
diff changeset
  1876
        if ((flags & BRIDGE) != 0  && target.useBridgeFlag())
06bc494ca11e Initial load
duke
parents:
diff changeset
  1877
            result |= ACC_BRIDGE;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1878
        if ((flags & VARARGS) != 0  && target.useVarargsFlag())
06bc494ca11e Initial load
duke
parents:
diff changeset
  1879
            result |= ACC_VARARGS;
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1880
        if ((flags & DEFAULT) != 0)
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14359
diff changeset
  1881
            result &= ~ABSTRACT;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1882
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1883
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1884
06bc494ca11e Initial load
duke
parents:
diff changeset
  1885
    long getLastModified(FileObject filename) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1886
        long mod = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1887
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1888
            mod = filename.getLastModified();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1889
        } catch (SecurityException e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1890
            throw new AssertionError("CRT: couldn't get source file modification date: " + e.getMessage());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1891
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1892
        return mod;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1893
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1894
}