/* * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* * @test * @bug 8011738 * @author sogoel * @summary Code translation test for Lambda expressions, method references * @modules jdk.jdeps/com.sun.tools.classfile * @run main ByteCodeTest
*/
TestCases(String src, BSMSpecifier bsmSpecifier) { this.srcCode = src; // By default, all test cases will have bootstrap method specifier as Lambda.MetaFactory // For serializable lambda test cases, bootstrap method specifier changed to altMetaFactory this.bsmSpecifier = bsmSpecifier;
}
staticclass ConstantPoolVisitor implements ConstantPool.Visitor<String, Integer> { final List<String> slist; final ClassFile cf; final ConstantPool cfpool; final Map<Integer, String> bsmMap;
public ConstantPoolVisitor(ClassFile cf, int size) {
slist = new ArrayList<>(size); for (int i = 0 ; i < size; i++) {
slist.add(null);
} this.cf = cf; this.cfpool = cf.constant_pool;
bsmMap = readBSM();
}
public Map<Integer, String> getBSMMap() { return Collections.unmodifiableMap(bsmMap);
}
public String visit(CPInfo c, int index) { return c.accept(this, index);
}
private Map<Integer, String> readBSM() {
BootstrapMethods_attribute bsmAttr =
(BootstrapMethods_attribute) cf.getAttribute(Attribute.BootstrapMethods); if (bsmAttr != null) {
Map<Integer, String> out = new HashMap<>(bsmAttr.bootstrap_method_specifiers.length); for (BootstrapMethods_attribute.BootstrapMethodSpecifier bsms :
bsmAttr.bootstrap_method_specifiers) { int index = bsms.bootstrap_method_ref; try {
String value = slist.get(index); if (value == null) {
value = visit(cfpool.get(index), index);
debugln("[SG]: index " + index);
debugln("[SG]: value " + value);
slist.set(index, value);
out.put(index, value);
} for (int idx : bsms.bootstrap_arguments) {
value = slist.get(idx); if (value == null) {
value = visit(cfpool.get(idx), idx);
debugln("[SG]: idx " + idx);
debugln("[SG]: value " + value);
slist.set(idx, value);
out.put(idx, value);
}
}
} catch (InvalidIndex ex) {
ex.printStackTrace();
}
} return out;
} returnnew HashMap<>(0);
}
@Override public String visitClass(CONSTANT_Class_info c, Integer p) {
String value = slist.get(p); if (value == null) { try {
value = visit(cfpool.get(c.name_index), c.name_index);
slist.set(p, value);
} catch (ConstantPoolException ex) {
ex.printStackTrace();
}
} return value;
}
@Override public String visitDouble(CONSTANT_Double_info c, Integer p) {
String value = slist.get(p); if (value == null) {
value = Double.toString(c.value);
slist.set(p, value);
} return value;
}
@Override public String visitFieldref(CONSTANT_Fieldref_info c, Integer p) {
String value = slist.get(p); if (value == null) { try {
value = visit(cfpool.get(c.class_index), c.class_index);
value = value.concat(" " + visit(cfpool.get(c.name_and_type_index),
c.name_and_type_index));
slist.set(p, value);
} catch (ConstantPoolException ex) {
ex.printStackTrace();
}
} return value;
}
@Override public String visitFloat(CONSTANT_Float_info c, Integer p) {
String value = slist.get(p); if (value == null) {
value = Float.toString(c.value);
slist.set(p, value);
} return value;
}
@Override public String visitInteger(CONSTANT_Integer_info cnstnt, Integer p) {
String value = slist.get(p); if (value == null) {
value = Integer.toString(cnstnt.value);
slist.set(p, value);
} return value;
}
@Override public String visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info c,
Integer p) {
String value = slist.get(p); if (value == null) { try {
value = visit(cfpool.get(c.class_index), c.class_index);
value = value.concat(" " +
visit(cfpool.get(c.name_and_type_index),
c.name_and_type_index));
slist.set(p, value);
} catch (ConstantPoolException ex) {
ex.printStackTrace();
}
} return value;
}
@Override public String visitInvokeDynamic(CONSTANT_InvokeDynamic_info c, Integer p) {
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.