Skip to content

Commit

Permalink
Misc changes (#185)
Browse files Browse the repository at this point in the history
- [Make more
readable.](f114256)
-
[Spelling.](1f6ca35)
- Metadata changes (increase JDK version).
- [Update Google Java
format.](a8252fe)
- Add logging to constructor trampoline target selector.
  • Loading branch information
khatchad authored Apr 25, 2024
1 parent 3302c06 commit 6214a26
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ org.eclipse.jdt.core.classpath.mainOnlyProjectHasTestOnlyDependency=error
org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled
org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=error
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.maxProblemPerUnit=100
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17
org.eclipse.jdt.core.incompatibleJDKLevel=ignore
org.eclipse.jdt.core.incompleteClasspath=error
2 changes: 1 addition & 1 deletion com.ibm.wala.cast.python.jython3/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ Export-Package: com.ibm.wala.cast.python.client,
com.ibm.wala.cast.python.util,
org.python.antlr
Bundle-Vendor: IBM
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-RequiredExecutionEnvironment: JavaSE-17
Automatic-Module-Name: com.ibm.wala.cast.python
7 changes: 4 additions & 3 deletions com.ibm.wala.cast.python.ml.test/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
<classpath>
<classpathentry kind="src" output="target/test-classes" path="source">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
Expand All @@ -25,8 +26,8 @@
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled
org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=error
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
Expand All @@ -22,8 +22,8 @@ org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17
org.eclipse.jdt.core.incompatibleJDKLevel=ignore
org.eclipse.jdt.core.incompleteClasspath=error
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_SHOW_CODEDETAILS_IN_EXCEPTION_MESSAGES" value="true"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_CLASSPATH_ONLY_JAR" value="false"/>
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11/"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.ibm.wala.cast.python.ml.test.TestTensorflow2Model"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="com.ibm.wala.cast.python.ml.test"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
Expand Down
8 changes: 4 additions & 4 deletions com.ibm.wala.cast.python/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled
org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=error
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
Expand All @@ -22,8 +22,8 @@ org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.compiler.source=17
org.eclipse.jdt.core.incompatibleJDKLevel=ignore
org.eclipse.jdt.core.incompleteClasspath=error
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@
import com.ibm.wala.util.collections.Pair;
import java.util.Collections;
import java.util.Map;
import java.util.logging.Logger;

public class PythonConstructorTargetSelector implements MethodTargetSelector {

private static final Logger LOGGER =
Logger.getLogger(PythonConstructorTargetSelector.class.getName());

private final Map<IClass, IMethod> ctors = HashMapFactory.make();

private final MethodTargetSelector base;
Expand All @@ -48,6 +53,9 @@ public PythonConstructorTargetSelector(MethodTargetSelector base) {
@Override
public IMethod getCalleeTarget(CGNode caller, CallSiteReference site, IClass receiver) {
if (receiver != null) {
LOGGER.fine("Getting callee target for receiver: " + receiver);
LOGGER.fine("Calling method name is: " + caller.getMethod().getName());

IClassHierarchy cha = receiver.getClassHierarchy();
if (cha.isSubclassOf(receiver, cha.lookupClass(PythonTypes.object))
&& receiver instanceof PythonClass) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
public class PythonTrampolineTargetSelector<T> implements MethodTargetSelector {

private static final Logger logger =
Logger.getLogger(PythonSSAPropagationCallGraphBuilder.class.getName());
Logger.getLogger(PythonTrampolineTargetSelector.class.getName());

/**
* The method name that is used for Python callables.
Expand Down Expand Up @@ -100,6 +100,7 @@ public IMethod getCalleeTarget(CGNode caller, CallSiteReference site, IClass rec
}

Pair<IClass, Integer> key = Pair.make(receiver, call.getNumberOfTotalParameters());

if (!codeBodies.containsKey(key)) {
Map<Integer, Atom> names = HashMapFactory.make();
MethodReference tr =
Expand All @@ -110,6 +111,7 @@ public IMethod getCalleeTarget(CGNode caller, CallSiteReference site, IClass rec
PythonSummary x = new PythonSummary(tr, call.getNumberOfTotalParameters());
IClass filter = ((PythonInstanceMethodTrampoline) receiver).getRealClass();
int v = call.getNumberOfTotalParameters() + 1;

x.addStatement(
PythonLanguage.Python.instructionFactory()
.GetInstruction(
Expand All @@ -120,11 +122,15 @@ public IMethod getCalleeTarget(CGNode caller, CallSiteReference site, IClass rec
PythonTypes.Root,
Atom.findOrCreateUnicodeAtom("$function"),
PythonTypes.Root)));

int v0 = v + 1;

x.addStatement(
PythonLanguage.Python.instructionFactory()
.CheckCastInstruction(1, v0, v, filter.getReference(), true));

int v1 = v + 2;

x.addStatement(
PythonLanguage.Python.instructionFactory()
.GetInstruction(
Expand All @@ -140,14 +146,15 @@ public IMethod getCalleeTarget(CGNode caller, CallSiteReference site, IClass rec
int[] params = new int[Math.max(2, call.getNumberOfPositionalParameters() + 1)];
params[i++] = v0;
params[i++] = v1;
for (int j = 1; j < call.getNumberOfPositionalParameters(); j++) {
params[i++] = j + 1;
}

for (int j = 1; j < call.getNumberOfPositionalParameters(); j++) params[i++] = j + 1;

int ki = 0, ji = call.getNumberOfPositionalParameters() + 1;
Pair<String, Integer>[] keys = new Pair[0];

if (call.getKeywords() != null) {
keys = new Pair[call.getKeywords().size()];

for (String k : call.getKeywords()) {
names.put(ji, Atom.findOrCreateUnicodeAtom(k));
keys[ki++] = Pair.make(k, ji++);
Expand All @@ -156,12 +163,12 @@ public IMethod getCalleeTarget(CGNode caller, CallSiteReference site, IClass rec

int result = v1 + 1;
int except = v1 + 2;

CallSiteReference ref =
new DynamicCallSiteReference(call.getCallSite().getDeclaredTarget(), 2);
x.addStatement(new PythonInvokeInstruction(2, result, except, ref, params, keys));

x.addStatement(new PythonInvokeInstruction(2, result, except, ref, params, keys));
x.addStatement(new SSAReturnInstruction(3, result, false));

x.setValueNames(names);

codeBodies.put(key, new PythonSummarizedFunction(tr, x, receiver));
Expand Down Expand Up @@ -273,7 +280,7 @@ else if (baseInstanceKey instanceof ConstantKey) {
* AllocationSiteInNode} cannot be extracted from the given {@link ConstantKey}. A value of <code>
* null</code> most likely indicates that a receiver can potentially be <code>null</code>.
*
* @param constantKey The {@link ConstantKey} from which to extract the correspondoing {@link
* @param constantKey The {@link ConstantKey} from which to extract the corresponding {@link
* AllocationSiteInNode}.
* @return <code>null</code> if the given {@link ConstantKey}'s value is <code>null</code>.
* @throws IllegalArgumentException If the constant's value is another else other than <code>null
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
</formats>
<java>
<googleJavaFormat>
<version>1.17.0</version>
<version>1.19.2</version>
<reflowLongStrings>true</reflowLongStrings>
</googleJavaFormat>
</java>
Expand Down

0 comments on commit 6214a26

Please sign in to comment.