8134329: TeeOpTest.java fails across platforms after fix for JDK-8129547

Wrong indexes associated to CONSTANT_InvokeDynamic_info entries.

Reviewed-by: sundar
This commit is contained in:
Aleksey Shipilev 2015-08-25 15:10:25 +01:00 committed by Maurizio Cimadamore
parent 3672dbcddf
commit d2e6717c87
3 changed files with 75 additions and 5 deletions
langtools
src/jdk.compiler/share/classes/com/sun/tools/javac/jvm
test/tools/javac/lambda/8134329

@ -138,7 +138,7 @@ public class ClassWriter extends ClassFile {
/** The bootstrap methods to be written in the corresponding class attribute
* (one for each invokedynamic)
*/
Map<DynamicMethod.BootstrapMethodsKey, MethodHandle> bootstrapMethods;
Map<DynamicMethod.BootstrapMethodsKey, DynamicMethod.BootstrapMethodsValue> bootstrapMethods;
/** The log to use for verbose output.
*/
@ -402,7 +402,15 @@ public class ClassWriter extends ClassFile {
DynamicMethodSymbol dynSym = (DynamicMethodSymbol)m;
MethodHandle handle = new MethodHandle(dynSym.bsmKind, dynSym.bsm, types);
DynamicMethod.BootstrapMethodsKey key = new DynamicMethod.BootstrapMethodsKey(dynSym, types);
bootstrapMethods.put(key, handle);
// Figure out the index for existing BSM; create a new BSM if no key
DynamicMethod.BootstrapMethodsValue val = bootstrapMethods.get(key);
if (val == null) {
int index = bootstrapMethods.size();
val = new DynamicMethod.BootstrapMethodsValue(handle, index);
bootstrapMethods.put(key, val);
}
//init cp entries
pool.put(names.BootstrapMethods);
pool.put(handle);
@ -410,7 +418,7 @@ public class ClassWriter extends ClassFile {
pool.put(staticArg);
}
poolbuf.appendByte(CONSTANT_InvokeDynamic);
poolbuf.appendChar(bootstrapMethods.size() - 1);
poolbuf.appendChar(val.index);
poolbuf.appendChar(pool.put(nameType(dynSym)));
}
} else if (value instanceof VarSymbol) {
@ -1024,10 +1032,10 @@ public class ClassWriter extends ClassFile {
void writeBootstrapMethods() {
int alenIdx = writeAttr(names.BootstrapMethods);
databuf.appendChar(bootstrapMethods.size());
for (Map.Entry<DynamicMethod.BootstrapMethodsKey, MethodHandle> entry : bootstrapMethods.entrySet()) {
for (Map.Entry<DynamicMethod.BootstrapMethodsKey, DynamicMethod.BootstrapMethodsValue> entry : bootstrapMethods.entrySet()) {
DynamicMethod.BootstrapMethodsKey bsmKey = entry.getKey();
//write BSM handle
databuf.appendChar(pool.get(entry.getValue()));
databuf.appendChar(pool.get(entry.getValue().mh));
Object[] uniqueArgs = bsmKey.getUniqueArgs();
//write static args length
databuf.appendChar(uniqueArgs.length);

@ -251,6 +251,16 @@ public class Pool {
return uniqueStaticArgs;
}
}
static class BootstrapMethodsValue {
final MethodHandle mh;
final int index;
public BootstrapMethodsValue(MethodHandle mh, int index) {
this.mh = mh;
this.index = index;
}
}
}
static class Variable extends DelegatedSymbol<VarSymbol> {

@ -0,0 +1,52 @@
/*
* Copyright (c) 2015, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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 8134329
* @summary TeeOpTest.java fails across platforms after fix for JDK-8129547
*/
import java.util.function.Supplier;
public class T8134329 {
static void assertEquals(Object o1, Object o2) {
if (!o1.equals(o2)) {
throw new AssertionError(String.format("Expected %s - found %s", o2, o1));
}
}
public static void main(String[] args) {
Supplier<String> s1 = new T8134329() { }::m;
assertEquals(s1.get(), "m");
Supplier<String> s2 = new T8134329() { }::g;
assertEquals(s2.get(), "g");
Supplier<String> s3 = new T8134329() { }::m;
assertEquals(s3.get(), "m");
}
String m() { return "m"; }
String g() { return "g"; }
}