Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add java.lang.invoke.MethodHandleNatives.registerNatives()V and jdk.internal.misc.PreviewFeatures.isPreviewEnabled()Z #144

Merged
merged 1 commit into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions ristretto_vm/src/native_methods/java_lang_invoke_methodhandles.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use crate::arguments::Arguments;
use crate::native_methods::registry::MethodRegistry;
use crate::thread::Thread;
use crate::Result;
use async_recursion::async_recursion;
use ristretto_classloader::Value;
use std::sync::Arc;

/// Register all native methods for java.lang.invoke.MethodHandleNatives.
pub(crate) fn register(registry: &mut MethodRegistry) {
let class_name = "java/lang/invoke/MethodHandleNatives";
registry.register(class_name, "registerNatives", "()V", register_natives);
}

#[expect(clippy::needless_pass_by_value)]
#[async_recursion(?Send)]
async fn register_natives(_thread: Arc<Thread>, _arguments: Arguments) -> Result<Option<Value>> {
Ok(None)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use crate::arguments::Arguments;
use crate::native_methods::registry::MethodRegistry;
use crate::thread::Thread;
use crate::Result;
use async_recursion::async_recursion;
use ristretto_classloader::Value;
use std::sync::Arc;

/// Register all native methods for jdk.internal.misc.PreviewFeatures.
pub(crate) fn register(registry: &mut MethodRegistry) {
let class_name = "jdk/internal/misc/PreviewFeatures";
registry.register(class_name, "isPreviewEnabled", "()Z", is_preview_enabled);
}

#[expect(clippy::needless_pass_by_value)]
#[async_recursion(?Send)]
pub(crate) async fn is_preview_enabled(
_thread: Arc<Thread>,
_arguments: Arguments,
) -> Result<Option<Value>> {
Ok(Some(Value::from(false)))
}
2 changes: 2 additions & 0 deletions ristretto_vm/src/native_methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod java_lang_class;
mod java_lang_classloader;
mod java_lang_double;
mod java_lang_float;
mod java_lang_invoke_methodhandles;
mod java_lang_object;
mod java_lang_processenvironment;
mod java_lang_processimpl;
Expand All @@ -29,6 +30,7 @@ mod java_security_accesscontroller;
mod jdk_internal_loader_bootloader;
mod jdk_internal_loader_nativelibraries;
mod jdk_internal_misc_cds;
mod jdk_internal_misc_previewfeatures;
mod jdk_internal_misc_scopedmemoryaccess;
mod jdk_internal_misc_signal;
mod jdk_internal_misc_unsafe;
Expand Down
14 changes: 8 additions & 6 deletions ristretto_vm/src/native_methods/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use crate::native_methods::{
java_awt_component, java_awt_container, java_awt_frame, java_awt_toolkit, java_awt_window,
java_io_filedescriptor, java_io_fileinputstream, java_io_fileoutputstream,
java_io_unixfilesystem, java_io_winntfilesystem, java_lang_class, java_lang_classloader,
java_lang_double, java_lang_float, java_lang_object, java_lang_processenvironment,
java_lang_processimpl, java_lang_ref_reference, java_lang_reflect_array, java_lang_runtime,
java_lang_securitymanager, java_lang_shutdown, java_lang_stacktraceelement,
java_lang_stringutf16, java_lang_system, java_lang_thread, java_lang_throwable,
java_security_accesscontroller, jdk_internal_loader_bootloader,
jdk_internal_loader_nativelibraries, jdk_internal_misc_cds,
java_lang_double, java_lang_float, java_lang_invoke_methodhandles, java_lang_object,
java_lang_processenvironment, java_lang_processimpl, java_lang_ref_reference,
java_lang_reflect_array, java_lang_runtime, java_lang_securitymanager, java_lang_shutdown,
java_lang_stacktraceelement, java_lang_stringutf16, java_lang_system, java_lang_thread,
java_lang_throwable, java_security_accesscontroller, jdk_internal_loader_bootloader,
jdk_internal_loader_nativelibraries, jdk_internal_misc_cds, jdk_internal_misc_previewfeatures,
jdk_internal_misc_scopedmemoryaccess, jdk_internal_misc_signal, jdk_internal_misc_unsafe,
jdk_internal_misc_vm, jdk_internal_module_modulebootstrap, jdk_internal_reflect_reflection,
jdk_internal_util_systemprops_raw, sun_io_win32errormode, sun_misc_unsafe, sun_misc_vm,
Expand Down Expand Up @@ -59,6 +59,7 @@ impl MethodRegistry {
java_lang_classloader::register(&mut method_registry);
java_lang_double::register(&mut method_registry);
java_lang_float::register(&mut method_registry);
java_lang_invoke_methodhandles::register(&mut method_registry);
java_lang_object::register(&mut method_registry);
java_lang_processenvironment::register(&mut method_registry);
java_lang_processimpl::register(&mut method_registry);
Expand All @@ -76,6 +77,7 @@ impl MethodRegistry {
jdk_internal_loader_bootloader::register(&mut method_registry);
jdk_internal_loader_nativelibraries::register(&mut method_registry);
jdk_internal_misc_cds::register(&mut method_registry);
jdk_internal_misc_previewfeatures::register(&mut method_registry);
jdk_internal_misc_scopedmemoryaccess::register(&mut method_registry);
jdk_internal_misc_signal::register(&mut method_registry);
jdk_internal_misc_unsafe::register(&mut method_registry);
Expand Down