Skip to content

26.1. Meeting Notes

David Kozak edited this page Jan 26, 2023 · 12 revisions

IGV tutorial

How to start it?

cd graal/substratevm
mx igv

Example code

public class Main {
    public static void main(String[] args) {
        add(10, 20);
        helloWorld();
        linearBlockOfCode();
        ifElse();
        forLoop();
        methodCallWithArgs();
    }

    private static int add(int x, int y) {
        return x + y;
    }

    private static void helloWorld() {
        System.out.println("Hello World");
    }

    private static int linearBlockOfCode() {
        int x = getX();
        int y = getY();
        return x + y;
    }

    private static int ifElse() {
        int x = getX();
        int y = getY();
        int res;
        if (x + y < 100) {
            res = x;
        } else {
            res = y;
        }
        return res;
    }

    private static int forLoop() {
        int y = 0;
        for (int i = 0; i < 100; i++) {
            y += 42;
        }
        return y;
    }


    static String baseName = "foo";

    private static void methodCallWithArgs() {
        String methodName = "bar";
        int data = 42;
        restCall(baseName + "/" + methodName, data);
    }

    private static void restCall(String s, int data) {
        System.out.println("Calling into " + s + " with data " + data);
    }


    private static int getX() {
        return 42;
    }

    private static int getY() {
        return 21;
    }
}

How to dump the graphs

# In substratevm directory
GRAAL_HOME=$(mx graalvm-home)

# then save the file above somewhere as Main.java
$GRAAL_HOME/bin/javac Main.java # compile it to bytecode
$GRAAL_HOME/bin/javap -p -c Main # look at the bytecode
$GRAAL_HOME/bin/native-image -H:PrintGraph=Network -H:MethodFilter="Main.*" -H:Dump=:1  -H:-InlineBeforeAnalysis Main  # compile via native image, dump graphs to IGV

Options

  • -H:PrintGraph=Network
    • Outputs the graphs directly to IGV instead saving them to files
  • -H:MethodFilter="Main.*"
    • Which graphs are we interested in?
  • -H:Dump=:1
    • Controls how detailed output we want, :1 is very high-level, in practise we might need :2 should be enough
  • -H:-InlineBeforeAnalysis
    • This one does not have to be turned on, it was just to prevent the compiler from being to smart and totally eliminate some of the graphs from the example.

Links to learn more

Prophet Plugin Example

tms repository

git clone [email protected]:cloudhubs/tms.git
cd tms/cms
mvn -DskipTests package
cd target
unzip cms-0.0.1-SNAPSHOT.jar
cd BOOT-INF
$GRAAL_HOME/bin/native-image -H:+ProphetPlugin -cp "classes:lib/*"  dummy

Prophet Utils

AnalysisFormat - input for the prophet-utils main

{
  "microservices": [
    {
      "baseDir": "$PATH_TO_BOOT-INF",
      "basePackage": "edu.baylor.ecs.cms",
      "microserviceName": "cms"
    },
    {
      "baseDir": "$PATH_TO_BOOT-INF",
      "basePackage": "edu.baylor.ems",
      "microserviceName": "ems"
    },
    {
      "baseDir": "$PATH_TO_BOOT-INF",
      "basePackage": "baylor.csi",
      "microserviceName": "qms"
    }
  ]
}
Clone this wiki locally