| // Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| package com.android.tools.r8.ir.code; |
| |
| import com.android.tools.r8.graph.AppView; |
| import com.android.tools.r8.graph.DexEncodedMethod; |
| import com.android.tools.r8.graph.DexMethod; |
| import com.android.tools.r8.graph.DexType; |
| import com.android.tools.r8.ir.analysis.ClassInitializationAnalysis; |
| import com.android.tools.r8.ir.analysis.type.ClassTypeLatticeElement; |
| import com.android.tools.r8.ir.analysis.type.TypeAnalysis; |
| import com.android.tools.r8.ir.analysis.type.TypeLatticeElement; |
| import com.android.tools.r8.ir.optimize.DefaultInliningOracle; |
| import com.android.tools.r8.ir.optimize.Inliner.InlineAction; |
| import com.android.tools.r8.ir.optimize.Inliner.Reason; |
| import com.android.tools.r8.ir.optimize.inliner.WhyAreYouNotInliningReporter; |
| import com.android.tools.r8.shaking.AppInfoWithLiveness; |
| import java.util.List; |
| |
| public abstract class InvokeMethodWithReceiver extends InvokeMethod { |
| |
| InvokeMethodWithReceiver(DexMethod target, Value result, List<Value> arguments) { |
| super(target, result, arguments); |
| } |
| |
| @Override |
| public boolean isInvokeMethodWithReceiver() { |
| return true; |
| } |
| |
| @Override |
| public InvokeMethodWithReceiver asInvokeMethodWithReceiver() { |
| return this; |
| } |
| |
| public Value getReceiver() { |
| assert inValues.size() > 0; |
| return inValues.get(0); |
| } |
| |
| @Override |
| public final InlineAction computeInlining( |
| DexEncodedMethod singleTarget, |
| Reason reason, |
| DefaultInliningOracle decider, |
| ClassInitializationAnalysis classInitializationAnalysis, |
| WhyAreYouNotInliningReporter whyAreYouNotInliningReporter) { |
| return decider.computeForInvokeWithReceiver( |
| this, singleTarget, reason, whyAreYouNotInliningReporter); |
| } |
| |
| @Override |
| public boolean throwsNpeIfValueIsNull(Value value, AppView<?> appView, DexType context) { |
| return value == getReceiver() || super.throwsNpeIfValueIsNull(value, appView, context); |
| } |
| |
| @Override |
| public boolean throwsOnNullInput() { |
| return true; |
| } |
| |
| @Override |
| public Value getNonNullInput() { |
| return getReceiver(); |
| } |
| |
| @Override |
| public boolean verifyTypes(AppView<?> appView) { |
| assert super.verifyTypes(appView); |
| |
| Value receiver = getReceiver(); |
| TypeLatticeElement receiverType = receiver.getTypeLattice(); |
| assert receiverType.isPreciseType(); |
| |
| if (appView.appInfo().hasLiveness()) { |
| AppView<AppInfoWithLiveness> appViewWithLiveness = appView.withLiveness(); |
| ClassTypeLatticeElement receiverLowerBoundType = |
| receiver.getDynamicLowerBoundType(appViewWithLiveness); |
| if (receiverLowerBoundType != null) { |
| DexType refinedReceiverType = |
| TypeAnalysis.getRefinedReceiverType(appViewWithLiveness, this); |
| assert receiverLowerBoundType.getClassType() == refinedReceiverType |
| || receiverLowerBoundType.isBasedOnMissingClass(appViewWithLiveness) |
| : "The receiver lower bound does not match the receiver type"; |
| } |
| } |
| |
| return true; |
| } |
| } |