-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #666 from soot-oss/fix/InvokeDynamics
fix invoke dynamics
- Loading branch information
Showing
22 changed files
with
393 additions
and
107 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import java.time.LocalDate; | ||
import java.time.Period; | ||
import java.util.stream.Stream; | ||
import java.util.stream.IntStream; | ||
|
||
/** conversion failed when there is a merge (here: after the if) and an invokedynamic followed */ | ||
class Indy{ | ||
public IntStream test(IntStream s) { | ||
int sign; | ||
if (s.isParallel()) { | ||
sign = 1; | ||
}else{ | ||
sign = -1; | ||
} | ||
return s.map(n -> n+42); | ||
} | ||
} |
Binary file not shown.
6 changes: 6 additions & 0 deletions
6
shared-test-resources/miniTestSuite/java14/source/RecordTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
record RecordTest(int a, String b) { | ||
public RecordTest(int a, String b) { | ||
this.a = a; | ||
this.b = b; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
sootup.core/src/test/java/sootup/core/jimple/common/constant/MethodHandleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package sootup.core.jimple.common.constant; | ||
|
||
import static org.junit.Assert.assertNotEquals; | ||
import static org.junit.Assert.assertThrows; | ||
|
||
import categories.Java8Test; | ||
import java.util.Collections; | ||
import junit.framework.TestCase; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import sootup.core.jimple.common.constant.MethodHandle.Kind; | ||
import sootup.core.signatures.FieldSignature; | ||
import sootup.core.signatures.MethodSignature; | ||
import sootup.core.signatures.PackageName; | ||
import sootup.core.types.ClassType; | ||
import sootup.core.types.PrimitiveType.IntType; | ||
import sootup.core.types.VoidType; | ||
|
||
@Category(Java8Test.class) | ||
public class MethodHandleTest extends TestCase { | ||
|
||
@Test | ||
public void testMethodHandle() { | ||
assertEquals(Kind.REF_GET_FIELD.toString(), "REF_GET_FIELD"); | ||
assertEquals(Kind.REF_GET_FIELD.getValueName(), "REF_GET_FIELD"); | ||
assertEquals(Kind.REF_GET_FIELD.getValue(), 1); | ||
|
||
for (Kind currentKind : Kind.values()) { | ||
assertEquals(currentKind, Kind.getKind(currentKind.getValueName())); | ||
assertEquals(currentKind, Kind.getKind(currentKind.getValue())); | ||
} | ||
// not valid kinds | ||
assertThrows(RuntimeException.class, () -> Kind.getKind(0)); | ||
assertThrows(RuntimeException.class, () -> Kind.getKind("invalid")); | ||
|
||
assertTrue(MethodHandle.isMethodRef(Kind.REF_INVOKE_VIRTUAL.getValue())); | ||
assertTrue(MethodHandle.isMethodRef(Kind.REF_INVOKE_STATIC.getValue())); | ||
assertTrue(MethodHandle.isMethodRef(Kind.REF_INVOKE_SPECIAL.getValue())); | ||
assertTrue(MethodHandle.isMethodRef(Kind.REF_INVOKE_CONSTRUCTOR.getValue())); | ||
assertTrue(MethodHandle.isMethodRef(Kind.REF_INVOKE_INTERFACE.getValue())); | ||
assertFalse(MethodHandle.isMethodRef(Kind.REF_GET_FIELD.getValue())); | ||
assertFalse(MethodHandle.isMethodRef(Kind.REF_PUT_FIELD.getValue())); | ||
assertFalse(MethodHandle.isMethodRef(Kind.REF_PUT_FIELD_STATIC.getValue())); | ||
assertFalse(MethodHandle.isMethodRef(Kind.REF_GET_FIELD_STATIC.getValue())); | ||
|
||
assertFalse(MethodHandle.isFieldRef(Kind.REF_INVOKE_VIRTUAL.getValue())); | ||
assertFalse(MethodHandle.isFieldRef(Kind.REF_INVOKE_STATIC.getValue())); | ||
assertFalse(MethodHandle.isFieldRef(Kind.REF_INVOKE_SPECIAL.getValue())); | ||
assertFalse(MethodHandle.isFieldRef(Kind.REF_INVOKE_CONSTRUCTOR.getValue())); | ||
assertFalse(MethodHandle.isFieldRef(Kind.REF_INVOKE_INTERFACE.getValue())); | ||
assertTrue(MethodHandle.isFieldRef(Kind.REF_GET_FIELD.getValue())); | ||
assertTrue(MethodHandle.isFieldRef(Kind.REF_PUT_FIELD.getValue())); | ||
assertTrue(MethodHandle.isFieldRef(Kind.REF_PUT_FIELD_STATIC.getValue())); | ||
assertTrue(MethodHandle.isFieldRef(Kind.REF_GET_FIELD_STATIC.getValue())); | ||
|
||
ClassType classType = | ||
new ClassType() { | ||
@Override | ||
public boolean isBuiltInClass() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public String getFullyQualifiedName() { | ||
return "test.A"; | ||
} | ||
|
||
@Override | ||
public String getClassName() { | ||
return "A"; | ||
} | ||
|
||
@Override | ||
public PackageName getPackageName() { | ||
return new PackageName("test"); | ||
} | ||
}; | ||
MethodSignature ms = | ||
new MethodSignature(classType, "m1", Collections.emptyList(), VoidType.getInstance()); | ||
FieldSignature fs = new FieldSignature(classType, "f", IntType.getInstance()); | ||
|
||
MethodHandle mhms = new MethodHandle(ms, Kind.REF_INVOKE_VIRTUAL.getValue(), classType); | ||
MethodHandle mhfs = new MethodHandle(fs, Kind.REF_GET_FIELD, classType); | ||
|
||
// not valid Method handles | ||
assertThrows( | ||
IllegalArgumentException.class, | ||
() -> new MethodHandle(fs, Kind.REF_INVOKE_CONSTRUCTOR, classType)); | ||
assertThrows( | ||
IllegalArgumentException.class, () -> new MethodHandle(ms, Kind.REF_GET_FIELD, classType)); | ||
|
||
assertTrue(mhms.isMethodRef()); | ||
assertFalse(mhms.isFieldRef()); | ||
|
||
assertFalse(mhfs.isMethodRef()); | ||
assertTrue(mhfs.isFieldRef()); | ||
|
||
assertEquals(mhfs.getType(), classType); | ||
assertEquals( | ||
mhfs.toString(), | ||
"methodhandle: \"" + mhfs.getKind() + "\" " + mhfs.getReferenceSignature()); | ||
|
||
MethodHandle mhms2 = new MethodHandle(ms, Kind.REF_INVOKE_VIRTUAL.getValue(), classType); | ||
assertTrue(mhfs.equals(mhfs)); | ||
assertFalse(mhfs.equals(mhms)); | ||
assertFalse(mhfs.equals(null)); | ||
assertFalse(mhfs.equals(classType)); | ||
assertFalse(mhfs.equals(mhms2)); | ||
|
||
assertEquals(mhfs.hashCode(), mhfs.hashCode()); | ||
assertEquals(mhms.hashCode(), mhms2.hashCode()); | ||
assertNotEquals(mhfs.hashCode(), mhms.hashCode()); | ||
} | ||
} |
Oops, something went wrong.