0

I am currently working on getting the CPU footprint from AcmeAir monolithic application: https://github.com/blueperf/acmeair-monolithic-java

I have correctly setup the webapp and database and it can normally function in a docker container.

Normally If I run this command inside the container:

/opt/java/openjdk/bin/java -javaagent:/opt/ol/wlp/bin/tools/ws-javaagent.jar -Djava.awt.headless=true -Djdk.attach.allowAttachSelf=true --add-exports java.base/sun.security.action=ALL-UNNAMED --add-exports java.naming/com.sun.jndi.ldap=ALL-UNNAMED --add-exports java.naming/com.sun.jndi.url.ldap=ALL-UNNAMED --add-exports jdk.naming.dns/com.sun.jndi.dns=ALL-UNNAMED --add-exports java.security.jgss/sun.security.krb5.internal=ALL-UNNAMED --add-exports jdk.attach/sun.tools.attach=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util.concurrent=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED --add-opens java.naming/javax.naming.spi=ALL-UNNAMED --add-opens jdk.naming.rmi/com.sun.jndi.url.rmi=ALL-UNNAMED --add-opens java.naming/javax.naming=ALL-UNNAMED --add-opens java.rmi/java.rmi=ALL-UNNAMED --add-opens java.sql/java.sql=ALL-UNNAMED --add-opens java.management/javax.management=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.desktop/java.awt.image=ALL-UNNAMED --add-opens java.base/java.security=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.base/sun.net.www.protocol.https=ALL-UNNAMED --add-exports jdk.management.agent/jdk.internal.agent=ALL-UNNAMED --add-exports java.base/jdk.internal.vm=ALL-UNNAMED -jar /opt/ol/wlp/bin/tools/ws-server.jar defaultServer

The server will properly boot up and function normally.

However, when I attach PIN onto the process, the server stop function normally.

I have tried three approach:

  1. Use PIN as entrypoint. I overwrite the entrypoint using docker-compose.override.yml to force the java program to start with my script. Here is the docker-compose file:
acmeair-db:
  container_name: acmeair-db
  image: mongo:4.0.0
  net: ${NETWORK}
  privileged: true

acmeair-monolithic-java:
  container_name: acmeair-monolithic-java
  dockerfile: Dockerfile
  net: ${NETWORK}
  entrypoint: ./startup-pin.sh
  build: .
  ports:
    - "80:9080"
  environment:
    - MONGO_HOST=acmeair-db
  volumes_from:
    - acmeair-db
  mem_limit: 1024m
  privileged: true

And here is my starting script:

#!/bin/bash

/pin-gcc-linux/pin -t /pin-gcc-linux/source/tools/ManualExamples/obj-intel64/proccount.so -- /opt/java/openjdk/bin/java -javaagent:/opt/ol/wlp/bin/tools/ws-javaagent.jar -Djava.awt.headless=true -Djdk.attach.allowAttachSelf=true --add-exports java.base/sun.security.action=ALL-UNNAMED --add-exports java.naming/com.sun.jndi.ldap=ALL-UNNAMED --add-exports java.naming/com.sun.jndi.url.ldap=ALL-UNNAMED --add-exports jdk.naming.dns/com.sun.jndi.dns=ALL-UNNAMED --add-exports java.security.jgss/sun.security.krb5.internal=ALL-UNNAMED --add-exports jdk.attach/sun.tools.attach=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util.concurrent=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED --add-opens java.naming/javax.naming.spi=ALL-UNNAMED --add-opens jdk.naming.rmi/com.sun.jndi.url.rmi=ALL-UNNAMED --add-opens java.naming/javax.naming=ALL-UNNAMED --add-opens java.rmi/java.rmi=ALL-UNNAMED --add-opens java.sql/java.sql=ALL-UNNAMED --add-opens java.management/javax.management=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.desktop/java.awt.image=ALL-UNNAMED --add-opens java.base/java.security=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.base/sun.net.www.protocol.https=ALL-UNNAMED --add-exports jdk.management.agent/jdk.internal.agent=ALL-UNNAMED --add-exports java.base/jdk.internal.vm=ALL-UNNAMED -jar /opt/ol/wlp/bin/tools/ws-server.jar defaultServer

There will be trace out, but the server is not functioning normally at all. Most of the services are down and I can't access the server log as well.

  1. I tried to attach the PID to PIN like: /pin-gcc-linux/pin -pid <PID> -t /pin-gcc-linux/source/tools/ManualExamples/obj-intel64/proccount.so

If I attach it from host to container, it will say:

A:  /tmp_proj/pinjen/workspace/pypl-pin-nightly/GitPin/Source/pin/base_l/sysfuncs_linux.cpp: GetProcessName: 107: assertion failed: p

Which is an error I can not find at anywhere.

If I attach it from within the container, it won't crash but will stall and do nothing. It also prints no output.

I would like to know how can Intel PIN work with Java server, and any direction and help will be appreciated. Thank you!

  • 1
    1) I'm not sure Pin is the right tool for your need, unless you have JNI calls. Java is a JIT-ed language (your source is translated to bytecode which is then JIT-ed, that is translated to target CPU instructions). What you're going to obtain here is what the JVM is currently executing internally: you won't see anything (e.g. java function names and things like that) that could be possibly interesting for you (unless you are actually wanting to inspect how the JVM is performing internally). Moreover PIN is itself a JIT-er (of the target executables and binaries), that's double Jit-ing :( – Neitsa Nov 09 '22 at 09:31
  • 1
    2) So unless you need to do dynamic binary instrumentation on JNI calls or inspect the inner workings of the JVM I would definitely try to look for a tool dedicated specifically to Java, e.g. a Java profiler. – Neitsa Nov 09 '22 at 09:33
  • @Neitsa Thank you! If that is the case, do you think disabling JIT would help? – De Santa Michell Nov 09 '22 at 20:54
  • I actually attempted to disable JIT but the server still doesn't seem to run normally. By my understanding, PIN is injecting codes to extract runtime information, which is why we can't allow Java to use JIT since otherwise, it would be injecting into byte code, not machine code. But Since disabling JIT doesn't help, I suppose there are some other issue as well? – De Santa Michell Nov 09 '22 at 21:43
  • The issue isn't jit, it is that pin is not made for managed languages/runtimes like java. You should look for java specific tools for java. – nitzanms Nov 21 '22 at 06:05

0 Answers0