Skip to content

Commit

Permalink
Ignore signature-polymorphic VarHandle invocations in `ImportDepsCh…
Browse files Browse the repository at this point in the history
…ecker`.

Compare unknown commit.

PiperOrigin-RevId: 705983301
Change-Id: Ifb86253dcfde7b4c7ff1f345840c3eba7ad0f7f0
  • Loading branch information
cpovirk authored and copybara-github committed Dec 13, 2024
1 parent 42be307 commit 499d5ee
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public void visitFieldInsn(int opcode, String owner, String name, String desc) {

@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
if (!isMethodHandle(opcode, owner, name)) {
if (!isMethodHandle(opcode, owner, name) && !isVarHandle(opcode, owner, name)) {
checkMember(owner, name, desc);
}
super.visitMethodInsn(opcode, owner, name, desc, itf);
Expand All @@ -363,6 +363,52 @@ private boolean isMethodHandle(int opcode, String owner, String name) {
return true;
}

private boolean isVarHandle(int opcode, String owner, String name) {
if (opcode != Opcodes.INVOKEVIRTUAL) {
return false;
}
if (!owner.equals("java/lang/invoke/VarHandle")) {
return false;
}
switch (name) {
case "compareAndExchange":
case "compareAndExchangeAcquire":
case "compareAndExchangeRelease":
case "compareAndSet":
case "get":
case "getAcquire":
case "getAndAdd":
case "getAndAddAcquire":
case "getAndAddRelease":
case "getAndBitwiseAnd":
case "getAndBitwiseAndAcquire":
case "getAndBitwiseAndRelease":
case "getAndBitwiseOr":
case "getAndBitwiseOrAcquire":
case "getAndBitwiseOrRelease":
case "getAndBitwiseXor":
case "getAndBitwiseXorAcquire":
case "getAndBitwiseXorRelease":
case "getAndSet":
case "getAndSetAcquire":
case "getAndSetRelease":
case "getOpaque":
case "getVolatile":
case "set":
case "setOpaque":
case "setRelease":
case "setVolatile":
case "weakCompareAndSet":
case "weakCompareAndSetAcquire":
case "weakCompareAndSetPlain":
case "weakCompareAndSetRelease":
break;
default:
return false;
}
return true;
}

@Override
public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, Object... bsmArgs) {
checkDescriptor(desc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
package com.google.devtools.build.importdeps.testdata;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.VarHandle;

public class InvokePolymorphic {
void f(MethodHandle mh) throws Throwable {
void f(MethodHandle mh, VarHandle vh) throws Throwable {
mh.invoke(true, "hello", 42);
vh.setRelease("foo", 1);
}
}

0 comments on commit 499d5ee

Please sign in to comment.