repo
stringlengths
1
191
file
stringlengths
23
351
code
stringlengths
0
5.32M
file_length
int64
0
5.32M
avg_line_length
float64
0
2.9k
max_line_length
int64
0
288k
extension_type
stringclasses
1 value
soot
soot-master/src/systemTest/resources/soot/dexpler/instructions/DexBytecodeTarget.java
package soot.dexpler.instructions; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2018 Manuel Benz * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.lang.invoke.MethodHandle; import java.util.function.Supplier; /** * Compile by using "$JAVA_HOME/bin/javac -cp $JAVA_HOME/lib/jrt-fs.jar *; dx --dex --min-sdk-version=26 * --output=dexBytecodeTarget.dex ../../../ " * */ public class DexBytecodeTarget { void invokePolymorphicTarget(MethodHandle handle) throws Throwable { handle.invoke("foo", "bar"); } void invokeCustomTarget() throws Throwable { Supplier<String> someLambda = () -> "foo"; } }
1,311
28.818182
104
java
soot
soot-master/src/systemTest/targets-resources/soot/lambdaMetaFactory/Issue1292.java
package soot.lambdaMetaFactory; import java.util.List; /** * Please check the issue for detail: * https://github.com/soot-oss/soot/issues/1292 * * @author raintung.li * */ public class Issue1292 { /** * test class for new Issue1292 * @author raintung.li * */ class test { public test(String s) { } } /** * TestNew method for lambda new * @param list */ public void testNew(List<String> list){ list.stream().forEach(test::new); } }
468
14.633333
48
java
soot
soot-master/src/systemTest/targets/android/os/AsyncTask.java
package android.os; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2021 Qidan He * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ //A Mock for android.os.AsyncTask public abstract class AsyncTask<Params, Progress, Result> { protected Result doInBackground(Params... params) { return null; } protected void onPostExecute(Result result) { } protected void onPreExecute() { } protected void onProgressUpdate(Progress... values) { } public final AsyncTask<Params, Progress, Result> execute(Params... params) { return null; } }
1,267
26.565217
80
java
soot
soot-master/src/systemTest/targets/soot/SootMethodRefImplTestInput.java
package soot; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2021 Timothy Hoffman * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ /** * @author Timothy Hoffman */ public class SootMethodRefImplTestInput { public SootMethodRefImplTestInput() { } public void m1() { m2(); } public void m2() { } }
999
24
71
java
soot
soot-master/src/systemTest/targets/soot/asm/LineNumberExtraction.java
package soot.asm; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2020 Manuel Benz * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.util.ArrayList; /** @author Manuel Benz at 13.02.20 */ public class LineNumberExtraction { public void iterator() { for (java.lang.Object object : new ArrayList<>()) { System.out.println(object); } } }
1,047
28.111111
71
java
soot
soot-master/src/systemTest/targets/soot/asm/LocalNaming.java
package soot.asm; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2020 Timothy Hoffman * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.io.PrintStream; /** * @author Timothy Hoffman */ public class LocalNaming { public void localNaming(String alpha, Integer beta, byte[] gamma, StringBuilder delta) { byte epsilon = 23; gamma[0] = epsilon; delta.append(alpha); delta.append(beta); long zeta = (long) 'Z'; long iota = zeta * 2L; Long eta = Long.valueOf(iota); long theta = eta; delta.append(zeta); delta.append(theta); PrintStream omega = System.out; omega.println(delta); } static class Config { static int getD() { return 0; } static int getF() { return 1; } } public void test() { int d = Config.getD(); int f = Config.getF(); int[] arr = new int[2]; arr[0] = d; arr[1] = f; System.out.println(arr); } }
1,622
22.185714
90
java
soot
soot-master/src/systemTest/targets/soot/asm/ResolveFieldInitializers.java
package soot.asm; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2020 Manuel Benz * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.util.ArrayDeque; import java.util.Deque; import java.util.LinkedList; import java.util.function.Supplier; /** @author Manuel Benz at 20.02.20 */ public class ResolveFieldInitializers { private Supplier<Deque> refSupplier = ArrayDeque::new; private Deque plainOld = new LinkedList(); }
1,117
29.216216
71
java
soot
soot-master/src/systemTest/targets/soot/asm/ScopeFinderTarget.java
package soot.asm; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2012 Andreas Dann * * (c) 2012 University of Luxembourg - Interdisciplinary Centre for * Security Reliability and Trust (SnT) - All rights reserved * Alexandre Bartel * * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import javax.annotation.Nullable; public class ScopeFinderTarget { public Object field; public static Object static_field; static { static_field = new Object(); } public ScopeFinderTarget() { field = new Object(); } @Nullable public void method() { System.out.println("in method"); } public static class Inner { public Object field; public static Object static_field; static { static_field = new Object(); } public Inner() { field = new Object(); } public void method() { System.out.println("in method"); } public class InnerInner { public Object field; public InnerInner() { field = new Object(); } public void method() { System.out.println("in method"); } } } public ScopeFinderTarget(Object param) { field = param; } public void methodPara(String p1) { System.out.println(p1); } public void methodPara(String p1, String p2) { System.out.println(p1); System.out.println(p2); } }
2,035
20.431579
71
java
soot
soot-master/src/systemTest/targets/soot/defaultInterfaceDifferentPackage/AbstractCheck.java
package soot.defaultInterfaceDifferentPackage; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2018 Manuel Benz * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ /** * @author Pavan Gurkhi Bhimesh created on 29.06.20 */ public class AbstractCheck { public final void log(String key, String value) { System.out.println("The string value is " + value + "The string key is " + key); } }
1,075
30.647059
83
java
soot
soot-master/src/systemTest/targets/soot/defaultInterfaceMethods/ClassInterfaceSameSignature.java
package soot.defaultInterfaceMethods; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2019 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public class ClassInterfaceSameSignature implements HelloWorld { public void print() { System.out.println("Welcome to Java 8"); } public void main() { ClassInterfaceSameSignature testClass = new ClassInterfaceSameSignature(); testClass.print(); } } interface HelloWorld{ default void print() { System.out.println("Hello World !!"); } }
1,215
27.952381
76
java
soot
soot-master/src/systemTest/targets/soot/defaultInterfaceMethods/DerivedInterfaces.java
package soot.defaultInterfaceMethods; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2019 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public class DerivedInterfaces implements InterfaceTestOne, InterfaceTestTwo{ public void main() { DerivedInterfaces testClass = new DerivedInterfaces(); testClass.print(); } } interface InterfaceTestOne{ default void print() { System.out.println("This is interface one"); } } interface InterfaceTestTwo extends InterfaceTestOne{ default void print() { System.out.println("This is interface two"); } }
1,276
28.697674
77
java
soot
soot-master/src/systemTest/targets/soot/defaultInterfaceMethods/InterfaceInheritance.java
package soot.defaultInterfaceMethods; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2019 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public class InterfaceInheritance implements InterfaceTestB{ public void main() { InterfaceInheritance testClass = new InterfaceInheritance(); testClass.print(); } @Override public void printMessage() { System.out.println("This is print method of main class"); } } interface InterfaceTestA{ default void print() { System.out.println("This is interface A"); } } interface InterfaceTestB extends InterfaceTestA{ void printMessage(); }
1,310
27.5
71
java
soot
soot-master/src/systemTest/targets/soot/defaultInterfaceMethods/InterfaceReAbstracting.java
package soot.defaultInterfaceMethods; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2019 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public class InterfaceReAbstracting implements InterfaceA, InterfaceB{ public void main() { InterfaceReAbstracting testClass = new InterfaceReAbstracting(); testClass.print(); } public void print() { System.out.println("This is print method of main class"); } } interface InterfaceA{ default void print() { System.out.println("This is interface A"); } } interface InterfaceB extends InterfaceA{ void print(); }
1,289
27.043478
71
java
soot
soot-master/src/systemTest/targets/soot/defaultInterfaceMethods/InterfaceSameSignature.java
package soot.defaultInterfaceMethods; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2019 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public class InterfaceSameSignature implements Read, Write { public void print() { Write.super.print(); Read.super.print(); } public void main() { InterfaceSameSignature testClass = new InterfaceSameSignature(); testClass.read(); testClass.write(); testClass.print(); } } interface Read{ default void read() { System.out.println("Reading the console input.."); } default void print() { System.out.println("This is a read method"); } } interface Write{ default void write() { System.out.println("Writing to console output.."); } default void print() { System.out.println("This is a write method"); } }
1,497
25.280702
71
java
soot
soot-master/src/systemTest/targets/soot/defaultInterfaceMethods/JavaNCSSCheck.java
package soot.defaultInterfaceMethods; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2018 Manuel Benz * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import javax.print.attribute.standard.Finishings; import soot.defaultInterfaceDifferentPackage.AbstractCheck; /** * @author Pavan Gurkhi Bhimesh created on 29.06.20 */ public class JavaNCSSCheck extends AbstractCheck { public void main() { JavaNCSSCheck mainClass = new JavaNCSSCheck(); mainClass.finishTree(); } public void finishTree() { //logging the values here log("1234", "Test"); } }
1,246
26.108696
71
java
soot
soot-master/src/systemTest/targets/soot/defaultInterfaceMethods/MaximallySpecificSuperInterface.java
package soot.defaultInterfaceMethods; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2019 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ /** @author Manuel Benz at 21.10.19 */ public class MaximallySpecificSuperInterface extends B implements D { public void main() { new B().print(); // Prints C } } class B implements C {} interface C extends D { default void print() { System.out.println("C"); } } interface D { default void print() { System.out.println("D"); } }
1,214
25.413043
71
java
soot
soot-master/src/systemTest/targets/soot/defaultInterfaceMethods/SimpleDefaultInterface.java
package soot.defaultInterfaceMethods; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2019 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public class SimpleDefaultInterface implements Default { public void main() { SimpleDefaultInterface testClass = new SimpleDefaultInterface(); testClass.target(); testClass.printMessage(); } public void printMessage() { System.out.println("Hello World!"); } } interface Default{ default void target() { System.out.println("Hello!"); } void printMessage(); }
1,237
25.913043
71
java
soot
soot-master/src/systemTest/targets/soot/defaultInterfaceMethods/SuperClass.java
package soot.defaultInterfaceMethods; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2019 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public class SuperClass{ public void print() { System.out.println("This is the print method of the super class"); } }
980
30.645161
71
java
soot
soot-master/src/systemTest/targets/soot/defaultInterfaceMethods/SuperClassImplementsInterface.java
package soot.defaultInterfaceMethods; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2019 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public class SuperClassImplementsInterface implements DefaultPrint{ public void main() { SuperClassImplementsInterface main = new SuperClassImplementsInterface(); main.print(); } public void print() { System.out.println("This is super class print method"); } } interface DefaultPrint{ default void print() { System.out.println("This is default print method"); } }
1,241
28.571429
75
java
soot
soot-master/src/systemTest/targets/soot/defaultInterfaceMethods/SuperClassInterfaceSameSignature.java
package soot.defaultInterfaceMethods; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2019 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public class SuperClassInterfaceSameSignature extends SuperClassImplementsInterface implements PrintInterface { public void main() { SuperClassInterfaceSameSignature main = new SuperClassInterfaceSameSignature(); main.print(); } } interface PrintInterface{ default void print() { System.out.println("This is default Print Interface Print Method"); } }
1,228
28.97561
112
java
soot
soot-master/src/systemTest/targets/soot/defaultInterfaceMethods/SuperClassPreferenceOverDefaultMethod.java
package soot.defaultInterfaceMethods; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2019 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public class SuperClassPreferenceOverDefaultMethod extends SuperClass implements InterfaceOne, InterfaceTwo{ public void main() { SuperClassPreferenceOverDefaultMethod testClass = new SuperClassPreferenceOverDefaultMethod(); testClass.print(); } } interface InterfaceOne{ default void print() { System.out.println("This is the default method of interface one"); } } interface InterfaceTwo{ default void print() { System.out.println("This is the default method of interface two"); } }
1,359
29.222222
108
java
soot
soot-master/src/systemTest/targets/soot/jimple/PolymorphicDispatch.java
package soot.jimple; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2018 Manuel Benz * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; /** * @author Andreas Dann created on 06.02.19 * @author Manuel Benz 27.2.19 */ public class PolymorphicDispatch { public void unambiguousMethod() throws Throwable { MethodHandle methodHandle = MethodHandles.lookup().findVirtual(PolymorphicDispatch.class, "someMethod", null); Object ob = methodHandle.invoke(); System.out.println(ob); } public void ambiguousMethod() throws Throwable { MethodHandle methodHandle = MethodHandles.lookup().findVirtual(PolymorphicDispatch.class, "someMethod", null); // call on sig 1 Object ob = methodHandle.invoke(); System.out.println(ob); // call on sig 2 int res = (int) methodHandle.invoke(1); System.out.println(res); } }
1,607
31.16
114
java
soot
soot-master/src/systemTest/targets/soot/jimple/PropagateLineNumberTag.java
package soot.jimple; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2020 Manuel Benz * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ /** @author Manuel Benz at 20.01.20 */ public class PropagateLineNumberTag { public static class A { public A() {} } public void nullAssignment() { PropagateLineNumberTag.A b = new PropagateLineNumberTag.A(); PropagateLineNumberTag.A a = null; A z = foo(a); } public void transitiveNullAssignment() { PropagateLineNumberTag.A b = new PropagateLineNumberTag.A(); PropagateLineNumberTag.A a = null; PropagateLineNumberTag.A c = a; A z = foo(a); A y = foo(c); } private static A foo(A param) { return param; } }
1,384
27.265306
71
java
soot
soot-master/src/systemTest/targets/soot/jimple/toolkit/callgraph/A.java
package soot.jimple.toolkit.callgraph; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2018 John Toman * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public class A { public void doNotcall(final B arg) { } }
898
28.966667
71
java
soot
soot-master/src/systemTest/targets/soot/jimple/toolkit/callgraph/AsyncTaskTestMainSample.java
package soot.jimple.toolkit.callgraph; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2021 Qidan He * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import android.os.AsyncTask; public class AsyncTaskTestMainSample { AsyncTask task; public void target1() { task = new LongOperation().execute("stub"); } } class LongOperation extends AsyncTask<String, Void, String> { @Override protected String doInBackground(String... params) { return null; } @Override protected void onPostExecute(String result) { } @Override protected void onPreExecute() { } @Override protected void onProgressUpdate(Void... values) { } }
1,378
23.192982
71
java
soot
soot-master/src/systemTest/targets/soot/jimple/toolkit/callgraph/B.java
package soot.jimple.toolkit.callgraph; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2018 John Toman * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public class B extends A { public void invokeTarget(final String x) { } public void doNotCall(Interface x) { } }
961
27.294118
71
java
soot
soot-master/src/systemTest/targets/soot/jimple/toolkit/callgraph/C.java
package soot.jimple.toolkit.callgraph; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2018 John Toman * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public class C extends B { public void invokeTarget2(final String x) { } public void doNotCall2(final B arg) { } }
965
27.411765
71
java
soot
soot-master/src/systemTest/targets/soot/jimple/toolkit/callgraph/ContainerMultiTypeSample.java
package soot.jimple.toolkit.callgraph; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2021 Qidan He * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; public class ContainerMultiTypeSample { Helper helper; int i; public void target() { //this.helpers.get("").handle(); for(Helper helper: helpers) helper.handle(); //helper.handle(); } //Map<String, Helper> helpers; Set<Helper> helpers; public ContainerMultiTypeSample () { //this.helpers = new HashMap<>(); //this.helpers.put("a", new AHelper()); //this.helpers.put("b", new BHelper()); this.helpers = new HashSet<>(); this.helpers.add(new AHelper()); //if(i > 0) // helper = new AHelper(); //else // helper = new BHelper(); } } interface Helper { public void handle(); } class AHelper implements Helper { @Override public void handle() { System.out.println("wtf"); } } class BHelper implements Helper { @Override public void handle() { } }
1,856
24.791667
71
java
soot
soot-master/src/systemTest/targets/soot/jimple/toolkit/callgraph/EntryPoint.java
package soot.jimple.toolkit.callgraph; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2018 John Toman * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.lang.reflect.Method; import soot.jimple.toolkit.callgraph.A; public class EntryPoint { public void ptaResolution() { final Interface f = PhantomField.fld; try { final Method m = f.getClass().getMethod(System.currentTimeMillis() + "", String.class); m.invoke(f, f.args()); final A x = PhantomField.fld2; final Method m2 = x.getClass().getMethod(System.currentTimeMillis() + "", String.class); m2.invoke(x, f.args()); } catch(Exception e) { } } public void typestateResolution() { final Interface f = PhantomField.fld; try { final Method m = f.getClass().getMethod(System.currentTimeMillis() + "", String.class); m.invoke(f, "foo"); final A x = PhantomField.fld2; final Method m2 = x.getClass().getMethod(System.currentTimeMillis() + "", String.class); m2.invoke(x, "foo"); } catch(Exception e) { } } }
1,737
31.185185
94
java
soot
soot-master/src/systemTest/targets/soot/jimple/toolkit/callgraph/Interface.java
package soot.jimple.toolkit.callgraph; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2018 John Toman * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface Interface { public Object[] args(); }
891
30.857143
71
java
soot
soot-master/src/systemTest/targets/soot/jimple/toolkit/callgraph/PhantomField.java
package soot.jimple.toolkit.callgraph; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2018 John Toman * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public class PhantomField { public static Interface fld; public static A fld2; }
920
30.758621
71
java
soot
soot-master/src/systemTest/targets/soot/jimple/toolkit/callgraph/SubClass.java
package soot.jimple.toolkit.callgraph; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2018 John Toman * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public class SubClass extends SubImplementation { public void invokeTarget2(final String arg) { } public void doNotCall2(final Interface arg) { } }
998
28.382353
71
java
soot
soot-master/src/systemTest/targets/soot/jimple/toolkit/callgraph/SubImplementation.java
package soot.jimple.toolkit.callgraph; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2018 John Toman * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public class SubImplementation implements SubInterface { public void invokeTarget(final String arg) { } public void doNotCall(final A arg) { } public String getName() { return "foobar" + System.currentTimeMillis(); } @Override public Object[] args() { return new Object[] { "foo" }; } }
1,146
25.674419
71
java
soot
soot-master/src/systemTest/targets/soot/jimple/toolkit/callgraph/SubInterface.java
package soot.jimple.toolkit.callgraph; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2018 John Toman * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public interface SubInterface extends Interface { }
888
30.75
71
java
soot
soot-master/src/systemTest/targets/soot/lambdaMetaFactory/Adapt.java
package soot.lambdaMetaFactory; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2018 Jon Mathews * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ /** * Tests parameter and return value adaptations for modeling of LambdaMetaFactory. * * <p> * According to the javadoc for * <a href="https://docs.oracle.com/javase/10/docs/api/java/lang/invoke/LambdaMetafactory.html">LambaMetaFactory</a>, * adaptations may include boxing and unboxing. Varargs are expected to be handled by the caller, hence need not be tested * here. * * * <p> * Parameters are adapted per <a href="https://docs.oracle.com/javase/specs/jls/se10/html/jls-5.html#jls-5.3">JLS §5.3 * Invocation Contexts</a>; the cases below enumerate the adaptations which may occur to parameters. * * <pre> <ol> <li>an identity conversion (§5.1.1) <li>a widening primitive conversion (§5.1.2) <li>a widening reference conversion (§5.1.5) <li>a widening reference conversion followed by an unboxing conversion <li>a widening reference conversion followed by an unboxing conversion, then followed by a widening primitive conversion <li>a boxing conversion (§5.1.7) <li>a boxing conversion followed by widening reference conversion <li>an unboxing conversion (§5.1.8) <li>an unboxing conversion followed by a widening primitive conversion </ol> * </pre> * * <p> * Return values are adapted per <a href="https://docs.oracle.com/javase/specs/jls/se10/html/jls-5.html#jls-5.2">JLS §5.2 * Assignment Contexts</a>. * * <pre> * <ol> <li>an identity conversion (§5.1.1) <li>a widening primitive conversion (§5.1.2) <li>a widening reference conversion (§5.1.5) <li>a widening reference conversion followed by an unboxing conversion <li>a widening reference conversion followed by an unboxing conversion, then followed by a widening primitive conversion <li>a boxing conversion (§5.1.7) <li>a boxing conversion followed by a widening reference conversion <li>an unboxing conversion (§5.1.8) <li>an unboxing conversion followed by a widening primitive conversion </ol> * </pre> * */ public class Adapt { public void parameterBoxingTarget() { parameterBoxing(p -> System.out.println(p), p -> System.out.println(p), p -> System.out.println(p)); } public void parameterBoxing(IntInterfaceParam I0param, IntegerInterfaceParam I1param, LongInterfaceParam L0param) { // unbox; parameter // CASE 8 // JLS 5.1.8 // Integer -> int IntegerInterfaceParam I1var = I0param::adapt; I1var.adapt(Integer.valueOf(1)); // unbox, widen; parameter // CASE 9 // JLS 5.1.8, 5.1.2 // Short -> short -> int ShortInterfaceParam S1var = I0param::adapt; S1var.adapt(Short.valueOf((short) 1)); // auto box; parameter // CASE 6 // JLS 5.1.7 // int -> Integer IntInterfaceParam I0var = I1param::adapt; I0var.adapt(1); } public void parameterWidening() { parameterWidening(p -> System.out.println(p), p -> System.out.println(p), p -> System.out.println(p), p -> System.out.println(p), p -> System.out.println(p), p -> System.out.println(p)); } public void parameterWidening(IntInterfaceParam I0param, IntegerInterfaceParam I1param, LongInterfaceParam L0param, FloatInterfaceParam F0param, NumberInterfaceParam Nparam, ObjectInterfaceParam Oparam) { // primitive widening; parameter // CASE 2 // JLS 5.1.2 // int -> long IntInterfaceParam I0var = L0param::adapt; I0var.adapt(1); // primitive widening; parameter // CASE 2 // JLS 5.1.2 // int -> float /* IntInterfaceParam */ I0var = F0param::adapt; I0var.adapt(1); // autobox followed by reference widening // CASE 7 (which includes CASE 3) // JLS 5.1.2, 5.1.5 // int -> Integer -> Number /* IntInterfaceParam */ I0var = Nparam::adapt; // autobox followed by reference widening // CASE 7 (which includes CASE 3) // JLS 5.1.2, 5.1.5 // int -> Integer -> Object /* IntInterfaceParam */ I0var = Oparam::adapt; } public void returnBoxing() { returnBoxing(() -> 1, () -> new Integer(2), () -> 3L); } public void returnBoxing(IntInterfaceReturn I0param, IntegerInterfaceReturn I1param, LongInterfaceReturn L0param) { // unbox; parameter // Integer -> int IntegerInterfaceReturn I1var = I0param::adapt; I1var.adapt(); // auto box; parameter // int -> Integer IntInterfaceReturn I0var = I1param::adapt; I0var.adapt(); } public void returnWidening() { returnWidening(() -> 1, () -> new Integer(2), () -> 3L); } public void returnWidening(IntInterfaceReturn I0param, IntegerInterfaceReturn I1param, LongInterfaceReturn L0param) { // primitive widening; return // JLS 5.1.2 // int -> long LongInterfaceReturn L0var = I0param::adapt; L0var.adapt(); } interface ShortInterfaceParam { public void adapt(Short p); } interface IntInterfaceParam { public void adapt(int p); } interface IntegerInterfaceParam { public void adapt(Integer p); } interface LongInterfaceParam { public void adapt(long p); } interface FloatInterfaceParam { public void adapt(float p); } interface NumberInterfaceParam { public void adapt(Number p); } interface ObjectInterfaceParam { public void adapt(Object p); } interface IntInterfaceReturn { public int adapt(); } interface ShortInterfaceReturn { public short adapt(); } interface IntegerInterfaceReturn { public Integer adapt(); } interface LongInterfaceReturn { public long adapt(); } };
6,274
28.460094
122
java
soot
soot-master/src/systemTest/targets/soot/lambdaMetaFactory/ConstructorMethodRef.java
package soot.lambdaMetaFactory; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2018 Manuel Benz * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.util.function.Supplier; /** * @author Manuel Benz created on 2018-12-18 */ public class ConstructorMethodRef { public void main() { Supplier<ConstructorMethodRef> supplier = ConstructorMethodRef::new; System.out.println(supplier.get()); } }
1,095
29.444444
72
java
soot
soot-master/src/systemTest/targets/soot/lambdaMetaFactory/InheritedMethodRef.java
package soot.lambdaMetaFactory; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2018 Manuel Benz * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.util.function.Supplier; /** * @author Manuel Benz created on 2018-12-18 */ public class InheritedMethodRef extends Super { public void main() { Supplier<Integer> supplier = super::superMethod; System.out.println(supplier.get()); } } class Super { protected int superMethod() { return 5; } }
1,154
26.5
71
java
soot
soot-master/src/systemTest/targets/soot/lambdaMetaFactory/Issue1146.java
package soot.lambdaMetaFactory; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2019 Manuel Benz * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.util.Arrays; import java.util.List; import java.util.Optional; /** * Code according to issue 1146: https://github.com/soot-oss/soot/issues/1146 * * @author Manuel Benz at 2019-05-14 */ public class Issue1146 { public Vertrag getVertrag(String vsnr) { List<String> myList = Arrays.asList("element1", "element2", "element3"); myList.forEach(element -> System.out.println(element)); return new Vertrag(); } public Vertrag getVertrag2(String vsnr) throws BpmnError { Vertrag vertrag = null; return Optional.ofNullable(vertrag).orElseThrow(() -> { return new BpmnError("not found"); }); } private class Vertrag { } private class BpmnError extends Exception { public BpmnError(String msg) { super(msg); } } }
1,610
27.263158
77
java
soot
soot-master/src/systemTest/targets/soot/lambdaMetaFactory/Issue1367.java
package soot.lambdaMetaFactory; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2019 Manuel Benz * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.util.function.Supplier; /** * Test case for issue 1367: https://github.com/Sable/soot/issues/1367 * * @author David Seekatz */ public class Issue1367 { public Supplier<Object> constructorReference() { return Object::new; } }
1,084
29.138889
71
java
soot
soot-master/src/systemTest/targets/soot/lambdaMetaFactory/LambdaNoCaptures.java
package soot.lambdaMetaFactory; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2018 Manuel Benz * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.util.function.Function; class LambdaNoCaptures { private static void staticCallee(Integer i) { System.out.println(i); } public void main() { Function<Integer, String> intToString = (Integer i) -> { staticCallee(i); return String.valueOf(i); }; final String res = intToString.apply(2); System.out.println(res); } }
1,194
28.875
71
java
soot
soot-master/src/systemTest/targets/soot/lambdaMetaFactory/LambdaWithCaptures.java
package soot.lambdaMetaFactory; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2018 Manuel Benz * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.util.function.Supplier; /** * @author Manuel Benz created on 2018-12-18 */ public class LambdaWithCaptures { public void main() { String capture = "Hello"; Supplier<String> s = () -> capture + " " + getString(); System.out.println(s.get()); } private String getString() { return "World"; } }
1,161
26.023256
71
java
soot
soot-master/src/systemTest/targets/soot/lambdaMetaFactory/MarkerInterfaces.java
package soot.lambdaMetaFactory; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2018 Manuel Benz * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.util.function.Supplier; /** * @author Manuel Benz created on 2018-12-18 */ public class MarkerInterfaces { public void main() { Supplier<String> supplier = (Supplier & Marker1 & Marker2) () -> getString(); System.out.println(supplier.get()); } public String getString() { return "Hello"; } public interface Marker1 { } public interface Marker2 { } }
1,223
25.608696
81
java
soot
soot-master/src/systemTest/targets/soot/lambdaMetaFactory/MethodRefWithParameters.java
package soot.lambdaMetaFactory; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2018 Manuel Benz * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.util.function.BiFunction; /** * @author Manuel Benz created on 2018-12-18 */ public class MethodRefWithParameters { public static int staticWithCaptures(int a, Integer b) { return a + b; } public void main() { BiFunction<Integer, Integer, Integer> fun = MethodRefWithParameters::staticWithCaptures; System.out.println(fun.apply(1, 2)); } }
1,203
29.1
92
java
soot
soot-master/src/systemTest/targets/soot/lambdaMetaFactory/PrivateMethodRef.java
package soot.lambdaMetaFactory; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2018 Manuel Benz * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.util.function.Supplier; /** * @author Manuel Benz created on 2018-12-18 */ public class PrivateMethodRef { public void main() { Supplier<Integer> supplier = this::privateMethod; System.out.println(supplier.get()); } private int privateMethod() { return 5; } }
1,123
27.1
71
java
soot
soot-master/src/systemTest/targets/soot/lambdaMetaFactory/PublicMethodRef.java
package soot.lambdaMetaFactory; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2018 Manuel Benz * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.util.function.Supplier; /** * @author Manuel Benz created on 2018-12-18 */ public class PublicMethodRef { public void main() { Supplier<Integer> supplier = this::publicMethod; System.out.println(supplier.get()); } public int publicMethod() { return 5; } }
1,119
27
71
java
soot
soot-master/src/systemTest/targets/soot/lambdaMetaFactory/StaticMethodRef.java
package soot.lambdaMetaFactory; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2018 Manuel Benz * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import java.util.function.Supplier; /** * @author Manuel Benz created on 2018-12-18 */ public class StaticMethodRef { static int staticMethod() { return 5; } public void main() { Supplier<Integer> supplier = StaticMethodRef::staticMethod; System.out.println(supplier.get()); } }
1,129
27.974359
71
java
soot
soot-master/src/systemTest/targets/soot/testing/framework/HelloTestingFrameworkTarget.java
package soot.testing.framework; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2018 Manuel Benz * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ /** * @author Manuel Benz created on 22.06.18 */ public class HelloTestingFrameworkTarget { public void helloWorld() { System.out.println("Hello testing world!"); } }
1,007
28.647059
71
java
soot
soot-master/src/systemTest/targets/soot/toolkits/scalar/LocalPackerTestInput.java
package soot.toolkits.scalar; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 2020 Timothy Hoffman * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ /** * @author Timothy Hoffman */ public class LocalPackerTestInput { public void prefixVariableNames() { // NOTE: with Options.v().setPhaseOption("jb", "use-original-names:true"), // this method body will contain locals like "a" and "a#1" (i.e. the part // before the '#' character matches the exact name of another Local). If // the LocalPacker does not add all names (even those without '#') to the // "usedLocalNames" set, then the body will contain multiple locals with // the same name after running the LocalPacker becuase "a#1" will be // renamed to "a" because it did not consider that "a" is already used. { int a = getInt(); int b = getInt(); System.out.println(a + b); } { String a = getString(); String b = getString(); System.out.println(a + b); } { double a = getDouble(); double b = getDouble(); System.out.println(a + b); } { long a = getLong(); long b = getLong(); System.out.println(a + b); } } private static int getInt() { return 0; } private static String getString() { return ""; } private static double getDouble() { return 0.0d; } private static long getLong() { return 1L; } }
2,108
26.038462
78
java
soot
soot-master/src/test/java/categories/Java11Test.java
package categories; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ /** * @author Andreas Dann */ public interface Java11Test { /* category marker */ }
924
29.833333
71
java
soot
soot-master/src/test/java/categories/Java9Test.java
package categories; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ /** * @author Andreas Dann */ public interface Java9Test { /* category marker */ }
923
29.8
71
java
soot
soot-master/src/test/java/soot/AbnormalTest.java
/*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2014 Raja Vallee-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ package soot; import org.junit.Test; import soot.options.Options; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collections; import static org.junit.Assert.assertTrue; /** * Tests abnormal cases. * * @author Linghui Luo */ public class AbnormalTest { public void setup() { Path cp = Paths.get("src", "test", "resources", "AbnormalClass"); G.reset(); Options.v().set_prepend_classpath(true); Options.v().set_process_dir(Collections.singletonList(cp.toFile().getAbsolutePath())); Options.v().set_src_prec(Options.src_prec_class); Options.v().set_drop_bodies_after_load(false); } @Test public void testMethodWithNoInstruction() { setup(); Options.v().set_output_format(Options.output_format_jimple); runTest(); setup(); Options.v().set_output_format(Options.output_format_grimp); runTest(); setup(); Options.v().set_output_format(Options.output_format_baf); runTest(); setup(); Options.v().set_output_format(Options.output_format_dava); runTest(); setup(); Options.v().set_output_format(Options.output_format_shimp); runTest(); setup(); Options.v().set_output_format(Options.output_format_class); runTest(); } public void runTest() { Scene.v().loadNecessaryClasses(); PackManager.v().runBodyPacks(); // The method test in class E has no opcode instruction at all. // Such method can be created by a bytecode editor. SootMethod method = Scene.v().getSootClass("E").getMethodByName("test"); assertTrue(!method.hasActiveBody()); assertTrue(method.isConcrete()); } }
2,588
30.962963
94
java
soot
soot-master/src/test/java/soot/EntryPointsTest.java
/*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2014 Raja Vallee-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ package soot; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.junit.Test; import soot.jimple.toolkits.callgraph.CallGraph; import soot.jimple.toolkits.callgraph.Edge; import soot.options.Options; /** * Tests the EntryPoints class * * @author Linghui Luo */ public class EntryPointsTest { @Test public void testClinitOf() { Path cp = Paths.get("src", "test", "resources", "Clinit", "bin"); G.reset(); Options.v().set_prepend_classpath(true); Options.v().set_process_dir(Collections.singletonList(cp.toFile().getAbsolutePath())); Options.v().set_src_prec(Options.src_prec_class); Options.v().set_allow_phantom_refs(true); Options.v().set_ignore_resolving_levels(true); Options.v().setPhaseOption("cg.spark", "on"); Options.v().setPhaseOption("cg.spark", "string-constants:true"); Options.v().set_whole_program(true); Scene.v().loadNecessaryClasses(); SootMethod mainMethod = Scene.v().getMainMethod(); Scene.v().setEntryPoints(Collections.singletonList(mainMethod)); PackManager.v().getPack("cg").apply(); CallGraph cg = Scene.v().getCallGraph(); boolean found = false; for (Edge edge : cg) { if (edge.getSrc().method().getSignature().equals("<soot.Main: void main(java.lang.String[])>")) { if (edge.getTgt().method().getSignature().equals("<soot.A: void <clinit>()>")) { // A1 is used in main found = true; break; } } } assertTrue(found); SootClass a1 = Scene.v().getSootClassUnsafe("soot.A1"); SootClass a = Scene.v().getSootClassUnsafe("soot.A"); assertTrue(a1 != null); List<String> clinits1 = new ArrayList<>(); EntryPoints.v().clinitsOf(a1).forEach(e -> { clinits1.add(e.toString()); }); List<String> clinits = new ArrayList<>(); EntryPoints.v().clinitsOf(a).forEach(e -> { clinits.add(e.toString()); }); assertEquals(clinits1, clinits); } }
2,850
31.770115
106
java
soot
soot-master/src/test/java/soot/FastHierarchyTest.java
package soot; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import static org.hamcrest.Matchers.containsInAnyOrder; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; import java.util.ArrayList; import java.util.Collections; import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import org.junit.Test; public class FastHierarchyTest { @Test public void testGetAllSubinterfaces() { G.reset(); Scene s = Scene.v(); s.loadNecessaryClasses(); SootClass scA = generacteSceneClass("InterfaceA", Modifier.INTERFACE); SootClass scB = generacteSceneClass("InterfaceB", Modifier.INTERFACE); SootClass scC1 = generacteSceneClass("InterfaceC1", Modifier.INTERFACE); SootClass scC2 = generacteSceneClass("InterfaceC2", Modifier.INTERFACE); SootClass scD = generacteSceneClass("InterfaceD", Modifier.INTERFACE); SootClass scE1 = generacteSceneClass("InterfaceE1", Modifier.INTERFACE); SootClass scE2 = generacteSceneClass("InterfaceE2", Modifier.INTERFACE); SootClass sc6 = generacteSceneClass("Class1", 0); scA.addInterface(scB); scB.addInterface(scC1); scB.addInterface(scC2); scC1.addInterface(scD); scD.addInterface(scE1); scD.addInterface(scE2); FastHierarchy fh = s.getOrMakeFastHierarchy(); // A sc6 is not an interface -> empty result assertEquals(Collections.emptySet(), fh.getAllSubinterfaces(sc6)); assertThat(fh.getAllSubinterfaces(scA), containsInAnyOrder(scA)); assertThat(fh.getAllSubinterfaces(scB), containsInAnyOrder(scA, scB)); assertThat(fh.getAllSubinterfaces(scC1), containsInAnyOrder(scA, scB, scC1)); assertThat(fh.getAllSubinterfaces(scC2), containsInAnyOrder(scA, scB, scC2)); assertThat(fh.getAllSubinterfaces(scD), containsInAnyOrder(scA, scB, scC1, scD)); assertThat(fh.getAllSubinterfaces(scE1), containsInAnyOrder(scA, scB, scC1, scD, scE1)); assertThat(fh.getAllSubinterfaces(scE2), containsInAnyOrder(scA, scB, scC1, scD, scE2)); } /** * Execute {@link FastHierarchy#getAllSubinterfaces(SootClass)} concurrently and check the result * * This test uses a subclass of {@link FastHierarchy} that has a built-in delay to increase the time-span a potential * problem because of concurrent access can arise. * * @throws Exception */ @Test public void testGetAllSubinterfacesMultiThreaded() throws Exception { G.reset(); Scene s = Scene.v(); s.loadNecessaryClasses(); SootClass scA = generacteSceneClass("InterfaceA", Modifier.INTERFACE); SootClass scB = generacteSceneClass("InterfaceB", Modifier.INTERFACE); SootClass scC = generacteSceneClass("InterfaceC", Modifier.INTERFACE); SootClass scD = generacteSceneClass("InterfaceD", Modifier.INTERFACE); SootClass scE = generacteSceneClass("InterfaceE", Modifier.INTERFACE); scA.addInterface(scB); scB.addInterface(scC); scC.addInterface(scD); scD.addInterface(scE); final FastHierarchy hierarchy = new FastHierarchyForUnittest(); s.setFastHierarchy(hierarchy); ExecutorService executor = Executors.newFixedThreadPool(4); Callable<Set<SootClass>> c = new Callable<Set<SootClass>>() { @Override public Set<SootClass> call() throws Exception { return hierarchy.getAllSubinterfaces(scE); } }; ArrayList<Future<Set<SootClass>>> results = new ArrayList<>(10); for (int i = 0; i < 10; i++) { results.add(executor.submit(c)); } for (Future<Set<SootClass>> future : results) { Set<SootClass> res = future.get(); assertThat(res, containsInAnyOrder(scA, scB, scC, scD, scE)); } executor.shutdown(); } @Test public void testGetAllImplementersOfInterface() { G.reset(); Scene s = Scene.v(); s.loadNecessaryClasses(); SootClass interfaceA = generacteSceneClass("InterfaceA", Modifier.INTERFACE); SootClass interfaceB = generacteSceneClass("InterfaceB", Modifier.INTERFACE); SootClass interfaceC1 = generacteSceneClass("InterfaceC1", Modifier.INTERFACE); SootClass interfaceC2 = generacteSceneClass("InterfaceC2", Modifier.INTERFACE); SootClass interfaceD = generacteSceneClass("InterfaceD", Modifier.INTERFACE); SootClass scA = generacteSceneClass("ClassA", 0); SootClass scB = generacteSceneClass("ClassB", 0); SootClass scC1 = generacteSceneClass("ClassC1", 0); SootClass scC2 = generacteSceneClass("ClassC2", 0); SootClass scD = generacteSceneClass("ClassD", 0); SootClass scZ = generacteSceneClass("ClassZ", 0); interfaceA.addInterface(interfaceB); interfaceB.addInterface(interfaceC1); interfaceB.addInterface(interfaceC2); interfaceC1.addInterface(interfaceD); scA.addInterface(interfaceA); scB.addInterface(interfaceB); scC1.addInterface(interfaceC1); scC2.addInterface(interfaceC2); scD.addInterface(interfaceD); FastHierarchy fh = s.getOrMakeFastHierarchy(); // A sc6 is not an interface -> empty result assertEquals(Collections.emptySet(), fh.getAllImplementersOfInterface(scZ)); assertThat(fh.getAllImplementersOfInterface(interfaceA), containsInAnyOrder(scA)); assertThat(fh.getAllImplementersOfInterface(interfaceB), containsInAnyOrder(scA, scB)); assertThat(fh.getAllImplementersOfInterface(interfaceC1), containsInAnyOrder(scA, scB, scC1)); assertThat(fh.getAllImplementersOfInterface(interfaceC2), containsInAnyOrder(scA, scB, scC2)); assertThat(fh.getAllImplementersOfInterface(interfaceD), containsInAnyOrder(scA, scB, scC1, scD)); } private static class FastHierarchyForUnittest extends FastHierarchy { @Override public Set<SootClass> getAllSubinterfaces(SootClass parent) { try { // We add a delay to increase the chance of a concurrent access Thread.sleep(100); } catch (InterruptedException e) { } return super.getAllSubinterfaces(parent); } } private static SootClass generacteSceneClass(String name, int modifier) { SootClass sootClass = new SootClass(name, modifier); Scene.v().addClass(sootClass); SootClass objectClass = Scene.v().getObjectType().getSootClass(); sootClass.setSuperclass(objectClass); return sootClass; } }
7,163
34.82
119
java
soot
soot-master/src/test/java/soot/ModuleUtilTest.java
package soot; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.junit.Test; import org.junit.Assert; public class ModuleUtilTest { @Test public void ownPackage() { G.reset(); ModuleUtil moduleUtil = ModuleUtil.v(); ModuleScene moduleScene = ModuleScene.v(); SootModuleInfo moduleA = new SootModuleInfo(SootModuleInfo.MODULE_INFO, "moduleA"); moduleA.addExportedPackage("de.upb"); moduleScene.addClassSilent(moduleA); String foundModule = moduleUtil.declaringModule("de.upb", "moduleA"); Assert.assertEquals("moduleA", foundModule); } @Test public void simpleExport() { G.reset(); ModuleScene moduleScene = ModuleScene.v(); SootModuleInfo moduleA = new SootModuleInfo(SootModuleInfo.MODULE_INFO, "moduleA"); moduleA.addExportedPackage("de.upb"); moduleScene.addClassSilent(moduleA); SootModuleInfo moduleB = new SootModuleInfo(SootModuleInfo.MODULE_INFO, "moduleB"); moduleB.getRequiredModules().put(moduleA, Modifier.REQUIRES_STATIC); moduleScene.addClassSilent(moduleB); ModuleUtil moduleUtil = ModuleUtil.v(); String foundModule = moduleUtil.declaringModule("de.upb.A", "moduleB"); Assert.assertEquals("moduleA", foundModule); } @Test public void simpleRequiresTransitiveExport() { G.reset(); ModuleScene moduleScene = ModuleScene.v(); SootModuleInfo moduleA = new SootModuleInfo(SootModuleInfo.MODULE_INFO, "moduleA"); moduleA.addExportedPackage("de.upb"); moduleScene.addClassSilent(moduleA); SootModuleInfo moduleB = new SootModuleInfo(SootModuleInfo.MODULE_INFO, "moduleB"); moduleB.getRequiredModules().put(moduleA, Modifier.REQUIRES_TRANSITIVE); moduleScene.addClassSilent(moduleB); SootModuleInfo moduleC = new SootModuleInfo(SootModuleInfo.MODULE_INFO, "moduleC"); moduleC.getRequiredModules().put(moduleB, Modifier.REQUIRES_STATIC); moduleScene.addClassSilent(moduleC); ModuleUtil moduleUtil = ModuleUtil.v(); String foundModule = moduleUtil.declaringModule("de.upb.A", "moduleC"); Assert.assertEquals("moduleA", foundModule); } @Test public void TwoLevelRequiresTransitiveExport() { G.reset(); ModuleScene moduleScene = ModuleScene.v(); SootModuleInfo moduleA = new SootModuleInfo(SootModuleInfo.MODULE_INFO, "moduleA"); moduleA.addExportedPackage("de.upb"); moduleScene.addClassSilent(moduleA); SootModuleInfo moduleB = new SootModuleInfo(SootModuleInfo.MODULE_INFO, "moduleB"); moduleB.getRequiredModules().put(moduleA, Modifier.REQUIRES_TRANSITIVE); moduleScene.addClassSilent(moduleB); SootModuleInfo moduleC = new SootModuleInfo(SootModuleInfo.MODULE_INFO, "moduleC"); moduleC.getRequiredModules().put(moduleB, Modifier.REQUIRES_TRANSITIVE); moduleScene.addClassSilent(moduleC); SootModuleInfo moduleD = new SootModuleInfo(SootModuleInfo.MODULE_INFO, "moduleD"); moduleD.getRequiredModules().put(moduleC, Modifier.REQUIRES_STATIC); moduleScene.addClassSilent(moduleD); ModuleUtil moduleUtil = ModuleUtil.v(); String foundModule = moduleUtil.declaringModule("de.upb.A", "moduleD"); // output should be D, because module C, does NOT REQUIERS TRANSITIVE module B Assert.assertEquals("moduleA", foundModule); } //the test should fail, as the requires transitive relations are not set in the module graph @Test public void TwoLevelRequiresTransitiveExportFailing() { G.reset(); ModuleScene moduleScene = ModuleScene.v(); SootModuleInfo moduleA = new SootModuleInfo(SootModuleInfo.MODULE_INFO, "moduleA"); moduleA.addExportedPackage("de.upb"); moduleScene.addClassSilent(moduleA); SootModuleInfo moduleB = new SootModuleInfo(SootModuleInfo.MODULE_INFO, "moduleB"); moduleB.getRequiredModules().put(moduleA, Modifier.REQUIRES_TRANSITIVE); moduleScene.addClassSilent(moduleB); SootModuleInfo moduleC = new SootModuleInfo(SootModuleInfo.MODULE_INFO, "moduleC"); moduleC.getRequiredModules().put(moduleB, Modifier.REQUIRES_STATIC); moduleScene.addClassSilent(moduleC); SootModuleInfo moduleD = new SootModuleInfo(SootModuleInfo.MODULE_INFO, "moduleD"); moduleD.getRequiredModules().put(moduleC, Modifier.REQUIRES_STATIC); moduleScene.addClassSilent(moduleD); ModuleUtil moduleUtil = ModuleUtil.v(); String foundModule = moduleUtil.declaringModule("de.upb.A", "moduleD"); // output should be D, because module C, does NOT REQUIERS TRANSITIVE module B Assert.assertEquals("moduleD", foundModule); } }
5,639
35.862745
96
java
soot
soot-master/src/test/java/soot/PackManagerTest.java
package soot; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2014 Raja Vallee-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.junit.Test; import soot.options.Options; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; import static org.junit.Assert.assertEquals; /** * Some tests to disable jb transformers. * @author Linghui Luo */ public class PackManagerTest { public void setup() { Path cp = Paths.get("src", "test", "resources", "SimpleClass"); G.reset(); Options.v().set_prepend_classpath(true); Options.v().set_process_dir(Collections.singletonList(cp.toFile().getAbsolutePath())); Options.v().set_src_prec(Options.src_prec_class); Options.v().set_output_format(Options.output_format_jimple); } @Test public void testDisableCopyPropagatorInJBPhase() { { // default CopyPropagator enabled setup(); Scene.v().loadNecessaryClasses(); PackManager.v().runBodyPacks(); SootClass cls = Scene.v().getSootClass("Example"); SootMethod foo = cls.getMethodByName("foo"); List<String> actual = bodyAsStrings(foo.getActiveBody()); List<String> expected = expectedBody("r0 := @this: Example", "virtualinvoke r0.<Example: void bar(int,int)>(0, 2)", "return"); assertEquals(expected, actual); } { // disable CopyPropagator setup(); Options.v().setPhaseOption("jb.sils", "enabled:false");// this transformer calls a lot of other transformers Options.v().setPhaseOption("jb.cp", "enabled:false"); Scene.v().loadNecessaryClasses(); PackManager.v().runBodyPacks(); SootClass cls = Scene.v().getSootClass("Example"); SootMethod foo = cls.getMethodByName("foo"); List<String> actual = bodyAsStrings(foo.getActiveBody()); List<String> expected = expectedBody("r0 := @this: Example", "b0 = 0", "b1 = 2", "virtualinvoke r0.<Example: void bar(int,int)>(b0, b1)", "return"); assertEquals(expected, actual); } } @Test public void testDisableUnusedLocalEliminatorInJBPhase() { { // default UnusedLocalEliminator enabled setup(); Scene.v().loadNecessaryClasses(); PackManager.v().runBodyPacks(); SootClass cls = Scene.v().getSootClass("Example"); SootMethod bar = cls.getMethodByName("bar"); List<String> actual = bodyAsStrings(bar.getActiveBody()); List<String> expected = expectedBody("r1 := @this: Example", "i0 := @parameter0: int", "i1 := @parameter1: int", "i2 = i0 * i1", "$r0 = <java.lang.System: java.io.PrintStream out>", "virtualinvoke $r0.<java.io.PrintStream: void println(int)>(i2)", "return"); } { //disable UnusedLocalEliminator setup(); Options.v().setPhaseOption("jb.sils", "enabled:false");// this transformer calls a lot of other transformers Options.v().setPhaseOption("jb.cp-ule", "enabled:false"); Scene.v().loadNecessaryClasses(); PackManager.v().runBodyPacks(); SootClass cls = Scene.v().getSootClass("Example"); SootMethod bar = cls.getMethodByName("bar"); List<String> actual = bodyAsStrings(bar.getActiveBody()); List<String> expected = expectedBody("r1 := @this: Example", "i0 := @parameter0: int", "i1 := @parameter1: int", "i2 = i0 * i1", "z0 = 0", "$r0 = <java.lang.System: java.io.PrintStream out>", "virtualinvoke $r0.<java.io.PrintStream: void println(int)>(i2)", "return"); } } public static List<String> expectedBody(String... jimpleLines) { return Stream.of(jimpleLines).collect(Collectors.toList()); } public static List<String> bodyAsStrings(Body body) { List<String> units = new ArrayList<>(); for (Unit u : body.getUnits()) { units.add(u.toString()); } return units; } }
5,316
37.810219
120
java
soot
soot-master/src/test/java/soot/RefTypeTest.java
package soot; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.junit.Assert; import org.junit.Test; public class RefTypeTest { @Test public void testMerge() { G.reset(); Scene.v().loadNecessaryClasses(); SootClass sc1 = new SootClass("Class1"); SootClass sc2 = new SootClass("Class2"); SootClass sc3 = new SootClass("Class3"); SootClass sc4 = new SootClass("Class4"); SootClass sc5 = new SootClass("Class5"); Scene.v().addClass(sc1); Scene.v().addClass(sc2); Scene.v().addClass(sc3); Scene.v().addClass(sc4); Scene.v().addClass(sc5); sc1.setSuperclass(Scene.v().getObjectType().getSootClass()); sc2.setSuperclass(sc1); sc3.setSuperclass(sc2); sc4.setSuperclass(sc2); sc5.setSuperclass(sc4); Type tpMerged = sc5.getType().merge(sc3.getType(), Scene.v()); Assert.assertEquals("Class2", ((RefType) tpMerged).getClassName()); } }
1,671
26.409836
71
java
soot
soot-master/src/test/java/soot/SootResolverTest.java
package soot; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 1999 Raja Vallee-Rai * Copyright (C) 2004 Ondrej Lhotak * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.junit.Test; import soot.options.Options; /** * Created by canliture on 2021/6/28 <br/> * * A minimal Test for evaluating the bug in the Method {@link soot.Scene#defaultJavaClassPath}. <br/> * * When {@link soot.SootResolver} and {@link soot.SourceLocator#getClassSource} resolve classes, * they will get default java classPath by call `Scene.v().getSootClassPath()`. <br/> * * <b>Test under Java 8 environment: </b> <br/> * * Before fixed the bug, we will get default java class path when <br/> * - we set <pre>Options.v().set_whole_program(true);</pre>: `path/to/rt.jar;path/to/jce.jar` <br/> * - we set <pre>Options.v().set_whole_shimple(true);</pre>: `path/to/rt.jar` <br/> * * After fixed the bug, we will get default java class path when <br/> * - we set <pre>Options.v().set_whole_program(true);</pre>: `path/to/rt.jar;path/to/jce.jar` <br/> * - we set <pre>Options.v().set_whole_shimple(true);</pre>: `path/to/rt.jar;path/to/jce.jar` <br/> * * @author canliture */ public class SootResolverTest { @Test public void test1() { G.reset(); // setting Options.v().set_whole_program(true); // No throw. ^_^ Scene.v().loadNecessaryClasses(); } @Test public void test2() { G.reset(); // setting Options.v().set_whole_shimple(true); // throw java.lang.AssertionError !!! Scene.v().loadNecessaryClasses(); } }
2,304
30.575342
101
java
soot
soot-master/src/test/java/soot/asm/backend/ASMBackendTestSuite.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.junit.runner.RunWith; import org.junit.runners.Suite; import soot.baf.ASMBackendMockingTest; import soot.util.backend.SootASMClassWriterTest; /** * Suite for testing all of the ASM backend * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ @RunWith(Suite.class) @Suite.SuiteClasses({ AnnotatedAnnotatedClassTest.class, AnnotatedAnnotationTest.class, AnnotatedClassTest.class, AnnotatedFieldTest.class, AnnotatedMethodTest.class, AnnotatedParameterTest.class, AnnotationTest.class, ArithmeticTest.class, ArraysTest.class, CompareArithmeticInstructions2Test.class, CompareArithmeticInstructionsTest.class, CompareInstructionsTest.class, ConstantPoolTest.class, ControlStructuresTest.class, DupsTest.class, EnumTest.class, ExceptionTest.class, ExtendedArithmeticLibTest.class, InnerClass2Test.class, InnerClassTest.class, InstanceOfCastsTest.class, InterfaceTest.class, // LambdaTest.class, LineNumbersTest.class, LogicalOperationsTest.class, MethodExampleTest.class, ModifiersTest.class, MonitorTest.class, NullTypesTest.class, OuterClassTest.class, ReturnsTest.class, StoresTest.class, TryCatchTest.class, ASMBackendMockingTest.class, SootASMClassWriterTest.class, MinimalJavaVersionTest.class }) public class ASMBackendTestSuite { }
2,158
41.333333
120
java
soot
soot-master/src/test/java/soot/asm/backend/AbstractASMBackendTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.util.Scanner; import org.junit.Ignore; import org.junit.Test; import org.objectweb.asm.Opcodes; import org.objectweb.asm.util.TraceClassVisitor; import soot.G; import soot.Main; import soot.ModulePathSourceLocator; import soot.Scene; /** * Abstract base class for tests for the ASM backend that work with compiled class files * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer */ @Ignore("Abstract base class") public abstract class AbstractASMBackendTest implements Opcodes { private final StringWriter sw = new StringWriter(); private final PrintWriter pw = new PrintWriter(sw); private final TraceClassVisitor visitor = new TraceClassVisitor(pw); protected TargetCompiler targetCompiler = getJavaCompiler(); protected TargetCompiler getJavaCompiler() { final String version = System.getProperty("java.version"); if (Scene.isJavaGEQ9(version)) { return TargetCompiler.javac9; } return TargetCompiler.javac; } /** Runs Soot with the arguments needed for running one test */ protected void runSoot() { G.reset(); // Location of the rt.jar String rtJar = ""; if (Scene.isJavaGEQ9(System.getProperty("java.version"))) { rtJar = ModulePathSourceLocator.DUMMY_CLASSPATH_JDK9_FS; } else { rtJar = System.getProperty("java.home") + File.separator + "lib" + File.separator + "rt.jar"; } String classpath = getClassPathFolder() + File.pathSeparator + rtJar; System.out.println("Class path: " + classpath); // Run Soot and print output to .asm-files. Main.main(new String[] { "-cp", classpath, "-src-prec", "only-class", "-output-format", "asm", "-allow-phantom-refs", "-java-version", getRequiredJavaVersion(), "-no-derive-java-version", getTargetClass() }); } /** Generates the textual output and saves it for later for comparison */ private String createComparison() throws IOException { generate(visitor); return sw.toString(); } /** * Compares the generated test output with Soot's output for the tested class line by line * * @throws FileNotFoundException * if either the file for comparison could not be created or the soot output could not be opened */ @Test public void runTestAndCompareOutput() throws IOException { runSoot(); String comparisonOutput = createComparison(); /* * Print output for comparison to file for debugging purposes. */ File compareFile = new File("sootOutput/" + getTargetClass() + ".asm.compare"); PrintWriter ow = new PrintWriter(compareFile); ow.print(comparisonOutput); ow.flush(); ow.close(); File targetFile = new File("sootOutput/" + getTargetClass() + ".asm"); assertTrue(String.format("Soot output file %s not found", targetFile.getAbsolutePath()), targetFile.exists()); Scanner sootOutput = new Scanner(targetFile); Scanner compareOutput = new Scanner(comparisonOutput); try { System.out.println( String.format("Comparing files %s and %s...", compareFile.getAbsolutePath(), targetFile.getAbsolutePath())); int line = 1; while (compareOutput.hasNextLine()) { // Soot-output must have as much lines as the compared output. assertTrue(String.format("Too few lines in Soot-output for class %s! Current line: %d. Comparison output: %s", getTargetClass(), line, comparisonOutput), sootOutput.hasNextLine()); // Get both lines String compare = compareOutput.nextLine(); String output = sootOutput.nextLine(); // Compare lines assertTrue(String.format("Expected line %s, but got %s in line %d for class %s", compare.trim(), output.trim(), line, getTargetClass()), compare.equals(output)); ++line; } assertFalse(String.format("Too many lines in Soot-output for class %s!", getTargetClass()), sootOutput.hasNextLine()); System.out.println("File comparison successful."); } finally { sootOutput.close(); compareOutput.close(); } } /** * Generates the textual output for comparison with Soot's output * * @param cw * The TraceClassVisitor used to generate the textual output */ protected abstract void generate(TraceClassVisitor cw); /** * Returns the name of the class to be tested * * @return The fully qualified name of the tested class */ protected abstract String getTargetClass(); /** * Return a folder for the process-dir option of Soot * * @return The location of the process-dir folder */ protected String getTargetFolder() { File f = new File("./target/test-classes"); return f.getAbsolutePath(); } /** * Returns the folder that is to be added to the class path for running soot * * @return The location of the folder containing the test files */ protected String getClassPathFolder() { File f = new File("./target/test-classes"); return f.getAbsolutePath(); } /** * Returns the Java version required, can be overridden by individual tests if needed * * @return The required Java version, "default" by default */ protected String getRequiredJavaVersion() { return "default"; } /** Enumeration containing the supported Java compilers */ enum TargetCompiler { eclipse, javac, javac9 } }
6,442
32.21134
125
java
soot
soot-master/src/test/java/soot/asm/backend/AbstractASMBackendTestWithSources.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.io.StringWriter; import java.util.Scanner; import org.junit.Before; import org.junit.Test; import org.objectweb.asm.Opcodes; import org.objectweb.asm.util.TraceClassVisitor; import soot.G; import soot.Main; import soot.ModulePathSourceLocator; import soot.Scene; /** * Abstract base class for tests for the ASM backend that work with source code files * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public abstract class AbstractASMBackendTestWithSources implements Opcodes { private final StringWriter sw = new StringWriter(); private final PrintWriter pw = new PrintWriter(sw); private final TraceClassVisitor visitor = new TraceClassVisitor(pw); private String comparisonOutput; /** * Sets up everything for testing by generation of Soot's output and reference output */ @Before public void setupTest() { runSoot(); createComparison(); } /** * Runs Soot with the arguments needed for running one test */ private void runSoot() { G.reset(); // Location of the rt.jar String rtJar = ""; if (Scene.isJavaGEQ9(System.getProperty("java.version"))) { rtJar = ModulePathSourceLocator.DUMMY_CLASSPATH_JDK9_FS; } else { rtJar = System.getProperty("java.home") + File.separator + "lib" + File.separator + "rt.jar"; } // Run Soot and print output to .asm-files. Main.main(new String[] { "-cp", getClassPathFolder() + File.pathSeparator + rtJar, "-src-prec", "java", "-output-format", "asm", "-allow-phantom-refs", "-keep-line-number", "-java-version", getRequiredJavaVersion(), "-no-derive-java-version", getTargetClass() }); } /** * Generates the textual output and saves it for later for comparison */ private void createComparison() { generate(visitor); comparisonOutput = sw.toString(); } /** * Compares the generated test output with Soot's output for the tested class line by line * * @throws FileNotFoundException * if either the file for comparison could not be created or the soot output could not be opened */ @Test public void compareOutput() throws FileNotFoundException { /* * Print output for comparison to file for debugging purposes. */ PrintWriter ow = new PrintWriter(new File("sootOutput/" + getTargetClass() + ".asm.compare")); ow.print(comparisonOutput); ow.flush(); ow.close(); Scanner sootOutput = new Scanner(new File("sootOutput/" + getTargetClass() + ".asm")); Scanner compareOutput = new Scanner(comparisonOutput); int line = 1; while (compareOutput.hasNextLine()) { // Soot-output must have as much lines as the compared output. assertTrue("Too few lines in Soot-output!", sootOutput.hasNextLine()); // Get both lines String compare = compareOutput.nextLine(); String output = sootOutput.nextLine(); // Compare lines assertTrue("Expected line " + compare.trim() + " but got " + output.trim() + " in line " + line, compare.equals(output)); ++line; } assertFalse("Too many lines in Soot-output!", sootOutput.hasNextLine()); sootOutput.close(); compareOutput.close(); } /** * Generates the textual output for comparison with Soot's output * * @param cw * The TraceClassVisitor used to generate the textual output */ protected abstract void generate(TraceClassVisitor cw); /** * Returns the name of the class to be tested * * @return The fully qualified name of the tested class */ protected abstract String getTargetClass(); /** * Return a folder for the process-dir option of Soot * * @return The location of the process-dir folder */ protected String getTargetFolder() { File f = new File("./target/test-classes"); return f.getAbsolutePath(); } /** * Returns the folder that is to be added to the class path for running soot * * @return The location of the folder containing the test files */ protected String getClassPathFolder() { File f = new File("./target/test-classes"); return f.getAbsolutePath(); } /** * Returns the Java version required, can be overridden by individual tests if needed * * @return The required Java version, "default" by default */ protected String getRequiredJavaVersion() { return "default"; } }
5,425
29.144444
149
java
soot
soot-master/src/test/java/soot/asm/backend/AnnotatedAnnotatedClassTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Type; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for annotations of annotations * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer */ public class AnnotatedAnnotatedClassTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor cw) { MethodVisitor mv; AnnotationVisitor av0; cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/AnnotatedAnnotatedClass", null, "java/lang/Object", null); cw.visitSource("AnnotatedAnnotatedClass.java", null); { av0 = cw.visitAnnotation("Lsoot/asm/backend/targets/MyAnnotatedAnnotation;", false); { AnnotationVisitor av1 = av0.visitAnnotation("value", "Lsoot/asm/backend/targets/MyTestAnnotation;"); av1.visit("iVal", new Integer(1)); av1.visit("fVal", new Float("1.0")); av1.visit("lVal", new Long(1L)); av1.visit("dVal", new Double("1.0")); av1.visit("zVal", Boolean.TRUE); av1.visit("bVal", new Byte((byte) 1)); av1.visit("sVal", new Short((short) 1)); av1.visit("strVal", "1"); av1.visit("rVal", Type.getType("Lsoot/asm/backend/targets/AnnotatedClass;")); av1.visit("iAVal", new int[] { 1, 2, 3, 4 }); { AnnotationVisitor av2 = av1.visitArray("sAVal"); av2.visit(null, "A"); av2.visit(null, "B"); av2.visit(null, "C"); av2.visitEnd(); } av1.visitEnd(); } av0.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.AnnotatedAnnotatedClass"; } }
2,910
31.707865
120
java
soot
soot-master/src/test/java/soot/asm/backend/AnnotatedAnnotationTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for annotation class that contains an annotation * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer */ public class AnnotatedAnnotationTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor cw) { MethodVisitor mv; cw.visit(V1_5, ACC_PUBLIC + ACC_ANNOTATION + ACC_ABSTRACT + ACC_INTERFACE, "soot/asm/backend/targets/MyAnnotatedAnnotation", null, "java/lang/Object", new String[] { "java/lang/annotation/Annotation" }); // TODO V1_1 seems wrong here cw.visitSource("MyAnnotatedAnnotation.java", null); { mv = cw.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, "value", "()Lsoot/asm/backend/targets/MyTestAnnotation;", null, null); mv.visitEnd(); } cw.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.MyAnnotatedAnnotation"; } }
1,838
30.706897
123
java
soot
soot-master/src/test/java/soot/asm/backend/AnnotatedClassTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Type; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for annotations on a class * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class AnnotatedClassTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor cw) { MethodVisitor mv; AnnotationVisitor av0; cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/AnnotatedClass", null, "java/lang/Object", null); cw.visitSource("AnnotatedClass.java", null); { av0 = cw.visitAnnotation("Lsoot/asm/backend/targets/MyTestAnnotation;", true); av0.visit("iVal", new Integer(1)); av0.visit("fVal", new Float("1.0")); av0.visit("lVal", new Long(1L)); av0.visit("dVal", new Double("1.0")); av0.visit("zVal", Boolean.TRUE); av0.visit("bVal", new Byte((byte) 1)); av0.visit("sVal", new Short((short) 1)); av0.visit("strVal", "1"); av0.visit("rVal", Type.getType("Lsoot/asm/backend/targets/AnnotatedClass;")); av0.visit("iAVal", new int[] { 1, 2, 3, 4 }); { AnnotationVisitor av1 = av0.visitArray("sAVal"); av1.visit(null, "A"); av1.visit(null, "B"); av1.visit(null, "C"); av1.visitEnd(); } av0.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.AnnotatedClass"; } }
2,679
29.454545
118
java
soot
soot-master/src/test/java/soot/asm/backend/AnnotatedFieldTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Type; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for annotations on fields * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class AnnotatedFieldTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor cw) { FieldVisitor fv; MethodVisitor mv; AnnotationVisitor av0; cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/AnnotatedField", null, "java/lang/Object", null); cw.visitSource("AnnotatedField.java", null); { fv = cw.visitField(0, "a", "Ljava/lang/String;", null, null); { av0 = fv.visitAnnotation("Lsoot/asm/backend/targets/MyTestAnnotation;", true); av0.visit("iVal", new Integer(124)); av0.visit("fVal", new Float("5132.0")); av0.visit("lVal", new Long(5123L)); av0.visit("dVal", new Double("745.0")); av0.visit("zVal", Boolean.TRUE); av0.visit("bVal", new Byte((byte) 1)); av0.visit("sVal", new Short((short) 123)); av0.visit("strVal", "435243"); av0.visit("rVal", Type.getType("Lsoot/asm/backend/targets/AnnotatedClass;")); av0.visit("iAVal", new int[] { 123, 234, 345, 456 }); { AnnotationVisitor av1 = av0.visitArray("sAVal"); av1.visit(null, "A"); av1.visit(null, "B"); av1.visit(null, "C"); av1.visitEnd(); } av0.visitEnd(); } fv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.AnnotatedField"; } @Override protected String getRequiredJavaVersion() { return "1.8"; } }
2,991
28.623762
118
java
soot
soot-master/src/test/java/soot/asm/backend/AnnotatedMethodTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Type; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for annotations on methods * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class AnnotatedMethodTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor cw) { MethodVisitor mv; AnnotationVisitor av0; cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/AnnotatedMethod", null, "java/lang/Object", null); cw.visitSource("AnnotatedMethod.java", null); { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "doSth", "()V", null, null); { av0 = mv.visitAnnotation("Lsoot/asm/backend/targets/MyTestAnnotation;", true); av0.visit("iVal", new Integer(124)); av0.visit("fVal", new Float("5132.0")); av0.visit("lVal", new Long(5123L)); av0.visit("dVal", new Double("745.0")); av0.visit("zVal", Boolean.TRUE); av0.visit("bVal", new Byte((byte) 1)); av0.visit("sVal", new Short((short) 123)); av0.visit("strVal", "435243"); av0.visit("rVal", Type.getType("Lsoot/asm/backend/targets/AnnotatedClass;")); av0.visit("iAVal", new int[] { 123, 234, 345, 456 }); { AnnotationVisitor av1 = av0.visitArray("sAVal"); av1.visit(null, "A"); av1.visit(null, "B"); av1.visit(null, "C"); av1.visitEnd(); } av0.visitEnd(); } mv.visitCode(); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.AnnotatedMethod"; } }
2,928
29.195876
119
java
soot
soot-master/src/test/java/soot/asm/backend/AnnotatedParameterTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Type; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for annotations on parameters * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class AnnotatedParameterTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor cw) { MethodVisitor mv; AnnotationVisitor av0; cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/AnnotatedParameter", null, "java/lang/Object", null); cw.visitSource("AnnotatedParameter.java", null); { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "doSth", "(Ljava/lang/String;)V", null, null); { av0 = mv.visitParameterAnnotation(0, "Lsoot/asm/backend/targets/MyTestAnnotation;", true); av0.visit("iVal", new Integer(1)); av0.visit("fVal", new Float("1.0")); av0.visit("lVal", new Long(1L)); av0.visit("dVal", new Double("1.0")); av0.visit("zVal", Boolean.TRUE); av0.visit("bVal", new Byte((byte) 1)); av0.visit("sVal", new Short((short) 1)); av0.visit("strVal", "1"); av0.visit("rVal", Type.getType("Lsoot/asm/backend/targets/AnnotatedClass;")); av0.visit("iAVal", new int[] { 1, 2, 3, 4 }); { AnnotationVisitor av1 = av0.visitArray("sAVal"); av1.visit(null, "A"); av1.visit(null, "B"); av1.visit(null, "C"); av1.visitEnd(); } av0.visitEnd(); } mv.visitCode(); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.AnnotatedParameter"; } }
2,947
29.708333
122
java
soot
soot-master/src/test/java/soot/asm/backend/AnnotationTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for an annotation class * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class AnnotationTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor cw) { MethodVisitor mv; AnnotationVisitor av0; cw.visit(V1_5, ACC_PUBLIC + ACC_ANNOTATION + ACC_ABSTRACT + ACC_INTERFACE, "soot/asm/backend/targets/MyTestAnnotation", null, "java/lang/Object", new String[] { "java/lang/annotation/Annotation" }); cw.visitSource("MyTestAnnotation.java", null); { av0 = cw.visitAnnotation("Ljava/lang/annotation/Retention;", true); av0.visitEnum("value", "Ljava/lang/annotation/RetentionPolicy;", "RUNTIME"); av0.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, "bVal", "()B", null, null); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, "dVal", "()D", null, null); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, "fVal", "()F", null, null); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, "iAVal", "()[I", null, null); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, "iVal", "()I", null, null); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, "lVal", "()J", null, null); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, "rVal", "()Ljava/lang/Class;", "()Ljava/lang/Class<Lsoot/asm/backend/targets/AnnotatedClass;>;", null); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, "sAVal", "()[Ljava/lang/String;", null, null); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, "sVal", "()S", null, null); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, "strVal", "()Ljava/lang/String;", null, null); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, "zVal", "()Z", null, null); mv.visitEnd(); } cw.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.MyTestAnnotation"; } }
3,243
28.490909
123
java
soot
soot-master/src/test/java/soot/asm/backend/ArithmeticTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for several arithmetic bytecode instructions * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class ArithmeticTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor cw) { FieldVisitor fv; MethodVisitor mv; cw.visit(V1_2, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/ArithmeticLib", null, "java/lang/Object", null); cw.visitSource("ArithmeticLib.java", null); { fv = cw.visitField(ACC_PRIVATE, "rInt", "I", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE, "rFloat", "F", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE, "rLong", "J", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE, "rDouble", "D", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE, "rShort", "S", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE, "rChar", "C", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE, "rByte", "B", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_FINAL, "cInt", "I", null, new Integer(1)); fv.visitEnd(); } { fv = cw.visitField(ACC_FINAL, "cFloat", "F", null, new Float("1.0")); fv.visitEnd(); } { fv = cw.visitField(ACC_FINAL, "cLong", "J", null, new Long(1L)); fv.visitEnd(); } { fv = cw.visitField(ACC_FINAL, "cDouble", "D", null, new Double("1.0")); fv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_1); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "cInt", "I"); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(FCONST_1); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "cFloat", "F"); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(LCONST_1); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "cLong", "J"); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(DCONST_1); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "cDouble", "D"); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "castInt2Byte", "()B", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ArithmeticLib", "rInt", "I"); mv.visitInsn(I2B); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rByte", "B"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ArithmeticLib", "rByte", "B"); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "castInt2Char", "()C", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ArithmeticLib", "rInt", "I"); mv.visitInsn(I2C); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rChar", "C"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ArithmeticLib", "rChar", "C"); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "castInt2Short", "()S", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ArithmeticLib", "rInt", "I"); mv.visitInsn(I2S); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rShort", "S"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ArithmeticLib", "rShort", "S"); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "doCompDouble", "(D)D", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(DLOAD, 1); mv.visitInsn(DCONST_1); mv.visitInsn(DDIV); mv.visitInsn(D2I); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rInt", "I"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(DLOAD, 1); mv.visitLdcInsn(new Double("6.0")); mv.visitInsn(DMUL); mv.visitInsn(D2L); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rLong", "J"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(DLOAD, 1); mv.visitInsn(DCONST_0); mv.visitInsn(DADD); mv.visitInsn(D2F); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rFloat", "F"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(DLOAD, 1); mv.visitLdcInsn(new Double("4.0")); mv.visitInsn(DSUB); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rDouble", "D"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ArithmeticLib", "rDouble", "D"); mv.visitInsn(DRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "doCompFloat", "(F)F", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(FLOAD, 1); mv.visitLdcInsn(new Float("13.0")); mv.visitInsn(FDIV); mv.visitInsn(F2I); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rInt", "I"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(FLOAD, 1); mv.visitLdcInsn(new Float("3.0")); mv.visitInsn(FMUL); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rFloat", "F"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(FLOAD, 1); mv.visitInsn(FCONST_2); mv.visitInsn(FSUB); mv.visitInsn(F2L); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rLong", "J"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(FLOAD, 1); mv.visitInsn(FCONST_1); mv.visitInsn(FADD); mv.visitInsn(F2D); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rDouble", "D"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ArithmeticLib", "rFloat", "F"); mv.visitInsn(FRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "doCompInt", "(I)I", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ILOAD, 1); mv.visitInsn(ICONST_M1); mv.visitInsn(IDIV); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rInt", "I"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ILOAD, 1); mv.visitIntInsn(BIPUSH, 17); mv.visitInsn(IMUL); mv.visitInsn(I2F); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rFloat", "F"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ILOAD, 1); mv.visitInsn(ICONST_5); mv.visitInsn(IADD); mv.visitInsn(I2L); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rLong", "J"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ILOAD, 1); mv.visitInsn(ICONST_2); mv.visitInsn(ISUB); mv.visitInsn(I2D); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rDouble", "D"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ArithmeticLib", "rInt", "I"); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "doCompLong", "(J)J", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(LLOAD, 1); mv.visitLdcInsn(new Long(5L)); mv.visitInsn(LMUL); mv.visitInsn(L2I); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rInt", "I"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(LLOAD, 1); mv.visitLdcInsn(new Long(2L)); mv.visitInsn(LADD); mv.visitInsn(L2F); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rFloat", "F"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(LLOAD, 1); mv.visitLdcInsn(new Long(6L)); mv.visitInsn(LMUL); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rLong", "J"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(LLOAD, 1); mv.visitLdcInsn(new Long(6L)); mv.visitInsn(LDIV); mv.visitInsn(L2D); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ArithmeticLib", "rDouble", "D"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ArithmeticLib", "rLong", "J"); mv.visitInsn(LRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.ArithmeticLib"; } @Override protected String getRequiredJavaVersion() { return "1.2"; } }
10,468
34.130872
117
java
soot
soot-master/src/test/java/soot/asm/backend/ArraysTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for array stores, loads and creation * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class ArraysTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor cw) { MethodVisitor mv; cw.visit(V1_1, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/Arrays", null, "java/lang/Object", null); cw.visitSource("Arrays.java", null); { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "doBool", "()V", null, null); mv.visitCode(); mv.visitInsn(ICONST_3); mv.visitIntInsn(NEWARRAY, T_BOOLEAN); mv.visitInsn(DUP); mv.visitInsn(ICONST_1); mv.visitInsn(BALOAD); mv.visitVarInsn(ISTORE, 0); mv.visitInsn(ICONST_0); mv.visitVarInsn(ILOAD, 0); mv.visitInsn(BASTORE); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "doByte", "()V", null, null); mv.visitCode(); mv.visitInsn(ICONST_4); mv.visitIntInsn(NEWARRAY, T_BYTE); mv.visitInsn(DUP); mv.visitInsn(ICONST_1); mv.visitInsn(BALOAD); mv.visitVarInsn(ISTORE, 0); mv.visitInsn(ICONST_0); mv.visitVarInsn(ILOAD, 0); mv.visitInsn(BASTORE); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "doChar", "()V", null, null); mv.visitCode(); mv.visitInsn(ICONST_5); mv.visitIntInsn(NEWARRAY, T_CHAR); mv.visitInsn(DUP); mv.visitInsn(ICONST_1); mv.visitInsn(CALOAD); mv.visitVarInsn(ISTORE, 0); mv.visitInsn(ICONST_0); mv.visitVarInsn(ILOAD, 0); mv.visitInsn(CASTORE); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "doDouble", "()V", null, null); mv.visitCode(); mv.visitIntInsn(BIPUSH, 6); mv.visitIntInsn(NEWARRAY, T_DOUBLE); mv.visitInsn(DUP); mv.visitInsn(ICONST_1); mv.visitInsn(DALOAD); mv.visitVarInsn(DSTORE, 1); mv.visitInsn(ICONST_0); mv.visitVarInsn(DLOAD, 1); mv.visitInsn(DASTORE); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "doFloat", "()V", null, null); mv.visitCode(); mv.visitIntInsn(BIPUSH, 7); mv.visitIntInsn(NEWARRAY, T_FLOAT); mv.visitInsn(DUP); mv.visitInsn(ICONST_1); mv.visitInsn(FALOAD); mv.visitVarInsn(FSTORE, 0); mv.visitInsn(ICONST_0); mv.visitVarInsn(FLOAD, 0); mv.visitInsn(FASTORE); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "doInt", "()V", null, null); mv.visitCode(); mv.visitIntInsn(BIPUSH, 8); mv.visitIntInsn(NEWARRAY, T_INT); mv.visitInsn(DUP); mv.visitInsn(ICONST_1); mv.visitInsn(IALOAD); mv.visitVarInsn(ISTORE, 0); mv.visitInsn(ICONST_0); mv.visitVarInsn(ILOAD, 0); mv.visitInsn(IASTORE); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "doIntInt", "()V", null, null); mv.visitCode(); mv.visitInsn(ICONST_3); mv.visitInsn(ICONST_3); mv.visitMultiANewArrayInsn("[[I", 2); mv.visitVarInsn(ASTORE, 0); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_0); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_1); mv.visitInsn(AALOAD); mv.visitInsn(AASTORE); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_1); mv.visitInsn(AALOAD); mv.visitInsn(ICONST_2); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_2); mv.visitInsn(AALOAD); mv.visitInsn(ICONST_1); mv.visitInsn(IALOAD); mv.visitInsn(IASTORE); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "doLong", "()V", null, null); mv.visitCode(); mv.visitIntInsn(BIPUSH, 9); mv.visitIntInsn(NEWARRAY, T_LONG); mv.visitInsn(DUP); mv.visitInsn(ICONST_1); mv.visitInsn(LALOAD); mv.visitVarInsn(LSTORE, 1); mv.visitInsn(ICONST_0); mv.visitVarInsn(LLOAD, 1); mv.visitInsn(LASTORE); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "doObject", "()V", null, null); mv.visitCode(); mv.visitIntInsn(BIPUSH, 11); mv.visitTypeInsn(ANEWARRAY, "java/lang/Object"); mv.visitVarInsn(ASTORE, 0); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_0); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_1); mv.visitInsn(AALOAD); mv.visitInsn(AASTORE); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_3); mv.visitInsn(ACONST_NULL); mv.visitInsn(AASTORE); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "doObjectObject", "()V", null, null); mv.visitCode(); mv.visitInsn(ICONST_4); mv.visitInsn(ICONST_4); mv.visitMultiANewArrayInsn("[[Ljava/lang/Object;", 2); mv.visitVarInsn(ASTORE, 0); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_0); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_1); mv.visitInsn(AALOAD); mv.visitInsn(AASTORE); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_1); mv.visitInsn(AALOAD); mv.visitInsn(ICONST_2); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_2); mv.visitInsn(AALOAD); mv.visitInsn(ICONST_1); mv.visitInsn(AALOAD); mv.visitInsn(AASTORE); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "doShort", "()V", null, null); mv.visitCode(); mv.visitIntInsn(BIPUSH, 10); mv.visitIntInsn(NEWARRAY, T_SHORT); mv.visitInsn(DUP); mv.visitInsn(ICONST_1); mv.visitInsn(SALOAD); mv.visitVarInsn(ISTORE, 0); mv.visitInsn(ICONST_0); mv.visitVarInsn(ILOAD, 0); mv.visitInsn(SASTORE); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "doString", "()V", null, null); mv.visitCode(); mv.visitIntInsn(BIPUSH, 12); mv.visitTypeInsn(ANEWARRAY, "java/lang/String"); mv.visitInsn(DUP); mv.visitInsn(ICONST_1); mv.visitInsn(AALOAD); mv.visitVarInsn(ASTORE, 0); mv.visitInsn(ICONST_0); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(AASTORE); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.Arrays"; } }
8,073
27.631206
110
java
soot
soot-master/src/test/java/soot/asm/backend/CompareArithmeticInstructions2Test.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for less-than and greater-equal bytecode instructions * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class CompareArithmeticInstructions2Test extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor cw) { FieldVisitor fv; MethodVisitor mv; cw.visit(V1_1, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/CompareArithmeticInstructions2", null, "java/lang/Object", null); cw.visitSource("CompareArithmeticInstructions2.java", null); { fv = cw.visitField(0, "i", "I", null, null); fv.visitEnd(); } { fv = cw.visitField(0, "f", "F", null, null); fv.visitEnd(); } { fv = cw.visitField(0, "d", "D", null, null); fv.visitEnd(); } { fv = cw.visitField(0, "l", "J", null, null); fv.visitEnd(); } { fv = cw.visitField(0, "b", "B", null, null); fv.visitEnd(); } { fv = cw.visitField(0, "c", "C", null, null); fv.visitEnd(); } { fv = cw.visitField(0, "s", "S", null, null); fv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_2); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "i", "I"); mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn(new Float("221349.02")); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "f", "F"); mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn(new Double("2123996.1231231233")); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "d", "D"); mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn(new Long(2L)); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "l", "J"); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_2); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "b", "B"); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_4); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "c", "C"); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_3); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "s", "S"); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "compareb", "(B)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "b", "B"); mv.visitVarInsn(ILOAD, 1); Label l0 = new Label(); mv.visitJumpInsn(IF_ICMPLT, l0); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_2); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "b", "B"); mv.visitLabel(l0); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "b", "B"); mv.visitVarInsn(ILOAD, 1); Label l1 = new Label(); mv.visitJumpInsn(IF_ICMPGE, l1); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_1); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "b", "B"); mv.visitLabel(l1); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "comparec", "(C)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "c", "C"); mv.visitVarInsn(ILOAD, 1); Label l0 = new Label(); mv.visitJumpInsn(IF_ICMPLT, l0); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_2); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "c", "C"); mv.visitLabel(l0); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "c", "C"); mv.visitVarInsn(ILOAD, 1); Label l1 = new Label(); mv.visitJumpInsn(IF_ICMPGE, l1); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_3); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "c", "C"); mv.visitLabel(l1); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "compared", "(D)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "d", "D"); mv.visitVarInsn(DLOAD, 1); mv.visitInsn(DCMPL); Label l0 = new Label(); mv.visitJumpInsn(IFLT, l0); mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn(new Double("2.0")); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "d", "D"); mv.visitLabel(l0); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "d", "D"); mv.visitVarInsn(DLOAD, 1); mv.visitInsn(DCMPG); Label l1 = new Label(); mv.visitJumpInsn(IFGE, l1); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(DCONST_1); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "d", "D"); mv.visitLabel(l1); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "comparef", "(F)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "f", "F"); mv.visitVarInsn(FLOAD, 1); mv.visitInsn(FCMPL); Label l0 = new Label(); mv.visitJumpInsn(IFLT, l0); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(FCONST_2); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "f", "F"); mv.visitLabel(l0); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "f", "F"); mv.visitVarInsn(FLOAD, 1); mv.visitInsn(FCMPG); Label l1 = new Label(); mv.visitJumpInsn(IFGE, l1); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(FCONST_1); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "f", "F"); mv.visitLabel(l1); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "comparei", "(I)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "i", "I"); mv.visitVarInsn(ILOAD, 1); Label l0 = new Label(); mv.visitJumpInsn(IF_ICMPLT, l0); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_2); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "i", "I"); mv.visitLabel(l0); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "i", "I"); mv.visitVarInsn(ILOAD, 1); Label l1 = new Label(); mv.visitJumpInsn(IF_ICMPGE, l1); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_1); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "i", "I"); mv.visitLabel(l1); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "comparel", "(J)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "l", "J"); mv.visitVarInsn(LLOAD, 1); mv.visitInsn(LCMP); Label l0 = new Label(); mv.visitJumpInsn(IFLT, l0); mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn(new Long(2L)); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "l", "J"); mv.visitLabel(l0); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "l", "J"); mv.visitVarInsn(LLOAD, 1); mv.visitInsn(LCMP); Label l1 = new Label(); mv.visitJumpInsn(IFGE, l1); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(LCONST_1); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "l", "J"); mv.visitLabel(l1); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "compares", "(S)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "s", "S"); mv.visitVarInsn(ILOAD, 1); Label l0 = new Label(); mv.visitJumpInsn(IF_ICMPLT, l0); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_1); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "s", "S"); mv.visitLabel(l0); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "s", "S"); mv.visitVarInsn(ILOAD, 1); Label l1 = new Label(); mv.visitJumpInsn(IF_ICMPGE, l1); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_3); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstructions2", "s", "S"); mv.visitLabel(l1); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.CompareArithmeticInstructions2"; } }
11,999
37.338658
107
java
soot
soot-master/src/test/java/soot/asm/backend/CompareArithmeticInstructionsTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for greater-than and less-equal bytecode instructions * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class CompareArithmeticInstructionsTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor cw) { FieldVisitor fv; MethodVisitor mv; cw.visit(V1_1, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/CompareArithmeticInstuctions", null, "java/lang/Object", null); cw.visitSource("CompareArithmeticInstuctions.java", null); { fv = cw.visitField(0, "i", "I", null, null); fv.visitEnd(); } { fv = cw.visitField(0, "f", "F", null, null); fv.visitEnd(); } { fv = cw.visitField(0, "d", "D", null, null); fv.visitEnd(); } { fv = cw.visitField(0, "l", "J", null, null); fv.visitEnd(); } { fv = cw.visitField(0, "b", "B", null, null); fv.visitEnd(); } { fv = cw.visitField(0, "c", "C", null, null); fv.visitEnd(); } { fv = cw.visitField(0, "s", "S", null, null); fv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_2); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "i", "I"); mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn(new Float("221349.02")); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "f", "F"); mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn(new Double("2123996.1231231233")); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "d", "D"); mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn(new Long(2L)); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "l", "J"); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_2); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "b", "B"); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_4); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "c", "C"); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_3); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "s", "S"); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "compareb", "(B)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "b", "B"); mv.visitVarInsn(ILOAD, 1); Label l0 = new Label(); mv.visitJumpInsn(IF_ICMPGT, l0); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_2); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "b", "B"); mv.visitLabel(l0); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "b", "B"); mv.visitVarInsn(ILOAD, 1); Label l1 = new Label(); mv.visitJumpInsn(IF_ICMPLE, l1); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_1); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "b", "B"); mv.visitLabel(l1); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "comparec", "(C)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "c", "C"); mv.visitVarInsn(ILOAD, 1); Label l0 = new Label(); mv.visitJumpInsn(IF_ICMPGT, l0); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_2); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "c", "C"); mv.visitLabel(l0); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "c", "C"); mv.visitVarInsn(ILOAD, 1); Label l1 = new Label(); mv.visitJumpInsn(IF_ICMPLE, l1); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_3); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "c", "C"); mv.visitLabel(l1); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "compared", "(D)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "d", "D"); mv.visitVarInsn(DLOAD, 1); mv.visitInsn(DCMPG); Label l0 = new Label(); mv.visitJumpInsn(IFGT, l0); mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn(new Double("2.0")); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "d", "D"); mv.visitLabel(l0); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "d", "D"); mv.visitVarInsn(DLOAD, 1); mv.visitInsn(DCMPL); Label l1 = new Label(); mv.visitJumpInsn(IFLE, l1); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(DCONST_1); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "d", "D"); mv.visitLabel(l1); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "comparef", "(F)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "f", "F"); mv.visitVarInsn(FLOAD, 1); mv.visitInsn(FCMPG); Label l0 = new Label(); mv.visitJumpInsn(IFGT, l0); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(FCONST_2); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "f", "F"); mv.visitLabel(l0); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "f", "F"); mv.visitVarInsn(FLOAD, 1); mv.visitInsn(FCMPL); Label l1 = new Label(); mv.visitJumpInsn(IFLE, l1); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(FCONST_1); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "f", "F"); mv.visitLabel(l1); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "comparei", "(I)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "i", "I"); mv.visitVarInsn(ILOAD, 1); Label l0 = new Label(); mv.visitJumpInsn(IF_ICMPGT, l0); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_2); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "i", "I"); mv.visitLabel(l0); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "i", "I"); mv.visitVarInsn(ILOAD, 1); Label l1 = new Label(); mv.visitJumpInsn(IF_ICMPLE, l1); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_1); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "i", "I"); mv.visitLabel(l1); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "comparel", "(J)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "l", "J"); mv.visitVarInsn(LLOAD, 1); mv.visitInsn(LCMP); Label l0 = new Label(); mv.visitJumpInsn(IFGT, l0); mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn(new Long(2L)); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "l", "J"); mv.visitLabel(l0); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "l", "J"); mv.visitVarInsn(LLOAD, 1); mv.visitInsn(LCMP); Label l1 = new Label(); mv.visitJumpInsn(IFLE, l1); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(LCONST_1); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "l", "J"); mv.visitLabel(l1); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "compares", "(S)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "s", "S"); mv.visitVarInsn(ILOAD, 1); Label l0 = new Label(); mv.visitJumpInsn(IF_ICMPGT, l0); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_1); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "s", "S"); mv.visitLabel(l0); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "s", "S"); mv.visitVarInsn(ILOAD, 1); Label l1 = new Label(); mv.visitJumpInsn(IF_ICMPLE, l1); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_3); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareArithmeticInstuctions", "s", "S"); mv.visitLabel(l1); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.CompareArithmeticInstuctions"; } }
11,922
37.092652
125
java
soot
soot-master/src/test/java/soot/asm/backend/CompareInstructionsTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for equals and not-equals bytecode instructions * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class CompareInstructionsTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor cw) { FieldVisitor fv; MethodVisitor mv; cw.visit(V1_1, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/CompareInstructions", null, "java/lang/Object", null); cw.visitSource("CompareInstructions.java", null); { fv = cw.visitField(0, "i", "I", null, null); fv.visitEnd(); } { fv = cw.visitField(0, "f", "F", null, null); fv.visitEnd(); } { fv = cw.visitField(0, "d", "D", null, null); fv.visitEnd(); } { fv = cw.visitField(0, "l", "J", null, null); fv.visitEnd(); } { fv = cw.visitField(0, "b", "B", null, null); fv.visitEnd(); } { fv = cw.visitField(0, "bool", "Z", null, null); fv.visitEnd(); } { fv = cw.visitField(0, "c", "C", null, null); fv.visitEnd(); } { fv = cw.visitField(0, "s", "S", null, null); fv.visitEnd(); } { fv = cw.visitField(0, "o", "Ljava/lang/Object;", null, null); fv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_2); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareInstructions", "i", "I"); mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn(new Float("221349.02")); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareInstructions", "f", "F"); mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn(new Double("2123996.1231231233")); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareInstructions", "d", "D"); mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn(new Long(2L)); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareInstructions", "l", "J"); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_2); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareInstructions", "b", "B"); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_1); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareInstructions", "bool", "Z"); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_4); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareInstructions", "c", "C"); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_3); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareInstructions", "s", "S"); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "compareBool", "(Z)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareInstructions", "bool", "Z"); mv.visitVarInsn(ILOAD, 1); Label l0 = new Label(); mv.visitJumpInsn(IF_ICMPNE, l0); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_1); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareInstructions", "bool", "Z"); mv.visitLabel(l0); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareInstructions", "bool", "Z"); mv.visitVarInsn(ILOAD, 1); Label l1 = new Label(); mv.visitJumpInsn(IF_ICMPEQ, l1); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_0); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareInstructions", "bool", "Z"); mv.visitLabel(l1); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "compareb", "(B)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareInstructions", "b", "B"); mv.visitVarInsn(ILOAD, 1); Label l0 = new Label(); mv.visitJumpInsn(IF_ICMPNE, l0); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_2); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareInstructions", "b", "B"); mv.visitLabel(l0); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareInstructions", "b", "B"); mv.visitVarInsn(ILOAD, 1); Label l1 = new Label(); mv.visitJumpInsn(IF_ICMPEQ, l1); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_1); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareInstructions", "b", "B"); mv.visitLabel(l1); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "comparec", "(C)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareInstructions", "c", "C"); mv.visitVarInsn(ILOAD, 1); Label l0 = new Label(); mv.visitJumpInsn(IF_ICMPNE, l0); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_2); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareInstructions", "c", "C"); mv.visitLabel(l0); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareInstructions", "c", "C"); mv.visitVarInsn(ILOAD, 1); Label l1 = new Label(); mv.visitJumpInsn(IF_ICMPEQ, l1); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_3); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareInstructions", "c", "C"); mv.visitLabel(l1); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "compared", "(D)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareInstructions", "d", "D"); mv.visitVarInsn(DLOAD, 1); mv.visitInsn(DCMPL); Label l0 = new Label(); mv.visitJumpInsn(IFNE, l0); mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn(new Double("2.0")); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareInstructions", "d", "D"); mv.visitLabel(l0); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareInstructions", "d", "D"); mv.visitVarInsn(DLOAD, 1); mv.visitInsn(DCMPL); Label l1 = new Label(); mv.visitJumpInsn(IFEQ, l1); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(DCONST_1); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareInstructions", "d", "D"); mv.visitLabel(l1); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "comparef", "(F)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareInstructions", "f", "F"); mv.visitVarInsn(FLOAD, 1); mv.visitInsn(FCMPL); Label l0 = new Label(); mv.visitJumpInsn(IFNE, l0); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(FCONST_0); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareInstructions", "f", "F"); mv.visitLabel(l0); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareInstructions", "f", "F"); mv.visitVarInsn(FLOAD, 1); mv.visitInsn(FCMPL); Label l1 = new Label(); mv.visitJumpInsn(IFEQ, l1); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(FCONST_1); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareInstructions", "f", "F"); mv.visitLabel(l1); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "comparei", "(I)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareInstructions", "i", "I"); mv.visitVarInsn(ILOAD, 1); Label l0 = new Label(); mv.visitJumpInsn(IF_ICMPNE, l0); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_2); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareInstructions", "i", "I"); mv.visitLabel(l0); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareInstructions", "i", "I"); mv.visitVarInsn(ILOAD, 1); Label l1 = new Label(); mv.visitJumpInsn(IF_ICMPEQ, l1); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_1); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareInstructions", "i", "I"); mv.visitLabel(l1); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "comparel", "(J)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareInstructions", "l", "J"); mv.visitVarInsn(LLOAD, 1); mv.visitInsn(LCMP); Label l0 = new Label(); mv.visitJumpInsn(IFNE, l0); mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn(new Long(2L)); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareInstructions", "l", "J"); mv.visitLabel(l0); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareInstructions", "l", "J"); mv.visitVarInsn(LLOAD, 1); mv.visitInsn(LCMP); Label l1 = new Label(); mv.visitJumpInsn(IFEQ, l1); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(LCONST_1); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareInstructions", "l", "J"); mv.visitLabel(l1); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "comparenull", "(Ljava/lang/Object;)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareInstructions", "o", "Ljava/lang/Object;"); Label l0 = new Label(); mv.visitJumpInsn(IFNONNULL, l0); mv.visitVarInsn(ALOAD, 0); mv.visitTypeInsn(NEW, "java/lang/Object"); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareInstructions", "o", "Ljava/lang/Object;"); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 1); Label l1 = new Label(); mv.visitJumpInsn(IFNULL, l1); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ACONST_NULL); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareInstructions", "o", "Ljava/lang/Object;"); mv.visitLabel(l1); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "compares", "(S)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareInstructions", "s", "S"); mv.visitVarInsn(ILOAD, 1); Label l0 = new Label(); mv.visitJumpInsn(IF_ICMPNE, l0); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_1); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareInstructions", "s", "S"); mv.visitLabel(l0); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/CompareInstructions", "s", "S"); mv.visitVarInsn(ILOAD, 1); Label l1 = new Label(); mv.visitJumpInsn(IF_ICMPEQ, l1); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_3); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/CompareInstructions", "s", "S"); mv.visitLabel(l1); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.CompareInstructions"; } }
14,053
36.57754
123
java
soot
soot-master/src/test/java/soot/asm/backend/ConstantPoolTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import static org.junit.Assert.fail; import java.io.File; import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import org.junit.Test; import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.util.TraceClassVisitor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import soot.G; import soot.Main; /** * Test for fields that contain constant values * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class ConstantPoolTest extends AbstractASMBackendTest { private static final Logger logger = LoggerFactory.getLogger(ConstantPoolTest.class); @Override protected void generate(TraceClassVisitor cw) { FieldVisitor fv; MethodVisitor mv; cw.visit(V1_1, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/ConstantPool", null, "java/lang/Object", null); cw.visitSource("ConstantPool.java", null); { fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "s1", "Ljava/lang/String;", null, "H:mm:ss.SSS"); fv.visitEnd(); } { fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "s2", "Ljava/lang/String;", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "o1", "Ljava/lang/Object;", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "o2", "Ljava/lang/Object;", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "o3", "Ljava/lang/Object;", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "o4", "Ljava/lang/Object;", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "o5", "Ljava/lang/Object;", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "i1", "I", null, new Integer(123)); fv.visitEnd(); } { fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "i2", "I", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "l1", "J", null, new Long(12233L)); fv.visitEnd(); } { fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "l2", "J", null, new Long(123L)); fv.visitEnd(); } { fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "l3", "J", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "d1", "D", null, new Double("123.142")); fv.visitEnd(); } { fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "d2", "D", null, new Double("1234.123046875")); fv.visitEnd(); } { fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "d3", "D", null, null); fv.visitEnd(); } { mv = cw.visitMethod(ACC_STATIC, "<clinit>", "()V", null, null); mv.visitCode(); mv.visitInsn(ACONST_NULL); mv.visitFieldInsn(PUTSTATIC, "soot/asm/backend/targets/ConstantPool", "s2", "Ljava/lang/String;"); mv.visitLdcInsn("O"); mv.visitFieldInsn(PUTSTATIC, "soot/asm/backend/targets/ConstantPool", "o1", "Ljava/lang/Object;"); mv.visitInsn(ACONST_NULL); mv.visitFieldInsn(PUTSTATIC, "soot/asm/backend/targets/ConstantPool", "o2", "Ljava/lang/Object;"); mv.visitIntInsn(BIPUSH, 123); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false); mv.visitFieldInsn(PUTSTATIC, "soot/asm/backend/targets/ConstantPool", "o3", "Ljava/lang/Object;"); mv.visitLdcInsn(new Long(1234L)); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;", false); mv.visitFieldInsn(PUTSTATIC, "soot/asm/backend/targets/ConstantPool", "o4", "Ljava/lang/Object;"); mv.visitLdcInsn(new Double("123.3")); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;", false); mv.visitFieldInsn(PUTSTATIC, "soot/asm/backend/targets/ConstantPool", "o5", "Ljava/lang/Object;"); mv.visitTypeInsn(NEW, "java/lang/Integer"); mv.visitInsn(DUP); mv.visitIntInsn(BIPUSH, 123); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Integer", "<init>", "(I)V", false); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Integer", "intValue", "()I", false); mv.visitFieldInsn(PUTSTATIC, "soot/asm/backend/targets/ConstantPool", "i2", "I"); mv.visitTypeInsn(NEW, "java/lang/Long"); mv.visitInsn(DUP); mv.visitLdcInsn(new Long(12341L)); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Long", "<init>", "(J)V", false); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Long", "longValue", "()J", false); mv.visitFieldInsn(PUTSTATIC, "soot/asm/backend/targets/ConstantPool", "l3", "J"); mv.visitTypeInsn(NEW, "java/lang/Double"); mv.visitInsn(DUP); mv.visitLdcInsn(new Double("1234.123")); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Double", "<init>", "(D)V", false); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Double", "doubleValue", "()D", false); mv.visitFieldInsn(PUTSTATIC, "soot/asm/backend/targets/ConstantPool", "d3", "D"); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); } @Test public void loadClass() { G.reset(); // Location of the rt.jar String rtJar = System.getProperty("java.home") + File.separator + "lib" + File.separator + "rt.jar"; // Run Soot and print output to .asm-files. Main.main(new String[] { "-cp", getClassPathFolder() + File.pathSeparator + rtJar, "-process-dir", getTargetFolder(), "-src-prec", "only-class", "-output-format", "class", "-asm-backend", "-allow-phantom-refs", "-java-version", getRequiredJavaVersion(), getTargetClass() }); File file = new File("./sootOutput/ConstantPool.class"); URL[] urls = null; try { URL url = file.toURI().toURL(); urls = new URL[] { url }; URLClassLoader cl = new URLClassLoader(urls); cl.loadClass(getTargetClass()); // cl.close(); // Java 6 backwards compatibility hack try { for (Method m : URLClassLoader.class.getDeclaredMethods()) { if (m.getName().equals("close")) { m.invoke(cl); break; } } } catch (Exception e) { } return; } catch (MalformedURLException e) { logger.error(e.getMessage(), e); } catch (ClassNotFoundException e) { logger.error(e.getMessage(), e); } fail(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.ConstantPool"; } }
7,989
34.829596
121
java
soot
soot-master/src/test/java/soot/asm/backend/ControlStructuresTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for table and lookup switch bytecode instructions * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class ControlStructuresTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor cw) { MethodVisitor mv; FieldVisitor fv; cw.visit(V1_6, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/ControlStructures", null, "java/lang/Object", null); cw.visitSource("ControlStructures.java", null); { fv = cw.visitField(0, "result", "Ljava/util/List;", "Ljava/util/List<Ljava/lang/Integer;>;", null); fv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PROTECTED, "get", "(I)Ljava/util/List;", "(I)Ljava/util/List<Ljava/lang/Integer;>;", null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitTypeInsn(NEW, "java/util/ArrayList"); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, "java/util/ArrayList", "<init>", "()V", false); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ControlStructures", "result", "Ljava/util/List;"); mv.visitVarInsn(ILOAD, 1); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); Label l3 = new Label(); mv.visitTableSwitchInsn(1, 3, l3, new Label[] { l0, l1, l2 }); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ControlStructures", "result", "Ljava/util/List;"); mv.visitInsn(ICONST_1); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true); mv.visitInsn(POP); Label l4 = new Label(); mv.visitJumpInsn(GOTO, l4); mv.visitLabel(l1); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ControlStructures", "result", "Ljava/util/List;"); mv.visitInsn(ICONST_2); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true); mv.visitInsn(POP); mv.visitLabel(l2); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ControlStructures", "result", "Ljava/util/List;"); mv.visitInsn(ICONST_3); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true); mv.visitInsn(POP); mv.visitJumpInsn(GOTO, l4); mv.visitLabel(l3); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ControlStructures", "result", "Ljava/util/List;"); mv.visitInsn(ACONST_NULL); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true); mv.visitInsn(POP); mv.visitLabel(l4); mv.visitVarInsn(ILOAD, 1); Label l5 = new Label(); Label l6 = new Label(); Label l7 = new Label(); Label l8 = new Label(); Label l9 = new Label(); mv.visitLookupSwitchInsn(l9, new int[] { 1, 10, 100, 1000 }, new Label[] { l5, l6, l7, l8 }); mv.visitLabel(l5); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ControlStructures", "result", "Ljava/util/List;"); mv.visitInsn(ICONST_1); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true); mv.visitInsn(POP); mv.visitLabel(l6); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ControlStructures", "result", "Ljava/util/List;"); mv.visitIntInsn(BIPUSH, 10); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true); mv.visitInsn(POP); mv.visitLabel(l7); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ControlStructures", "result", "Ljava/util/List;"); mv.visitIntInsn(BIPUSH, 100); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true); mv.visitInsn(POP); mv.visitLabel(l8); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ControlStructures", "result", "Ljava/util/List;"); mv.visitIntInsn(SIPUSH, 1000); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true); mv.visitInsn(POP); mv.visitLabel(l9); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ControlStructures", "result", "Ljava/util/List;"); mv.visitInsn(ACONST_NULL); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true); mv.visitInsn(POP); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ControlStructures", "result", "Ljava/util/List;"); mv.visitInsn(ARETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.ControlStructures"; } @Override protected String getRequiredJavaVersion() { return "1.6"; } }
7,133
41.464286
121
java
soot
soot-master/src/test/java/soot/asm/backend/DupsTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for dup bytecode instructions * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class DupsTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor cw) { MethodVisitor mv; cw.visit(V1_1, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/Dups", null, "java/lang/Object", null); cw.visitSource("Dups.java", null); { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "dubl", "()J", null, null); mv.visitCode(); // Note that due to constant folding we already evaluated 1234+1234 mv.visitLdcInsn(new Long(2468L)); mv.visitInsn(LRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "dup", "()Ljava/lang/Object;", null, null); mv.visitCode(); mv.visitTypeInsn(NEW, "java/lang/Object"); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(ARETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.Dups"; } }
2,410
28.402439
108
java
soot
soot-master/src/test/java/soot/asm/backend/EnumTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Type; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for enum classes * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class EnumTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor cw) { FieldVisitor fv; MethodVisitor mv; cw.visit(V1_5, ACC_PUBLIC + ACC_FINAL + ACC_SUPER + ACC_ENUM, "soot/asm/backend/targets/MyEnum", "Ljava/lang/Enum<Lsoot/asm/backend/targets/MyEnum;>;", "java/lang/Enum", null); cw.visitSource("MyEnum.java", null); { fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC + ACC_ENUM, "JA", "Lsoot/asm/backend/targets/MyEnum;", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC + ACC_ENUM, "NEIN", "Lsoot/asm/backend/targets/MyEnum;", null, null); fv.visitEnd(); } { if (targetCompiler == TargetCompiler.eclipse) fv = cw.visitField(ACC_PRIVATE + ACC_FINAL + ACC_STATIC + ACC_SYNTHETIC, "ENUM$VALUES", "[Lsoot/asm/backend/targets/MyEnum;", null, null); else fv = cw.visitField(ACC_PRIVATE + ACC_FINAL + ACC_STATIC + ACC_SYNTHETIC, "$VALUES", "[Lsoot/asm/backend/targets/MyEnum;", null, null); fv.visitEnd(); } { mv = cw.visitMethod(ACC_STATIC, "<clinit>", "()V", null, null); mv.visitCode(); mv.visitTypeInsn(NEW, "soot/asm/backend/targets/MyEnum"); mv.visitInsn(DUP); mv.visitLdcInsn("JA"); mv.visitInsn(ICONST_0); mv.visitMethodInsn(INVOKESPECIAL, "soot/asm/backend/targets/MyEnum", "<init>", "(Ljava/lang/String;I)V", false); mv.visitFieldInsn(PUTSTATIC, "soot/asm/backend/targets/MyEnum", "JA", "Lsoot/asm/backend/targets/MyEnum;"); mv.visitTypeInsn(NEW, "soot/asm/backend/targets/MyEnum"); mv.visitInsn(DUP); mv.visitLdcInsn("NEIN"); mv.visitInsn(ICONST_1); mv.visitMethodInsn(INVOKESPECIAL, "soot/asm/backend/targets/MyEnum", "<init>", "(Ljava/lang/String;I)V", false); mv.visitFieldInsn(PUTSTATIC, "soot/asm/backend/targets/MyEnum", "NEIN", "Lsoot/asm/backend/targets/MyEnum;"); mv.visitInsn(ICONST_2); mv.visitTypeInsn(ANEWARRAY, "soot/asm/backend/targets/MyEnum"); mv.visitVarInsn(ASTORE, 0); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_0); mv.visitFieldInsn(GETSTATIC, "soot/asm/backend/targets/MyEnum", "JA", "Lsoot/asm/backend/targets/MyEnum;"); mv.visitInsn(AASTORE); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ICONST_1); mv.visitFieldInsn(GETSTATIC, "soot/asm/backend/targets/MyEnum", "NEIN", "Lsoot/asm/backend/targets/MyEnum;"); mv.visitInsn(AASTORE); mv.visitVarInsn(ALOAD, 0); if (targetCompiler == TargetCompiler.eclipse) mv.visitFieldInsn(PUTSTATIC, "soot/asm/backend/targets/MyEnum", "ENUM$VALUES", "[Lsoot/asm/backend/targets/MyEnum;"); else mv.visitFieldInsn(PUTSTATIC, "soot/asm/backend/targets/MyEnum", "$VALUES", "[Lsoot/asm/backend/targets/MyEnum;"); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { if (targetCompiler == TargetCompiler.eclipse) mv = cw.visitMethod(ACC_PRIVATE, "<init>", "(Ljava/lang/String;I)V", null, null); else mv = cw.visitMethod(ACC_PRIVATE, "<init>", "(Ljava/lang/String;I)V", "()V", null); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitVarInsn(ILOAD, 2); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Enum", "<init>", "(Ljava/lang/String;I)V", false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "valueOf", "(Ljava/lang/String;)Lsoot/asm/backend/targets/MyEnum;", null, null); mv.visitCode(); mv.visitLdcInsn(Type.getType("Lsoot/asm/backend/targets/MyEnum;")); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Enum", "valueOf", "(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;", false); mv.visitTypeInsn(CHECKCAST, "soot/asm/backend/targets/MyEnum"); mv.visitInsn(ARETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } if (targetCompiler == TargetCompiler.eclipse) { mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "values", "()[Lsoot/asm/backend/targets/MyEnum;", null, null); mv.visitCode(); mv.visitFieldInsn(GETSTATIC, "soot/asm/backend/targets/MyEnum", "ENUM$VALUES", "[Lsoot/asm/backend/targets/MyEnum;"); mv.visitInsn(DUP); mv.visitInsn(ARRAYLENGTH); mv.visitInsn(DUP); mv.visitVarInsn(ISTORE, 0); mv.visitTypeInsn(ANEWARRAY, "soot/asm/backend/targets/MyEnum"); mv.visitVarInsn(ASTORE, 1); mv.visitInsn(ICONST_0); mv.visitVarInsn(ALOAD, 1); mv.visitInsn(ICONST_0); mv.visitVarInsn(ILOAD, 0); mv.visitMethodInsn(INVOKESTATIC, "java/lang/System", "arraycopy", "(Ljava/lang/Object;ILjava/lang/Object;II)V", false); mv.visitVarInsn(ALOAD, 1); mv.visitInsn(ARETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } else { mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "values", "()[Lsoot/asm/backend/targets/MyEnum;", null, null); mv.visitCode(); mv.visitFieldInsn(GETSTATIC, "soot/asm/backend/targets/MyEnum", "$VALUES", "[Lsoot/asm/backend/targets/MyEnum;"); // mv.visitMethodInsn(INVOKEVIRTUAL, "[Lsoot/asm/backend/targets/MyEnum;", "clone", "()Ljava/lang/Object;", false); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "clone", "()Ljava/lang/Object;", false); mv.visitTypeInsn(CHECKCAST, "[Lsoot/asm/backend/targets/MyEnum;"); mv.visitInsn(ARETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.MyEnum"; } }
6,872
39.910714
125
java
soot
soot-master/src/test/java/soot/asm/backend/ExceptionTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for method declaring exception * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class ExceptionTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor cw) { MethodVisitor mv; cw.visit(V1_4, ACC_PUBLIC + ACC_ABSTRACT + ACC_INTERFACE, "soot/asm/backend/targets/ExceptionMethods", null, "java/lang/Object", null); cw.visitSource("ExceptionMethods.java", null); { mv = cw.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, "foo", "()V", null, new String[] { "java/lang/NullPointerException" }); mv.visitEnd(); } cw.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.ExceptionMethods"; } @Override protected String getRequiredJavaVersion() { return "1.4"; } }
1,786
25.279412
124
java
soot
soot-master/src/test/java/soot/asm/backend/ExtendedArithmeticLibTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for more arithmetic bytecode instructions * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class ExtendedArithmeticLibTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor cw) { MethodVisitor mv; FieldVisitor fv; cw.visit(V1_1, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/ExtendedArithmeticLib", null, "java/lang/Object", null); cw.visitSource("ExtendedArithmeticLib.java", null); { fv = cw.visitField(ACC_PRIVATE, "i1", "I", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE, "f1", "F", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE, "l1", "J", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE, "d1", "D", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE, "s1", "S", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE, "b1", "B", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE, "i2", "I", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE, "f2", "F", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE, "l2", "J", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE, "d2", "D", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE, "i3", "I", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE, "f3", "F", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE, "l3", "J", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE, "d3", "D", null, null); fv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "doBNeg", "(B)I", null, null); mv.visitCode(); mv.visitVarInsn(ILOAD, 1); mv.visitInsn(INEG); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "doCNeg", "(C)I", null, null); mv.visitCode(); mv.visitVarInsn(ILOAD, 1); mv.visitInsn(INEG); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "doDNeg", "(D)D", null, null); mv.visitCode(); mv.visitVarInsn(DLOAD, 1); mv.visitInsn(DNEG); mv.visitInsn(DRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "doFNeg", "(F)F", null, null); mv.visitCode(); mv.visitVarInsn(FLOAD, 1); mv.visitInsn(FNEG); mv.visitInsn(FRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "doINeg", "(I)I", null, null); mv.visitCode(); mv.visitVarInsn(ILOAD, 1); mv.visitInsn(INEG); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } if (targetCompiler == TargetCompiler.eclipse) { mv = cw.visitMethod(ACC_PUBLIC, "doInc", "()I", null, null); mv.visitCode(); mv.visitInsn(ICONST_0); mv.visitVarInsn(ISTORE, 0); mv.visitInsn(ICONST_0); mv.visitVarInsn(ISTORE, 1); Label l0 = new Label(); mv.visitJumpInsn(GOTO, l0); Label l1 = new Label(); mv.visitLabel(l1); mv.visitIincInsn(0, 4); mv.visitIincInsn(1, 1); mv.visitLabel(l0); mv.visitVarInsn(ILOAD, 1); mv.visitIntInsn(BIPUSH, 100); mv.visitJumpInsn(IF_ICMPLT, l1); mv.visitVarInsn(ILOAD, 0); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } else { mv = cw.visitMethod(ACC_PUBLIC, "doInc", "()I", null, null); mv.visitCode(); mv.visitInsn(ICONST_0); mv.visitVarInsn(ISTORE, 0); mv.visitInsn(ICONST_0); mv.visitVarInsn(ISTORE, 1); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ILOAD, 1); mv.visitIntInsn(BIPUSH, 100); Label l1 = new Label(); mv.visitJumpInsn(IF_ICMPGE, l1); mv.visitIincInsn(0, 4); mv.visitIincInsn(1, 1); mv.visitJumpInsn(GOTO, l0); mv.visitLabel(l1); mv.visitVarInsn(ILOAD, 0); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "doLNeg", "(J)J", null, null); mv.visitCode(); mv.visitVarInsn(LLOAD, 1); mv.visitInsn(LRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "doMod", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "i2", "I"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "i3", "I"); mv.visitInsn(IREM); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "i1", "I"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "f2", "F"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "f3", "F"); mv.visitInsn(FREM); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "f1", "F"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "l2", "J"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "l3", "J"); mv.visitInsn(LREM); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "l1", "J"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "d2", "D"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "d3", "D"); mv.visitInsn(DREM); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "d1", "D"); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "doSNeg", "(S)I", null, null); mv.visitCode(); mv.visitVarInsn(ILOAD, 1); mv.visitInsn(INEG); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "doSub", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "i2", "I"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "i3", "I"); mv.visitInsn(ISUB); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "i1", "I"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "f2", "F"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "f3", "F"); mv.visitInsn(FSUB); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "f1", "F"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "l2", "J"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "l3", "J"); mv.visitInsn(LSUB); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "l1", "J"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "d2", "D"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "d3", "D"); mv.visitInsn(DSUB); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/ExtendedArithmeticLib", "d1", "D"); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.ExtendedArithmeticLib"; } }
9,914
32.383838
125
java
soot
soot-master/src/test/java/soot/asm/backend/InnerClass2Test.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for inner class in method * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class InnerClass2Test extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor cw) { MethodVisitor mv; FieldVisitor fv; cw.visit(V1_1, ACC_SUPER, "soot/asm/backend/targets/InnerClass$1", null, "java/lang/Object", new String[] { "soot/asm/backend/targets/Measurable" }); cw.visitSource("InnerClass.java", null); cw.visitOuterClass("soot/asm/backend/targets/InnerClass", "doInner", "()V"); cw.visitInnerClass("soot/asm/backend/targets/InnerClass$1", null, null, 0); { fv = cw.visitField(ACC_FINAL + ACC_SYNTHETIC, "this$0", "Lsoot/asm/backend/targets/InnerClass;", null, null); fv.visitEnd(); } { mv = cw.visitMethod(0, "<init>", "(Lsoot/asm/backend/targets/InnerClass;)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/InnerClass$1", "this$0", "Lsoot/asm/backend/targets/InnerClass;"); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.InnerClass$1"; } }
2,444
29.5625
115
java
soot
soot-master/src/test/java/soot/asm/backend/InnerClassTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for inner class in class * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class InnerClassTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor visitor) { MethodVisitor mv; FieldVisitor fv; visitor.visit(V1_1, ACC_SUPER , "soot/asm/backend/targets/InnerClass$Inner", null, "java/lang/Object", null); visitor.visitSource("InnerClass.java", null); visitor.visitOuterClass("soot/asm/backend/targets/InnerClass", null, null); visitor.visitInnerClass("soot/asm/backend/targets/InnerClass$Inner", "soot/asm/backend/targets/InnerClass", "Inner", ACC_PRIVATE); { fv = visitor.visitField(ACC_FINAL + ACC_STATIC, "a", "I", null, new Integer(3)); fv.visitEnd(); } { fv = visitor.visitField(ACC_FINAL + ACC_SYNTHETIC, "this$0", "Lsoot/asm/backend/targets/InnerClass;", null, null); fv.visitEnd(); } { mv = visitor.visitMethod(ACC_PRIVATE, "<init>", "(Lsoot/asm/backend/targets/InnerClass;)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/InnerClass$Inner", "this$0", "Lsoot/asm/backend/targets/InnerClass;"); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } visitor.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.InnerClass$Inner"; } }
2,618
30.554217
120
java
soot
soot-master/src/test/java/soot/asm/backend/InnerStaticClassTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for inner class in class * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class InnerStaticClassTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor visitor) { MethodVisitor mv; FieldVisitor fv; visitor.visit(V1_1, ACC_PUBLIC +ACC_SUPER, "soot/asm/backend/targets/InnerStaticClass$Inner", null, "java/lang/Object", null); visitor.visitSource("InnerStaticClass.java", null); visitor.visitOuterClass("soot/asm/backend/targets/InnerStaticClass", null, null); visitor.visitInnerClass("soot/asm/backend/targets/InnerStaticClass$Inner", "soot/asm/backend/targets/InnerStaticClass", "Inner", ACC_PUBLIC + ACC_STATIC); { fv = visitor.visitField(ACC_FINAL + ACC_STATIC, "a", "I", null, new Integer(3)); fv.visitEnd(); } { mv = visitor.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } visitor.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.InnerStaticClass$Inner"; } }
2,289
29.131579
132
java
soot
soot-master/src/test/java/soot/asm/backend/InstanceOfCastsTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for instanceof and cast bytecode instructions * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class InstanceOfCastsTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor cw) { MethodVisitor mv; cw.visit(V1_1, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/InstanceOfCasts", null, "java/lang/Object", null); cw.visitSource("InstanceOfCasts.java", null); { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "convertMeasurableArray", "([Ljava/lang/Object;)[Lsoot/asm/backend/targets/Measurable;", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(INSTANCEOF, "[Lsoot/asm/backend/targets/Measurable;"); Label l0 = new Label(); mv.visitJumpInsn(IFEQ, l0); mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(CHECKCAST, "[Lsoot/asm/backend/targets/Measurable;"); // the eclipse compiler and javac >= version 1.9 produce different bytecode @see https://github.com/soot-oss/soot/pull/1155 if (targetCompiler != TargetCompiler.eclipse && targetCompiler != TargetCompiler.javac9) mv.visitTypeInsn(CHECKCAST, "[Lsoot/asm/backend/targets/Measurable;"); mv.visitInsn(ARETURN); mv.visitLabel(l0); mv.visitInsn(ACONST_NULL); mv.visitInsn(ARETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "isMeasurable", "(Ljava/lang/Object;)Z", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(INSTANCEOF, "soot/asm/backend/targets/Measurable"); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.InstanceOfCasts"; } }
3,109
32.085106
129
java
soot
soot-master/src/test/java/soot/asm/backend/InterfaceTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.Opcodes; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for an interface class and accessibility modifiers * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class InterfaceTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor visitor) { visitor.visit(Opcodes.V1_1, Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT + Opcodes.ACC_INTERFACE, "soot/asm/backend/targets/Comparable", null, "java/lang/Object", new String[] { "soot/asm/backend/targets/Measurable" }); visitor.visitSource("Comparable.java", null); visitor.visitField(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC, "LESS", "I", null, new Integer(-1)) .visitEnd(); visitor.visitField(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC, "EQUAL", "I", null, new Integer(0)) .visitEnd(); visitor.visitField(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC, "GREATER", "I", null, new Integer(1)) .visitEnd(); visitor.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT, "compareTo", "(Ljava/lang/Object;)I", null, null) .visitEnd(); visitor.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.Comparable"; } }
2,189
34.322581
121
java
soot
soot-master/src/test/java/soot/asm/backend/LineNumbersTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for line number labels * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class LineNumbersTest extends AbstractASMBackendTestWithSources { @Override protected void generate(TraceClassVisitor cw) { MethodVisitor mv; cw.visit(V1_1, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/LineNumbers", null, "java/lang/Object", null); cw.visitSource("LineNumbers.java", null); { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLineNumber(25, l1); mv.visitVarInsn(ALOAD, 0); Label l2 = new Label(); mv.visitLabel(l2); mv.visitLineNumber(25, l2); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); Label l3 = new Label(); mv.visitLabel(l3); mv.visitLineNumber(25, l3); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(28, l0); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.LineNumbers"; } }
2,397
27.547619
115
java
soot
soot-master/src/test/java/soot/asm/backend/LogicalOperationsTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for bitwise logical operation bytecode instructions * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class LogicalOperationsTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor cw) { MethodVisitor mv; FieldVisitor fv; cw.visit(V1_1, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/LogicalOperations", null, "java/lang/Object", null); cw.visitSource("LogicalOperations.java", null); { fv = cw.visitField(ACC_PRIVATE, "i1", "I", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE, "b1", "Z", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE, "l1", "J", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE, "i2", "I", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE, "b2", "Z", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE, "l2", "J", null, null); fv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "doAnd", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "i2", "I"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "i1", "I"); mv.visitInsn(IAND); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/LogicalOperations", "i1", "I"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "l2", "J"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "l1", "J"); mv.visitInsn(LAND); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/LogicalOperations", "l1", "J"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "b2", "Z"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "b1", "Z"); mv.visitInsn(IAND); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/LogicalOperations", "b1", "Z"); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "doInv", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "i2", "I"); mv.visitInsn(ICONST_M1); mv.visitInsn(IXOR); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/LogicalOperations", "i1", "I"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "i2", "I"); mv.visitInsn(ICONST_M1); mv.visitInsn(IXOR); mv.visitInsn(I2L); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/LogicalOperations", "l1", "J"); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "doOr", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "i2", "I"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "i1", "I"); mv.visitInsn(IOR); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/LogicalOperations", "i1", "I"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "l2", "J"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "l1", "J"); mv.visitInsn(LOR); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/LogicalOperations", "l1", "J"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "b2", "Z"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "b1", "Z"); mv.visitInsn(IOR); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/LogicalOperations", "b1", "Z"); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "doShl", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "i1", "I"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "i2", "I"); mv.visitInsn(ISHL); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/LogicalOperations", "i1", "I"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "l1", "J"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "l2", "J"); mv.visitInsn(L2I); mv.visitInsn(LSHL); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/LogicalOperations", "l1", "J"); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "doShr", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "i1", "I"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "i2", "I"); mv.visitInsn(ISHR); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/LogicalOperations", "i1", "I"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "l1", "J"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "l2", "J"); mv.visitInsn(L2I); mv.visitInsn(LSHR); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/LogicalOperations", "l1", "J"); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "doUShr", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "i1", "I"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "i2", "I"); mv.visitInsn(IUSHR); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/LogicalOperations", "i1", "I"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "l1", "J"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "l2", "J"); mv.visitInsn(L2I); mv.visitInsn(LUSHR); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/LogicalOperations", "l1", "J"); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "doXOr", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "i2", "I"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "i1", "I"); mv.visitInsn(IXOR); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/LogicalOperations", "i1", "I"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "l2", "J"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "l1", "J"); mv.visitInsn(LXOR); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/LogicalOperations", "l1", "J"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "b2", "Z"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/LogicalOperations", "b1", "Z"); mv.visitInsn(IXOR); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/LogicalOperations", "b1", "Z"); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.LogicalOperations"; } }
10,432
39.437984
121
java
soot
soot-master/src/test/java/soot/asm/backend/MethodExampleTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for methods taken from the ASM 4.0 guide * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class MethodExampleTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor visitor) { FieldVisitor fv; MethodVisitor mv; visitor.visit(Opcodes.V1_1, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, "soot/asm/backend/targets/Bean", null, "java/lang/Object", null); visitor.visitSource("Bean.java", null); { fv = visitor.visitField(Opcodes.ACC_PRIVATE, "f", "I", null, null); fv.visitEnd(); } { mv = visitor.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = visitor.visitMethod(Opcodes.ACC_PUBLIC, "checkAndSetF", "(I)V", null, null); mv.visitCode(); mv.visitVarInsn(Opcodes.ILOAD, 1); Label l0 = new Label(); mv.visitJumpInsn(Opcodes.IFLT, l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ILOAD, 1); mv.visitFieldInsn(Opcodes.PUTFIELD, "soot/asm/backend/targets/Bean", "f", "I"); Label l1 = new Label(); mv.visitJumpInsn(Opcodes.GOTO, l1); mv.visitLabel(l0); mv.visitTypeInsn(Opcodes.NEW, "java/lang/IllegalArgumentException"); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/IllegalArgumentException", "<init>", "()V", false); mv.visitInsn(Opcodes.ATHROW); mv.visitLabel(l1); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = visitor.visitMethod(Opcodes.ACC_PUBLIC, "getF", "()I", null, null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "soot/asm/backend/targets/Bean", "f", "I"); mv.visitInsn(Opcodes.IRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = visitor.visitMethod(Opcodes.ACC_PUBLIC, "setF", "(I)V", null, null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ILOAD, 1); mv.visitFieldInsn(Opcodes.PUTFIELD, "soot/asm/backend/targets/Bean", "f", "I"); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } visitor.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.Bean"; } }
3,663
31.714286
110
java
soot
soot-master/src/test/java/soot/asm/backend/MinimalJavaVersionTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import static org.junit.Assert.fail; import java.io.File; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import soot.G; import soot.Main; import soot.ModulePathSourceLocator; import soot.Scene; /** * Test for the correct determination of the required Java version * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class MinimalJavaVersionTest { @Rule public ExpectedException thrown = ExpectedException.none(); @Test public void testMinimalVersionAnnotation() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Enforced Java version 1.3 too low to support required features (1.5 required)"); runSoot("soot.asm.backend.targets.AnnotatedClass", "1.3"); } @Test public void testSufficientUserVersion() { try { runSoot("soot.asm.backend.targets.AnnotatedClass", "1.7"); return; } catch (RuntimeException e) { fail("Version 1.7 should be sufficient for features of pkg.AnnotatedClass!"); } } /** * Returns the folder that is to be added to the class path for running soot * * @return The location of the folder containing the test files */ protected String getClassPathFolder() { File f = new File("./target/test-classes"); return f.getAbsolutePath(); } protected void runSoot(String className, String version) { G.reset(); // Location of the rt.jar String rtJar = ""; if (Scene.isJavaGEQ9(System.getProperty("java.version"))) { rtJar = ModulePathSourceLocator.DUMMY_CLASSPATH_JDK9_FS; } else { // java version >= 9 do not have an rt.jar rtJar = System.getProperty("java.home") + File.separator + "lib" + File.separator + "rt.jar"; } // Run Soot and print output to .asm-files. Main.v().run(new String[] { "-cp", getClassPathFolder() + File.pathSeparator + rtJar, "-src-prec", "only-class", "-output-format", "asm", "-allow-phantom-refs", "-java-version", version, className }); } }
2,885
28.44898
116
java
soot
soot-master/src/test/java/soot/asm/backend/ModifiersTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for various combinations of accessibility modifiers * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class ModifiersTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor cw) { MethodVisitor mv; FieldVisitor fv; cw.visit(V1_3, ACC_PUBLIC + ACC_SUPER + ACC_ABSTRACT, "soot/asm/backend/targets/Modifiers", null, "java/lang/Object", null); cw.visitSource("Modifiers.java", null); { fv = cw.visitField(ACC_PRIVATE + ACC_VOLATILE, "i", "I", null, null); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE + ACC_FINAL, "j", "I", null, new Integer(213)); fv.visitEnd(); } { fv = cw.visitField(ACC_PRIVATE + ACC_TRANSIENT, "k", "I", null, null); fv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_STRICT, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitVarInsn(ALOAD, 0); mv.visitIntInsn(SIPUSH, 213); mv.visitFieldInsn(PUTFIELD, "soot/asm/backend/targets/Modifiers", "j", "I"); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_FINAL + ACC_STRICT, "a", "()V", null, null); mv.visitCode(); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_SYNCHRONIZED + ACC_STRICT, "b", "()V", null, null); mv.visitCode(); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC + ACC_STRICT, "c", "()V", null, null); mv.visitCode(); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_STRICT, "d", "()V", null, null); mv.visitCode(); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PROTECTED + ACC_STRICT, "e", "()V", null, null); mv.visitCode(); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_ABSTRACT, "f", "()V", null, null); mv.visitEnd(); } { if (targetCompiler == TargetCompiler.eclipse) mv = cw.visitMethod(ACC_PRIVATE + ACC_NATIVE, "g", "()V", null, null); else mv = cw.visitMethod(ACC_PRIVATE + ACC_NATIVE + ACC_STRICT, "g", "()V", null, null); mv.visitEnd(); } cw.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.Modifiers"; } @Override protected String getRequiredJavaVersion() { return "1.3"; } }
3,802
27.593985
121
java
soot
soot-master/src/test/java/soot/asm/backend/MonitorTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for monitor bytecode instructions * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class MonitorTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor cw) { FieldVisitor fv; MethodVisitor mv; cw.visit(V1_1, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/Monitor", null, "java/lang/Object", null); cw.visitSource("Monitor.java", null); { fv = cw.visitField(0, "o", "Ljava/lang/Object;", null, null); fv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } if (targetCompiler == TargetCompiler.eclipse) { mv = cw.visitMethod(ACC_PUBLIC, "doSth", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/Monitor", "o", "Ljava/lang/Object;"); mv.visitInsn(DUP); mv.visitInsn(MONITORENTER); mv.visitInsn(MONITOREXIT); mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "()V", false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } else { mv = cw.visitMethod(ACC_PUBLIC, "doSth", "()V", null, null); mv.visitCode(); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Throwable"); Label l3 = new Label(); mv.visitTryCatchBlock(l2, l3, l2, "java/lang/Throwable"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "soot/asm/backend/targets/Monitor", "o", "Ljava/lang/Object;"); mv.visitVarInsn(ASTORE, 0); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(MONITORENTER); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(MONITOREXIT); mv.visitLabel(l1); Label l4 = new Label(); mv.visitJumpInsn(GOTO, l4); mv.visitLabel(l2); mv.visitVarInsn(ASTORE, 1); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(MONITOREXIT); mv.visitLabel(l3); mv.visitVarInsn(ALOAD, 1); mv.visitInsn(ATHROW); mv.visitLabel(l4); mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "()V", false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.Monitor"; } }
3,851
31.644068
111
java
soot
soot-master/src/test/java/soot/asm/backend/NullTypesTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for null types * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class NullTypesTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor cw) { MethodVisitor mv; cw.visit(V1_1, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/nullTypes", null, "java/lang/Object", null); cw.visitSource("nullTypes.java", null); { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(0, "doStuff", "(Ljava/lang/Integer;)Ljava/lang/Integer;", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 1); Label l0 = new Label(); mv.visitJumpInsn(IFNONNULL, l0); mv.visitInsn(ACONST_NULL); mv.visitInsn(ARETURN); mv.visitLabel(l0); // mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(ICONST_1); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false); mv.visitInsn(ARETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.nullTypes"; } }
2,395
28.95
113
java
soot
soot-master/src/test/java/soot/asm/backend/OuterClassTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for class containing inner classes * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class OuterClassTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor cw) { MethodVisitor mv; cw.visit(V1_1, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/InnerClass", null, "java/lang/Object", null); cw.visitSource("InnerClass.java", null); cw.visitInnerClass("soot/asm/backend/targets/InnerClass$1", null, null, 0); cw.visitInnerClass("soot/asm/backend/targets/InnerClass$Inner", "soot/asm/backend/targets/InnerClass", "Inner", ACC_PRIVATE); { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "doInner", "()V", null, null); mv.visitCode(); mv.visitTypeInsn(NEW, "soot/asm/backend/targets/InnerClass$1"); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "soot/asm/backend/targets/InnerClass$1", "<init>", "(Lsoot/asm/backend/targets/InnerClass;)V", false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "getA", "()I", null, null); mv.visitCode(); mv.visitInsn(ICONST_3); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.InnerClass"; } }
2,660
28.898876
115
java
soot
soot-master/src/test/java/soot/asm/backend/ReturnsTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for several return bytecode instructions * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class ReturnsTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor visitor) { MethodVisitor mv; visitor.visit(V1_1, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/Returns", null, "java/lang/Object", null); visitor.visitSource("Returns.java", null); { mv = visitor.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = visitor.visitMethod(ACC_PUBLIC, "getIntArray", "()[I", null, null); mv.visitCode(); mv.visitInsn(ICONST_4); mv.visitIntInsn(NEWARRAY, T_INT); mv.visitInsn(ARETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = visitor.visitMethod(ACC_PUBLIC, "getNull", "()Ljava/lang/Object;", null, null); mv.visitCode(); mv.visitInsn(ACONST_NULL); mv.visitInsn(ARETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = visitor.visitMethod(ACC_PUBLIC, "getObjectArray", "()[Ljava/lang/Object;", null, null); mv.visitCode(); mv.visitInsn(ICONST_4); mv.visitTypeInsn(ANEWARRAY, "java/lang/Object"); mv.visitInsn(ARETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } visitor.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.Returns"; } }
2,606
27.648352
116
java
soot
soot-master/src/test/java/soot/asm/backend/StoresTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for several store bytecode instructions * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class StoresTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor visitor) { MethodVisitor mv; visitor.visit(V1_1, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/Stores", null, "java/lang/Object", null); visitor.visitSource("Stores.java", null); { mv = visitor.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } if (targetCompiler == TargetCompiler.eclipse) { mv = visitor.visitMethod(ACC_PUBLIC, "doSth", "()I", null, null); mv.visitCode(); mv.visitLdcInsn(new Integer(2343249)); mv.visitVarInsn(ISTORE, 0); mv.visitLdcInsn(new Double("3.14324")); mv.visitVarInsn(DSTORE, 1); mv.visitLdcInsn(new Float("3.143")); mv.visitVarInsn(FSTORE, 3); mv.visitIntInsn(SIPUSH, 4636); mv.visitVarInsn(ISTORE, 4); mv.visitMethodInsn(INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J", false); mv.visitInsn(LCONST_0); mv.visitInsn(LCMP); Label l0 = new Label(); mv.visitJumpInsn(IFLE, l0); mv.visitInsn(ICONST_1); mv.visitVarInsn(ISTORE, 6); Label l1 = new Label(); mv.visitJumpInsn(GOTO, l1); mv.visitLabel(l0); // mv.visitFrame(F_FULL, 5, new Object[] {"soot/asm/backend/targets/Stores", INTEGER, DOUBLE, FLOAT, INTEGER}, 0, new // Object[] {}); mv.visitInsn(ICONST_0); mv.visitVarInsn(ISTORE, 6); mv.visitLabel(l1); // mv.visitFrame(F_SAME1, 0, null, 1, new Object[] {INTEGER}); mv.visitTypeInsn(NEW, "java/lang/Object"); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitVarInsn(ASTORE, 5); mv.visitInsn(ICONST_3); mv.visitIntInsn(NEWARRAY, T_INT); mv.visitInsn(ICONST_1); mv.visitLdcInsn(new Integer(24355764)); mv.visitInsn(IASTORE); mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); mv.visitTypeInsn(NEW, "java/lang/StringBuilder"); mv.visitInsn(DUP); mv.visitVarInsn(ILOAD, 0); mv.visitInsn(I2D); mv.visitVarInsn(DLOAD, 1); mv.visitInsn(DADD); mv.visitVarInsn(FLOAD, 3); mv.visitInsn(F2D); mv.visitInsn(DADD); mv.visitVarInsn(ILOAD, 4); mv.visitInsn(I2D); mv.visitInsn(DADD); mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf", "(D)Ljava/lang/String;", false); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(Ljava/lang/String;)V", false); mv.visitVarInsn(ILOAD, 6); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Z)Ljava/lang/StringBuilder;", false); mv.visitVarInsn(ILOAD, 0); mv.visitInsn(I2B); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(I)Ljava/lang/StringBuilder;", false); mv.visitLdcInsn(314435665); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(J)Ljava/lang/StringBuilder;", false); mv.visitIntInsn(BIPUSH, 123); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(C)Ljava/lang/StringBuilder;", false); mv.visitLdcInsn(" "); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false); mv.visitVarInsn(ALOAD, 5); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/Object;)Ljava/lang/StringBuilder;", false); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false); mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false); mv.visitVarInsn(ILOAD, 0); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } else { mv = visitor.visitMethod(ACC_PUBLIC, "doSth", "()I", null, null); mv.visitCode(); mv.visitMethodInsn(INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J", false); mv.visitInsn(LCONST_0); mv.visitInsn(LCMP); Label l0 = new Label(); mv.visitJumpInsn(IFLE, l0); mv.visitInsn(ICONST_1); mv.visitVarInsn(ISTORE, 0); Label l1 = new Label(); mv.visitJumpInsn(GOTO, l1); mv.visitLabel(l0); mv.visitInsn(ICONST_0); mv.visitVarInsn(ISTORE, 0); mv.visitLabel(l1); mv.visitLdcInsn(new Integer(2343249)); mv.visitInsn(I2B); mv.visitTypeInsn(NEW, "java/lang/Object"); mv.visitVarInsn(ASTORE, 1); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(ICONST_3); mv.visitIntInsn(NEWARRAY, T_INT); mv.visitInsn(ICONST_1); mv.visitLdcInsn(new Integer(24355764)); mv.visitInsn(IASTORE); mv.visitVarInsn(ISTORE, 2); mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); mv.visitTypeInsn(NEW, "java/lang/StringBuilder"); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "()V", false); mv.visitLdcInsn(new Integer(2343249)); mv.visitInsn(I2D); mv.visitLdcInsn(new Double("3.14324")); mv.visitInsn(DADD); mv.visitLdcInsn(new Float("3.143")); mv.visitInsn(F2D); mv.visitInsn(DADD); mv.visitIntInsn(SIPUSH, 4636); mv.visitInsn(I2D); mv.visitInsn(DADD); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(D)Ljava/lang/StringBuilder;", false); mv.visitLdcInsn(""); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false); mv.visitVarInsn(ILOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Z)Ljava/lang/StringBuilder;", false); mv.visitVarInsn(ILOAD, 2); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(I)Ljava/lang/StringBuilder;", false); mv.visitLdcInsn(new Long(314435665L)); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(J)Ljava/lang/StringBuilder;", false); mv.visitIntInsn(BIPUSH, 123); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(C)Ljava/lang/StringBuilder;", false); mv.visitLdcInsn(" "); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/Object;)Ljava/lang/StringBuilder;", false); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false); mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false); mv.visitLdcInsn(new Integer(2343249)); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } visitor.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.Stores"; } }
8,538
40.653659
125
java
soot
soot-master/src/test/java/soot/asm/backend/TryCatchTest.java
package soot.asm.backend; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.util.TraceClassVisitor; /** * Test for try catch bytecode instructions * * @author Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer * */ public class TryCatchTest extends AbstractASMBackendTest { @Override protected void generate(TraceClassVisitor cw) { MethodVisitor mv; cw.visit(V1_1, ACC_PUBLIC + ACC_SUPER, "soot/asm/backend/targets/TryCatch", null, "java/lang/Object", null); cw.visitSource("TryCatch.java", null); { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } if (targetCompiler == TargetCompiler.eclipse) { mv = cw.visitMethod(0, "doSth", "(Ljava/lang/Object;)I", null, null); mv.visitCode(); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, "java/lang/NullPointerException"); Label l3 = new Label(); Label l4 = new Label(); mv.visitTryCatchBlock(l0, l3, l4, "java/lang/Throwable"); mv.visitInsn(ICONST_0); mv.visitVarInsn(ISTORE, 0); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "notify", "()V", false); mv.visitInsn(ICONST_1); mv.visitVarInsn(ISTORE, 0); mv.visitLabel(l1); Label l5 = new Label(); mv.visitJumpInsn(GOTO, l5); mv.visitLabel(l2); // mv.visitFrame(F_FULL, 3, new Object[] {"soot/asm/backend/targets/TryCatch", "java/lang/Object", INTEGER}, 1, new // Object[] {"java/lang/NullPointerException"}); mv.visitVarInsn(ASTORE, 1); mv.visitInsn(ICONST_M1); mv.visitVarInsn(ISTORE, 0); mv.visitLabel(l3); mv.visitJumpInsn(GOTO, l5); mv.visitLabel(l4); // mv.visitFrame(F_SAME1, 0, null, 1, new Object[] {"java/lang/Throwable"}); mv.visitVarInsn(ASTORE, 1); mv.visitLabel(l5); // mv.visitFrame(F_SAME, 0, null, 0, null); mv.visitVarInsn(ILOAD, 0); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } else { mv = cw.visitMethod(0, "doSth", "(Ljava/lang/Object;)I", null, null); mv.visitCode(); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, "java/lang/NullPointerException"); Label l3 = new Label(); mv.visitTryCatchBlock(l0, l1, l3, "java/lang/Throwable"); Label l4 = new Label(); mv.visitTryCatchBlock(l2, l4, l3, "java/lang/Throwable"); Label l5 = new Label(); mv.visitTryCatchBlock(l3, l5, l3, "java/lang/Throwable"); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "notify", "()V", false); mv.visitLabel(l1); mv.visitInsn(ICONST_1); mv.visitInsn(IRETURN); mv.visitLabel(l2); mv.visitVarInsn(ASTORE, 0); mv.visitLabel(l4); mv.visitInsn(ICONST_M1); mv.visitInsn(IRETURN); mv.visitLabel(l3); mv.visitVarInsn(ASTORE, 0); mv.visitLabel(l5); mv.visitInsn(ICONST_0); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); } @Override protected String getTargetClass() { return "soot.asm.backend.targets.TryCatch"; } }
4,433
32.338346
121
java
soot
soot-master/src/test/java/soot/asm/backend/targets/AnnotatedAnnotatedClass.java
package soot.asm.backend.targets; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ @MyAnnotatedAnnotation(@MyTestAnnotation(iVal=1,fVal=1,lVal=1,dVal=1,zVal=true,bVal=1,sVal=1,strVal="1",rVal=AnnotatedClass.class,iAVal={1,2,3,4},sAVal={"A", "B", "C"})) public class AnnotatedAnnotatedClass { }
1,064
37.035714
169
java
soot
soot-master/src/test/java/soot/asm/backend/targets/AnnotatedClass.java
package soot.asm.backend.targets; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ @MyTestAnnotation(iVal=1,fVal=1,lVal=1,dVal=1,zVal=true,bVal=1,sVal=1,strVal="1",rVal=AnnotatedClass.class,iAVal={1,2,3,4},sAVal={"A", "B", "C"}) public class AnnotatedClass { }
1,031
35.857143
145
java
soot
soot-master/src/test/java/soot/asm/backend/targets/AnnotatedField.java
package soot.asm.backend.targets; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public class AnnotatedField { @MyTestAnnotation(iVal=124,fVal=5132,lVal=5123,dVal=745,zVal=true,bVal=1,sVal=123,strVal="435243",rVal=AnnotatedClass.class,iAVal={123,234,345,456},sAVal={"A", "B", "C"}) String a; }
1,072
33.612903
171
java
soot
soot-master/src/test/java/soot/asm/backend/targets/AnnotatedMethod.java
package soot.asm.backend.targets; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public class AnnotatedMethod { @MyTestAnnotation(iVal=124,fVal=5132,lVal=5123,dVal=745,zVal=true,bVal=1,sVal=123,strVal="435243",rVal=AnnotatedClass.class,iAVal={123,234,345,456},sAVal={"A", "B", "C"}) public void doSth(){ } }
1,087
33
171
java
soot
soot-master/src/test/java/soot/asm/backend/targets/AnnotatedParameter.java
package soot.asm.backend.targets; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public class AnnotatedParameter { public void doSth( @MyTestAnnotation(iVal=1,fVal=1,lVal=1,dVal=1,zVal=true,bVal=1,sVal=1,strVal="1",rVal=AnnotatedClass.class,iAVal={1,2,3,4},sAVal={"A", "B", "C"}) String a){ } }
1,075
32.625
159
java
soot
soot-master/src/test/java/soot/asm/backend/targets/ArithmeticLib.java
package soot.asm.backend.targets; /*- * #%L * Soot - a J*va Optimization Framework * %% * Copyright (C) 1997 - 2018 Raja Vallée-Rai and others * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-2.1.html>. * #L% */ public class ArithmeticLib { private int rInt; private float rFloat; private long rLong; private double rDouble; private short rShort; private char rChar; private byte rByte; final int cInt = 1; final float cFloat = 1; final long cLong = 1; final double cDouble = 1; public int doCompInt(int i){ rInt = i / -1; rFloat = i * 17; rLong = i + 5; rDouble = i - 2; return rInt; } public float doCompFloat(float f){ rInt = (int) (f / 13f); rFloat = f * 3f; rLong = (long) (f - 2f); rDouble = f + 1f; return rFloat; } public long doCompLong(long l){ rInt = (int) (l * 5l); rFloat = l + 2l; rLong = l * 6l; rDouble = l / 6l; return rLong; } public double doCompDouble(double d){ rInt = (int) (d / 1.0); rLong = (long) (d * 6.0); rFloat = (float) (d + 0.0); rDouble = d - 4.0; return rDouble; } public short castInt2Short(){ rShort = (short) rInt; return rShort; } public char castInt2Char(){ rChar = (char) rInt; return rChar; } public byte castInt2Byte(){ rByte = (byte) rInt; return rByte; } }
1,937
21.022727
71
java