提交 8008dc49 编写于 作者: J jlahoda

8027191: Fix for JDK-8026861 refers to an incorrect bug number

Summary: Reverting changeset b05db8c815e8, so that it can be applied again with a correct bug number
Reviewed-by: jjg
上级 dd975d93
......@@ -156,15 +156,12 @@ public class LambdaToMethod extends TreeTranslator {
*/
private final VarSymbol deserParamSym;
private final JCClassDecl clazz;
private KlassInfo(JCClassDecl clazz) {
this.clazz = clazz;
private KlassInfo(Symbol kSym) {
appendedMethodList = new ListBuffer<>();
deserializeCases = new HashMap<String, ListBuffer<JCStatement>>();
MethodType type = new MethodType(List.of(syms.serializedLambdaType), syms.objectType,
List.<Type>nil(), syms.methodClass);
deserMethodSym = makePrivateSyntheticMethod(STATIC, names.deserializeLambda, type, clazz.sym);
deserMethodSym = makePrivateSyntheticMethod(STATIC, names.deserializeLambda, type, kSym);
deserParamSym = new VarSymbol(FINAL, names.fromString("lambda"),
syms.serializedLambdaType, deserMethodSym);
}
......@@ -224,16 +221,10 @@ public class LambdaToMethod extends TreeTranslator {
}
KlassInfo prevKlassInfo = kInfo;
try {
kInfo = new KlassInfo(tree);
kInfo = new KlassInfo(tree.sym);
super.visitClassDef(tree);
if (!kInfo.deserializeCases.isEmpty()) {
int prevPos = make.pos;
try {
make.at(tree);
kInfo.addMethod(makeDeserializeMethod(tree.sym));
} finally {
make.at(prevPos);
}
kInfo.addMethod(makeDeserializeMethod(tree.sym));
}
//add all translated instance methods here
List<JCTree> newMethods = kInfo.appendedMethodList.toList();
......@@ -409,21 +400,14 @@ public class LambdaToMethod extends TreeTranslator {
if (context == null || !analyzer.lambdaIdentSymbolFilter(tree.sym)) {
super.visitIdent(tree);
} else {
int prevPos = make.pos;
try {
make.at(tree);
LambdaTranslationContext lambdaContext = (LambdaTranslationContext) context;
JCTree ltree = lambdaContext.translate(tree);
if (ltree != null) {
result = ltree;
} else {
//access to untranslated symbols (i.e. compile-time constants,
//members defined inside the lambda body, etc.) )
super.visitIdent(tree);
}
} finally {
make.at(prevPos);
LambdaTranslationContext lambdaContext = (LambdaTranslationContext) context;
JCTree ltree = lambdaContext.translate(tree);
if (ltree != null) {
result = ltree;
} else {
//access to untranslated symbols (i.e. compile-time constants,
//members defined inside the lambda body, etc.) )
super.visitIdent(tree);
}
}
}
......@@ -433,21 +417,11 @@ public class LambdaToMethod extends TreeTranslator {
LambdaTranslationContext lambdaContext = (LambdaTranslationContext)context;
if (context != null && lambdaContext.getSymbolMap(LOCAL_VAR).containsKey(tree.sym)) {
JCExpression init = translate(tree.init);
int prevPos = make.pos;
try {
result = make.at(tree).VarDef((VarSymbol)lambdaContext.getSymbolMap(LOCAL_VAR).get(tree.sym), init);
} finally {
make.at(prevPos);
}
result = make.VarDef((VarSymbol)lambdaContext.getSymbolMap(LOCAL_VAR).get(tree.sym), init);
} else if (context != null && lambdaContext.getSymbolMap(TYPE_VAR).containsKey(tree.sym)) {
JCExpression init = translate(tree.init);
VarSymbol xsym = (VarSymbol)lambdaContext.getSymbolMap(TYPE_VAR).get(tree.sym);
int prevPos = make.pos;
try {
result = make.at(tree).VarDef(xsym, init);
} finally {
make.at(prevPos);
}
result = make.VarDef(xsym, init);
// Replace the entered symbol for this variable
Scope sc = tree.sym.owner.members();
if (sc != null) {
......@@ -474,28 +448,23 @@ public class LambdaToMethod extends TreeTranslator {
boolean isLambda_void = expr.type.hasTag(VOID);
boolean isTarget_void = restype.hasTag(VOID);
boolean isTarget_Void = types.isSameType(restype, types.boxedClass(syms.voidType).type);
int prevPos = make.pos;
try {
if (isTarget_void) {
//target is void:
// BODY;
JCStatement stat = make.at(expr).Exec(expr);
return make.Block(0, List.<JCStatement>of(stat));
} else if (isLambda_void && isTarget_Void) {
//void to Void conversion:
// BODY; return null;
ListBuffer<JCStatement> stats = new ListBuffer<>();
stats.append(make.at(expr).Exec(expr));
stats.append(make.Return(make.Literal(BOT, null).setType(syms.botType)));
return make.Block(0, stats.toList());
} else {
//non-void to non-void conversion:
// return (TYPE)BODY;
JCExpression retExpr = transTypes.coerce(attrEnv, expr, restype);
return make.at(retExpr).Block(0, List.<JCStatement>of(make.Return(retExpr)));
}
} finally {
make.at(prevPos);
if (isTarget_void) {
//target is void:
// BODY;
JCStatement stat = make.Exec(expr);
return make.Block(0, List.<JCStatement>of(stat));
} else if (isLambda_void && isTarget_Void) {
//void to Void conversion:
// BODY; return null;
ListBuffer<JCStatement> stats = new ListBuffer<>();
stats.append(make.Exec(expr));
stats.append(make.Return(make.Literal(BOT, null).setType(syms.botType)));
return make.Block(0, stats.toList());
} else {
//non-void to non-void conversion:
// return (TYPE)BODY;
JCExpression retExpr = transTypes.coerce(attrEnv, expr, restype);
return make.at(retExpr).Block(0, List.<JCStatement>of(make.Return(retExpr)));
}
}
......@@ -997,14 +966,8 @@ public class LambdaToMethod extends TreeTranslator {
}
}
if (context.isSerializable()) {
int prevPos = make.pos;
try {
make.at(kInfo.clazz);
addDeserializationCase(refKind, refSym, tree.type, samSym,
tree, staticArgs, indyType);
} finally {
make.at(prevPos);
}
addDeserializationCase(refKind, refSym, tree.type, samSym,
tree, staticArgs, indyType);
}
}
......
......@@ -25,11 +25,11 @@
/*
* @test
* @bug 8019486 8026861
* @bug 8019486
* @summary javac, generates erroneous LVT for a test case with lambda code
* @library /tools/javac/lib
* @build ToolBox
* @run main WrongLNTForLambdaTest
* @run main WrongLVTForLambdaTest
*/
import java.io.File;
......@@ -41,7 +41,7 @@ import com.sun.tools.classfile.LineNumberTable_attribute;
import com.sun.tools.classfile.Method;
import com.sun.tools.javac.util.Assert;
public class WrongLNTForLambdaTest {
public class WrongLVTForLambdaTest {
static final String testSource =
/* 01 */ "import java.util.List;\n" +
......@@ -54,72 +54,21 @@ public class WrongLNTForLambdaTest {
/* 08 */ " final List<Integer> numbersPlusOne = \n" +
/* 09 */ " numbers.stream().map(number -> number / 1).collect(Collectors.toList());\n" +
/* 10 */ " }\n" +
/* 11 */ " void variablesInLambdas(int value) {\n" +
/* 12 */ " Runnable r1 = () -> {\n" +
/* 13 */ " int i = value;\n" +
/* 14 */ " class FooBar<T extends CharSequence> {\n" +
/* 15 */ " public void run() {\n" +
/* 16 */ " T t = null;\n" +
/* 17 */ " }\n" +
/* 18 */ " }\n" +
/* 19 */ " };\n" +
/* 20 */ " Runnable r2 = () -> System.err.println(1);\n" +
/* 21 */ " Runnable r3 = (Runnable & java.io.Serializable) this::foo;\n" +
/* 22 */ " Runnable r4 = super :: notify;\n" +
/* 23 */ " }\n" +
/* 24 */ " private void foo() {}\n" +
/* 25 */ "}";
/* 11 */ "}";
static final int[][] simpleLambdaExpectedLNT = {
static final int[][] expectedLNT = {
// {line-number, start-pc},
{9, 0}, //number -> number / 1
};
static final int[][] lambdaWithVarsExpectedLNT = {
// {line-number, start-pc},
{13, 0}, //number -> number / 1
{19, 2}, //number -> number / 1
};
static final int[][] insideLambdaWithVarsExpectedLNT = {
// {line-number, start-pc},
{16, 0}, //number -> number / 1
{17, 2}, //number -> number / 1
};
static final int[][] lambdaVoid2VoidExpectedLNT = {
// {line-number, start-pc},
{20, 0}, //number -> number / 1
};
static final int[][] deserializeExpectedLNT = {
// {line-number, start-pc},
{05, 0}, //number -> number / 1
};
static final int[][] lambdaBridgeExpectedLNT = {
// {line-number, start-pc},
{22, 0}, //number -> number / 1
};
public static void main(String[] args) throws Exception {
new WrongLNTForLambdaTest().run();
new WrongLVTForLambdaTest().run();
}
void run() throws Exception {
compileTestClass();
checkClassFile(new File(Paths.get(System.getProperty("user.dir"),
"Foo.class").toUri()), "lambda$bar$0", simpleLambdaExpectedLNT);
checkClassFile(new File(Paths.get(System.getProperty("user.dir"),
"Foo.class").toUri()), "lambda$variablesInLambdas$1", lambdaWithVarsExpectedLNT);
checkClassFile(new File(Paths.get(System.getProperty("user.dir"),
"Foo$1FooBar.class").toUri()), "run", insideLambdaWithVarsExpectedLNT);
checkClassFile(new File(Paths.get(System.getProperty("user.dir"),
"Foo.class").toUri()), "lambda$variablesInLambdas$2", lambdaVoid2VoidExpectedLNT);
checkClassFile(new File(Paths.get(System.getProperty("user.dir"),
"Foo.class").toUri()), "$deserializeLambda$", deserializeExpectedLNT);
checkClassFile(new File(Paths.get(System.getProperty("user.dir"),
"Foo.class").toUri()), "lambda$MR$variablesInLambdas$notify$8bc4f5bd$1", lambdaBridgeExpectedLNT);
"Foo.class").toUri()));
}
void compileTestClass() throws Exception {
......@@ -128,12 +77,12 @@ public class WrongLNTForLambdaTest {
ToolBox.javac(javacSuccessArgs);
}
void checkClassFile(final File cfile, String methodToFind, int[][] expectedLNT) throws Exception {
void checkClassFile(final File cfile) throws Exception {
ClassFile classFile = ClassFile.read(cfile);
boolean methodFound = false;
int methodsFound = 0;
for (Method method : classFile.methods) {
if (method.getName(classFile.constant_pool).equals(methodToFind)) {
methodFound = true;
if (method.getName(classFile.constant_pool).startsWith("lambda$")) {
++methodsFound;
Code_attribute code = (Code_attribute) method.attributes.get("Code");
LineNumberTable_attribute lnt =
(LineNumberTable_attribute) code.attributes.get("LineNumberTable");
......@@ -150,7 +99,7 @@ public class WrongLNTForLambdaTest {
}
}
}
Assert.check(methodFound, "The seek method was not found");
Assert.check(methodsFound == 1, "Expected to find one lambda method, found " + methodsFound);
}
void error(String msg) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册