`OP_INVOKEDYNAMIC` is not be handled correctly in `CallResolver`
See original GitHub issueI’m using CallResolver
to make a call graph for CPA algorithm.
My Java source code:
List<String> names = new ArrayList();
names.add(request.getParameter("as"));
names.forEach(System.out::println);
Compiled bytecodes:
200: getstatic #214 // Field java/lang/System.out:Ljava/io/PrintStream;
203: dup
204: invokevirtual #220 // Method java/lang/Object.getClass:()Ljava/lang/Class;
207: pop
208: invokedynamic #229, 0 // InvokeDynamic #0:accept:(Ljava/io/PrintStream;)Ljava/util/function/Consumer;
213: invokeinterface #230, 2 // InterfaceMethod java/util/List.forEach:(Ljava/util/function/Consumer;)V
When CallResolver
run into line 208, it is handled in handleInvokeDynamic
as follows:
private void handleInvokeDynamic(CodeLocation location, InvokeDynamicConstant constant)
{
if (lambdaExpressionMap.containsKey(constant))
{
LambdaExpression target = lambdaExpressionMap.get(constant);
addCall(location,
target.invokedClassName,
target.invokedMethodName,
target.invokedMethodDesc,
Value.NEVER,
Instruction.OP_INVOKEDYNAMIC,
false
);
}
else
{
log.debug("invokedynamic without matching lambda expression at {}", location);
}
}
Notice that it using the target method and class info to create a call node instead of bootstrap method (factoryMethodDescriptor
).
In my case:
And the problem is, when we taking this wrong call node to transfer state in CPA algorithm,
since the target invokedMethod returned the type V
, so no callSite
will be pushed in the frame. (makes the stack unbalanced)
Finally when arriving to JvmTransferRelation:processCall
operands.add(state.pop());
will pop from a null operands, so get CPA run stopped for the following error: null
…
Issue Analytics
- State:
- Created a year ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Understanding Java method invocation with invokedynamic
The invokedynamic instruction added in Java 7 makes it possible to resolve method calls dynamically at runtime.
Read more >How can I invoke a virtual method handle using ByteBuddy's ...
I've found the InvokeDynamic class and have made it work with a static method handle acquired via MethodHandles.Lookup.findStatic() . Now I am ...
Read more >Deep Static Modeling of invokedynamic - Yannis Smaragdakis
The call site is a Java object, so the program can access it and can later mutate its method handle so that the...
Read more >Java 7: A complete invokedynamic example - 2022
I am using ASM here, an all purpose Java bytecode manipulation and analysis framework, to do the job of creating a correct class...
Read more >Deep Static Modeling of invokedynamic - arXiv
The call site is a Java object, so the program can access it and can later mutate its method handle so that the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I see. For the time being, we use the CFA for modeling control flow information in CPA, which can be constructed e.g. with this utility method. But semantically it is equivalent to general control flow information, so you could theoretically also create the CFA inside your
PartialEvaluator
execution.Yes, I’m using
PartialEvaluator
not only for collecting particular values, but collecting control flow information in the meantime. So I prefer to reuse it in CPA.