141 // Validation check
142 for (String type : speciesTypes) {
143 for (char c : type.toCharArray()) {
144 if ("LIJFD".indexOf(c) < 0) {
145 throw new PluginException("All characters must "
146 + "correspond to a basic field type: LIJFD");
147 }
148 }
149 }
150 }
151 }
152
153 @Override
154 public void visit(Pool in, Pool out) {
155 for (Pool.ModuleData data : in.getContent()) {
156 if (("/java.base/" + BMH + ".class").equals(data.getPath())) {
157 // Add BoundMethodHandle unchanged
158 out.add(data);
159 speciesTypes.forEach(types -> generateConcreteClass(types, data, out));
160 } else {
161 out.add(data);
162 }
163 }
164 }
165
166 @SuppressWarnings("unchecked")
167 private void generateConcreteClass(String types, Pool.ModuleData data, Pool out) {
168 try {
169 // Generate class
170 Map.Entry<String, byte[]> result = (Map.Entry<String, byte[]>)
171 FACTORY_METHOD.invoke(null, types);
172 String className = result.getKey();
173 byte[] bytes = result.getValue();
174
175 // Add class to pool
176 Pool.ModuleData ndata = new Pool.ModuleData(data.getModule(),
177 "/java.base/" + className + ".class",
178 Pool.ModuleDataType.CLASS_OR_RESOURCE,
179 new ByteArrayInputStream(bytes), bytes.length);
180 out.add(ndata);
181 } catch (Exception ex) {
182 throw new PluginException(ex);
183 }
184 }
185
186 static {
187 try {
188 Class<?> BMHFactory = Class.forName("java.lang.invoke.BoundMethodHandle$Factory");
189 Method genClassMethod = BMHFactory.getDeclaredMethod("generateConcreteBMHClassBytes",
190 String.class);
191 genClassMethod.setAccessible(true);
192 FACTORY_METHOD = genClassMethod;
193 } catch (Exception e) {
194 throw new PluginException(e);
195 }
196 }
197
198 // Convert LL -> LL, L3 -> LLL
199 private static String expandSignature(String signature) {
200 StringBuilder sb = new StringBuilder();
|
141 // Validation check
142 for (String type : speciesTypes) {
143 for (char c : type.toCharArray()) {
144 if ("LIJFD".indexOf(c) < 0) {
145 throw new PluginException("All characters must "
146 + "correspond to a basic field type: LIJFD");
147 }
148 }
149 }
150 }
151 }
152
153 @Override
154 public void visit(Pool in, Pool out) {
155 for (Pool.ModuleData data : in.getContent()) {
156 if (("/java.base/" + BMH + ".class").equals(data.getPath())) {
157 // Add BoundMethodHandle unchanged
158 out.add(data);
159 speciesTypes.forEach(types -> generateConcreteClass(types, data, out));
160 } else {
161 if (!out.contains(data)) {
162 out.add(data);
163 }
164 }
165 }
166 }
167
168 @SuppressWarnings("unchecked")
169 private void generateConcreteClass(String types, Pool.ModuleData data, Pool out) {
170 try {
171 // Generate class
172 Map.Entry<String, byte[]> result = (Map.Entry<String, byte[]>)
173 FACTORY_METHOD.invoke(null, types);
174 String className = result.getKey();
175 byte[] bytes = result.getValue();
176
177 // Add class to pool
178 Pool.ModuleData ndata = new Pool.ModuleData(data.getModule(),
179 "/java.base/" + className + ".class",
180 Pool.ModuleDataType.CLASS_OR_RESOURCE,
181 new ByteArrayInputStream(bytes), bytes.length);
182 if (!out.contains(ndata)) {
183 out.add(ndata);
184 }
185 } catch (Exception ex) {
186 throw new PluginException(ex);
187 }
188 }
189
190 static {
191 try {
192 Class<?> BMHFactory = Class.forName("java.lang.invoke.BoundMethodHandle$Factory");
193 Method genClassMethod = BMHFactory.getDeclaredMethod("generateConcreteBMHClassBytes",
194 String.class);
195 genClassMethod.setAccessible(true);
196 FACTORY_METHOD = genClassMethod;
197 } catch (Exception e) {
198 throw new PluginException(e);
199 }
200 }
201
202 // Convert LL -> LL, L3 -> LLL
203 private static String expandSignature(String signature) {
204 StringBuilder sb = new StringBuilder();
|