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