Skip to content

Commit

Permalink
feat(jvm): add support for Java 22
Browse files Browse the repository at this point in the history
  • Loading branch information
henryhchchc committed Jun 9, 2024
1 parent b6f1650 commit 2cef6c0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Setup JDK
uses: actions/setup-java@v4
with:
java-version: 21
java-version: 22
distribution: corretto
- uses: actions/checkout@v4
name: Checkout source code
Expand Down
11 changes: 9 additions & 2 deletions src/jvm/class/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub struct ConstantPool {
}

/// The maximum supported major version of a class file.
pub const MAX_MAJOR_VERSION: u16 = 65;
pub const MAX_MAJOR_VERSION: u16 = 66;

/// The version of a class file.
#[derive(Debug, PartialOrd, PartialEq, Eq, Copy, Clone)]
Expand Down Expand Up @@ -109,6 +109,8 @@ pub enum Version {
Jdk20(bool),
/// JDK 21
Jdk21(bool),
/// JDK 22
Jdk22(bool),
}
impl Version {
pub(crate) const fn from_versions(major: u16, minor: u16) -> Result<Self, Error> {
Expand Down Expand Up @@ -144,6 +146,8 @@ impl Version {
(64, 0xFFFF) => Ok(Self::Jdk20(true)),
(65, 0x0000) => Ok(Self::Jdk21(false)),
(65, 0xFFFF) => Ok(Self::Jdk21(true)),
(66, 0x0000) => Ok(Self::Jdk22(false)),
(66, 0xFFFF) => Ok(Self::Jdk22(true)),
(major, _) if major > MAX_MAJOR_VERSION => {
Err(Error::Other("Unsupportted class version"))
}
Expand All @@ -166,6 +170,7 @@ impl Version {
| Self::Jdk19(true)
| Self::Jdk20(true)
| Self::Jdk21(true)
| Self::Jdk22(true)
)
}

Expand Down Expand Up @@ -194,6 +199,7 @@ impl Version {
Self::Jdk19(_) => 63,
Self::Jdk20(_) => 64,
Self::Jdk21(_) => 65,
Self::Jdk22(_) => 66,
}
}

Expand All @@ -214,7 +220,8 @@ impl Version {
| Jdk18(enable_preview)
| Jdk19(enable_preview)
| Jdk20(enable_preview)
| Jdk21(enable_preview) => {
| Jdk21(enable_preview)
| Jdk22(enable_preview) => {
if *enable_preview {
u16::MAX
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ macro_rules! malform {
}

macro_rules! see_jvm_spec {
(__latest_jdk) => { 21 };
(__latest_jdk) => { 22 };
($sec:literal $(, $sub_sec:literal )*) => {
concat!(
"See the [JVM Specification §", $sec, $( ".", $sub_sec, )* "]",
Expand Down

0 comments on commit 2cef6c0

Please sign in to comment.