Title: IntelliJ plugin: format in the IDE's JVM, without a new JVM for each call · Issue #223 · openjavaformat/open-java-format · GitHub
Open Graph Title: IntelliJ plugin: format in the IDE's JVM, without a new JVM for each call · Issue #223 · openjavaformat/open-java-format
X Title: IntelliJ plugin: format in the IDE's JVM, without a new JVM for each call · Issue #223 · openjavaformat/open-java-format
Description: What happens The IntelliJ plugin formats in one of two ways. With the Java-based formatter, BootstrappingFormatterService starts a new JVM for every Reformat; with the native binary, NativeImageFormatterService starts the binary. Either ...
Open Graph Description: What happens The IntelliJ plugin formats in one of two ways. With the Java-based formatter, BootstrappingFormatterService starts a new JVM for every Reformat; with the native binary, NativeImageFor...
X Description: What happens The IntelliJ plugin formats in one of two ways. With the Java-based formatter, BootstrappingFormatterService starts a new JVM for every Reformat; with the native binary, NativeImageFor...
Opengraph URL: https://github.com/openjavaformat/open-java-format/issues/223
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"IntelliJ plugin: format in the IDE's JVM, without a new JVM for each call","articleBody":"### What happens\n\nThe IntelliJ plugin formats in one of two ways. With the Java-based formatter, `BootstrappingFormatterService` starts a new JVM for every Reformat; with the native binary, `NativeImageFormatterService` starts the binary. Either way each call pays for a process, and an import optimizer (#222) would pay it again, inside a read action.\n\nTimes of one call on JDK 21, macOS aarch64, with 21.0.2:\n\n| How the formatter runs | `JavaInputAstVisitor.java`, 4,026 lines | A 5-line file |\n|---|---|---|\n| A new JVM for each call (today's Java-based mode) | 0.97 s | 0.3 s |\n| Native binary | 0.28 s | 0.02 s |\n| In the IDE's JVM, first call | 0.65 s | |\n| In the IDE's JVM, warm (median of 30) | 124 ms to format, 9 ms for `fixImports` | |\n\n### How google-java-format does it\n\nIt formats in the IDE's own JVM, never in a process of its own. Its README asks users to add six `--add-exports jdk.compiler/...=ALL-UNNAMED` lines to the IDE's VM options, and `JreConfigurationChecker` shows those instructions when the javac classes cannot be reached.\n\n### Formatting in the IDE's JVM without editing VM options\n\nIntelliJ IDEA 2024.2.6 starts its JVM with, among the `additionalJvmArguments` of its `product-info.json`, `--add-opens=java.base/java.lang=ALL-UNNAMED` and `--add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED`. With `java.lang` open, a plugin can call `Module.implAddExports` and export the javac packages the formatter needs to the class loader it loads the formatter into. Tried in a JVM started with those two flags only, not in a running IDE yet: the formatter loaded into a `URLClassLoader` of its own formatted the file above byte for byte as the command line does, at the times in the table.\n\n### Proposal\n\nLet the plugin run the formatter in the fastest way available, falling back to the next:\n\n1. **In the IDE's JVM**, when the javac packages can be exported to the formatter's class loader, or already are. One class loader per formatter version, as `FormatterServiceLoader` in the Gradle plugin keeps one per set of jars. A formatter bug then happens inside the IDE, and the javac of the IDE's runtime decides which syntax parses, as it does today.\n2. **A formatter daemon**, as Gradle has one: a JVM per formatter version that stays up and takes files over its standard input. As fast as the in-process mode once warm, isolated from the IDE, and free to run on a newer JDK than the IDE's. It needs a server mode in `Main`, a protocol, restarts and cleanup. Worth it only if the in-process mode turns out not to work.\n3. **The native binary**, as today. No JVM to start, slower than warm JIT-compiled code on big files, and its parser is the one of GraalVM 25.\n4. **A new JVM for each call**, as today, when nothing else is possible.\n\n### Open questions\n\n- `Module.implAddExports` is not public API; if JetBrains stops opening `java.lang`, the plugin falls back to the next mode.\n- Which mode the plugin's settings show and which it picks by itself.\n","author":{"url":"https://github.com/abashev","@type":"Person","name":"abashev"},"datePublished":"2026-11-13T20:35:47Z","url":"https://github.com/openjavaformat/open-java-format/issues/223"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a71612c9-6b69-5796-d8f7-cf0cc0edd4a1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D788:6188:2BB2B2:39FEDE:6AFBB795 |
| html-safe-nonce | 5117f0a8985b2624a0671762a47e8d4bb01e4db1f63a87bba0deda5415fb35af |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENzg4OjYxODg6MkJCMkIyOjM5RkVERTo2QUZCQjc5NSIsInZpc2l0b3JfaWQiOiIyNjgyODgyMjQyNzEwODQ1MzMzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 41821bc96bc93ff0aa8c24302bd7e3e5b701c894a6e618ff5a226646c882e49d |
| hovercard-subject-tag | issue:6379505672 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/openjavaformat/open-java-format/223/issue_layout |
| twitter:image | https://opengraph.githubassets.com/511d57952ece20d1ca63b281bf101dcbdff1ff122553f0950bc5da3ef4429fc5/openjavaformat/open-java-format/issues/223 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/511d57952ece20d1ca63b281bf101dcbdff1ff122553f0950bc5da3ef4429fc5/openjavaformat/open-java-format/issues/223 |
| og:image:alt | What happens The IntelliJ plugin formats in one of two ways. With the Java-based formatter, BootstrappingFormatterService starts a new JVM for every Reformat; with the native binary, NativeImageFor... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | abashev |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2b2ef9c1578c18d8ed27027940544c958743213cf4461659f14d3ccdf51e162c |
| turbo-cache-control | no-preview |
| go-import | github.com/openjavaformat/open-java-format git https://github.com/openjavaformat/open-java-format.git |
| octolytics-dimension-user_id | 325177626 |
| octolytics-dimension-user_login | openjavaformat |
| octolytics-dimension-repository_id | 1288055459 |
| octolytics-dimension-repository_nwo | openjavaformat/open-java-format |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | true |
| octolytics-dimension-repository_parent_id | 214273098 |
| octolytics-dimension-repository_parent_nwo | palantir/palantir-java-format |
| octolytics-dimension-repository_network_root_id | 214273098 |
| octolytics-dimension-repository_network_root_nwo | palantir/palantir-java-format |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | e4cce0e99cf61481a318ff12c2e8580153a6c7c6 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width