RFR: 8339358: Optimize TypeKind#from

Shaojin Wen swen at openjdk.org
Sun Sep 1 23:34:57 UTC 2024


TypeKind.from(Class) is a frequently called method, which provides a specialized method to improve performance.

The following Compiler log shows that the call stack level is reduced and two reference accesses (descriptorString() -> String.value) are reduced, which can reduce the performance degradation caused by cache misses.

* baseline

@ 48   java.lang.classfile.TypeKind::from (25 bytes)   inline
  @ 1   java.lang.Class::isPrimitive (0 bytes)   intrinsic
  @ 10   java.lang.Class::descriptorString (170 bytes)   failed to inline: callee is too large
  @ 15   java.lang.classfile.TypeKind::fromDescriptor (232 bytes)   failed to inline: callee is too large


* current

@ 52   java.lang.classfile.TypeKind::from (103 bytes)   failed to inline: callee is too large

-------------

Commit messages:
 - remove benchmark incorrect comments
 - use Class#isPrimitive
 - Reorder by frequency
 - Suggestions from @ExE-Boss
 - Update src/java.base/share/classes/java/lang/classfile/TypeKind.java
 - move benchmark to classfile
 - Merge remote-tracking branch 'upstream/master' into optim_type_kind_from
 - add benchmark
 - fix build test error
 - optimize TypeKind#from
 - ... and 2 more: https://git.openjdk.org/jdk/compare/b840b130...91d247af

Changes: https://git.openjdk.org/jdk/pull/20762/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=20762&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8339358
  Stats: 123 lines in 3 files changed: 116 ins; 0 del; 7 mod
  Patch: https://git.openjdk.org/jdk/pull/20762.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/20762/head:pull/20762

PR: https://git.openjdk.org/jdk/pull/20762


More information about the core-libs-dev mailing list