blob: 585699f6abaed115b205146d63af7942e20cf438 [file] [log] [blame]
// Copyright (c) 2020, 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.optimize.info.bridge;
import com.android.tools.r8.graph.DexMethod;
/**
* Optimization info computed for bridge methods that use an invoke-virtual instruction.
*
* <p>If the method is {@code String A.m(Object)} and {@link #invokedMethod} is {@code Object
* B.m(String)}, then the bridge is implemented as:
*
* <pre>
* java.lang.String A.m(java.lang.Object o) {
* v0 <- Argument
* v1 <- CheckCast v0, java.lang.String
* v2 <- InvokeVirtual { v0, v1 }, java.lang.Object B.m(java.lang.String)
* v3 <- CheckCast v2, java.lang.String
* Return v3
* }
* </pre>
*
* <p>This currently does not allow any permutation of the argument order, and it also does not
* allow constants to be passed as arguments.
*/
public class VirtualBridgeInfo extends BridgeInfo {
// The targeted method.
private final DexMethod invokedMethod;
public VirtualBridgeInfo(DexMethod invokedMethod) {
this.invokedMethod = invokedMethod;
}
public DexMethod getInvokedMethod() {
return invokedMethod;
}
@Override
public boolean hasSameTarget(BridgeInfo bridgeInfo) {
assert bridgeInfo.isVirtualBridgeInfo();
VirtualBridgeInfo virtualBridgeInfo = bridgeInfo.asVirtualBridgeInfo();
return invokedMethod.match(virtualBridgeInfo.invokedMethod);
}
@Override
public boolean isVirtualBridgeInfo() {
return true;
}
@Override
public VirtualBridgeInfo asVirtualBridgeInfo() {
return this;
}
}