Skip to content

Workaround: run concrete execution for invokedynamic #423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 5, 2022

Conversation

dtim
Copy link
Collaborator

@dtim dtim commented Jul 5, 2022

Description

This PR adds a fake implementation of invokedynamic opcode: symbolic engine just initiates concrete execution for the branch.

This is a temporary solution to make operator + on Strings work on JDK 11.

Fixes #388

Type of Change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Automated Testing

Unit tests for utbot-framework should not fail (on JDK 1.8) because this commit implements the function that previously was just throwing an exception. Actually no existing tests should depend on the behavior of the new function.

Manual Scenario

Tests can now be generated for the following methods on JDK 11:

public class Concatenation {
    public String concatWithConstant(@NotNull String text) {
        return "prefix:" + text;
    }

    public String concatTwoStrings(@NotNull String a, @NotNull String b) {
        return a + b;
    }
}

Expected (with fuzzing turned off):

    @Test
    public void testConcatWithConstant() {
        Concatenation concatenation = new Concatenation();
        String string = "";

        String actual = concatenation.concatWithConstant(string);

        String expected = "prefix:";

        assertEquals(expected, actual);
    }

    @Test
    public void testConcatTwoStrings() {
        Concatenation concatenation = new Concatenation();
        String string = "";

        String actual = concatenation.concatTwoStrings(string, string);

        String expected = "";

        assertEquals(expected, actual);
    }

Before this PR no tests could be generated:

 public void testConcatWithConstant_errors() {
        // Couldn't generate some tests. List of errors:
        // 
        // 1 occurrences of:
        /* An operation is not implemented: dynamicinvoke "makeConcatWithConstants" <java.lang.String (java.lang.String)>(r0) <java.lang.invoke.StringConcatFactory:
        java.lang.invoke.CallSite makeConcatWithConstants(java.lang.invoke.MethodHandles$Lookup,java.lang.String,java.lang.invoke.MethodType,java.lang.String,java.lang.Object[])>("prefix:\u0001") */

    }
    
public void testConcatTwoStrings_errors() {
        // Couldn't generate some tests. List of errors:
        // 
        // 1 occurrences of:
        /* An operation is not implemented: dynamicinvoke "makeConcatWithConstants" <java.lang.String (java.lang.String,java.lang.String)>(r0, r1)
        <java.lang.invoke.StringConcatFactory: java.lang.invoke.CallSite makeConcatWithConstants(java.lang.invoke.MethodHandles$Lookup,java.lang.String,java.lang.invoke.MethodType,java.lang.String,java.lang.Object[])>("\u0001\u0001") */

    }

Checklist (remove irrelevant options):

  • The change followed the style guidelines of the UTBot project
  • Self-review of the code is passed
  • The change contains enough commentaries, particularly in hard-to-understand areas
  • All tests pass locally with my changes

@dtim dtim requested a review from CaelmBleidd July 5, 2022 15:01
@dtim dtim enabled auto-merge (squash) July 5, 2022 15:02
@dtim dtim disabled auto-merge July 5, 2022 15:27
@dtim dtim enabled auto-merge (rebase) July 5, 2022 15:28
@dtim dtim merged commit 1d48789 into main Jul 5, 2022
@dtim dtim deleted the dtim/388-invokedynamic-concrete-execution branch July 5, 2022 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

String concatenation: dynamicinvoke is not implemented - JDK 11
2 participants