Giter VIP home page Giter VIP logo

native-image-playground's Introduction

GraalVM Native Image Playground

GitHub Workflow Status GraalVM CE Kotlin release Style guide GraalVM Reachability

GraalVM Native Image of a kotlin/java app and publish the platform binaries using GitHub action.

Install GraalVM CE Dev

# Install GraalVM CE Dev
$ ./scripts/graalvm-ce-dev.sh

# Install GraalVM CE
$ curl -s "https://get.sdkman.io" | bash
$ sdk i java 21.0.2-graalce

Build

# Build the native image
$ ./gradlew nativeCompile

# Use trace agent for metadata generation
$ ./gradlew -Pagent run [--rerun-tasks]
# Gracefully shutdown the server instead of killing Gradle run.
$ curl http://localhost:9080/shutdown
$ ./gradlew metadataCopy

# Run native image tests
$ ./gradlew nativeTest
$ ./gradlew -Pagent nativeTest

# Native Image Quick Build
$ ./gradlew nativeCompile -Pquick

# Build Native Image Bundles
$ ./gradlew nativeCompile -Pbundle
$ native-image --bundle-apply="build/native/nativeCompile/native-image-playground.nib"
$ build/native-image-playground.output/default/native-image-playground

# Build by disabling the build cache
$ ./gradlew clean nativeCompile --rerun-tasks --no-build-cache

# GraalVM JIT Mode
$ ./gradlew build
$ java --enable-preview \
       --add-modules=ALL-SYSTEM \
       -jar build/libs/native-image-playground-*-all.jar

# Find out the classes/jars using top modules mentioned in the native-image build output
$ jdeps -q \
        -R \
        --ignore-missing-deps \
        --multi-release=23 \
        build/libs/native-image-playground-*-all.jar

# Build native image from modular jars
$ native-image \
    -p base-module.jar:main-module.jar \
    -m dev.suresh.Main

Run & Debugging

  • Using Distroless

    # Download https://github.com/sureshg/native-image-playground/releases/latest and extract it
    $ chmod +x native-image-playground
    
    # Running "mostly static native image" built on GithubAction (Linux amd64)
    $ docker run \
           -it \
           --rm \
           --platform=linux/amd64 \
           --pull always \
           --publish 9080:9080 \
           --name native-image-playground \
           --mount type=bind,source=$(pwd),destination=/app,readonly \
           --entrypoint=/app/native-image-playground \
           gcr.io/distroless/base
    
    # Running static image compiled using musl libc
    $ docker run \
           -it \
           --rm \
           --pull always \
           --publish 9080:9080 \
           --name native-image-playground \
           --mount type=bind,source=$(pwd),destination=/app,readonly \
           --entrypoint=/app/native-image-playground \
           gcr.io/distroless/static
    
    # To kill the container
    $ docker kill native-image-playground
  • List all runtime options

    $ build/native/nativeCompile/native-image-playground -XX:PrintFlags= 2>&1
    
    # Eg: Set HeapDump path
    $ build/native/nativeCompile/native-image-playground -XX:HeapDumpPath=$HOME/heapdump.hprof
  • Object/Shared Lib Details

    # Show shared libs
    $ otool -L build/native/nativeCompile/native-image-playground
    
    # SVM details
    $ strings -a build/native/nativeCompile/native-image-playground | grep -i com.oracle.svm.core.VM
    
    # Show all bundled CA Certs
    $ strings -a build/native/nativeCompile/native-image-playground | grep -i "cn="
  • Mach-O Format Viewer

  • Misc Gradle Tasks

    # Detect unused and misused dependencies
    $ ./gradlew buildHealth
    $ cat build/reports/dependency-analysis/build-health-report.txt
    
    $ ./gradlew reason --id org.jetbrains.kotlin:kotlin-stdlib

Resources


native-image-playground's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar sureshg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

alexrogalskiy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.