Packages

  • package root
    Definition Classes
    root
  • package org
    Definition Classes
    root
  • package opalj

    OPAL is a Scala-based framework for the static analysis, manipulation and creation of Java bytecode.

    OPAL is a Scala-based framework for the static analysis, manipulation and creation of Java bytecode. OPAL is designed with performance, scalability and adaptability in mind.

    Its main components are:

    • a library (Common) which provides generally useful data-structures and algorithms for static analyses.
    • a framework for implementing lattice based static analyses (Static Analysis Infrastructure)
    • a framework for parsing Java bytecode (Bytecode Infrastructure) that can be used to create arbitrary representations.
    • a library to create a one-to-one in-memory representation of Java bytecode (Bytecode Disassembler).
    • a library to create a representation of Java bytecode that facilitates writing simple static analyses (Bytecode Representation - org.opalj.br).
    • a scalable, easily customizable framework for the abstract interpretation of Java bytecode (Abstract Interpretation Framework - org.opalj.ai).
    • a library to extract dependencies between code elements and to facilitate checking architecture definitions.
    • a library for the lightweight manipulation and creation of Java bytecode (Bytecode Assembler).

    General Design Decisions

    Thread Safety

    Unless explicitly noted, OPAL is thread safe. I.e., the classes defined by OPAL can be considered to be thread safe unless otherwise stated. (For example, it is possible to read and process class files concurrently without explicit synchronization on the client side.)

    No null Values

    Unless explicitly noted, OPAL does not null values I.e., fields that are accessible will never contain null values and methods will never return null. If a method accepts null as a value for a parameter or returns a null value it is always explicitly documented. In general, the behavior of methods that are passed null values is undefined unless explicitly documented.

    No Typecasts for Collections

    For efficiency reasons, OPAL sometimes uses mutable data-structures internally. After construction time, these data-structures are generally represented using their generic interfaces (e.g., scala.collection.{Set,Map}). However, a downcast (e.g., to add/remove elements) is always forbidden as it would effectively prevent thread-safety.

    Assertions

    OPAL makes heavy use of Scala's Assertion Facility to facilitate writing correct code. Hence, for production builds (after thorough testing(!)) it is highly recommend to build OPAL again using -Xdisable-assertions.

    Definition Classes
    org
  • package util

    Utility methods.

    Utility methods.

    Definition Classes
    opalj
  • Counting
  • GlobalPerformanceEvaluation
  • InMemoryClassLoader
  • IntStatistics
  • Milliseconds
  • Nanoseconds
  • PerformanceEvaluation
  • Return
  • Seconds

object PerformanceEvaluation

Collection of helper functions useful when evaluating the performance of some code.

Source
PerformanceEvaluation.scala
Example:
  1. Measuring the time and memory used by some piece of code:

    import org.opalj.util.PerformanceEvaluation.{memory,time}
    var store : Array[Object] = null
    implicit val logContext = Some(org.opalj.log.GlobalLogContext)
    for(i <- 1 to 5){
      memory{store = null}(l => println("empty: "+l))
      memory{
        time{
          store = Array.fill(1000000){val l : Object = List(i); l}
       }(t => println("time:"+t.toSeconds))
      }(l => println("non-empty:"+l))
    }
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. PerformanceEvaluation
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @IntrinsicCandidate()
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  8. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @IntrinsicCandidate()
  9. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @IntrinsicCandidate()
  10. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  11. def memory[T](f: => T)(mu: (Long) => Unit)(implicit logContext: Option[LogContext] = None): T

    Measures the amount of memory that is used as a side-effect of executing the given function f.

    Measures the amount of memory that is used as a side-effect of executing the given function f. I.e., the amount of memory is measured that is used before and after executing f; i.e., the permanent data structures that are created by f are measured.

    Note

    If large data structures are used by f that are not used anymore afterwards then it may happen that the used amount of memory is negative.

  12. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  13. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @IntrinsicCandidate()
  14. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @IntrinsicCandidate()
  15. def run[T, X](f: => T)(r: (Nanoseconds, T) => X): X

    Times the execution of a given function f.

    Times the execution of a given function f.

    r

    A function that is passed the time that it took to evaluate f and the result produced by f; r is only called if f succeeds.

  16. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  17. def time[T](epsilon: Int, consideredRunsEpsilon: Int, minimalNumberOfRelevantRuns: Int, f: => T, runGC: Boolean = false)(r: (Nanoseconds, Seq[Nanoseconds]) => Unit): T

    Times the execution of a given function f until the execution time has stabilized and the average time for evaluating f is only changing in a well-understood manner.

    Times the execution of a given function f until the execution time has stabilized and the average time for evaluating f is only changing in a well-understood manner.

    In general, time repeats the execution of f as long as the average changes significantly. Furthermore, f is executed at least minimalNumberOfRelevantRuns times and only those runs are taken into consideration for the calculation of the average that are consideredRunsEpsilon% worse than the best run. However, if we have more than 10*minimalNumberOfRelevantRuns runs that did not contribute to the calculation of the average, the last run is added anyway. This way, we ensure that the evaluation will more likely terminate in reasonable time without affecting the average too much. Nevertheless, if the behavior of f is extremely erratic, the evaluation may not terminate.

    Example Usage

    import org.opalj.util.PerformanceEvaluation._
    import org.opalj.util._
    time[String](2,4,3,{Thread.sleep(300).toString}){ (t, ts) =>
        val sTs = ts.map(t => f"${t.toSeconds.timeSpan}%1.4f").mkString(", ")
        println(f"Avg: ${avg(ts).timeSpan}%1.4f; T: ${t.toSeconds.timeSpan}%1.4f; Ts: $sTs")
    }
    import org.opalj.util.PerformanceEvaluation.{gc,memory,time,avg}
    var store : Array[Object] = null
    implicit val logContext = Some(org.opalj.log.GlobalLogContext)
    time{
      for(i <- 1 to 5){
        memory{store = null}(l => println("empty: "+l))
        memory{
          time(2,4,3,
               {store = Array.fill(1000000){val l : Object = List(i); l}},
               runGC=true
          ){ (t, ts) =>
             val sTs = ts.map(t => f"${t.toSeconds.timeSpan}%1.4f").mkString(", ")
             println(f"Avg: ${avg(ts).timeSpan}%1.4f; T:${t.toSeconds.timeSpan}%1.4f; Ts:$sTs")
           }
        }(l => println("non-empty:"+l))
      }
    }{t => println("overall-time:"+t.toSeconds)}
    epsilon

    The maximum percentage that *the final run* is allowed to affect the average. In other words, if the effect of the last execution on the average is less than epsilon percent then the evaluation halts and the result of the last run is returned.

    consideredRunsEpsilon

    Controls which runs are taken into consideration when calculating the average. Only those runs are used that are at most consideredRunsEpsilon% slower than the last run. Additionally, the last run is only considered if it is at most consideredRunsEpsilon% slower than the average. Hence, it is even possible that the average may rise during the evaluation of f.

    f

    The side-effect free function that will be measured.

    runGC

    If true the garbage collector is run using org.opalj.util.gc() before each run. This may be necessary to get reasonable stable behavior between multiple runs. However, if each run takes very long and the VM has to perform garbage collection as part of executing f (and also has to increase the JVM's heap) getting stable measurements is unlikely.

    r

    A function that is called back whenever f was successfully evaluated. The signature is:

    def r(
        lastExecutionTime:Nanoseconds,
        consideredExecutionTimes : Seq[Nanoseconds]
    ) : Unit
    1. The first parameter is the last execution time of f.
    2. The last parameter is the list of times required to evaluate f that are taken into consideration when calculating the average.
    Note

    **If f has side effects it may not be possible to use this method.**

    ,

    If epsilon is too small we can get an endless loop as the termination condition is never met. However, in practice often a value such as "1 or 2" is still useable.

    ,

    This method can generally only be used to measure the time of some process that does not require user interaction or disk/network access. In the latter case the variation between two runs will be too coarse grained to get meaningful results.

  18. def time[T](f: => T)(r: (Nanoseconds) => Unit): T

    Times the execution of a given function f.

    Times the execution of a given function f. If the timing may be affected by (required) garbage collection runs it is recommended to first run the garbage collector.

    r

    A function that is passed the time (in nanoseconds) that it took to evaluate f. r is called even if f fails with an exception.

  19. def timed[T](f: => T): (Nanoseconds, T)
  20. def toString(): String
    Definition Classes
    AnyRef → Any
  21. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  22. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  23. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

Inherited from AnyRef

Inherited from Any

Ungrouped