use crate::get_thread; use jni::sys::{JNIEnv, jint, jlong, jobject}; #[unsafe(no_mangle)] pub unsafe extern "system" fn Java_java_lang_Object_hashCode( env: *mut JNIEnv, obj: jobject, ) -> jint { obj as u32 as i32 } #[unsafe(no_mangle)] pub unsafe extern "system" fn Java_java_lang_Object_clone( env: *mut JNIEnv, obj: jobject, ) -> jobject { let thread = &*get_thread(env); let mut gc = thread.gc.write(); let source = gc.get(obj as u32); match gc.clone_object(&source) { Ok(cloned) => cloned.id() as jobject, Err(e) => { // TODO: throw CloneNotSupportedException eprintln!("Clone failed: {:?}", e); std::ptr::null_mut() } } } #[unsafe(no_mangle)] unsafe extern "system" fn Java_java_lang_Object_notifyAll(env: *mut JNIEnv, this: jobject) { // Wake all threads waiting on this object's monitor let thread = &*get_thread(env); thread.gc.read().notify_all(this as u32); } #[unsafe(no_mangle)] unsafe extern "system" fn Java_java_lang_Object_notify(env: *mut JNIEnv, this: jobject) { // Wake one thread waiting on this object's monitor let thread = &*get_thread(env); thread.gc.read().notify_one(this as u32); } #[unsafe(no_mangle)] unsafe extern "system" fn Java_java_lang_Object_wait( env: *mut JNIEnv, this: jobject, timeout_millis: jlong, ) { let thread = &*get_thread(env); let thread_id = thread.id; thread .gc .read() .wait(thread_id, this as u32, timeout_millis) .unwrap(); }