8187962: Optimistic types ignore JavaAdapter return types

Reviewed-by: sundar, attila
This commit is contained in:
Hannes Wallnöfer 2017-09-27 14:56:19 +02:00
parent 26f4eca08c
commit 047f60b678
5 changed files with 59 additions and 2 deletions

View file

@ -273,7 +273,8 @@ abstract class CompilationPhase {
private static final class LocalVariableTypeCalculationPhase extends CompilationPhase {
@Override
FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) {
final FunctionNode newFunctionNode = transformFunction(fn, new LocalVariableTypesCalculator(compiler));
final FunctionNode newFunctionNode = transformFunction(fn, new LocalVariableTypesCalculator(compiler,
compiler.getReturnType()));
final ScriptEnvironment senv = compiler.getScriptEnvironment();
final PrintWriter err = senv.getErr();

View file

@ -619,6 +619,10 @@ public final class Compiler implements Loggable {
return types == null ? null : types.get(fn, pos);
}
Type getReturnType() {
return types == null || !isOnDemandCompilation() ? Type.UNKNOWN : types.getReturnType();
}
/**
* Do a compilation job
*

View file

@ -405,10 +405,15 @@ final class LocalVariableTypesCalculator extends SimpleNodeVisitor {
// variables).
private final Deque<Label> catchLabels = new ArrayDeque<>();
LocalVariableTypesCalculator(final Compiler compiler) {
private LocalVariableTypesCalculator(final Compiler compiler) {
this.compiler = compiler;
}
LocalVariableTypesCalculator(final Compiler compiler, final Type returnType) {
this(compiler);
this.returnType = returnType;
}
private JumpTarget createJumpTarget(final Label label) {
assert !jumpTargets.containsKey(label);
final JumpTarget jumpTarget = new JumpTarget();

View file

@ -117,6 +117,15 @@ public final class TypeMap {
return null;
}
/**
* Get the return type required for the call site we're compiling for. This only determines
* whether object return type is required or not.
* @return Type.OBJECT for call sites with object return types, Type.UNKNOWN for everything else
*/
Type getReturnType() {
return returnType.isObject() ? Type.OBJECT : Type.UNKNOWN;
}
@Override
public String toString() {
return toString("");