Snippets

Michael Eichberg [OPAL - 0.8.15] Method call target resolution

Updated by Michael Eichberg

File MethodResolution.scala Modified

  • Ignore whitespace
  • Hide word diff
 }
 
 // (3) Finding the call targets of instance based calls (where the runtime type of the instance is known)
-p.instanceCall(ObjectType("java/langutil/LinkedHashMap"),ObjectType("java/util/AbstractCollection"),"spliterator",MethodDescriptor(IndexedSeq(),ObjectType("java/util/Spliterator"))).map(m => m.toJava(p.classFile(m)))
+p.instanceCall(ObjectType("java/langutil/LinkedHashMap"),ObjectType("java/util/AbstractCollection"),"spliterator",MethodDescriptor(IndexedSeq(),ObjectType("java/util/Spliterator"))).map(m => m.toJava)
 // => default method
 
 p.instanceCall(ObjectType.String,ObjectType("java/util/HashMap"),"reinitialize",MethodDescriptor.NoArgsAndReturnVoid)
   javax.swing.text.rtf.RTFAttributes$GenericAttribute which, however, is NOT already a subtype
   of the interface!
 **/
-p.interfaceCall(ObjectType("javax/swing/text/rtf/RTFAttribute"),"domain",MethodDescriptor.JustReturnsInteger).map(m => m.toJava(p.classFile(m)))
+p.interfaceCall(ObjectType("javax/swing/text/rtf/RTFAttribute"),"domain",MethodDescriptor.JustReturnsInteger).map(m => m.toJava)
 
 // This returns all toString methods which belong to some type which inherits from subtype;
 // as seen above not all methods may be defined by types which inherit from Serializable!
-p.interfaceCall(ObjectType("java/io/Serializable"),"toString",MethodDescriptor.JustReturnsString).map(m => m.toJava(p.classFile(m)))
+p.interfaceCall(ObjectType("java/io/Serializable"),"toString",MethodDescriptor.JustReturnsString).map(m => m.toJava)
Updated by Michael Eichberg

File MethodResolution.scala Modified

  • Ignore whitespace
  • Hide word diff
 
 // (0) General setup
 import org.opalj.collection.immutable._; import org.opalj.br._ ; import org.opalj.br.analyses._; import org.opalj.br.instructions._
-val p = Project(new java.io.File("/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home/jre/lib/"))
+val p = Project(/*some jar/folder with jars/classes*/org.opalj.bytecode.JRELibraryFolder)
 
 // (1) Finding the call targets of invoke static calls
 p.allMethodsWithBody.foreach {m => 
 
 p.instanceCall(ObjectType.String,ObjectType("java/util/HashMap"),"reinitialize",MethodDescriptor.NoArgsAndReturnVoid)
 // => <NO METHOD> (reinitialize is only package visible)
-p.instanceCall(ObjectType("java/util/LinkedHashMap"),ObjectType("java/util/HashMap"),"reinitialize",MethodDescriptor.NoArgsAndReturnVoid)p.instanceCall(ObjectType("java/util/LinkedHashMap"),ObjectType("java/util/HashMap"),"reinitialize",MethodDescriptor.NoArgsAndReturnVoid)
+p.instanceCall(ObjectType("java/util/LinkedHashMap"),ObjectType("java/util/HashMap"),"reinitialize",MethodDescriptor.NoArgsAndReturnVoid)
 // => package visible reinitialize method
 
 /////// HANDLING POLYMORPHIC CALLS
Updated by Michael Eichberg

File MethodResolution.scala Modified

  • Ignore whitespace
  • Hide word diff
 // should not resolve (invokeWithArguments is not signature polymorphic because the flags don't fit!)
 
 p.instanceCall(ObjectType.Object/*IRRELEVANT*/,ObjectType.MethodHandle,"invokeWithArguments",MethodDescriptor.SignaturePolymorphicMethod) 
-// should resolve as usual
+// should resolve as usual
+
+
+// (4) Handling invokeinterface based calls
+/**
+  The interface javax.swing.text.rtf.RTFAttribute defines the method "int domain()" which 
+  is implemented (for the class that implement the interface) by
+  javax.swing.text.rtf.RTFAttributes$GenericAttribute which, however, is NOT already a subtype
+  of the interface!
+**/
+p.interfaceCall(ObjectType("javax/swing/text/rtf/RTFAttribute"),"domain",MethodDescriptor.JustReturnsInteger).map(m => m.toJava(p.classFile(m)))
+
+// This returns all toString methods which belong to some type which inherits from subtype;
+// as seen above not all methods may be defined by types which inherit from Serializable!
+p.interfaceCall(ObjectType("java/io/Serializable"),"toString",MethodDescriptor.JustReturnsString).map(m => m.toJava(p.classFile(m)))
Updated by Michael Eichberg

File MethodResolution.scala Modified

  • Ignore whitespace
  • Hide word diff
 val p = Project(new java.io.File("/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home/jre/lib/"))
 
 // (1) Finding the call targets of invoke static calls
-p.allMethodsWithBody.forall {m => m.body.get.instructions.forall{ 
-    case i : INVOKESTATIC => 
-        val callTargets = p.invokestaticCall(i)
-		// let's report unresolved call targets...
-        if(callTargets.isEmpty) println(i)}
+p.allMethodsWithBody.foreach {m => 
+    m.body.get.instructions.foreach{ 
+      case i : INVOKESTATIC => 
+        val callTargets = p.staticCall(i)
+        // let's report unresolved call targets...
+        if(callTargets.isEmpty) println(i)
+      case _ => ()
+   }
 }
 
-// (e) Finding the call targets of instance based calls (where the runtime type of the instance is known)
+// (3) Finding the call targets of instance based calls (where the runtime type of the instance is known)
 p.instanceCall(ObjectType("java/langutil/LinkedHashMap"),ObjectType("java/util/AbstractCollection"),"spliterator",MethodDescriptor(IndexedSeq(),ObjectType("java/util/Spliterator"))).map(m => m.toJava(p.classFile(m)))
 // => default method
 
 p.instanceCall(ObjectType.String,ObjectType("java/util/HashMap"),"reinitialize",MethodDescriptor.NoArgsAndReturnVoid)
 // => <NO METHOD> (reinitialize is only package visible)
-p.instanceCall(ObjectType("java/util/LinkedHashMap"),ObjectType("java/util/HashMap"),"reinitialize",MethodDescriptor.NoArgsAndReturnVoid)
+p.instanceCall(ObjectType("java/util/LinkedHashMap"),ObjectType("java/util/HashMap"),"reinitialize",MethodDescriptor.NoArgsAndReturnVoid)p.instanceCall(ObjectType("java/util/LinkedHashMap"),ObjectType("java/util/HashMap"),"reinitialize",MethodDescriptor.NoArgsAndReturnVoid)
 // => package visible reinitialize method
 
 /////// HANDLING POLYMORPHIC CALLS
 p.instanceCall(ObjectType.Object/*IRRELEVANT*/,ObjectType.MethodHandle,"invoke",MethodDescriptor.NoArgsAndReturnVoid)
 p.instanceCall(ObjectType.Object/*IRRELEVANT*/,ObjectType.MethodHandle,"invoke",MethodDescriptor.JustReturnsDouble)
 p.instanceCall(ObjectType.Object/*IRRELEVANT*/,ObjectType.MethodHandle,"invokeExact",MethodDescriptor.NoArgsAndReturnVoid)
-p.instanceCall(ObjectType.Object/*IRRELEVANT*/,ObjectType.MethodHandle,"invokeExact",MethodDescriptor.SignaturePolymorphic)
+p.instanceCall(ObjectType.Object/*IRRELEVANT*/,ObjectType.MethodHandle,"invokeExact",MethodDescriptor.SignaturePolymorphicMethod)
 
 p.instanceCall(ObjectType.Object/*IRRELEVANT*/,ObjectType.MethodHandle,"invokeExacter",MethodDescriptor.NoArgsAndReturnVoid) 
 // should not resolve (name does not exist)
 
 p.instanceCall(ObjectType.Object/*IRRELEVANT*/,ObjectType.MethodHandle,"invokeWithArguments",MethodDescriptor.NoArgsAndReturnVoid) 
 // should not resolve (invokeWithArguments is not signature polymorphic because the flags don't fit!)
+
+p.instanceCall(ObjectType.Object/*IRRELEVANT*/,ObjectType.MethodHandle,"invokeWithArguments",MethodDescriptor.SignaturePolymorphicMethod) 
+// should resolve as usual
Updated by Michael Eichberg

File MethodResolution.scala Modified

  • Ignore whitespace
  • Hide word diff
 import org.opalj.collection.immutable._; import org.opalj.br._ ; import org.opalj.br.analyses._; import org.opalj.br.instructions._
 val p = Project(new java.io.File("/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home/jre/lib/"))
 
-// (1) Finding the call targets
-p.allMethodsWithBody.forall {m => m.body.get.instructions.forall{ case i : INVOKESTATIC => if(!p.invokestaticCall(i).isDefined) println(i)}}
+// (1) Finding the call targets of invoke static calls
+p.allMethodsWithBody.forall {m => m.body.get.instructions.forall{ 
+    case i : INVOKESTATIC => 
+        val callTargets = p.invokestaticCall(i)
+		// let's report unresolved call targets...
+        if(callTargets.isEmpty) println(i)}
+}
+
+// (e) Finding the call targets of instance based calls (where the runtime type of the instance is known)
+p.instanceCall(ObjectType("java/langutil/LinkedHashMap"),ObjectType("java/util/AbstractCollection"),"spliterator",MethodDescriptor(IndexedSeq(),ObjectType("java/util/Spliterator"))).map(m => m.toJava(p.classFile(m)))
+// => default method
+
+p.instanceCall(ObjectType.String,ObjectType("java/util/HashMap"),"reinitialize",MethodDescriptor.NoArgsAndReturnVoid)
+// => <NO METHOD> (reinitialize is only package visible)
+p.instanceCall(ObjectType("java/util/LinkedHashMap"),ObjectType("java/util/HashMap"),"reinitialize",MethodDescriptor.NoArgsAndReturnVoid)
+// => package visible reinitialize method
+
+/////// HANDLING POLYMORPHIC CALLS
+p.instanceCall(ObjectType.Object/*IRRELEVANT*/,ObjectType.MethodHandle,"invoke",MethodDescriptor.NoArgsAndReturnVoid)
+p.instanceCall(ObjectType.Object/*IRRELEVANT*/,ObjectType.MethodHandle,"invoke",MethodDescriptor.JustReturnsDouble)
+p.instanceCall(ObjectType.Object/*IRRELEVANT*/,ObjectType.MethodHandle,"invokeExact",MethodDescriptor.NoArgsAndReturnVoid)
+p.instanceCall(ObjectType.Object/*IRRELEVANT*/,ObjectType.MethodHandle,"invokeExact",MethodDescriptor.SignaturePolymorphic)
+
+p.instanceCall(ObjectType.Object/*IRRELEVANT*/,ObjectType.MethodHandle,"invokeExacter",MethodDescriptor.NoArgsAndReturnVoid) 
+// should not resolve (name does not exist)
+
+p.instanceCall(ObjectType.Object/*IRRELEVANT*/,ObjectType.MethodHandle,"invokeWithArguments",MethodDescriptor.NoArgsAndReturnVoid) 
+// should not resolve (invokeWithArguments is not signature polymorphic because the flags don't fit!)
  1. 1
  2. 2
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.