Skip to content
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
38 changes: 19 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async-recursion = "1.1.1"
bitflags = "2.9.1"
byteorder = "1.5.0"
byte-unit = "5.1.6"
clap = "4.5.42"
clap = "4.5.43"
console = "0.16.0"
cranelift = "0.122.0"
criterion = { version = "0.7.0", default-features = false }
Expand Down
14 changes: 6 additions & 8 deletions ristretto_classfile/src/attributes/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2068,14 +2068,12 @@ mod test {
let mut bytes = Cursor::new(expected_bytes.to_vec());

// Adjust the frame_type offest before comparing
if let Attribute::Code { attributes, .. } = &mut attribute {
if let Some(Attribute::StackMapTable { frames, .. }) = attributes.get_mut(2) {
if let Some(StackFrame::SameLocals1StackItemFrame { frame_type, .. }) =
frames.get_mut(1)
{
*frame_type = 66; // Update to match the expected frame type
}
}
if let Attribute::Code { attributes, .. } = &mut attribute
&& let Some(Attribute::StackMapTable { frames, .. }) = attributes.get_mut(2)
&& let Some(StackFrame::SameLocals1StackItemFrame { frame_type, .. }) =
frames.get_mut(1)
{
*frame_type = 66; // Update to match the expected frame type
}
let code_attribute = Attribute::from_bytes(&constant_pool, &mut bytes)?;
assert_eq!(attribute, code_attribute);
Expand Down
2 changes: 1 addition & 1 deletion ristretto_classfile/src/constant_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl ConstantPool {
/// assert_eq!(None, iterator.next());
/// ```
#[must_use]
pub fn iter(&self) -> ConstantPoolIterator {
pub fn iter(&self) -> ConstantPoolIterator<'_> {
ConstantPoolIterator::new(self)
}

Expand Down
8 changes: 4 additions & 4 deletions ristretto_classloader/src/class_path_entry/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ impl<'de> Deserialize<'de> for Manifest {
sections.insert(value.to_string(), IndexMap::new());
} else if current_section.is_none() {
attributes.insert(key.to_string(), value.to_string());
} else if let Some(section) = &current_section {
if let Some(section_map) = sections.get_mut(section) {
section_map.insert(key.to_string(), value.to_string());
}
} else if let Some(section) = &current_section
&& let Some(section_map) = sections.get_mut(section)
{
section_map.insert(key.to_string(), value.to_string());
}
}

Expand Down
47 changes: 23 additions & 24 deletions ristretto_gc/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,10 @@ impl GarbageCollector {
/// Checks if an object is already marked to avoid infinite loops during tracing. Used by
/// the `Trace` implementations for cycle detection.
pub(crate) fn is_object_marked(&self, ptr: SafePtr) -> bool {
if let Ok(objects) = self.objects.read() {
if let Some(metadata) = objects.get(&ptr) {
return metadata.is_marked();
}
if let Ok(objects) = self.objects.read()
&& let Some(metadata) = objects.get(&ptr)
{
return metadata.is_marked();
}
false
}
Expand All @@ -379,28 +379,28 @@ impl GarbageCollector {
/// Marks an object as reachable in the object registry. Used during garbage collection to mark
/// objects that are reachable from roots.
pub(crate) fn mark_object(&self, ptr: SafePtr) {
if let Ok(mut objects) = self.objects.write() {
if let Some(metadata) = objects.get_mut(&ptr) {
trace!("object: {:#x} marked reachable", ptr.0);
metadata.mark();
}
if let Ok(mut objects) = self.objects.write()
&& let Some(metadata) = objects.get_mut(&ptr)
{
trace!("object: {:#x} marked reachable", ptr.0);
metadata.mark();
}
}

/// Attempts to mark an object as reachable. Returns `true` if this is the first time marking
/// the object, `false` if already marked. This is used for cycle detection during tracing to
/// prevent infinite recursion.
pub(crate) fn try_mark_object(&self, ptr: SafePtr) -> bool {
if let Ok(mut objects) = self.objects.write() {
if let Some(metadata) = objects.get_mut(&ptr) {
let was_unmarked = metadata.mark();
if was_unmarked {
trace!("object: {:#x} marked reachable (first time)", ptr.0);
} else {
trace!("object: {:#x} already marked, skipping trace", ptr.0);
}
return was_unmarked;
if let Ok(mut objects) = self.objects.write()
&& let Some(metadata) = objects.get_mut(&ptr)
{
let was_unmarked = metadata.mark();
if was_unmarked {
trace!("object: {:#x} marked reachable (first time)", ptr.0);
} else {
trace!("object: {:#x} already marked, skipping trace", ptr.0);
}
return was_unmarked;
}
false
}
Expand Down Expand Up @@ -685,12 +685,11 @@ impl GarbageCollector {
};

let ptr = SafePtr::from_ptr(gc_trace_ptr.as_raw_ptr());
if let Ok(mut objects_guard) = objects.write() {
if let Some(metadata) = objects_guard.get_mut(&ptr) {
if metadata.mark() {
final_processed += 1;
}
}
if let Ok(mut objects_guard) = objects.write()
&& let Some(metadata) = objects_guard.get_mut(&ptr)
&& metadata.mark()
{
final_processed += 1;
}
}

Expand Down
44 changes: 22 additions & 22 deletions ristretto_gc/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,31 +154,31 @@ impl ObjectMetadata {
}

// First, run the finalizer if present
if let Ok(mut finalizer_guard) = self.finalizer.try_lock() {
if let Some(finalizer) = finalizer_guard.take() {
// Execute finalizer in a safe context
std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
finalizer();
}))
.unwrap_or_else(|_| {
// Log finalizer panic but don't propagate it
eprintln!("Warning: Finalizer panicked during object cleanup");
});
}
if let Ok(mut finalizer_guard) = self.finalizer.try_lock()
&& let Some(finalizer) = finalizer_guard.take()
{
// Execute finalizer in a safe context
std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
finalizer();
}))
.unwrap_or_else(|_| {
// Log finalizer panic but don't propagate it
eprintln!("Warning: Finalizer panicked during object cleanup");
});
}

// Then, drop the object with additional safety checks
if let Ok(mut drop_fn_guard) = self.drop_fn.try_lock() {
if let Some(drop_fn) = drop_fn_guard.take() {
// Execute drop function in a safe context
std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
drop_fn();
}))
.unwrap_or_else(|_| {
// Log drop panic but don't propagate it
eprintln!("Warning: Drop function panicked during object cleanup");
});
}
if let Ok(mut drop_fn_guard) = self.drop_fn.try_lock()
&& let Some(drop_fn) = drop_fn_guard.take()
{
// Execute drop function in a safe context
std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
drop_fn();
}))
.unwrap_or_else(|_| {
// Log drop panic but don't propagate it
eprintln!("Warning: Drop function panicked during object cleanup");
});
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions ristretto_vm/src/assignable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ impl Assignable for Arc<Class> {
}

// Check inheritance hierarchy
if let Some(parent) = other.parent()? {
if Box::pin(self.is_assignable_from(thread, &parent)).await? {
return Ok(true);
}
if let Some(parent) = other.parent()?
&& Box::pin(self.is_assignable_from(thread, &parent)).await?
{
return Ok(true);
}

// Check interfaces
Expand Down
10 changes: 5 additions & 5 deletions ristretto_vm/src/build/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,11 @@ fn java_version_vec(call: &ExprCall) -> Vec<Version> {
}
/// Returns the Java version based on the provided expression.
fn java_version(expression: Option<&Expr>) -> Version {
if let Some(Expr::Path(path)) = expression {
if let Some(segment) = path.path.segments.first() {
let version = segment.ident.to_string();
return parse_java_version(&version);
}
if let Some(Expr::Path(path)) = expression
&& let Some(segment) = path.path.segments.first()
{
let version = segment.ident.to_string();
return parse_java_version(&version);
}
panic!("Unsupported Java version in intrinsic method attribute: {expression:?}");
}
Expand Down
6 changes: 5 additions & 1 deletion ristretto_vm/src/instruction/invokedynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,11 @@ async fn validate_call_site(
// Validate CallSite.type() matches expected MethodType
let type_method = call_site_class.try_get_method("type", "()Ljava/lang/invoke/MethodType;")?;
let call_site_type = thread
.try_execute(&call_site_class, &type_method, &[call_site.clone()])
.try_execute(
&call_site_class,
&type_method,
std::slice::from_ref(call_site),
)
.await?;
let expected_method_type = get_method_type(thread, bootstrap_method_descriptor).await?;

Expand Down
5 changes: 2 additions & 3 deletions ristretto_vm/src/instruction/invokevirtual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ pub(crate) fn resolve_method(
while let Some(interface) = interfaces.pop() {
if let Ok((interface, method)) =
lookup_method_in_hierarchy(interface.clone(), name, descriptor)
&& !method.is_abstract()
{
if !method.is_abstract() {
return Ok((interface, method));
}
return Ok((interface, method));
}
let super_interfaces = interface.interfaces()?;
interfaces.extend(super_interfaces);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ mod tests {
.object(
"java/lang/ref/WeakReference",
"Ljava/lang/Object;",
&[value.clone()],
std::slice::from_ref(&value),
)
.await?;
let mut parameters = Parameters::default();
Expand Down
2 changes: 1 addition & 1 deletion ristretto_vm/src/java_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ async fn to_class_object(thread: &Thread, class: &Arc<Class>) -> Result<Value> {
.try_invoke(
"java.lang.ClassLoader",
"getUnnamedModule()Ljava/lang/Module;",
&[class_loader_object.clone()],
std::slice::from_ref(&class_loader_object),
)
.await?;
object.set_value_unchecked("module", module)?;
Expand Down
Loading
Loading