src/java.base/share/classes/jdk/internal/module/ClassFileAttributes.java
author rriggs
Sun, 29 Oct 2017 18:20:53 -0400
changeset 47471 304ef03403b1
parent 47216 71c04702a3d5
permissions -rw-r--r--
8190323: "the the" typos Reviewed-by: rriggs Contributed-by: christoph.dreis@freenet.de
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * accompanied this code).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    23
 * questions.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    24
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
package jdk.internal.module;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
import java.lang.module.ModuleDescriptor;
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    29
import java.lang.module.ModuleDescriptor.Builder;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
import java.lang.module.ModuleDescriptor.Requires;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import java.lang.module.ModuleDescriptor.Exports;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
    32
import java.lang.module.ModuleDescriptor.Opens;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import java.lang.module.ModuleDescriptor.Provides;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
import java.lang.module.ModuleDescriptor.Version;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
    35
import java.util.ArrayList;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import java.util.Collections;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.util.HashMap;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import java.util.HashSet;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
    39
import java.util.List;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import java.util.Map;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import java.util.Set;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
    43
import jdk.internal.misc.JavaLangModuleAccess;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
    44
import jdk.internal.misc.SharedSecrets;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
import jdk.internal.org.objectweb.asm.Attribute;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
import jdk.internal.org.objectweb.asm.ByteVector;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
import jdk.internal.org.objectweb.asm.ClassReader;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
import jdk.internal.org.objectweb.asm.ClassWriter;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
import jdk.internal.org.objectweb.asm.Label;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
import static jdk.internal.module.ClassFileConstants.*;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
 * Provides ASM implementations of {@code Attribute} to read and write the
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
 * class file attributes in a module-info class file.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
    58
public final class ClassFileAttributes {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
    private ClassFileAttributes() { }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
     * Module_attribute {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
     *   // See lang-vm.html for details.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
     * }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
     */
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
    67
    public static class ModuleAttribute extends Attribute {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
    68
        private static final JavaLangModuleAccess JLMA
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
    69
            = SharedSecrets.getJavaLangModuleAccess();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
        private ModuleDescriptor descriptor;
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    72
        private Version replacementVersion;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
    74
        public ModuleAttribute(ModuleDescriptor descriptor) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
            super(MODULE);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
            this.descriptor = descriptor;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    79
        public ModuleAttribute(Version v) {
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    80
            super(MODULE);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    81
            this.replacementVersion = v;
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    82
        }
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    83
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
    84
        public ModuleAttribute() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
            super(MODULE);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
        protected Attribute read(ClassReader cr,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
                                 int off,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
                                 int len,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
                                 char[] buf,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
                                 int codeOff,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
                                 Label[] labels)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
        {
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    96
            // module_name (CONSTANT_Module_info)
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    97
            String mn = cr.readModule(off, buf);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
    98
            off += 2;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
    99
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   100
            // module_flags
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   101
            int module_flags = cr.readUnsignedShort(off);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   102
            off += 2;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   103
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   104
            Set<ModuleDescriptor.Modifier> modifiers = new HashSet<>();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   105
            if ((module_flags & ACC_OPEN) != 0)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   106
                modifiers.add(ModuleDescriptor.Modifier.OPEN);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   107
            if ((module_flags & ACC_SYNTHETIC) != 0)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   108
                modifiers.add(ModuleDescriptor.Modifier.SYNTHETIC);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   109
            if ((module_flags & ACC_MANDATED) != 0)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   110
                modifiers.add(ModuleDescriptor.Modifier.MANDATED);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   111
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   112
            Builder builder = JLMA.newModuleBuilder(mn, false, modifiers);
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   113
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   114
            // module_version
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   115
            String module_version = cr.readUTF8(off, buf);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   116
            off += 2;
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   117
            if (replacementVersion != null) {
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   118
                builder.version(replacementVersion);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   119
            } else if (module_version != null) {
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   120
                builder.version(module_version);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   121
            }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   122
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   123
            // requires_count and requires[requires_count]
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   124
            int requires_count = cr.readUnsignedShort(off);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   125
            off += 2;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
            for (int i=0; i<requires_count; i++) {
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   127
                // CONSTANT_Module_info
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   128
                String dn = cr.readModule(off, buf);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   129
                off += 2;
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   130
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   131
                // requires_flags
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   132
                int requires_flags = cr.readUnsignedShort(off);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   133
                off += 2;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   134
                Set<Requires.Modifier> mods;
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   135
                if (requires_flags == 0) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   136
                    mods = Collections.emptySet();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   137
                } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   138
                    mods = new HashSet<>();
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   139
                    if ((requires_flags & ACC_TRANSITIVE) != 0)
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   140
                        mods.add(Requires.Modifier.TRANSITIVE);
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   141
                    if ((requires_flags & ACC_STATIC_PHASE) != 0)
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   142
                        mods.add(Requires.Modifier.STATIC);
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   143
                    if ((requires_flags & ACC_SYNTHETIC) != 0)
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   144
                        mods.add(Requires.Modifier.SYNTHETIC);
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   145
                    if ((requires_flags & ACC_MANDATED) != 0)
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   146
                        mods.add(Requires.Modifier.MANDATED);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   147
                }
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   148
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   149
                // requires_version
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   150
                String requires_version = cr.readUTF8(off, buf);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   151
                off += 2;
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   152
                if (requires_version == null) {
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   153
                    builder.requires(mods, dn);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   154
                } else {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   155
                    JLMA.requires(builder, mods, dn, requires_version);
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   156
                }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   159
            // exports_count and exports[exports_count]
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   160
            int exports_count = cr.readUnsignedShort(off);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   161
            off += 2;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   162
            if (exports_count > 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   163
                for (int i=0; i<exports_count; i++) {
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   164
                    // CONSTANT_Package_info
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   165
                    String pkg = cr.readPackage(off, buf).replace('/', '.');
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   166
                    off += 2;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   167
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   168
                    int exports_flags = cr.readUnsignedShort(off);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   169
                    off += 2;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   170
                    Set<Exports.Modifier> mods;
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   171
                    if (exports_flags == 0) {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   172
                        mods = Collections.emptySet();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   173
                    } else {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   174
                        mods = new HashSet<>();
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   175
                        if ((exports_flags & ACC_SYNTHETIC) != 0)
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   176
                            mods.add(Exports.Modifier.SYNTHETIC);
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   177
                        if ((exports_flags & ACC_MANDATED) != 0)
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   178
                            mods.add(Exports.Modifier.MANDATED);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   179
                    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   180
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   181
                    int exports_to_count = cr.readUnsignedShort(off);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   182
                    off += 2;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   183
                    if (exports_to_count > 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   184
                        Set<String> targets = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   185
                        for (int j=0; j<exports_to_count; j++) {
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   186
                            String t = cr.readModule(off, buf);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   187
                            off += 2;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   188
                            targets.add(t);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   189
                        }
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   190
                        builder.exports(mods, pkg, targets);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   191
                    } else {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   192
                        builder.exports(mods, pkg);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   193
                    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   194
                }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   195
            }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   196
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   197
            // opens_count and opens[opens_count]
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   198
            int open_count = cr.readUnsignedShort(off);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   199
            off += 2;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   200
            if (open_count > 0) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   201
                for (int i=0; i<open_count; i++) {
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   202
                    // CONSTANT_Package_info
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   203
                    String pkg = cr.readPackage(off, buf).replace('/', '.');
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   204
                    off += 2;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   205
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   206
                    int opens_flags = cr.readUnsignedShort(off);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   207
                    off += 2;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   208
                    Set<Opens.Modifier> mods;
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   209
                    if (opens_flags == 0) {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   210
                        mods = Collections.emptySet();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   211
                    } else {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   212
                        mods = new HashSet<>();
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   213
                        if ((opens_flags & ACC_SYNTHETIC) != 0)
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   214
                            mods.add(Opens.Modifier.SYNTHETIC);
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   215
                        if ((opens_flags & ACC_MANDATED) != 0)
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   216
                            mods.add(Opens.Modifier.MANDATED);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   217
                    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   218
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   219
                    int opens_to_count = cr.readUnsignedShort(off);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   220
                    off += 2;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   221
                    if (opens_to_count > 0) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   222
                        Set<String> targets = new HashSet<>();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   223
                        for (int j=0; j<opens_to_count; j++) {
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   224
                            String t = cr.readModule(off, buf);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   225
                            off += 2;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   226
                            targets.add(t);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   227
                        }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   228
                        builder.opens(mods, pkg, targets);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   229
                    } else {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   230
                        builder.opens(mods, pkg);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   231
                    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   232
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   233
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   234
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   235
            // uses_count and uses_index[uses_count]
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   236
            int uses_count = cr.readUnsignedShort(off);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   237
            off += 2;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   238
            if (uses_count > 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   239
                for (int i=0; i<uses_count; i++) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   240
                    String sn = cr.readClass(off, buf).replace('/', '.');
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   241
                    builder.uses(sn);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   242
                    off += 2;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   243
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   244
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   245
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   246
            // provides_count and provides[provides_count]
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   247
            int provides_count = cr.readUnsignedShort(off);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   248
            off += 2;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   249
            if (provides_count > 0) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   250
                for (int i=0; i<provides_count; i++) {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   251
                    String service = cr.readClass(off, buf).replace('/', '.');
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   252
                    off += 2;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   253
                    int with_count = cr.readUnsignedShort(off);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   254
                    off += 2;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   255
                    List<String> providers = new ArrayList<>();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   256
                    for (int j=0; j<with_count; j++) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   257
                        String cn = cr.readClass(off, buf).replace('/', '.');
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   258
                        off += 2;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   259
                        providers.add(cn);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   260
                    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   261
                    builder.provides(service, providers);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   262
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   263
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   264
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   265
            return new ModuleAttribute(builder.build());
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   266
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   267
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   268
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   269
        protected ByteVector write(ClassWriter cw,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   270
                                   byte[] code,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   271
                                   int len,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   272
                                   int maxStack,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   273
                                   int maxLocals)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   274
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   275
            assert descriptor != null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   276
            ByteVector attr = new ByteVector();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   277
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   278
            // module_name
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   279
            String mn = descriptor.name();
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   280
            int module_name_index = cw.newModule(mn);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   281
            attr.putShort(module_name_index);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   282
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   283
            // module_flags
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   284
            Set<ModuleDescriptor.Modifier> modifiers = descriptor.modifiers();
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   285
            int module_flags = 0;
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   286
            if (modifiers.contains(ModuleDescriptor.Modifier.OPEN))
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   287
                module_flags |= ACC_OPEN;
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   288
            if (modifiers.contains(ModuleDescriptor.Modifier.SYNTHETIC))
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   289
                module_flags |= ACC_SYNTHETIC;
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   290
            if (modifiers.contains(ModuleDescriptor.Modifier.MANDATED))
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   291
                module_flags |= ACC_MANDATED;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   292
            attr.putShort(module_flags);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   293
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   294
            // module_version
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   295
            String vs = descriptor.rawVersion().orElse(null);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   296
            if (vs == null) {
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   297
                attr.putShort(0);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   298
            } else {
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   299
                int module_version_index = cw.newUTF8(vs);
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   300
                attr.putShort(module_version_index);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   301
            }
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   302
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   303
            // requires_count
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   304
            attr.putShort(descriptor.requires().size());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   305
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   306
            // requires[requires_count]
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   307
            for (Requires r : descriptor.requires()) {
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   308
                int requires_index = cw.newModule(r.name());
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   309
                attr.putShort(requires_index);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   310
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   311
                int requires_flags = 0;
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   312
                if (r.modifiers().contains(Requires.Modifier.TRANSITIVE))
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   313
                    requires_flags |= ACC_TRANSITIVE;
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   314
                if (r.modifiers().contains(Requires.Modifier.STATIC))
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   315
                    requires_flags |= ACC_STATIC_PHASE;
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   316
                if (r.modifiers().contains(Requires.Modifier.SYNTHETIC))
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   317
                    requires_flags |= ACC_SYNTHETIC;
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   318
                if (r.modifiers().contains(Requires.Modifier.MANDATED))
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   319
                    requires_flags |= ACC_MANDATED;
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   320
                attr.putShort(requires_flags);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   321
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   322
                int requires_version_index;
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   323
                vs = r.rawCompiledVersion().orElse(null);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   324
                if (vs == null) {
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   325
                    requires_version_index = 0;
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   326
                } else {
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   327
                    requires_version_index = cw.newUTF8(vs);
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   328
                }
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   329
                attr.putShort(requires_version_index);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   330
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   331
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   332
            // exports_count and exports[exports_count];
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   333
            attr.putShort(descriptor.exports().size());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   334
            for (Exports e : descriptor.exports()) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   335
                String pkg = e.source().replace('.', '/');
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   336
                attr.putShort(cw.newPackage(pkg));
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   337
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   338
                int exports_flags = 0;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   339
                if (e.modifiers().contains(Exports.Modifier.SYNTHETIC))
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   340
                    exports_flags |= ACC_SYNTHETIC;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   341
                if (e.modifiers().contains(Exports.Modifier.MANDATED))
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   342
                    exports_flags |= ACC_MANDATED;
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   343
                attr.putShort(exports_flags);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   344
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   345
                if (e.isQualified()) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   346
                    Set<String> ts = e.targets();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   347
                    attr.putShort(ts.size());
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   348
                    ts.forEach(target -> attr.putShort(cw.newModule(target)));
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   349
                } else {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   350
                    attr.putShort(0);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   351
                }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   352
            }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   353
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   354
            // opens_counts and opens[opens_counts]
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   355
            attr.putShort(descriptor.opens().size());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   356
            for (Opens obj : descriptor.opens()) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   357
                String pkg = obj.source().replace('.', '/');
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   358
                attr.putShort(cw.newPackage(pkg));
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   359
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   360
                int opens_flags = 0;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   361
                if (obj.modifiers().contains(Opens.Modifier.SYNTHETIC))
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   362
                    opens_flags |= ACC_SYNTHETIC;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   363
                if (obj.modifiers().contains(Opens.Modifier.MANDATED))
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   364
                    opens_flags |= ACC_MANDATED;
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   365
                attr.putShort(opens_flags);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   366
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   367
                if (obj.isQualified()) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   368
                    Set<String> ts = obj.targets();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   369
                    attr.putShort(ts.size());
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   370
                    ts.forEach(target -> attr.putShort(cw.newModule(target)));
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   371
                } else {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   372
                    attr.putShort(0);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   373
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   374
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   375
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   376
            // uses_count and uses_index[uses_count]
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   377
            if (descriptor.uses().isEmpty()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   378
                attr.putShort(0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   379
            } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   380
                attr.putShort(descriptor.uses().size());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   381
                for (String s : descriptor.uses()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   382
                    String service = s.replace('.', '/');
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   383
                    int index = cw.newClass(service);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   384
                    attr.putShort(index);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   385
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   386
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   387
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   388
            // provides_count and provides[provides_count]
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   389
            if (descriptor.provides().isEmpty()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   390
                attr.putShort(0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   391
            } else {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   392
                attr.putShort(descriptor.provides().size());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   393
                for (Provides p : descriptor.provides()) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   394
                    String service = p.service().replace('.', '/');
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   395
                    attr.putShort(cw.newClass(service));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   396
                    int with_count = p.providers().size();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   397
                    attr.putShort(with_count);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   398
                    for (String provider : p.providers()) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   399
                        attr.putShort(cw.newClass(provider.replace('.', '/')));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   400
                    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   401
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   402
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   403
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   404
            return attr;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   405
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   406
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   407
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   408
    /**
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   409
     * ModulePackages attribute.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   410
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   411
     * <pre> {@code
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   412
     *
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   413
     * ModulePackages_attribute {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   414
     *   // index to CONSTANT_utf8_info structure in constant pool representing
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   415
     *   // the string "ModulePackages"
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   416
     *   u2 attribute_name_index;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   417
     *   u4 attribute_length;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   418
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   419
     *   // the number of entries in the packages table
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   420
     *   u2 packages_count;
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   421
     *   { // index to CONSTANT_Package_info structure with the package name
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   422
     *     u2 package_index
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   423
     *   } packages[package_count];
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   424
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   425
     * }</pre>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   426
     */
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   427
    public static class ModulePackagesAttribute extends Attribute {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   428
        private final Set<String> packages;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   429
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   430
        public ModulePackagesAttribute(Set<String> packages) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   431
            super(MODULE_PACKAGES);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   432
            this.packages = packages;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   433
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   434
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   435
        public ModulePackagesAttribute() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   436
            this(null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   437
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   438
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   439
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   440
        protected Attribute read(ClassReader cr,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   441
                                 int off,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   442
                                 int len,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   443
                                 char[] buf,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   444
                                 int codeOff,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   445
                                 Label[] labels)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   446
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   447
            // package count
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   448
            int package_count = cr.readUnsignedShort(off);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   449
            off += 2;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   450
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   451
            // packages
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   452
            Set<String> packages = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   453
            for (int i=0; i<package_count; i++) {
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   454
                String pkg = cr.readPackage(off, buf).replace('/', '.');
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   455
                packages.add(pkg);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   456
                off += 2;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   457
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   458
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   459
            return new ModulePackagesAttribute(packages);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   460
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   461
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   462
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   463
        protected ByteVector write(ClassWriter cw,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   464
                                   byte[] code,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   465
                                   int len,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   466
                                   int maxStack,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   467
                                   int maxLocals)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   468
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   469
            assert packages != null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   470
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   471
            ByteVector attr = new ByteVector();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   472
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   473
            // package_count
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   474
            attr.putShort(packages.size());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   475
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   476
            // packages
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   477
            packages.stream()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   478
                .map(p -> p.replace('.', '/'))
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   479
                .forEach(p -> attr.putShort(cw.newPackage(p)));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   480
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   481
            return attr;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   482
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   483
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   484
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   485
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   486
    /**
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   487
     * ModuleMainClass attribute.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   488
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   489
     * <pre> {@code
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   490
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   491
     * MainClass_attribute {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   492
     *   // index to CONSTANT_utf8_info structure in constant pool representing
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   493
     *   // the string "ModuleMainClass"
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   494
     *   u2 attribute_name_index;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   495
     *   u4 attribute_length;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   496
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   497
     *   // index to CONSTANT_Class_info structure with the main class name
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   498
     *   u2 main_class_index;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   499
     * }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   500
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   501
     * } </pre>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   502
     */
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   503
    public static class ModuleMainClassAttribute extends Attribute {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   504
        private final String mainClass;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   505
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   506
        public ModuleMainClassAttribute(String mainClass) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   507
            super(MODULE_MAIN_CLASS);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   508
            this.mainClass = mainClass;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   509
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   510
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   511
        public ModuleMainClassAttribute() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   512
            this(null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   513
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   514
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   515
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   516
        protected Attribute read(ClassReader cr,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   517
                                 int off,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   518
                                 int len,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   519
                                 char[] buf,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   520
                                 int codeOff,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   521
                                 Label[] labels)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   522
        {
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   523
            String value = cr.readClass(off, buf).replace('/', '.');
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   524
            return new ModuleMainClassAttribute(value);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   525
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   526
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   527
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   528
        protected ByteVector write(ClassWriter cw,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   529
                                   byte[] code,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   530
                                   int len,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   531
                                   int maxStack,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   532
                                   int maxLocals)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   533
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   534
            ByteVector attr = new ByteVector();
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   535
            int index = cw.newClass(mainClass.replace('.', '/'));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   536
            attr.putShort(index);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   537
            return attr;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   538
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   539
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   540
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   541
    /**
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   542
     * ModuleTarget attribute.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   543
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   544
     * <pre> {@code
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   545
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   546
     * TargetPlatform_attribute {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   547
     *   // index to CONSTANT_utf8_info structure in constant pool representing
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   548
     *   // the string "ModuleTarget"
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   549
     *   u2 attribute_name_index;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   550
     *   u4 attribute_length;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   551
     *
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44359
diff changeset
   552
     *   // index to CONSTANT_utf8_info structure with the target platform
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44359
diff changeset
   553
     *   u2 target_platform_index;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   554
     * }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   555
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   556
     * } </pre>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   557
     */
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   558
    public static class ModuleTargetAttribute extends Attribute {
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44359
diff changeset
   559
        private final String targetPlatform;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   560
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44359
diff changeset
   561
        public ModuleTargetAttribute(String targetPlatform) {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   562
            super(MODULE_TARGET);
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44359
diff changeset
   563
            this.targetPlatform = targetPlatform;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   564
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   565
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   566
        public ModuleTargetAttribute() {
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44359
diff changeset
   567
            this(null);
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   568
        }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   569
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44359
diff changeset
   570
        public String targetPlatform() {
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44359
diff changeset
   571
            return targetPlatform;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   572
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   573
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   574
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   575
        protected Attribute read(ClassReader cr,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   576
                                 int off,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   577
                                 int len,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   578
                                 char[] buf,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   579
                                 int codeOff,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   580
                                 Label[] labels)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   581
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   582
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44359
diff changeset
   583
            String targetPlatform = null;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   584
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44359
diff changeset
   585
            int target_platform_index = cr.readUnsignedShort(off);
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44359
diff changeset
   586
            if (target_platform_index != 0)
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44359
diff changeset
   587
                targetPlatform = cr.readUTF8(off, buf);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   588
            off += 2;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   589
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44359
diff changeset
   590
            return new ModuleTargetAttribute(targetPlatform);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   591
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   592
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   593
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   594
        protected ByteVector write(ClassWriter cw,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   595
                                   byte[] code,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   596
                                   int len,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   597
                                   int maxStack,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   598
                                   int maxLocals)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   599
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   600
            ByteVector attr = new ByteVector();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   601
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44359
diff changeset
   602
            int target_platform_index = 0;
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44359
diff changeset
   603
            if (targetPlatform != null && targetPlatform.length() > 0)
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44359
diff changeset
   604
                target_platform_index = cw.newUTF8(targetPlatform);
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44359
diff changeset
   605
            attr.putShort(target_platform_index);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   606
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   607
            return attr;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   608
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   609
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   610
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   611
    /**
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   612
     * ModuleHashes attribute.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   613
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   614
     * <pre> {@code
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   615
     *
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   616
     * ModuleHashes_attribute {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   617
     *   // index to CONSTANT_utf8_info structure in constant pool representing
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   618
     *   // the string "ModuleHashes"
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   619
     *   u2 attribute_name_index;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   620
     *   u4 attribute_length;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   621
     *
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   622
     *   // index to CONSTANT_utf8_info structure with algorithm name
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   623
     *   u2 algorithm_index;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   624
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   625
     *   // the number of entries in the hashes table
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   626
     *   u2 hashes_count;
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   627
     *   {   u2 module_name_index (index to CONSTANT_Module_info structure)
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   628
     *       u2 hash_length;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   629
     *       u1 hash[hash_length];
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   630
     *   } hashes[hashes_count];
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   631
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   632
     * } </pre>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   633
     */
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   634
    static class ModuleHashesAttribute extends Attribute {
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   635
        private final ModuleHashes hashes;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   636
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   637
        ModuleHashesAttribute(ModuleHashes hashes) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   638
            super(MODULE_HASHES);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   639
            this.hashes = hashes;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   640
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   641
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   642
        ModuleHashesAttribute() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   643
            this(null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   644
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   645
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   646
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   647
        protected Attribute read(ClassReader cr,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   648
                                 int off,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   649
                                 int len,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   650
                                 char[] buf,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   651
                                 int codeOff,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   652
                                 Label[] labels)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   653
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   654
            String algorithm = cr.readUTF8(off, buf);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   655
            off += 2;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   656
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   657
            int hashes_count = cr.readUnsignedShort(off);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   658
            off += 2;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   659
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   660
            Map<String, byte[]> map = new HashMap<>();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   661
            for (int i=0; i<hashes_count; i++) {
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   662
                String mn = cr.readModule(off, buf);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   663
                off += 2;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   664
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   665
                int hash_length = cr.readUnsignedShort(off);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   666
                off += 2;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   667
                byte[] hash = new byte[hash_length];
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   668
                for (int j=0; j<hash_length; j++) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   669
                    hash[j] = (byte) (0xff & cr.readByte(off+j));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   670
                }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   671
                off += hash_length;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   672
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   673
                map.put(mn, hash);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   674
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   675
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   676
            ModuleHashes hashes = new ModuleHashes(algorithm, map);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   677
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   678
            return new ModuleHashesAttribute(hashes);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   679
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   680
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   681
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   682
        protected ByteVector write(ClassWriter cw,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   683
                                   byte[] code,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   684
                                   int len,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   685
                                   int maxStack,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   686
                                   int maxLocals)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   687
        {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   688
            ByteVector attr = new ByteVector();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   689
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   690
            int index = cw.newUTF8(hashes.algorithm());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   691
            attr.putShort(index);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   692
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   693
            Set<String> names = hashes.names();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   694
            attr.putShort(names.size());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   695
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   696
            for (String mn : names) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   697
                byte[] hash = hashes.hashFor(mn);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   698
                assert hash != null;
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   699
                attr.putShort(cw.newModule(mn));
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   700
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   701
                attr.putShort(hash.length);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   702
                for (byte b: hash) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   703
                    attr.putByte(b);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 37779
diff changeset
   704
                }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   705
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   706
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   707
            return attr;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   708
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   709
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   710
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   711
    /**
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   712
     *  ModuleResolution_attribute {
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   713
     *    u2 attribute_name_index;    // "ModuleResolution"
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   714
     *    u4 attribute_length;        // 2
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   715
     *    u2 resolution_flags;
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   716
     *
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   717
     *  The value of the resolution_flags item is a mask of flags used to denote
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   718
     *  properties of module resolution. The flags are as follows:
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   719
     *
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   720
     *   // Optional
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   721
     *   0x0001 (DO_NOT_RESOLVE_BY_DEFAULT)
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   722
     *
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   723
     *   // At most one of:
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   724
     *   0x0002 (WARN_DEPRECATED)
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   725
     *   0x0004 (WARN_DEPRECATED_FOR_REMOVAL)
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   726
     *   0x0008 (WARN_INCUBATING)
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   727
     */
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   728
    static class ModuleResolutionAttribute extends Attribute {
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   729
        private final int value;
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   730
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   731
        ModuleResolutionAttribute() {
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   732
            super(MODULE_RESOLUTION);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   733
            value = 0;
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   734
        }
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   735
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   736
        ModuleResolutionAttribute(int value) {
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   737
            super(MODULE_RESOLUTION);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   738
            this.value = value;
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   739
        }
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   740
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   741
        @Override
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   742
        protected Attribute read(ClassReader cr,
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   743
                                 int off,
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   744
                                 int len,
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   745
                                 char[] buf,
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   746
                                 int codeOff,
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   747
                                 Label[] labels)
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   748
        {
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   749
            int flags = cr.readUnsignedShort(off);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   750
            return new ModuleResolutionAttribute(flags);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   751
        }
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   752
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   753
        @Override
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   754
        protected ByteVector write(ClassWriter cw,
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   755
                                   byte[] code,
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   756
                                   int len,
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   757
                                   int maxStack,
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   758
                                   int maxLocals)
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   759
        {
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   760
            ByteVector attr = new ByteVector();
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   761
            attr.putShort(value);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   762
            return attr;
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   763
        }
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   764
    }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   765
}