{"id":15664146,"url":"https://github.com/borkdude/refl","last_synced_at":"2025-05-06T18:49:18.988Z","repository":{"id":49419020,"uuid":"376284778","full_name":"borkdude/refl","owner":"borkdude","description":"Clean up generated reflection configs for GraalVM native-image compiled Clojure programs","archived":false,"fork":false,"pushed_at":"2021-06-30T09:42:27.000Z","size":15,"stargazers_count":17,"open_issues_count":3,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-31T01:51:16.615Z","etag":null,"topics":["clojure","graalvm","graalvm-native-image","reflection"],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/borkdude.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-12T12:29:50.000Z","updated_at":"2022-02-10T18:11:21.000Z","dependencies_parsed_at":"2022-09-06T07:30:49.393Z","dependency_job_id":null,"html_url":"https://github.com/borkdude/refl","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borkdude%2Frefl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borkdude%2Frefl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borkdude%2Frefl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borkdude%2Frefl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/borkdude","download_url":"https://codeload.github.com/borkdude/refl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252749881,"owners_count":21798611,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clojure","graalvm","graalvm-native-image","reflection"],"created_at":"2024-10-03T13:41:26.245Z","updated_at":"2025-05-06T18:49:18.961Z","avatar_url":"https://github.com/borkdude.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# refl\n\nAn example project and script to clean up reflection configurations produced by\nthe GraalVM native-image-agent for Clojure projects.\n\n## Problem description\n\nThe reflection configs produced by the GraalVM native-image-agent contain many\nfalse positives for Clojure programs. This can be alleviated using a\ncaller-based filter, like described\n[here](https://github.com/lread/clj-graal-docs#reflection). But excluding all\ncalls from `clojure.lang.RT` may be too coarse for some programs. This repo\noffers a finer-grained solution.\n\n## How it works\n\nThis project invokes `GRAALVM_HOME/bin/java` on an AOT-ed Clojure program that\ndoes runtime reflection, twice. In both runs the native-image-agent is used. The\nfirst time it is invoked a `trace-file.json` will be produced. The second time a\n`reflect-config.json` will be produced. Unfortunately the `reflect-config.json`\nisn't very usable for GraalVM native-image yet, since it contains a lot of false\npositives. Using the script `script/gen-reflect-config.clj` the information from\nboth JSON files is combined to create a cleaned up version of the reflect\nconfig, called `reflect-config-cleaned.json`. This config is then used for\nnative compilation.\n\n## How to use\n\nThis project is intended as a reference example on how you _could_ clean up your\ngenerated reflection config. Feel free to copy the code and change it to your\nneeds. See the [tasks](#tasks) section to see what you can do in this project.\n\n## Requirements\n\nDownload GraalVM and set `GRAALVM_HOME`. You will also need `clojure` for\nClojure compilation. Scripts are executed with `bb`\n([babashka](https://babashka.org/)).\n\n## The example\n\nThis is the example Clojure program that performs reflection at runtime:\n\n``` clojure\n(ns refl.main\n  (:require [clojure.java.io :as io])\n  (:gen-class))\n\n(defn refl-str [s]\n  s)\n\n(defn file [f]\n  (io/file f))\n\n(defn -main [\u0026 _]\n  (let [res (refl-str \"foo\")]\n    (println (.length res)) ;; reflect on string\n    (prn (type (into-array [res res]))) ;; make array of unknown type\n    (println (.getPath (file \".\"))))) ;; reflect on file\n```\n\nThis is the generated [reflection config](reflect-config-cleaned.json), after executing `bb gen-reflect-config`:\n\n``` json\n[ {\n  \"name\" : \"java.io.File\",\n  \"allPublicMethods\" : true\n}, {\n  \"name\" : \"java.lang.Object[]\"\n}, {\n  \"name\" : \"java.lang.String\",\n  \"allPublicMethods\" : true\n}, {\n  \"name\" : \"java.lang.String[]\"\n}, {\n  \"name\" : \"java.lang.reflect.AccessibleObject\",\n  \"methods\" : [ {\n    \"name\" : \"canAccess\",\n    \"parameterTypes\" : [ \"java.lang.Object\" ]\n  } ]\n} ]\n```\n\nNote that the raw [`reflect-config.json`](reflect-config.json) is 527 lines long and contains many\nfalse positives, mainly due to calls to `Class/forName` in `clojure.lang.RT` and\nsome other places. Unfortunately ignoring all calls from `clojure.lang.RT` is\ntoo coarse, since it also does reflection to create arrays.\n\nThe `java.lang.reflect.AccessibleObject` is needed because the\n`clojure.lang.Reflector` reflectively looks up the `canAccess` method on\n`Method` [here](https://github.com/clojure/clojure/blob/b1b88dd25373a86e41310a525a21b497799dbbf2/src/jvm/clojure/lang/Reflector.java#L38). How meta.\n\n## Tasks\n\nSee `bb tasks`:\n\n```\nThe following tasks are available:\n\ncompile-clj\nclasspath\ngen-reflect-config\ncompile-native\n```\n\n## License\n\n[Unlicense](https://unlicense.org/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborkdude%2Frefl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fborkdude%2Frefl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborkdude%2Frefl/lists"}