Track total module access times and add ScopedMemoryAccess registration

This commit is contained in:
james 2025-12-18 21:28:09 +10:30
parent 70d3d94d65
commit 1ed50300c4
No known key found for this signature in database
GPG Key ID: E1FFBA228F4CAD87
7 changed files with 44 additions and 19 deletions

View File

@ -2,6 +2,8 @@ use log::trace;
use sevenz_rust2::ArchiveReader;
use std::collections::{HashMap, HashSet};
use std::fs::File;
use std::ops::{Add, AddAssign};
use std::time::{Duration, Instant};
const DEFAULT_LOCATION: &str = "./lib/modules";
@ -11,6 +13,7 @@ pub struct Bimage {
// inversion, <Package, Module>
// eg. <java.lang, java.base>
packages: HashMap<String, String>,
pub total_access_time: Duration,
}
impl Default for Bimage {
@ -49,6 +52,7 @@ impl Default for Bimage {
image: reader,
modules,
packages,
total_access_time: Default::default(),
}
}
}
@ -81,13 +85,16 @@ impl Bimage {
pub fn get_class(&mut self, module: &str, class: &str) -> Result<Vec<u8>, String> {
// trace!("Modules{:#?}", self.modules);
if class.contains("ScopedMemoryAccess") {
println!("Time to scoped: {:?}", self.total_access_time)
}
let start = Instant::now();
let path = Self::resolve_path(module, class);
self.image
.read_file(&path)
.map_err(|e| {
log::trace!("Class not found {}", path);
e.to_string()
})
let res = self.image.read_file(&path).map_err(|e| {
log::trace!("Class not found {}", path);
e.to_string()
});
self.total_access_time.add_assign(start.elapsed());
res
}
}

View File

@ -14,9 +14,9 @@ use std::fs::File;
use std::io::Read;
use std::path::{Path, PathBuf};
use std::sync::{Arc, OnceLock};
use std::time::Duration;
pub type LoaderRef = Arc<Mutex<ClassLoader>>;
#[deprecated(note = "This method is deprecated and will be removed in future versions")]
pub fn resolve_path(what: &str) -> Result<(PathBuf, String), String> {
let (module, fqn) = what.split_once("/").unwrap_or(("", what));
@ -92,6 +92,9 @@ pub struct ClassLoader {
type LoaderId = Option<u32>;
impl ClassLoader {
pub fn access_time(&self) -> Duration {
self.bimage.total_access_time
}
pub fn new() -> Result<Self, String> {
let loader = Self::default();
// for entry in VM_CLASSES {

View File

@ -37,6 +37,8 @@ fn run() {
stack_trace,
}) => {
println!("took {:?}", start.elapsed());
let access = vm.loader.lock().access_time();
println!("total module access time was {:?}", access);
let thread = vm.threads.get(&vm.main_thread_id).unwrap();
let objs = thread
.gc

View File

@ -1652,7 +1652,7 @@ unsafe extern "system" fn release_string_chars(
str: jstring,
chars: *const jchar,
) {
todo!("release_string_chars")
warn!("release_string_chars")
}
unsafe extern "system" fn new_string_utf(env: *mut JNIEnv, utf: *const c_char) -> jstring {
@ -1697,11 +1697,13 @@ unsafe extern "system" fn get_string_utf_length(env: *mut JNIEnv, str: jstring)
}
unsafe extern "system" fn release_string_utf_chars(
env: *mut JNIEnv,
str: jstring,
_env: *mut JNIEnv,
_str: jstring,
chars: *const c_char,
) {
todo!("release_string_utf_chars")
if !chars.is_null() {
drop(CString::from_raw(chars as *mut c_char));
}
}
unsafe extern "system" fn get_array_length(env: *mut JNIEnv, array: jarray) -> jsize {

View File

@ -320,11 +320,11 @@ impl VmThread {
pub fn invoke_native(&self, method: &MethodRef, mut args: Vec<Value>) -> MethodCallResult {
let symbol_name = generate_jni_method_name(method, false);
// if symbol_name.contains("Java_jdk_internal_reflect_Reflection_getClassAccessFlags") {
// return Err(VmError::Debug(
// "RoastVM specific implementation required for Java_jdk_internal_reflect_Reflection_getClassAccessFlags",
// ));
// }
if symbol_name.contains("Java_jdk_internal_misc_Signal_handle0") {
return Err(VmError::Debug(
"RoastVM specific implementation required for Java_jdk_internal_misc_Signal_handle0",
));
}
if symbol_name.contains("Java_java_lang_Class_desiredAssertionStatus0") {
warn!("MAJOR HACK, figure out what is wrong with desiredAssertionStatus0");

View File

@ -2,6 +2,7 @@
mod CDS;
mod class;
mod memaccess;
mod misc_unsafe;
mod object;
mod reflection;
@ -12,10 +13,10 @@ use jni::objects::{JClass, JObject, JString};
use jni::strings::JNIString;
use jni::sys::{jclass, jlong, jobject, jobjectArray};
use jni::{JNIEnv, NativeMethod};
use roast_vm_core::VmThread;
use roast_vm_core::objects::ReferenceKind;
use roast_vm_core::objects::array::ArrayReference;
use roast_vm_core::objects::object::ObjectReference;
use roast_vm_core::objects::ReferenceKind;
use roast_vm_core::VmThread;
use std::ffi::c_void;
use std::io::Write;
use std::time::{SystemTime, UNIX_EPOCH};

View File

@ -0,0 +1,10 @@
use jni::sys::{JNIEnv, jclass};
#[unsafe(no_mangle)]
pub unsafe extern "system" fn Java_jdk_internal_misc_ScopedMemoryAccess_registerNatives(
env: *mut JNIEnv,
_class: jclass,
) {
// noop
()
}