From 79aaadfe83c57ae942333a3978f4bc29b04518a5 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Tue, 24 Oct 2023 12:07:16 +0200 Subject: [PATCH 1/7] draft of testinput: signatures do not find sth --- .../java/bytecode/bugs/Issue714Test.java | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 sootup.java.bytecode/src/test/java/sootup/java/bytecode/bugs/Issue714Test.java diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/bugs/Issue714Test.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/bugs/Issue714Test.java new file mode 100644 index 00000000000..cd86082d1ad --- /dev/null +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/bugs/Issue714Test.java @@ -0,0 +1,122 @@ +package sootup.java.bytecode.bugs; + +import categories.Java9Test; +import java.util.Collections; +import java.util.Optional; +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import sootup.core.graph.StmtGraph; +import sootup.core.model.SootMethod; +import sootup.core.signatures.MethodSignature; +import sootup.core.util.DotExporter; +import sootup.java.bytecode.inputlocation.BytecodeClassLoadingOptions; +import sootup.java.bytecode.inputlocation.JrtFileSystemAnalysisInputLocation; +import sootup.java.core.JavaProject; +import sootup.java.core.JavaSootClass; +import sootup.java.core.language.JavaLanguage; +import sootup.java.core.views.JavaView; + +@Category(Java9Test.class) +public class Issue714Test { + + @Test + public void slow_localSplitter() { + // "jdk.internal.jimage.ImageStringsReader :: mutf8FromString will cause LocalSplitter not halt + // / comsume unreasonable time" + JavaProject applicationProject = + JavaProject.builder(new JavaLanguage(8)) + .enableModules() + .addInputLocation(new JrtFileSystemAnalysisInputLocation()) + .build(); + + JavaView view = applicationProject.createMutableView(); + view.configBodyInterceptors(analysisInputLocation -> BytecodeClassLoadingOptions.Default); + + final MethodSignature methodSignature = + view.getIdentifierFactory() + .parseMethodSignature( + ""); + final Optional classOpt = view.getClass(methodSignature.getDeclClassType()); + Assert.assertTrue(classOpt.isPresent()); + + final Optional methodOpt = view.getMethod(methodSignature); + Assert.assertTrue(methodOpt.isPresent()); + + final StmtGraph stmtGraph = methodOpt.get().getBody().getStmtGraph(); + + System.out.println(DotExporter.createUrlToWebeditor(stmtGraph)); + System.out.println(stmtGraph); + } + + @Test + public void slow_TypeAssigner() { + // java.lang.Character$UnicodeScript :: will cause TypeAssigner not halt / comsume + // unreasonable time. It seems that the real problem occurs in the LocalNameStandardizer. + + JavaProject applicationProject = + JavaProject.builder(new JavaLanguage(11)) + .enableModules() + .addInputLocation(new JrtFileSystemAnalysisInputLocation()) + .build(); + + JavaView view = applicationProject.createMutableView(); + view.configBodyInterceptors(analysisInputLocation -> BytecodeClassLoadingOptions.Default); + + // https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Character.UnicodeScript.html + final MethodSignature methodSignature = + view.getIdentifierFactory() + .getMethodSignature( + "java.base/java.lang.Character$UnicodeScript", + "", + "void", + Collections.singletonList("")); + final Optional classOpt = view.getClass(methodSignature.getDeclClassType()); + Assert.assertTrue(classOpt.isPresent()); + + final Optional methodOpt = view.getMethod(methodSignature); + Assert.assertTrue(methodOpt.isPresent()); + + final StmtGraph stmtGraph = methodOpt.get().getBody().getStmtGraph(); + + System.out.println(DotExporter.createUrlToWebeditor(stmtGraph)); + System.out.println(stmtGraph); + } + + @Test + public void bloated_AsmMethodSource_worklist() { + // sun.jvm.hotspot.ui.classbrowser.HTMLGenerator :: genHTMLListForFields, with desc + // (Lsun/jvm/hotspot/oops/InstanceKlass;)Ljava/lang/String;, will cause AsmMethodSource :: + // convert not halt / comsume unreasonable time. It worth noting that the worklist will be full + // of elements, even through the length of instructions list is just 172. Please refer to the + // attached screenshot for more details. + + JavaProject applicationProject = + JavaProject.builder(new JavaLanguage(11)) + .enableModules() + .addInputLocation(new JrtFileSystemAnalysisInputLocation()) + .build(); + + JavaView view = applicationProject.createMutableView(); + view.configBodyInterceptors(analysisInputLocation -> BytecodeClassLoadingOptions.Default); + + // https://code.yawk.at/java/11/jdk.hotspot.agent/sun/jvm/hotspot/ui/classbrowser/HTMLGenerator.java#sun.jvm.hotspot.ui.classbrowser.HTMLGenerator%23genHTMLListForFields(sun.jvm.hotspot.oops.InstanceKlass) + final MethodSignature methodSignature = + view.getIdentifierFactory() + .getMethodSignature( + "jdk.hotspot.agent/sun.jvm.hotspot.ui.classbrowser.HTMLGenerator", + "genHTMLListForFields", + "java.lang.String", + Collections.singletonList("jdk.hotspot.agent/sun.jvm.hotspot.oops.InstanceKlass")); + final Optional classOpt = view.getClass(methodSignature.getDeclClassType()); + Assert.assertTrue(classOpt.isPresent()); + + final Optional methodOpt = view.getMethod(methodSignature); + Assert.assertTrue(methodOpt.isPresent()); + + final StmtGraph stmtGraph = methodOpt.get().getBody().getStmtGraph(); + + System.out.println(DotExporter.createUrlToWebeditor(stmtGraph)); + System.out.println(stmtGraph); + } +} From a024f72a2bb4578ccac8b1b400dd9bb129b7489b Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 26 Oct 2023 11:35:37 +0200 Subject: [PATCH 2/7] progress --- .../java/bytecode/bugs/Issue714Test.java | 19 +++++++++++-------- .../java/sootup/java/core/views/JavaView.java | 6 +----- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/bugs/Issue714Test.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/bugs/Issue714Test.java index cd86082d1ad..94a6d81bfde 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/bugs/Issue714Test.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/bugs/Issue714Test.java @@ -25,7 +25,7 @@ public void slow_localSplitter() { // "jdk.internal.jimage.ImageStringsReader :: mutf8FromString will cause LocalSplitter not halt // / comsume unreasonable time" JavaProject applicationProject = - JavaProject.builder(new JavaLanguage(8)) + JavaProject.builder(new JavaLanguage(9)) .enableModules() .addInputLocation(new JrtFileSystemAnalysisInputLocation()) .build(); @@ -36,9 +36,9 @@ public void slow_localSplitter() { final MethodSignature methodSignature = view.getIdentifierFactory() .parseMethodSignature( - ""); + ""); final Optional classOpt = view.getClass(methodSignature.getDeclClassType()); - Assert.assertTrue(classOpt.isPresent()); + Assert.assertTrue(methodSignature.getDeclClassType() + " not found", classOpt.isPresent()); final Optional methodOpt = view.getMethod(methodSignature); Assert.assertTrue(methodOpt.isPresent()); @@ -67,12 +67,12 @@ public void slow_TypeAssigner() { final MethodSignature methodSignature = view.getIdentifierFactory() .getMethodSignature( - "java.base/java.lang.Character$UnicodeScript", "", + "java.base/java.lang.Character$UnicodeScript", "void", - Collections.singletonList("")); + Collections.emptyList()); final Optional classOpt = view.getClass(methodSignature.getDeclClassType()); - Assert.assertTrue(classOpt.isPresent()); + Assert.assertTrue(methodSignature.getDeclClassType() + " not found", classOpt.isPresent()); final Optional methodOpt = view.getMethod(methodSignature); Assert.assertTrue(methodOpt.isPresent()); @@ -104,12 +104,15 @@ public void bloated_AsmMethodSource_worklist() { final MethodSignature methodSignature = view.getIdentifierFactory() .getMethodSignature( - "jdk.hotspot.agent/sun.jvm.hotspot.ui.classbrowser.HTMLGenerator", "genHTMLListForFields", + "jdk.hotspot.agent/sun.jvm.hotspot.ui.classbrowser.HTMLGenerator", "java.lang.String", Collections.singletonList("jdk.hotspot.agent/sun.jvm.hotspot.oops.InstanceKlass")); + + view.getClasses().forEach(System.out::println); + final Optional classOpt = view.getClass(methodSignature.getDeclClassType()); - Assert.assertTrue(classOpt.isPresent()); + Assert.assertTrue(methodSignature.getDeclClassType() + " not found", classOpt.isPresent()); final Optional methodOpt = view.getMethod(methodSignature); Assert.assertTrue(methodOpt.isPresent()); diff --git a/sootup.java.core/src/main/java/sootup/java/core/views/JavaView.java b/sootup.java.core/src/main/java/sootup/java/core/views/JavaView.java index f891055ad5f..6547889970b 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/views/JavaView.java +++ b/sootup.java.core/src/main/java/sootup/java/core/views/JavaView.java @@ -179,14 +179,10 @@ protected synchronized Collection resolveAll() { return cache.getClasses(); } - Collection> resolvedClassesOpts = + Collection resolvedClasses = getProject().getInputLocations().stream() .flatMap(location -> location.getClassSources(this).stream()) .map(this::buildClassFrom) - .collect(Collectors.toList()); - - Collection resolvedClasses = - resolvedClassesOpts.stream() .filter(Optional::isPresent) .map(Optional::get) .collect(Collectors.toList()); From b5aa7009cb4e98042c8d89abe8a0c89e0903a7f3 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Thu, 26 Oct 2023 15:35:38 +0200 Subject: [PATCH 3/7] throw unsupportedException - see #723; and dont use a MutableView here --- .../java/sootup/java/bytecode/bugs/Issue714Test.java | 9 ++++++--- .../main/java/sootup/java/core/JavaModuleProject.java | 6 ++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/bugs/Issue714Test.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/bugs/Issue714Test.java index 6e31f2968ac..a5257ee287c 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/bugs/Issue714Test.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/bugs/Issue714Test.java @@ -14,6 +14,7 @@ import sootup.java.bytecode.inputlocation.JrtFileSystemAnalysisInputLocation; import sootup.java.core.JavaProject; import sootup.java.core.JavaSootClass; +import sootup.java.core.JavaSootMethod; import sootup.java.core.language.JavaLanguage; import sootup.java.core.views.JavaView; @@ -97,7 +98,7 @@ public void bloated_AsmMethodSource_worklist() { .addInputLocation(new JrtFileSystemAnalysisInputLocation()) .build(); - JavaView view = applicationProject.createMutableView(); + JavaView view = applicationProject.createView(); view.configBodyInterceptors(analysisInputLocation -> BytecodeClassLoadingOptions.Default); // https://code.yawk.at/java/11/jdk.hotspot.agent/sun/jvm/hotspot/ui/classbrowser/HTMLGenerator.java#sun.jvm.hotspot.ui.classbrowser.HTMLGenerator%23genHTMLListForFields(sun.jvm.hotspot.oops.InstanceKlass) @@ -109,11 +110,13 @@ public void bloated_AsmMethodSource_worklist() { "java.lang.String", Collections.singletonList("jdk.hotspot.agent/sun.jvm.hotspot.oops.InstanceKlass")); - view.getClasses().forEach(System.out::println); - final Optional classOpt = view.getClass(methodSignature.getDeclClassType()); Assert.assertTrue(methodSignature.getDeclClassType() + " not found", classOpt.isPresent()); + for (JavaSootMethod javaSootMethod : classOpt.get().getMethods()) { + System.out.println(javaSootMethod); + } + final Optional methodOpt = view.getMethod(methodSignature); Assert.assertTrue(methodOpt.isPresent()); diff --git a/sootup.java.core/src/main/java/sootup/java/core/JavaModuleProject.java b/sootup.java.core/src/main/java/sootup/java/core/JavaModuleProject.java index b840df6125f..031bf3e3cb0 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/JavaModuleProject.java +++ b/sootup.java.core/src/main/java/sootup/java/core/JavaModuleProject.java @@ -8,6 +8,7 @@ import sootup.core.inputlocation.ClassLoadingOptions; import sootup.java.core.language.JavaLanguage; import sootup.java.core.views.JavaModuleView; +import sootup.java.core.views.MutableJavaView; public class JavaModuleProject extends JavaProject { @@ -61,6 +62,11 @@ public JavaModuleView createOnDemandView() { return new JavaModuleView(this); } + @Nonnull + public MutableJavaView createMutableView() { + throw new UnsupportedOperationException("Implement me!"); + } + @Deprecated @Nonnull public JavaModuleView configBodyInterceptors( From 51b6e4c03de000730799f5459ffea7b36ef3969d Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Tue, 31 Oct 2023 12:07:51 +0100 Subject: [PATCH 4/7] return more specific type --- .../java/sootup/core/jimple/common/expr/JNewMultiArrayExpr.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sootup.core/src/main/java/sootup/core/jimple/common/expr/JNewMultiArrayExpr.java b/sootup.core/src/main/java/sootup/core/jimple/common/expr/JNewMultiArrayExpr.java index 1be30ab14ce..acbea747fe9 100644 --- a/sootup.core/src/main/java/sootup/core/jimple/common/expr/JNewMultiArrayExpr.java +++ b/sootup.core/src/main/java/sootup/core/jimple/common/expr/JNewMultiArrayExpr.java @@ -106,7 +106,7 @@ public ArrayType getBaseType() { return baseType; } - public Value getSize(@Nonnull int index) { + public Immediate getSize(@Nonnull int index) { return sizes.get(index); } From 56fbd0f712bb7998f7ffcd9dd1852ad23fd2c1a2 Mon Sep 17 00:00:00 2001 From: "M.Schmidt" Date: Tue, 20 Feb 2024 11:11:46 +0100 Subject: [PATCH 5/7] adapt test to changes --- .../java/bytecode/bugs/Issue714Test.java | 41 +++++++------------ 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/bugs/Issue714Test.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/bugs/Issue714Test.java index a5257ee287c..49102d485ef 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/bugs/Issue714Test.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/bugs/Issue714Test.java @@ -10,12 +10,10 @@ import sootup.core.model.SootMethod; import sootup.core.signatures.MethodSignature; import sootup.core.util.DotExporter; -import sootup.java.bytecode.inputlocation.BytecodeClassLoadingOptions; import sootup.java.bytecode.inputlocation.JrtFileSystemAnalysisInputLocation; -import sootup.java.core.JavaProject; import sootup.java.core.JavaSootClass; import sootup.java.core.JavaSootMethod; -import sootup.java.core.language.JavaLanguage; +import sootup.java.core.views.JavaModuleView; import sootup.java.core.views.JavaView; @Category(Java9Test.class) @@ -25,14 +23,11 @@ public class Issue714Test { public void slow_localSplitter() { // "jdk.internal.jimage.ImageStringsReader :: mutf8FromString will cause LocalSplitter not halt // / comsume unreasonable time" - JavaProject applicationProject = - JavaProject.builder(new JavaLanguage(9)) - .enableModules() - .addInputLocation(new JrtFileSystemAnalysisInputLocation()) - .build(); - JavaView view = applicationProject.createMutableView(); - view.configBodyInterceptors(analysisInputLocation -> BytecodeClassLoadingOptions.Default); + JavaView view = + new JavaModuleView( + Collections.emptyList(), + Collections.singletonList(new JrtFileSystemAnalysisInputLocation())); final MethodSignature methodSignature = view.getIdentifierFactory() @@ -52,17 +47,15 @@ public void slow_localSplitter() { @Test public void slow_TypeAssigner() { + // 6s not fast but sounds reasonable.. + // java.lang.Character$UnicodeScript :: will cause TypeAssigner not halt / comsume // unreasonable time. It seems that the real problem occurs in the LocalNameStandardizer. - JavaProject applicationProject = - JavaProject.builder(new JavaLanguage(11)) - .enableModules() - .addInputLocation(new JrtFileSystemAnalysisInputLocation()) - .build(); - - JavaView view = applicationProject.createMutableView(); - view.configBodyInterceptors(analysisInputLocation -> BytecodeClassLoadingOptions.Default); + JavaView view = + new JavaModuleView( + Collections.emptyList(), + Collections.singletonList(new JrtFileSystemAnalysisInputLocation())); // https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Character.UnicodeScript.html final MethodSignature methodSignature = @@ -92,14 +85,10 @@ public void bloated_AsmMethodSource_worklist() { // of elements, even through the length of instructions list is just 172. Please refer to the // attached screenshot for more details. - JavaProject applicationProject = - JavaProject.builder(new JavaLanguage(11)) - .enableModules() - .addInputLocation(new JrtFileSystemAnalysisInputLocation()) - .build(); - - JavaView view = applicationProject.createView(); - view.configBodyInterceptors(analysisInputLocation -> BytecodeClassLoadingOptions.Default); + JavaView view = + new JavaModuleView( + Collections.emptyList(), + Collections.singletonList(new JrtFileSystemAnalysisInputLocation())); // https://code.yawk.at/java/11/jdk.hotspot.agent/sun/jvm/hotspot/ui/classbrowser/HTMLGenerator.java#sun.jvm.hotspot.ui.classbrowser.HTMLGenerator%23genHTMLListForFields(sun.jvm.hotspot.oops.InstanceKlass) final MethodSignature methodSignature = From a3c9999654862660fb4f8b7e3fa2b845fc63ab7a Mon Sep 17 00:00:00 2001 From: "M.Schmidt" Date: Wed, 21 Feb 2024 12:31:07 +0100 Subject: [PATCH 6/7] fix MethodSubSignature.equals() - compare name and return type as well --- .../main/java/sootup/core/signatures/MethodSubSignature.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sootup.core/src/main/java/sootup/core/signatures/MethodSubSignature.java b/sootup.core/src/main/java/sootup/core/signatures/MethodSubSignature.java index 6944f50bea2..3f8648222f0 100644 --- a/sootup.core/src/main/java/sootup/core/signatures/MethodSubSignature.java +++ b/sootup.core/src/main/java/sootup/core/signatures/MethodSubSignature.java @@ -85,6 +85,10 @@ public boolean equals(Object o) { MethodSubSignature that = (MethodSubSignature) o; + if (!super.equals(that)) { + return false; + } + return Objects.equal(getParameterTypes(), that.getParameterTypes()); } From 6b273a2f1dc13b0ca629fa991dbd20db31f82591 Mon Sep 17 00:00:00 2001 From: "M.Schmidt" Date: Wed, 21 Feb 2024 12:31:53 +0100 Subject: [PATCH 7/7] adapt test --- .../src/test/java/sootup/java/bytecode/bugs/Issue714Test.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/bugs/Issue714Test.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/bugs/Issue714Test.java index 49102d485ef..3d5e462719d 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/bugs/Issue714Test.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/bugs/Issue714Test.java @@ -24,7 +24,7 @@ public void slow_localSplitter() { // "jdk.internal.jimage.ImageStringsReader :: mutf8FromString will cause LocalSplitter not halt // / comsume unreasonable time" - JavaView view = + JavaModuleView view = new JavaModuleView( Collections.emptyList(), Collections.singletonList(new JrtFileSystemAnalysisInputLocation())); @@ -32,7 +32,7 @@ public void slow_localSplitter() { final MethodSignature methodSignature = view.getIdentifierFactory() .parseMethodSignature( - ""); + ""); final Optional classOpt = view.getClass(methodSignature.getDeclClassType()); Assert.assertTrue(methodSignature.getDeclClassType() + " not found", classOpt.isPresent());