I need to make smaller commits
This commit is contained in:
parent
64eef60c4e
commit
0c54a1d7e1
8 changed files with 377 additions and 83 deletions
|
@ -1,4 +1,7 @@
|
|||
|
||||
use crate::heap_area::FieldValue;
|
||||
use crate::jvm::wrap_stackframe_error;
|
||||
use crate::stackframe::StackValue;
|
||||
use crate::classfile::{ AbstractTypeDescription, AbstractTypeKind, MethodDescriptor };
|
||||
use crate::native_registry::NativeMethodCallable;
|
||||
use crate::jvm::JVM;
|
||||
|
@ -13,10 +16,110 @@ pub fn todo_call(_: &mut JVM) -> Result<JVMCallbackOperation, Error> {
|
|||
todo!()
|
||||
}
|
||||
|
||||
pub fn java_lang_object_get_class(jvm: &mut JVM) -> Result<JVMCallbackOperation, Error> {
|
||||
todo!()
|
||||
pub struct EntryPoint {}
|
||||
|
||||
impl EntryPoint {
|
||||
pub fn populate_unsafe_constants(jvm: &mut JVM) -> Result<JVMCallbackOperation, Error> {
|
||||
jvm.heap_area.static_area.set(&String::from("jdk/internal/misc/UnsafeConstants"), &String::from("ADDRESS_SIZE0"), FieldValue::Int(4))?; // objectreference use u32
|
||||
|
||||
jvm.heap_area.static_area.set(&String::from("jdk/internal/misc/UnsafeConstants"), &String::from("PAGE_SIZE"), FieldValue::Int(4096))?;
|
||||
// TODO: Get actual page size
|
||||
|
||||
jvm.heap_area.static_area.set(&String::from("jdk/internal/misc/UnsafeConstants"), &String::from("BIG_ENDIAN"), FieldValue::Boolean(cfg!(target_endian = "big")))?;
|
||||
|
||||
// This is the safe version, TODO: Change it to the actual value
|
||||
jvm.heap_area.static_area.set(&String::from("jdk/internal/misc/UnsafeConstants"), &String::from("UNALIGNED_ACCESS"), FieldValue::Boolean(false))?;
|
||||
|
||||
// This is the safe version, TODO: Change it to the actual value
|
||||
jvm.heap_area.static_area.set(&String::from("jdk/internal/misc/UnsafeConstants"), &String::from("DATA_CACHE_LINE_FLUSH_SIZE"), FieldValue::Int(0))?;
|
||||
|
||||
Ok(JVMCallbackOperation::PopFrame())
|
||||
}
|
||||
}
|
||||
|
||||
struct JavaLangClass {}
|
||||
|
||||
impl JavaLangClass {
|
||||
pub fn desired_assertion_status_0(_: &mut JVM) -> Result<JVMCallbackOperation, Error> {
|
||||
Ok(JVMCallbackOperation::ReturnFrame(StackValue::Int(1)))
|
||||
}
|
||||
}
|
||||
|
||||
struct JdkInternalMiscUnsafe {}
|
||||
|
||||
impl JdkInternalMiscUnsafe {
|
||||
pub fn array_index_scale_0(jvm: &mut JVM) -> Result<JVMCallbackOperation, Error> {
|
||||
let frame = {
|
||||
let frame_index = jvm.stack_frames.len() - 1;
|
||||
&mut jvm.stack_frames[frame_index]
|
||||
};
|
||||
let class = jvm.class_store.class_file_from_idx(frame.class_index).unwrap();
|
||||
let method = & class.methods[frame.method_index as usize];
|
||||
let class_class_index = jvm.class_store.class_idx_from_name(&String::from("java/lang/Class")).unwrap();
|
||||
|
||||
let class_reference = wrap_stackframe_error(class, method, frame.load_local_reference(1))?;
|
||||
let component_class_reference = match jvm.heap_area.object_area.get_object_field(class_reference, "componentType", class_class_index, &jvm.class_store).unwrap() {
|
||||
FieldValue::Reference(r) => r,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let index_scale: i32 = if component_class_reference == jvm.class_store.primitive_classes.boolean_class {
|
||||
1
|
||||
} else if component_class_reference == jvm.class_store.primitive_classes.byte_class {
|
||||
1
|
||||
} else if component_class_reference == jvm.class_store.primitive_classes.short_class {
|
||||
2
|
||||
} else if component_class_reference == jvm.class_store.primitive_classes.char_class {
|
||||
2
|
||||
} else if component_class_reference == jvm.class_store.primitive_classes.int_class {
|
||||
4
|
||||
} else if component_class_reference == jvm.class_store.primitive_classes.float_class {
|
||||
4
|
||||
} else if component_class_reference == jvm.class_store.primitive_classes.double_class {
|
||||
8
|
||||
} else if component_class_reference == jvm.class_store.primitive_classes.long_class {
|
||||
8
|
||||
} else {
|
||||
std::mem::size_of::<usize>() as i32
|
||||
};
|
||||
|
||||
Ok(JVMCallbackOperation::ReturnFrame(StackValue::Int(index_scale)))
|
||||
}
|
||||
|
||||
pub fn array_base_offset_0(jvm: &mut JVM) -> Result<JVMCallbackOperation, Error> {
|
||||
// TODO: Check passed class
|
||||
Ok(JVMCallbackOperation::ReturnFrame(StackValue::Int(0)))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct JdkInternalUtilSystemPropsRaw {}
|
||||
|
||||
impl JdkInternalUtilSystemPropsRaw {
|
||||
pub fn platform_properties(jvm: &mut JVM) -> Result<JVMCallbackOperation, Error> {
|
||||
let array_length = jvm.heap_area.static_area.
|
||||
get(
|
||||
&String::from("jdk/internal/util/SystemProps$Raw"),
|
||||
&String::from("FIXED_LENGTH"),
|
||||
AbstractTypeDescription { array_level: 0, kind: AbstractTypeKind::Int() })
|
||||
.unwrap();
|
||||
let array_length = match array_length {
|
||||
FieldValue::Int(i) => i as usize,
|
||||
_ => unreachable!()
|
||||
};
|
||||
|
||||
let array_reference = jvm.heap_area.make_empty_array(&jvm.class_store, AbstractTypeDescription { array_level: 0, kind: AbstractTypeKind::Classname("java/lang/String".into()) }, array_length);
|
||||
|
||||
Ok(JVMCallbackOperation::ReturnFrame(StackValue::Reference(array_reference)))
|
||||
}
|
||||
|
||||
pub fn vm_properties(jvm: &mut JVM) -> Result<JVMCallbackOperation, Error> {
|
||||
let array_reference = jvm.heap_area.make_empty_array(&jvm.class_store, AbstractTypeDescription { array_level: 0, kind: AbstractTypeKind::Classname("java/lang/String".into()) }, 2);
|
||||
|
||||
Ok(JVMCallbackOperation::ReturnFrame(StackValue::Reference(array_reference)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn function_for(class_name: &str, m: &crate::classfile::MethodInfo) -> Result<NativeMethodCallable, Error> {
|
||||
let method_name: &str = &m.name;
|
||||
match (class_name, method_name) {
|
||||
|
@ -51,7 +154,7 @@ pub fn function_for(class_name: &str, m: &crate::classfile::MethodInfo) -> Resul
|
|||
return Err(Error::RunTimeError(format!("Native descriptor mismatch for method '{class_name}.{method_name}': found '{}' but expected '{}'", m.descriptor.source_string(), expected_descriptor.source_string())));
|
||||
}
|
||||
|
||||
Ok(todo_call)
|
||||
Ok(JavaLangClass::desired_assertion_status_0)
|
||||
}
|
||||
|
||||
("java/lang/Class", "getClassAccessFlagsRaw0") => {
|
||||
|
@ -487,7 +590,7 @@ pub fn function_for(class_name: &str, m: &crate::classfile::MethodInfo) -> Resul
|
|||
return Err(Error::RunTimeError(format!("Native descriptor mismatch for method '{class_name}.{method_name}': found '{}' but expected '{}'", m.descriptor.source_string(), expected_descriptor.source_string())));
|
||||
}
|
||||
|
||||
Ok(todo_call)
|
||||
Ok(ignore_call)
|
||||
}
|
||||
|
||||
("java/lang/Class", "setSigners") => {
|
||||
|
@ -541,7 +644,7 @@ pub fn function_for(class_name: &str, m: &crate::classfile::MethodInfo) -> Resul
|
|||
return Err(Error::RunTimeError(format!("Native descriptor mismatch for method '{class_name}.{method_name}': found '{}' but expected '{}'", m.descriptor.source_string(), expected_descriptor.source_string())));
|
||||
}
|
||||
|
||||
Ok(java_lang_object_get_class)
|
||||
Ok(todo_call)
|
||||
}
|
||||
|
||||
("java/lang/Object", "hashCode") => {
|
||||
|
@ -746,7 +849,7 @@ pub fn function_for(class_name: &str, m: &crate::classfile::MethodInfo) -> Resul
|
|||
return Err(Error::RunTimeError(format!("Native descriptor mismatch for method '{class_name}.{method_name}': found '{}' but expected '{}'", m.descriptor.source_string(), expected_descriptor.source_string())));
|
||||
}
|
||||
|
||||
Ok(todo_call)
|
||||
Ok(JdkInternalMiscUnsafe::array_base_offset_0)
|
||||
}
|
||||
|
||||
("jdk/internal/misc/Unsafe", "arrayIndexScale0") => {
|
||||
|
@ -761,7 +864,7 @@ pub fn function_for(class_name: &str, m: &crate::classfile::MethodInfo) -> Resul
|
|||
return Err(Error::RunTimeError(format!("Native descriptor mismatch for method '{class_name}.{method_name}': found '{}' but expected '{}'", m.descriptor.source_string(), expected_descriptor.source_string())));
|
||||
}
|
||||
|
||||
Ok(todo_call)
|
||||
Ok(JdkInternalMiscUnsafe::array_index_scale_0)
|
||||
}
|
||||
|
||||
("jdk/internal/misc/Unsafe", "allocateInstance") => {
|
||||
|
@ -2109,6 +2212,34 @@ pub fn function_for(class_name: &str, m: &crate::classfile::MethodInfo) -> Resul
|
|||
Ok(todo_call)
|
||||
}
|
||||
|
||||
("jdk/internal/util/SystemProps$Raw", "platformProperties") => {
|
||||
let expected_descriptor = MethodDescriptor {
|
||||
argument_types: Box::new([
|
||||
]),
|
||||
return_type: AbstractTypeDescription { array_level: 1, kind: AbstractTypeKind::Classname("java/lang/String".to_string())},
|
||||
};
|
||||
|
||||
if m.descriptor != expected_descriptor {
|
||||
return Err(Error::RunTimeError(format!("Native descriptor mismatch for method '{class_name}.{method_name}': found '{}' but expected '{}'", m.descriptor.source_string(), expected_descriptor.source_string())));
|
||||
}
|
||||
|
||||
Ok(JdkInternalUtilSystemPropsRaw::platform_properties)
|
||||
}
|
||||
|
||||
("jdk/internal/util/SystemProps$Raw", "vmProperties") => {
|
||||
let expected_descriptor = MethodDescriptor {
|
||||
argument_types: Box::new([
|
||||
]),
|
||||
return_type: AbstractTypeDescription { array_level: 1, kind: AbstractTypeKind::Classname("java/lang/String".to_string())},
|
||||
};
|
||||
|
||||
if m.descriptor != expected_descriptor {
|
||||
return Err(Error::RunTimeError(format!("Native descriptor mismatch for method '{class_name}.{method_name}': found '{}' but expected '{}'", m.descriptor.source_string(), expected_descriptor.source_string())));
|
||||
}
|
||||
|
||||
Ok(JdkInternalUtilSystemPropsRaw::vm_properties)
|
||||
}
|
||||
|
||||
|
||||
_ => Err(Error::RunTimeError(format!("Failed to find native implementation for method '{class_name}.{method_name}'"))),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue