Skip to content

SONARJAVA-7339 [DRAFT][PoC] Serve SonarJava from udg-gen --server get-file/get-types (SemSitter PR #4952) - #6514

Draft
antonioaversa wants to merge 45 commits into
rombirli/semsitter-ecj-replacement-v2from
antonio/poc-semsitter-udg-server
Draft

antonioaversa wants to merge 45 commits into
rombirli/semsitter-ecj-replacement-v2from
antonio/poc-semsitter-udg-server

Conversation

@antonioaversa

@antonioaversa antonioaversa commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Draft PoC. Do not merge. Built on SemSitter's --server mode (get-file / get-types; the first measurements used PR #4952 of SonarSource/semsitter, head 22bbb0bd1f) and on top of #6415 (Romain's ECJ replacement; this PR's base is his branch so the diff shows only the client change). No Jira key.

Update (client rewritten against the current analyzer)

This push replaces the earlier head. The client now talks to a Java-only SemSitter analyzer (a trimmed build of the server that only analyzes Java) instead of the full udg-gen; the measurement tables below were taken with the earlier build and client and are kept only as history, they do not describe this head.

  • Executable: packaged as /semsitter/analyzer-<platform>.xz (linux-x64, linux-aarch64, macos-aarch64 and windows-x64 are packaged; other platforms need -Dsonar.java.semsitter.executable=<path> or SEMSITTER_ANALYZER, and fail with an explicit message otherwise). The packaged build is the optimized, stripped Java-only analyzer.
  • Client: the tree, symbols and types are rebuilt from the analyzer's answers, including generic signatures of library members, wildcards and captures, annotations (with class-file defaults), lambdas and method references, recovered types for unresolved code, and compiler-style warnings derived on the client. Syntax errors are reported as parse errors.
  • Tests, with this analyzer (run with JAVA_HOME on JDK 25): java-frontend 2,039 tests, 0 failures (3 skipped). java-checks 5 failures out of 2,492:
    • 2 ClassBuilderWithMethodCheckTest cases: lambda parameters of an overloaded JDK 25 method are not resolved by the analyzer yet.
    • 2 CollectorsToListCheckTest cases: need full inference of a nested generic call from its return target.
    • 1 SpringAntMatcherOrderCheckTest case: a member type written Outer<X>.Inner is substituted by a newer analyzer protocol that the client does not consume yet.
      The two TryWithResourcesCheckTest cases need a JDK 25 test JVM (Reader.of) and pass with JAVA_HOME on JDK 25. The analyzer-side items are being fixed; this description will be updated when they land.
  • Test expectations: tests and samples that encoded ECJ-only behaviour were adapted with a one-line reason each; no check was weakened. Two non-compiling samples now assert the parse error. java-checks tests run with the built-in library table off (sonar.java.semsitter.frameworkTypes=false) so that they see what the test classpath provides.
  • ECJ-only tests and helpers (bootclasspath handling and similar) were removed because ECJ is no longer part of this build.

What changes

  • The Rust semsitter-bridge process, its prebuilt binaries and the shm/JSONL sessions are replaced by one udg-gen --server per scanner JVM (AnalyzerSession): hello, set-settings + full-gen once per module, get-file per file, get-types with a session cache, release + counters at shutdown.
  • Classpath reaches the server as the scanner gives it: sonar.java.libraries/binaries/test.* become jvm.*, JDK home from sonar.java.jdkHome or the scanner JVM.
  • Executable: -Dsonar.java.semsitter.udg or SEMSITTER_UDG_GEN. Not done: single-source JParser.parse, a shared JVM-side type table.
  • ECJ is not selectable in one jar (Romain's branch removes it); the comparison is two plugin jars, the ECJ one being his merge base 5faffac831 unmodified.

How to read the table

What is measured. One run scans one whole project with the complete SonarJava sensor: parse the sources, build the semantic model, run all 780 java-checks rules, report the issues. Each cell is a single cold run: one fresh JVM, no warm-up iteration, one measured iteration, no cache from a previous run (PVF SensorBenchmark, JMH non-forked, -wi 0 -i 1). JIT warm-up is therefore inside the numbers. Both sides get exactly the same projects, rules and settings.

The two sides.

  • ECJ = baseline. The SonarJava plugin jar of Romain's merge base 5faffac831, unmodified. The scanner JVM parses with ECJ itself. No other process.
  • SemSitter = candidate. The jar of this PR. The same scanner JVM runs the rules, but the syntax and semantic information come from a separate udg-gen --server process (SemSitter PR SONARJAVA-5134 S2245 considers RandomStringUtils.secure|secureStrong as safe #4952). So a SemSitter run is two processes: the scanner JVM and the server.

Columns.

  • Project (classpath given): the project scanned and whether compiled dependencies were passed to both sides. no means no libraries or compiled classes at all (source-only checkout), so types from third-party libraries are unresolved on both sides. 312 jars + classes means OFBiz was built and its 312 dependency jars and compiled classes were given to both sides.
  • Issues ECJ / SemSitter: total number of issues reported by the 780 rules, counted as (rule, file, line) entries. In brackets: how many more (or fewer) issues SemSitter reports than ECJ, in %.
  • Only ECJ: issues reported by ECJ but not by SemSitter (SemSitter missed them). The percentage is relative to the ECJ issue total of that row.
  • Only SemSitter: issues reported by SemSitter but not by ECJ (extra; some are real, some are false positives, see Reading). The percentage is relative to the SemSitter issue total of that row.
  • Instr. G ECJ: CPU instructions retired by the whole ECJ run, in billions (G = 10^9; 1,743 means 1.743 trillion). It includes everything the process did: parsing, semantic model, the 780 rules, issue serialisation and the benchmark harness. Instructions are used instead of wall time because the host was loaded (1-minute load 31 to 89, threshold 5), which makes wall time invalid; instruction counts do not depend on the load. Measured with /usr/bin/time -l.
  • Instr. G SemSitter (JVM + server): scanner JVM + udg-gen server = total. /usr/bin/time -l does not count the instructions of a Java child process, so the server was measured under its own time -l and added. The JVM part is the same work as ECJ's column except that parsing is replaced by asking the server (get-file, get-types) and ingesting the answers. The server part is the whole udg-gen scan of the module plus answering those requests.
  • Ratio: SemSitter total divided by ECJ, with the same figure as a percentage. 1.30x (+30%) means 30 % more instructions than ECJ; below 1.0x would be a win.
  • JVM share of SemSitter total: JVM alone compares only the scanner-JVM part of SemSitter with the whole ECJ run (so it shows the cost on the client side before adding the server); server is the part of the SemSitter total spent in udg-gen.
  • Peak RSS MB ECJ / SemSitter JVM / server: peak resident memory (real RAM), in MB, of the ECJ JVM, the SemSitter scanner JVM and the udg-gen server. The server value comes from 1-second sampling and can under-read short peaks. SemSitter's total memory is the JVM plus the server. Heap was -Xmx4g everywhere except lucene on SemSitter (-Xmx8g).

Server counters line under the table (SemSitter only):

  • 1 scan per run: the server scanned the module once, whatever the batch size.
  • own_parses / shared_parses: files the server parsed for itself versus files it served from the scan it already had. own_parses 0 means no file was parsed twice; shared_parses equals the number of files.
  • type requests: how many get-types calls the client made. type bytes: total size of the answers.
  • Lists run in the table order: OFBiz, SonarQube, openmrs, guava, spring, lucene (OFBiz with classpath is given separately).

Caveats. One run per cell, instruction counts vary about ±5 % between runs, overlapping runs on a loaded host. Only the large gaps mean something.

Measurement (PVF, SensorBenchmark JMH non-forked, 780 rules, one run per cell)

Wall time invalid everywhere (1-minute load 31 to 89, threshold 5). Instructions retired from /usr/bin/time -l; the server runs under its own time -l because the parent's figure excludes a Java child (verified). Full method, caveats and classification: semsitter-dre/java-bridge/08-sonarjava-semsitter-pvf.md (local notes).

Project (classpath given) Issues ECJ / SemSitter Only ECJ (% of ECJ issues) Only SemSitter (% of SemSitter issues) Instr. G ECJ Instr. G SemSitter (JVM + server) Ratio (extra instructions vs ECJ) JVM share of SemSitter total Peak RSS MB ECJ / SemSitter JVM / server
OFBiz (no) 163,298 / 167,305 (SemSitter +2.5%) 241 (0.15%) 4,248 (2.5%) 1,743 1,947 + 318 = 2,265 1.30x (+30%) JVM alone +12% vs ECJ; server 14% of total 3,747 / 3,567 / 1,511
OFBiz (312 jars + classes) 166,736 / 168,359 (SemSitter +1.0%) 187 (0.11%) 1,810 (1.1%) 2,049 2,193 + 328 = 2,521 1.23x (+23%) JVM alone +7% vs ECJ; server 13% of total 2,412 / 3,414 / 1,511
SonarQube sources (no) 152,226 / 155,163 (SemSitter +1.9%) 159 (0.10%) 3,096 (2.0%) 2,022 2,837 + 642 = 3,480 1.72x (+72%) JVM alone +40% vs ECJ; server 18% of total 2,992 / 3,436 / 3,064
openmrs-core (no) 51,544 / 60,226 (SemSitter +16.8%) 163 (0.32%) 8,845 (14.7%) 889 884 + 204 = 1,088 1.22x (+22%) JVM alone -1% vs ECJ; server 19% of total 1,313 / 1,468 / 1,002
guava guava/src (no) 33,019 / 34,679 (SemSitter +5.0%) 105 (0.32%) 1,765 (5.1%) 604 524 + 368 = 891 1.48x (+48%) JVM alone -13% vs ECJ; server 41% of total 932 / 1,940 / 1,895
spring-framework (no) 238,160 / 247,987 (SemSitter +4.1%) 424 (0.18%) 10,251 (4.1%) 2,680 3,984 + 960 = 4,945 1.84x (+84%) JVM alone +49% vs ECJ; server 19% of total 3,911 / 3,905 / 3,814
lucene (no) 356,377 / 374,355 (SemSitter +5.0%) 1,181 (0.33%) 19,159 (5.1%) 3,431 4,930 + 1,248 = 6,178 1.80x (+80%) JVM alone +44% vs ECJ; server 20% of total 4,087 / 7,425 / 3,274 (SemSitter needed -Xmx8g; 4g ran out of memory)
JDK 21 java.base sources (no; the JDK home is given to both sides) 399,788 / 417,657 (SemSitter +4.5%) 1,569 (0.39%) 19,438 (4.7%) 2,947 3,293 + 657 = 3,950 1.34x (+34%) JVM alone +12% vs ECJ; server 17% of total 4,256 / 4,431 / 1,696
guava guava/src (5 jars + classes) 33,945 / 34,788 (SemSitter +2.5%) 187 (0.55%) 1,030 (3.0%) 667 542 + 349 = 891 1.34x (+34%) JVM alone -19% vs ECJ; server 39% of total 1,309 / 1,922 / 1,877
openmrs-core (285 jars + 9 class dirs) 63,798 / 64,987 (SemSitter +1.9%) 820 (1.29%) 2,009 (3.1%) 1,058 1,240 + 210 = 1,450 1.37x (+37%) JVM alone +17% vs ECJ; server 14% of total 1,676 / 2,042 / 1,417
SonarQube sources (350 jars + 111 class dirs) 161,842 / 161,246 (SemSitter -0.4%) 2,642 (1.63%) 2,046 (1.3%) 3,182 4,082 + 759 = 4,841 1.52x (+52%) JVM alone +28% vs ECJ; server 16% of total 2,746 / 3,915 / 3,117
spring-framework (380 jars + 121 class dirs) 255,085 / 260,841 (SemSitter +2.3%) 1,479 (0.58%) 7,235 (2.8%) 4,299 5,469 + 1,098 = 6,567 1.53x (+53%) JVM alone +27% vs ECJ; server 17% of total 4,023 / 4,368 / 3,716
lucene (113 jars + 93 class dirs) 371,173 / 389,318 (SemSitter +4.9%) 2,691 (0.72%) 20,836 (5.4%) 4,267 5,080 + 1,321 = 6,401 1.50x (+50%) JVM alone +19% vs ECJ; server 21% of total 4,003 / 8,399 / 3,359 (SemSitter needed -Xmx8g)

Server counters: 1 scan per run, own_parses 0, shared_parses = file count (1,261 / 7,576 / 1,473 / 611 / 9,516 / 6,085); type requests 10,583 / 43,615 / 13,289 / 1,874 / 34,191 / 17,648; type bytes 19 / 52 / 18 / 14 / 90 / 62 MB (OFBiz with classpath: 4,363 requests, 34 MB).

Added rows: the JDK and projects with jars + classes

Measured later with the same method (one cold run per cell, ECJ and SemSitter interleaved, each run started only with 1-minute load below 8 and no other server/PVF/build process; -Xmx4g, lucene on SemSitter -Xmx8g). Differences from the first rows:

  • Server build: udg-gen built from SemSitter master 15a8a877f7 (PR SONARJAVA-5134 S2245 considers RandomStringUtils.secure|secureStrong as safe #4952 is merged) instead of 22bbb0bd1f. A re-run of OFBiz with classpath on it gave 2,189 + 318 = 2,507 G (table: 2,521 G) and 168,446 issues (table: 168,359), inside the noise. The client jar and the ECJ jar are the same as in the first rows, i.e. measured before the Gitar fixes and the embedded binaries of this PR.
  • JDK row: the SapMachine 21.0.12.1 lib/src.zip, java.base/* only (3,477 files, 1,307,374 lines, ncloc 621,975 ECJ / 623,668 SemSitter). The JDK home is passed to both sides, so the platform classes are already available; a second JDK row with a classpath would only duplicate the scanned sources. The sources that define java.lang.* are scanned next to the same classes in the JDK home, which may affect override and type rules.
  • "jars + classes" rows: dependency jars (all scopes, the trees include tests) plus compiled class directories, passed to both sides as for OFBiz. Built in copies of the trees through Repox only. openmrs-core: the test-suite module (which needs the maven-openmrs-plugin extension, not on Repox) was left out of the build copy, so its sources are scanned without classes. Lucene: a build-copy tweak of the minimum Gradle version.

What the new rows show:

  • Ratio with a classpath: 1.34x to 1.53x (OFBiz 1.23x). Without classpath it was 1.22x to 1.84x. The instruction penalty does not go away with a classpath.
  • SemSitter-only issues drop with a classpath (guava 1,765 to 1,030, openmrs 8,845 to 2,009, SonarQube 3,096 to 2,046, spring 10,251 to 7,235) and the earlier junit-annotation differences (S100, S1176) disappear. Lucene goes up (19,159 to 20,836), driven by S1130 and S3878.
  • Largest SemSitter-only classes with a classpath (rule counts measured, causes mostly inferred): S1130 (unneeded throws; lucene 8,769, spring 2,591): the thrown types of inherited or generic cross-file methods seem to be lost, confirmed by reading two cases; S2175 and S9396/S2387 (generic substitution, member hiding); S3878 (probably varargs resolution); on the JDK S1226 (4,482, probably true positives that ECJ misses) and S1161 (override detection differs).
  • Largest ECJ-only classes: S1874 (deprecated-API use; SonarQube 1,714), S3252, S112, S2696, S2325, S3740, i.e. rules that need member annotations, constants or expression types.
  • S2109 (ReflectionOnNonRuntimeAnnotationCheck) throws ArrayIndexOutOfBoundsException on 1 to 6 files per project under SemSitter (JDK 3, guava 1, openmrs 1, SonarQube 1, spring 4, lucene 6) and never under ECJ.

Reading

  • No instruction win in this PoC: 1.2x to 1.8x of the ECJ run in total. Even the JVM part alone is above ECJ on OFBiz and the three big trees (1.1x to 1.5x); the Java-side ingest and the per-lookup supertype closure were not changed here and were not profiled.
  • Issue differences are mostly classpath-dependent (OFBiz: 4,248 extra issues without, 1,810 with) plus real false positives with the classpath (S2175 generic substitution through supertypes, S9396/S2387 member hiding) and ECJ-only findings that need expression types (S1905, S2293, S1698, S3252). Only OFBiz had a classpath; the other rows are upper bounds. Classification and evidence level per class are in the notes.
  • ReflectionOnNonRuntimeAnnotationCheck (S2109) throws ArrayIndexOutOfBoundsException on 1 to 5 files per project under SemSitter, none under ECJ.
  • Single runs on a loaded host, overlapping runs; only the large gaps are meaningful.

Test plan: mvn test -pl java-frontend,java-checks with the packaged analyzer (macOS aarch64) or -Dsonar.java.semsitter.executable; expected: java-frontend green, java-checks with the failures listed in the Update section. TryWithResourcesCheckTest needs JAVA_HOME on JDK 25.

@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod Bot changed the title [DRAFT][PoC] Serve SonarJava from udg-gen --server get-file/get-types (SemSitter PR #4952) SONARJAVA-7339 [DRAFT][PoC] Serve SonarJava from udg-gen --server get-file/get-types (SemSitter PR #4952) Nov 12, 2026
@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

SONARJAVA-7339

@gitar-bot

gitar-bot Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Warning

Gitar could not complete this run. Comment gitar review to request another review.

Analyzing CI failures

Verification Rules 2/2 met

Functional validation No results

Rules 2 passed 2 not applicable

✅ Internal artifact registries
✅ Repository license compliance

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

Comment on lines +93 to +107
synchronized JsonObject analyze(JsonObject request) throws IOException {
String root = projectRoot(request);
if (process == null) {
start(root);
}
if (!root.equals(scannedKey)) {
scan(request);
scannedKey = root;
}
JsonObject result = new JsonObject();
result.addProperty("ok", true);
result.addProperty("root", root);
result.add("files", request.getAsJsonArray("files"));
return result;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Cross-PR: Sourcepath files outside the module base dir are never scanned · #6501

Breaks when #6501's sourcepath experiment is combined with this PR's udg-gen session, and a sonar.java.internal.sourcepath directory lies outside the module base directory.

How

  1. #6501 adds the sourcepath files to the file list passed to bridge.analyze in JParserConfig.openBridge (java-frontend/src/main/java/org/sonar/java/model/JParserConfig.java:213).
  2. AnalyzerSession.analyze scans only the module root, which is the baseDir set by JavaFrontend. It echoes the request files back without ever sending them to the server (java-frontend/src/main/java/org/sonar/java/semsitter/AnalyzerSession.java:93-107).
  3. The server only indexes --src root (AnalyzerSession.java:136-137), so sourcepath types outside that root never resolve, and no error is reported. #6501's Rust-side changes in semsitter-bridge/src/types.rs are deleted by this PR.

Fix

  • This PR: Forward the extra source directories to the server (for example as an additional --src or a settings key), or fail loudly when a requested file is outside the scanned root.
  • #6501: When rebasing, pass the sourcepath directories through the udg-gen server settings instead of the deleted bridge file list.

Compared 5e3aebe with #6501 at 4be1331

Was this helpful? React with 👍 / 👎

@antonioaversa

Copy link
Copy Markdown
Contributor Author

/pvf

@hashicorp-vault-sonar-prod

Copy link
Copy Markdown
Contributor

📊 Performance Validation complete
🆕 38812 new · 🗑️ 1328168 lost issues
View dashboard

Projects with unexpected PVF results:

  • com.puppycrawl.tools-checkstyle
  • com.redhat.lightblue-lightblue-core-pom
  • guava
  • guava_java9
  • heritrix3
  • junit-junit
  • micrometer
  • netflix-metacat
  • org.activiti-activiti-root
  • org.apache.myfaces.extensions.cdi-myfaces-extcdi-parent
  • org.apache.wicket-wicket-parent
  • org.broadleafcommerce-broadleaf
  • org.codehaus.sonar-plugins.erlang-erlang
  • org.codehaus.sonar-plugins.l10n-sonar-l10n-fr-plugin
  • org.easyrules-easyrules
  • org.grouplens.grapht-grapht
  • org.polyforms-polyforms
  • redisson
  • ro.pippo-pippo-parent
  • tomcat7
  • tomcat8
  • tomcat9
  • xwiki-commons_fixed-9.3.1
  • xwiki-commons_master

leo-geoffroy-sonarsource added a commit that referenced this pull request Nov 13, 2026
# Conflicts:
#	java-frontend/src/main/resources/udg-gen/udg-gen-linux-aarch64.xz
…down on a failed handshake, and resolve a packaged analyzer by platform
…scan early, read declaration annotations and thrown types from the type answers, and decode the flat file frame of the analyzer protocol
…types, imports and constructor choice with the compiler
…ation views, overload choice, static imports, enum constants and generic calls from their targets
…quest on its own, and leave members of undeclared types unknown without libraries
…ild the tree of a file with syntax errors from the recovered answer
…pe-use and package annotations, and keep nullability of local classes local
…mbdas, arrays, instanceof patterns, casts, annotations and import uses with the compiler
…he frontend tests compile against the analyzer-based model
…uper as keywords, keep intersection bounds, report masked catch blocks and align symbol identity with the compiler
…s and constructor invocations, and read default values of annotation members
…ldcard equality and array element types, and align test expectations with the analyzer-based model
…thods when looking for overridden ones, annotate wildcards, type assignment targets and describe unresolved types
…the record, describe parameters of unseen methods and align frontend test expectations
…ons and type arguments where the compiler had them, and align frontend test expectations with the analyzer-based model
…library table out of check tests and align type tests
…ith inferred parameters, type getClass calls and return targets of lambdas, and keep fields of local classes
…supertypes, widen redundant casts in assignments and align non-compiling check tests
…d qualified names unbound in locals, leave lambda parameters without a target unbound and give unresolved annotations no member values
…rameterization with an undeclared argument as unknown
…members of an unknown parameterization unresolved
…class-file annotation class values as type symbols
@antonioaversa
antonioaversa force-pushed the antonio/poc-semsitter-udg-server branch from 3da4910 to 4b017f2 Compare November 16, 2026 12:54

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant