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