From a5d6a717e176d7384182cf713680c094600e74f3 Mon Sep 17 00:00:00 2001 From: Igor Rudenko Date: Sun, 22 Dec 2024 00:08:23 +0200 Subject: [PATCH 1/8] Add support of getting super class with Class.getSuperclass() --- tests/integration_tests.rs | 23 +++++++ tests/test_data/ArrayClass.java | 15 +++++ tests/test_data/GetSuperclassExample.java | 62 ++++++++++++++++++ .../reflection/trivial/ArrayClass.class | Bin 1582 -> 1897 bytes .../GetSuperclassExample$1.class | Bin 0 -> 471 bytes .../GetSuperclassExample$1LocalClass.class | Bin 0 -> 494 bytes ...etSuperclassExample$ExtendedRunnable.class | Bin 0 -> 373 bytes .../GetSuperclassExample$InnerClass.class | Bin 0 -> 428 bytes .../GetSuperclassExample.class | Bin 0 -> 1773 bytes .../execution_engine/system_native_table.rs | 4 ++ vm/src/heap/heap.rs | 5 -- vm/src/method_area/method_area.rs | 24 +++---- vm/src/system_native/class.rs | 24 +++++++ vm/src/system_native/mod.rs | 2 + vm/src/system_native/unsafe_.rs | 16 ++++- 15 files changed, 153 insertions(+), 22 deletions(-) create mode 100644 tests/test_data/GetSuperclassExample.java create mode 100644 tests/test_data/samples/reflection/trivial/classgetdeclaringclassexample/GetSuperclassExample$1.class create mode 100644 tests/test_data/samples/reflection/trivial/classgetdeclaringclassexample/GetSuperclassExample$1LocalClass.class create mode 100644 tests/test_data/samples/reflection/trivial/classgetdeclaringclassexample/GetSuperclassExample$ExtendedRunnable.class create mode 100644 tests/test_data/samples/reflection/trivial/classgetdeclaringclassexample/GetSuperclassExample$InnerClass.class create mode 100644 tests/test_data/samples/reflection/trivial/classgetdeclaringclassexample/GetSuperclassExample.class diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 6a306998..4262b049 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -581,3 +581,26 @@ HelloWorld! "#, ); } + +#[test] +fn should_support_getting_supper_class() { + assert_success( + "samples.reflection.trivial.classgetdeclaringclassexample.GetSuperclassExample", + r#"Superclass of java.lang.String: class java.lang.Object +Superclass of java.lang.Integer: class java.lang.Number +Superclass of java.lang.Object: null +Superclass of java.lang.Runnable: null +Superclass of samples.reflection.trivial.classgetdeclaringclassexample.GetSuperclassExample$ExtendedRunnable: null +Superclass of int: null +Superclass of void: null +Superclass of [Ljava.lang.String;: class java.lang.Object +Superclass of [I: class java.lang.Object +Superclass of [Ljava.lang.Runnable;: class java.lang.Object +Superclass of samples.reflection.trivial.classgetdeclaringclassexample.GetSuperclassExample$1: class java.lang.Object +Superclass of samples.reflection.trivial.classgetdeclaringclassexample.GetSuperclassExample$1LocalClass: class java.lang.Object +Superclass of samples.reflection.trivial.classgetdeclaringclassexample.GetSuperclassExample$InnerClass: class java.lang.Object +Superclass of java.util.concurrent.TimeUnit: class java.lang.Enum +Superclass of java.util.HashMap: class java.util.AbstractMap +"#, + ); +} diff --git a/tests/test_data/ArrayClass.java b/tests/test_data/ArrayClass.java index a7a7ac5f..fdc750dd 100644 --- a/tests/test_data/ArrayClass.java +++ b/tests/test_data/ArrayClass.java @@ -31,6 +31,15 @@ public static void main(String[] args) { int bit16 = classString == String.class ? 1 : 0; int bit17 = classString.getComponentType() == null ? 1 : 0; + var classRunnableArray = Runnable[].class; + int bit18 = classRunnableArray.isPrimitive() ? 0 : 1; + int bit19 = classRunnableArray.isArray() ? 1 : 0; + Class classRunnable = classRunnableArray.getComponentType(); + int bit20 = classRunnable.isPrimitive() ? 0 : 1; + int bit21 = classRunnable.isArray() ? 0 : 1; + int bit22 = classRunnable == Runnable.class ? 1 : 0; + int bit23 = classRunnable.getComponentType() == null ? 1 : 0; + int result = 0; result = setBit(result, 0, bit0); result = setBit(result, 1, bit1); @@ -50,6 +59,12 @@ public static void main(String[] args) { result = setBit(result, 15, bit15); result = setBit(result, 16, bit16); result = setBit(result, 17, bit17); + result = setBit(result, 18, bit17); + result = setBit(result, 19, bit17); + result = setBit(result, 20, bit17); + result = setBit(result, 21, bit17); + result = setBit(result, 22, bit17); + result = setBit(result, 23, bit17); System.out.println(result); } diff --git a/tests/test_data/GetSuperclassExample.java b/tests/test_data/GetSuperclassExample.java new file mode 100644 index 00000000..882dc4b9 --- /dev/null +++ b/tests/test_data/GetSuperclassExample.java @@ -0,0 +1,62 @@ +package samples.reflection.trivial.classgetdeclaringclassexample; + +import java.util.HashMap; +import java.util.concurrent.TimeUnit; + +public class GetSuperclassExample { + public static void main(String[] args) { + // 1. Basic Case: Standard class hierarchy + printSuperclass(String.class); // java.lang.Object + printSuperclass(Integer.class); // java.lang.Number + + // 2. Case: Object has no superclass + printSuperclass(Object.class); // null + + // 3. Case: Interfaces have no superclass + printSuperclass(Runnable.class); // null + + // 4. Case: Interface extending another interface + printSuperclass(ExtendedRunnable.class); + + // 5. Case: Primitive types have no superclass + printSuperclass(int.class); // null + printSuperclass(void.class); // null + + // 6. Case: Arrays + printSuperclass(String[].class); // java.lang.Object + printSuperclass(int[].class); // java.lang.Object + + // 7. Case: Array of interfaces + printSuperclass(Runnable[].class); // java.lang.Object + + // 8. Case: Anonymous class + Object anonymous = new Object() {}; + printSuperclass(anonymous.getClass()); // java.lang.Object + + // 9. Case: Local class + class LocalClass {} + printSuperclass(LocalClass.class); // java.lang.Object + + // 10. Case: Nested/Inner class + printSuperclass(InnerClass.class); // java.lang.Object + + // 11. Case: Enum classes + printSuperclass(TimeUnit.class); // java.lang.Enum + + // 12. Case: Classes extending from abstract classes + printSuperclass(HashMap.class); // AbstractClass + } + + private static void printSuperclass(Class clazz) { + System.out.print("Superclass of "); + System.out.print(clazz.getName()); + System.out.print(": "); + System.out.println(clazz.getSuperclass()); + } + + // Inner class + static class InnerClass {} + + // Interface extending another interface + interface ExtendedRunnable extends Runnable {} +} diff --git a/tests/test_data/samples/reflection/trivial/ArrayClass.class b/tests/test_data/samples/reflection/trivial/ArrayClass.class index 9a4b32923aa5d1a148e61be1d964c3fef01ddd1b..ef5081dc86b142054f09e197145d8387028ad56c 100644 GIT binary patch delta 769 zcmZY7KTK0m6bA6`oW9pb|IpS~PiwU(ML;T)777L00>uI$(KxUfrxJ{bA(cf36YbT?E>&d>t4@>7pB>DjF*KN|)Sdm(!{Azng~K=x#bYb2*i^$6xCsSKOxk zRmWjpDI*zQ`WO=~jG;bEF^^kkHNW`#MN6!{1|-l|%r8MrOG26hGN>7lh-Oftnjwj4 zhQ-z#l(=R@TB045gl0^Vn&;$#rtLBA@w`XznDChF^F5{|)5YA8dJ%^EI=|HFbd23r z4p*s)QM#$-WgFwvP{Xm033`Ss9bl3UF-2|U=oO~vE%MYwfxcjdPB2T~QKTQ3qo0_k z-zYI*fz@zu5=%USGUrg?MO3+tWxkCSzJpcXMU5X~ji2BKKSw>rhgj#A*uaYVsy8S& jJLXg8qnWeR4EE;f)Epc3=4q?9&jd%-NwrsdKUDh*EHi@Y delta 509 zcmYMxJxIeq6bJDCOHI-yX&aTNMl1+6{r>*)tBRn5IJ$Ik)m@wfrK5W@yE_TBP{pCR z>g?p=tfTJ5OUU7J@AvNBad+>&68DzzHhrD|*vHP$s8Za3i;Rw}g&gwUC3VdrN;=9G zDyVud)HLg8=xADKq3um+aO6S}`+*1uDl{>6M3xefL{tlpprHU^U5x&+UmC*(HiboL zWKZPFqTqM*q2#F_={W2}R-TadF_Q|RvKmTbEtJlBs3^xm*%}*?I-8PFj!VWkA!%?@ z(qubej~(0MIXNBYdC3H`WRe#oZC;d|<)wfRD6lg|&40EMJbR3?*H=$_C9F{!Y1)NL zhse+|vUGwRogq)>D9{y(bb}HNP^Mc{=nhpHp+*zb=@kunN0UC$qHnb6M>KCsoX|(w hyU?x;82*>}J@wMMyZYbl&7e$$k~r}HWIMQ3_YW!{OV0oR diff --git a/tests/test_data/samples/reflection/trivial/classgetdeclaringclassexample/GetSuperclassExample$1.class b/tests/test_data/samples/reflection/trivial/classgetdeclaringclassexample/GetSuperclassExample$1.class new file mode 100644 index 0000000000000000000000000000000000000000..afdeb239319f22573499fe067a1d652624017909 GIT binary patch literal 471 zcmb_YyG{c!5F9557mgzdPl*BvB#MNB6E%n?3J)odA}9@&b6E~YjxVyEh~J_@qTmDg zD8$}T&``3HJ?q&W?Rq}H-ai0zupgmCzql(AjU-I)}W0rPJs&mH!`{bYVX^4hE|6do4 zv5g(xbuN_=IA}fge$5*3|4nw;9t+e4_5JY)po?aJ63RZj5F4lnG-h%oBP~r5-A`r|=K_^WWmJA8 zP;RxyKB@wbnVc^)Ws#+4%`qx9QEt^rNgc&nW?4e{l-RP$B#xk0ml54iK3XowI`=?u1D$+GBz0kh1(X&A5r-oiSuxjl@+3>ymK{ zpJz}k!JDVRxXIQLqhrqAA>N!j;InW8r|_`FSVD+xMh`VKu;-W>_89|?^BE6-ANBQv AY5)KL literal 0 HcmV?d00001 diff --git a/tests/test_data/samples/reflection/trivial/classgetdeclaringclassexample/GetSuperclassExample$ExtendedRunnable.class b/tests/test_data/samples/reflection/trivial/classgetdeclaringclassexample/GetSuperclassExample$ExtendedRunnable.class new file mode 100644 index 0000000000000000000000000000000000000000..67c3573fe9455562530a810c73b24ab40b12a166 GIT binary patch literal 373 zcmb`D%SyvQ6o&uPY7%2D;?8~7&O?NHS=2(i7beLuOc*C+W>WfWE_?tVN_rZRf^^x% zx$vJG-}(Oe`~py5nqowF3;JVYIVjKXmaAwwr=mAoqphl}4x!;#vt-`5W)OHcOsFT0 z>wd$25a++*Y`%-^YOYtkbGo#g;(~D7>aA8*yGAX`R*s}d2zN*IubYssyWUs)Xe<-% zPn~!;j1jU|4)M7Qvg?|#I4cEV^5Pu(;=s>A0RCeo0AVb4DX)ZNsrV5xTn#bDL}D&= JA;L|P?E%boa>M`t literal 0 HcmV?d00001 diff --git a/tests/test_data/samples/reflection/trivial/classgetdeclaringclassexample/GetSuperclassExample$InnerClass.class b/tests/test_data/samples/reflection/trivial/classgetdeclaringclassexample/GetSuperclassExample$InnerClass.class new file mode 100644 index 0000000000000000000000000000000000000000..e246dc539028fb9ffadd58dc4776e61fa9f90d6f GIT binary patch literal 428 zcmb_YJx{|h5Pfb+6GCVU8v_yp12B*sA(n_Q3Cd7}Se^8UT)9qVI~9M635kIpz>h*) z%+Q4qOXqj@-recxzP>*`0TkFx(L)rYpJ4+7f$?0fWUi&D^M`Uyl@}PCE2I2{Ky-Bc z6eAIMc5<=Q{X1#ok|gPCM%Y$%LH0X`GKS61e|Ys{+~D zEV12mUE%;S-?DpxgRjZB$=N<*U{2m4-h!O+-^sukB5X1CkYPLE5M#!a)fhwUAo&4P CTXUWO literal 0 HcmV?d00001 diff --git a/tests/test_data/samples/reflection/trivial/classgetdeclaringclassexample/GetSuperclassExample.class b/tests/test_data/samples/reflection/trivial/classgetdeclaringclassexample/GetSuperclassExample.class new file mode 100644 index 0000000000000000000000000000000000000000..88ad61bf750a3afb9d2753ba28ea94d13e5ef8d7 GIT binary patch literal 1773 zcmb_cYflqF6g|Uh+I4vqD1su0fNfD16`!D@$V*#5iU^XJEbUm=w7X=xHTtjA4`?*; z2l%6mXSU!L^&?GsX76E7}CQ-rDbMt8BX^Yi;kX zDg**;vySTo_XV0$=`D%aF{gasJ8sE8erQ~%8wEP|>DaI!(3{FeMCWzL8O^OrpgXd! zxPdAuUm_uph|C)`*R}V`N}^Zb)rnFaTX-KRx2TFoXT;Hoq=|l<7HHYrSzjQ*f0)NH zh@`|BfsTmfmgf{Dh6H+c8#dIRdq!edplNqS;=Dj#qr=g`bh#j~cCxp-YG4%2x?(0w zTtrGB#!QCKPoAlC1JQa;Br*a!Crl#i73^{tU*eL$_Q{4{ab4vfM!zC36lSCrIILXH zE!2Epxq-FmRMc~dLSpKu;zE~YyZR<)@5gZs*CnP++`!G_a`{jVRE1LVYE)KV{lOg1 zS`Q06@RePeiQzUYA(Fv}_j<&@T`;AyChmbs>YW*t|p)+&3--_)w)LdABtFPUnr>p#~Ji07S>YX>!-zWt3?4ev3V zxgUl%@?Om^s6|JI9Qa>fxuRb{;MA(B205h(R0Yf^|B9boe+yc`i0Y3Ykvq<_2{y5* z0?lAD&_-P4*APd+u{HAr;u9y-B~dSHjAI?oIM=Qp89;~FPROr_CptAWY3SC_L->ro z5C^p3tcG(MMhM?Ay7L8N*~tTpYg<~wq=w5HEJAepBD#4_oHTXsZfBe7LN9tSfFy?5 zug2MvGB^VZ=P=Ey%~JXEn7}g9$l($;xbgy1;oc5%*6ec}^_|8)<7(p80q$_j9NSvtUzh)R+qfa{3ypac~&h?^M0Egk^|%=0xj!`X9eaWv3Env0AjCux6)*l*Nv(X;>n literal 0 HcmV?d00001 diff --git a/vm/src/execution_engine/system_native_table.rs b/vm/src/execution_engine/system_native_table.rs index 5f0ba6fa..fd27d1af 100644 --- a/vm/src/execution_engine/system_native_table.rs +++ b/vm/src/execution_engine/system_native_table.rs @@ -72,6 +72,10 @@ static SYSTEM_NATIVE_TABLE: Lazy> = Lazy::ne Basic(system_identity_hashcode_wrp), ); table.insert("java/lang/Class:getModifiers:()I", Basic(get_modifiers_wrp)); + table.insert( + "java/lang/Class:getSuperclass:()Ljava/lang/Class;", + Basic(get_superclass_wrp), + ); table.insert( "java/lang/Class:getPrimitiveClass:(Ljava/lang/String;)Ljava/lang/Class;", Basic(get_primitive_class_wrp), diff --git a/vm/src/heap/heap.rs b/vm/src/heap/heap.rs index bfb68f86..7fcac83e 100644 --- a/vm/src/heap/heap.rs +++ b/vm/src/heap/heap.rs @@ -1,7 +1,6 @@ use crate::error::Error; use crate::heap::java_instance::HeapValue::{Arr, Object}; use crate::heap::java_instance::{Array, HeapValue, JavaInstance}; -use crate::method_area::method_area::with_method_area; use indexmap::IndexMap; use once_cell::sync::Lazy; use serde::Serialize; @@ -104,10 +103,6 @@ impl Heap { pub(crate) fn create_array(&mut self, type_name: &str, len: i32) -> crate::error::Result { let id = self.next_id(); - - //ensure creation of ephemeral array class - with_method_area(|method_area| method_area.create_array_class_if_needed(type_name))?; - self.data.insert(id, Arr(Array::new(type_name, len))); Ok(id) diff --git a/vm/src/method_area/method_area.rs b/vm/src/method_area/method_area.rs index 4c200c50..a50bc011 100644 --- a/vm/src/method_area/method_area.rs +++ b/vm/src/method_area/method_area.rs @@ -66,6 +66,14 @@ impl MethodArea { return Ok(Arc::clone(java_class)); } + if fully_qualified_class_name.starts_with('[') { + let arc = Self::generate_synthetic_array_class(fully_qualified_class_name); + self.loaded_classes + .write()? + .insert(fully_qualified_class_name.to_string(), arc.clone()); + return Ok(arc); + } + //todo: make me thread-safe if move to multithreaded jvm let java_class = self.load_class_file(fully_qualified_class_name)?; self.loaded_classes.write()?.insert( @@ -484,22 +492,6 @@ impl MethodArea { self.ldc_resolution_manager.load_reflection_class(name) } - pub(crate) fn create_array_class_if_needed( - &self, - array_class_name: &str, - ) -> crate::error::Result<()> { - match self.get(array_class_name) { - Ok(_) => Ok(()), - Err(_) => { - let arc = Self::generate_synthetic_array_class(array_class_name); - self.loaded_classes - .write()? - .insert(array_class_name.to_string(), arc); - Ok(()) - } - } - } - pub fn system_thread_id(&self) -> crate::error::Result { self.system_thread_id .read()? diff --git a/vm/src/system_native/class.rs b/vm/src/system_native/class.rs index 4bc14f5b..034ffab6 100644 --- a/vm/src/system_native/class.rs +++ b/vm/src/system_native/class.rs @@ -40,6 +40,30 @@ fn get_modifiers(reference: i32) -> crate::error::Result { Ok(modifiers) } +pub(crate) fn get_superclass_wrp(args: &[i32]) -> crate::error::Result> { + let current_clazz_ref = args[0]; + let super_clazz_ref = get_superclass(current_clazz_ref)?; + + Ok(vec![super_clazz_ref]) +} +fn get_superclass(clazz_ref: i32) -> crate::error::Result { + let current_clazz_ref = with_method_area(|method_area| { + let name = method_area.get_from_reflection_table(clazz_ref)?; + let rc = method_area.get(&name)?; + let parent = if !rc.is_interface() { + rc.parent().clone() + } else { + None + }; + + let current_clazz_ref = + parent.map_or(Ok(0), |parent| method_area.load_reflection_class(&parent)); + current_clazz_ref + })?; + + Ok(current_clazz_ref) +} + pub(crate) fn get_primitive_class_wrp(args: &[i32]) -> crate::error::Result> { let string_ref = args[0]; let class_ref = get_primitive_class(string_ref)?; diff --git a/vm/src/system_native/mod.rs b/vm/src/system_native/mod.rs index 73943752..fab31ffd 100644 --- a/vm/src/system_native/mod.rs +++ b/vm/src/system_native/mod.rs @@ -1,6 +1,8 @@ pub(crate) mod class; +pub(crate) mod constant_pool; pub(crate) mod file_descriptor; pub(crate) mod file_output_stream; +pub(crate) mod method_handle_natives; pub(crate) mod object; mod platform_file; pub(crate) mod reflecton; diff --git a/vm/src/system_native/unsafe_.rs b/vm/src/system_native/unsafe_.rs index 31d04e58..f5ff20ce 100644 --- a/vm/src/system_native/unsafe_.rs +++ b/vm/src/system_native/unsafe_.rs @@ -163,13 +163,27 @@ pub(crate) fn get_int(obj_ref: i32, offset: i64) -> crate::error::Result { })?; Ok(result[0]) } else { - todo!("implement get_int for class field"); + let class_name = with_heap_read_lock(|heap| heap.get_instance_name(obj_ref))?; + + let jc = with_method_area(|area| area.get(class_name.as_str()))?; + + let (class_name, field_name) = jc.get_field_name_by_offset(offset)?; + + let result = with_heap_read_lock(|heap| { + let bytes = heap.get_object_field_value(obj_ref, &class_name, &field_name); + bytes + })?; + Ok(result[0]) } } else { todo!("implement get_int for null object"); } } +pub(crate) fn get_int_volatile_wrp(args: &[i32]) -> crate::error::Result> { + get_int_wrp(args) // todo! make me volatile +} + pub(crate) fn get_long_wrp(args: &[i32]) -> crate::error::Result> { let _unsafe_ref = args[0]; let obj_ref = args[1]; From 5f0958195be5241d6c948c94752230e57bc426d5 Mon Sep 17 00:00:00 2001 From: Igor Rudenko Date: Sun, 22 Dec 2024 00:12:32 +0200 Subject: [PATCH 2/8] Update mod.rs --- vm/src/system_native/mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/vm/src/system_native/mod.rs b/vm/src/system_native/mod.rs index fab31ffd..73943752 100644 --- a/vm/src/system_native/mod.rs +++ b/vm/src/system_native/mod.rs @@ -1,8 +1,6 @@ pub(crate) mod class; -pub(crate) mod constant_pool; pub(crate) mod file_descriptor; pub(crate) mod file_output_stream; -pub(crate) mod method_handle_natives; pub(crate) mod object; mod platform_file; pub(crate) mod reflecton; From 5acaa282a059ecba91c7b13935bc6b38f8a653c7 Mon Sep 17 00:00:00 2001 From: Igor Rudenko Date: Sun, 22 Dec 2024 00:12:56 +0200 Subject: [PATCH 3/8] Update system_native_table.rs --- vm/src/execution_engine/system_native_table.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/src/execution_engine/system_native_table.rs b/vm/src/execution_engine/system_native_table.rs index fd27d1af..c88af583 100644 --- a/vm/src/execution_engine/system_native_table.rs +++ b/vm/src/execution_engine/system_native_table.rs @@ -4,7 +4,7 @@ use crate::helper::i64_to_vec; use crate::stack::stack_frame::StackFrames; use crate::system_native::class::{ class_init_class_name_wrp, for_name0_wrp, get_modifiers_wrp, get_primitive_class_wrp, - is_array_wrp, is_interface_wrp, is_primitive_wrp, + is_array_wrp, is_interface_wrp, is_primitive_wrp, get_superclass_wrp, }; use crate::system_native::file_descriptor::{file_descriptor_close0_wrp, get_handle_wrp}; use crate::system_native::file_output_stream::{ From 08e4c4ca5caa656e85a53f27fafbd29c7043d94d Mon Sep 17 00:00:00 2001 From: Igor Rudenko Date: Sun, 22 Dec 2024 00:22:27 +0200 Subject: [PATCH 4/8] fix --- tests/integration_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 4262b049..c95a63fd 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -11,7 +11,7 @@ fn should_deal_with_abstract_class_without_interface_implementation() { #[test] fn should_create_array_class_type() { - assert_success("samples.reflection.trivial.ArrayClass", "262143\n"); + assert_success("samples.reflection.trivial.ArrayClass", "16777215\n"); } #[test] From 1abe52a9bd20deba549a93a10a9f30a6808999b4 Mon Sep 17 00:00:00 2001 From: Igor Rudenko Date: Sun, 22 Dec 2024 00:25:10 +0200 Subject: [PATCH 5/8] remove unused --- vm/src/system_native/unsafe_.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/vm/src/system_native/unsafe_.rs b/vm/src/system_native/unsafe_.rs index f5ff20ce..4dbdab9b 100644 --- a/vm/src/system_native/unsafe_.rs +++ b/vm/src/system_native/unsafe_.rs @@ -180,10 +180,6 @@ pub(crate) fn get_int(obj_ref: i32, offset: i64) -> crate::error::Result { } } -pub(crate) fn get_int_volatile_wrp(args: &[i32]) -> crate::error::Result> { - get_int_wrp(args) // todo! make me volatile -} - pub(crate) fn get_long_wrp(args: &[i32]) -> crate::error::Result> { let _unsafe_ref = args[0]; let obj_ref = args[1]; From 8274d61dbb023c48e0c2cedfba56c7cf806333e5 Mon Sep 17 00:00:00 2001 From: Igor Rudenko Date: Sun, 22 Dec 2024 00:45:50 +0200 Subject: [PATCH 6/8] extra --- vm/src/system_native/unsafe_.rs | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/vm/src/system_native/unsafe_.rs b/vm/src/system_native/unsafe_.rs index 4dbdab9b..31d04e58 100644 --- a/vm/src/system_native/unsafe_.rs +++ b/vm/src/system_native/unsafe_.rs @@ -163,17 +163,7 @@ pub(crate) fn get_int(obj_ref: i32, offset: i64) -> crate::error::Result { })?; Ok(result[0]) } else { - let class_name = with_heap_read_lock(|heap| heap.get_instance_name(obj_ref))?; - - let jc = with_method_area(|area| area.get(class_name.as_str()))?; - - let (class_name, field_name) = jc.get_field_name_by_offset(offset)?; - - let result = with_heap_read_lock(|heap| { - let bytes = heap.get_object_field_value(obj_ref, &class_name, &field_name); - bytes - })?; - Ok(result[0]) + todo!("implement get_int for class field"); } } else { todo!("implement get_int for null object"); From 605ef4ee89b0787e5855088e52adebdd492edf03 Mon Sep 17 00:00:00 2001 From: Igor Rudenko Date: Sun, 22 Dec 2024 00:48:48 +0200 Subject: [PATCH 7/8] moar --- vm/src/method_area/method_area.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/src/method_area/method_area.rs b/vm/src/method_area/method_area.rs index a50bc011..88231f3d 100644 --- a/vm/src/method_area/method_area.rs +++ b/vm/src/method_area/method_area.rs @@ -70,7 +70,7 @@ impl MethodArea { let arc = Self::generate_synthetic_array_class(fully_qualified_class_name); self.loaded_classes .write()? - .insert(fully_qualified_class_name.to_string(), arc.clone()); + .insert(fully_qualified_class_name.to_string(), Arc::clone(&arc)); return Ok(arc); } From b6ca53846c6bdd0daed454a23888ae27b65836c3 Mon Sep 17 00:00:00 2001 From: Igor Rudenko Date: Sun, 22 Dec 2024 09:10:37 +0200 Subject: [PATCH 8/8] rename package --- tests/integration_tests.rs | 10 +++++----- tests/test_data/GetSuperclassExample.java | 4 ++-- .../GetSuperclassExample$1.class | Bin 471 -> 0 bytes .../GetSuperclassExample$1LocalClass.class | Bin 494 -> 0 bytes ...etSuperclassExample$ExtendedRunnable.class | Bin 373 -> 0 bytes .../GetSuperclassExample$InnerClass.class | Bin 428 -> 0 bytes .../GetSuperclassExample$1.class | Bin 0 -> 463 bytes .../GetSuperclassExample$1LocalClass.class | Bin 0 -> 486 bytes ...etSuperclassExample$ExtendedRunnable.class | Bin 0 -> 365 bytes .../GetSuperclassExample$InnerClass.class | Bin 0 -> 420 bytes .../GetSuperclassExample.class | Bin 1773 -> 1753 bytes 11 files changed, 7 insertions(+), 7 deletions(-) delete mode 100644 tests/test_data/samples/reflection/trivial/classgetdeclaringclassexample/GetSuperclassExample$1.class delete mode 100644 tests/test_data/samples/reflection/trivial/classgetdeclaringclassexample/GetSuperclassExample$1LocalClass.class delete mode 100644 tests/test_data/samples/reflection/trivial/classgetdeclaringclassexample/GetSuperclassExample$ExtendedRunnable.class delete mode 100644 tests/test_data/samples/reflection/trivial/classgetdeclaringclassexample/GetSuperclassExample$InnerClass.class create mode 100644 tests/test_data/samples/reflection/trivial/classgetsuperclassexample/GetSuperclassExample$1.class create mode 100644 tests/test_data/samples/reflection/trivial/classgetsuperclassexample/GetSuperclassExample$1LocalClass.class create mode 100644 tests/test_data/samples/reflection/trivial/classgetsuperclassexample/GetSuperclassExample$ExtendedRunnable.class create mode 100644 tests/test_data/samples/reflection/trivial/classgetsuperclassexample/GetSuperclassExample$InnerClass.class rename tests/test_data/samples/reflection/trivial/{classgetdeclaringclassexample => classgetsuperclassexample}/GetSuperclassExample.class (51%) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index c95a63fd..9c1deab0 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -585,20 +585,20 @@ HelloWorld! #[test] fn should_support_getting_supper_class() { assert_success( - "samples.reflection.trivial.classgetdeclaringclassexample.GetSuperclassExample", + "samples.reflection.trivial.classgetsuperclassexample.GetSuperclassExample", r#"Superclass of java.lang.String: class java.lang.Object Superclass of java.lang.Integer: class java.lang.Number Superclass of java.lang.Object: null Superclass of java.lang.Runnable: null -Superclass of samples.reflection.trivial.classgetdeclaringclassexample.GetSuperclassExample$ExtendedRunnable: null +Superclass of samples.reflection.trivial.classgetsuperclassexample.GetSuperclassExample$ExtendedRunnable: null Superclass of int: null Superclass of void: null Superclass of [Ljava.lang.String;: class java.lang.Object Superclass of [I: class java.lang.Object Superclass of [Ljava.lang.Runnable;: class java.lang.Object -Superclass of samples.reflection.trivial.classgetdeclaringclassexample.GetSuperclassExample$1: class java.lang.Object -Superclass of samples.reflection.trivial.classgetdeclaringclassexample.GetSuperclassExample$1LocalClass: class java.lang.Object -Superclass of samples.reflection.trivial.classgetdeclaringclassexample.GetSuperclassExample$InnerClass: class java.lang.Object +Superclass of samples.reflection.trivial.classgetsuperclassexample.GetSuperclassExample$1: class java.lang.Object +Superclass of samples.reflection.trivial.classgetsuperclassexample.GetSuperclassExample$1LocalClass: class java.lang.Object +Superclass of samples.reflection.trivial.classgetsuperclassexample.GetSuperclassExample$InnerClass: class java.lang.Object Superclass of java.util.concurrent.TimeUnit: class java.lang.Enum Superclass of java.util.HashMap: class java.util.AbstractMap "#, diff --git a/tests/test_data/GetSuperclassExample.java b/tests/test_data/GetSuperclassExample.java index 882dc4b9..ef9b0ac1 100644 --- a/tests/test_data/GetSuperclassExample.java +++ b/tests/test_data/GetSuperclassExample.java @@ -1,4 +1,4 @@ -package samples.reflection.trivial.classgetdeclaringclassexample; +package samples.reflection.trivial.classgetsuperclassexample; import java.util.HashMap; import java.util.concurrent.TimeUnit; @@ -16,7 +16,7 @@ public static void main(String[] args) { printSuperclass(Runnable.class); // null // 4. Case: Interface extending another interface - printSuperclass(ExtendedRunnable.class); + printSuperclass(ExtendedRunnable.class); // null // 5. Case: Primitive types have no superclass printSuperclass(int.class); // null diff --git a/tests/test_data/samples/reflection/trivial/classgetdeclaringclassexample/GetSuperclassExample$1.class b/tests/test_data/samples/reflection/trivial/classgetdeclaringclassexample/GetSuperclassExample$1.class deleted file mode 100644 index afdeb239319f22573499fe067a1d652624017909..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 471 zcmb_YyG{c!5F9557mgzdPl*BvB#MNB6E%n?3J)odA}9@&b6E~YjxVyEh~J_@qTmDg zD8$}T&``3HJ?q&W?Rq}H-ai0zupgmCzql(AjU-I)}W0rPJs&mH!`{bYVX^4hE|6do4 zv5g(xbuN_=IA}fge$5*3|4nw;9t+e4_5JY)po?aJ63RZj5F4lnG-h%oBP~r5-A`r|=K_^WWmJA8 zP;RxyKB@wbnVc^)Ws#+4%`qx9QEt^rNgc&nW?4e{l-RP$B#xk0ml54iK3XowI`=?u1D$+GBz0kh1(X&A5r-oiSuxjl@+3>ymK{ zpJz}k!JDVRxXIQLqhrqAA>N!j;InW8r|_`FSVD+xMh`VKu;-W>_89|?^BE6-ANBQv AY5)KL diff --git a/tests/test_data/samples/reflection/trivial/classgetdeclaringclassexample/GetSuperclassExample$ExtendedRunnable.class b/tests/test_data/samples/reflection/trivial/classgetdeclaringclassexample/GetSuperclassExample$ExtendedRunnable.class deleted file mode 100644 index 67c3573fe9455562530a810c73b24ab40b12a166..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 373 zcmb`D%SyvQ6o&uPY7%2D;?8~7&O?NHS=2(i7beLuOc*C+W>WfWE_?tVN_rZRf^^x% zx$vJG-}(Oe`~py5nqowF3;JVYIVjKXmaAwwr=mAoqphl}4x!;#vt-`5W)OHcOsFT0 z>wd$25a++*Y`%-^YOYtkbGo#g;(~D7>aA8*yGAX`R*s}d2zN*IubYssyWUs)Xe<-% zPn~!;j1jU|4)M7Qvg?|#I4cEV^5Pu(;=s>A0RCeo0AVb4DX)ZNsrV5xTn#bDL}D&= JA;L|P?E%boa>M`t diff --git a/tests/test_data/samples/reflection/trivial/classgetdeclaringclassexample/GetSuperclassExample$InnerClass.class b/tests/test_data/samples/reflection/trivial/classgetdeclaringclassexample/GetSuperclassExample$InnerClass.class deleted file mode 100644 index e246dc539028fb9ffadd58dc4776e61fa9f90d6f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 428 zcmb_YJx{|h5Pfb+6GCVU8v_yp12B*sA(n_Q3Cd7}Se^8UT)9qVI~9M635kIpz>h*) z%+Q4qOXqj@-recxzP>*`0TkFx(L)rYpJ4+7f$?0fWUi&D^M`Uyl@}PCE2I2{Ky-Bc z6eAIMc5<=Q{X1#ok|gPCM%Y$%LH0X`GKS61e|Ys{+~D zEV12mUE%;S-?DpxgRjZB$=N<*U{2m4-h!O+-^sukB5X1CkYPLE5M#!a)fhwUAo&4P CTXUWO diff --git a/tests/test_data/samples/reflection/trivial/classgetsuperclassexample/GetSuperclassExample$1.class b/tests/test_data/samples/reflection/trivial/classgetsuperclassexample/GetSuperclassExample$1.class new file mode 100644 index 0000000000000000000000000000000000000000..ea137eaedceb0fe53ac8d85bf7df4c79999b82d0 GIT binary patch literal 463 zcmb_YJx{|h6g;<~DIv7wQ(`~@iJ@g6Vg|8P1u9Azin=hl=_9yuoho)J{uUDw13!Qt zg?I@PEQ~zKKEHeSr1O1zzP$tJVkbZaRUcl671RV;Gr5$JmL`erCNqkiK+~|kweUnG00$w+r zl0b8y3=Q-7gtB`%(aZ#+G|ytXR7JD**ZN7}mREZw)~Qt{xh40MPJJ{5`u}D!#0ECm z=Ugfyu-kqZ{Dw5*f1Bj2GZv^1$-3**a%5rO7|Oau6l8G#pF=K6@Zp#lSNXNiSTe`2 k5HIC8;JX+Dhw!k*SV4$&Mh^|NuvIb*Y%>O|^BK9m01l{leEBb5Pb_Lhvy0SMPgxMp$S-cvDVlSR1(AjrLkI$@m#X(k=up%x2#Mo`~m(b zK{G%JWglLMHBDJuecDb&$5x#2I_{UMLe`e`h6 zCodB4I_ZQ2>V0Ksu$YZ0yO(3lOfXCrSxi?d5BC3Rbehl2rCk&2)GCwQl6y`kKI#I! ze;YT%7PfiLnN&ug*?R1+>>9EICOL191gZnF?k2TtUf45+vSL5t4TIIXIE2sM=ST2m u_ZipucfeRMCvOn1MLOU&PXovBu)$bDh)qThH8ikOFg5Hl2CVZL_keGf-hgfZ literal 0 HcmV?d00001 diff --git a/tests/test_data/samples/reflection/trivial/classgetsuperclassexample/GetSuperclassExample$ExtendedRunnable.class b/tests/test_data/samples/reflection/trivial/classgetsuperclassexample/GetSuperclassExample$ExtendedRunnable.class new file mode 100644 index 0000000000000000000000000000000000000000..38dbab54de3299b974b65a875123ca6c4980d506 GIT binary patch literal 365 zcmb_YJ8r^25Pbv0HV&XDU3zNv5C{SdNYK$OWh%ZoQ1rwD!BZRYojuwz29)~<(^#?@Uf~^-yG%-aPSLu z2gks6#j9CqtzH_A(I9+m^+7A6?M6+PTUihzB7FX#_i92qFG`p3FgHy2dbOf=Ya=8R z_F+_bne|Q>{~H5BYiupM{*5<#IsTba1Q6;XZ}LKj7mKbTL9?)0T}R(5K9EK5-LM0b|*Y4SFTgpPQ`CAAu;d)d=%m( zNbSPNll;zi_iUZs*Z0RKfE1M;<9~}OkZpq!M@_dB xCy056O$k1{MaEse9W%Dd#XH1XYp2{B8@NJ*J;n|)?6=s*kTGR9Mjr=AegL^VaH0SJ literal 0 HcmV?d00001 diff --git a/tests/test_data/samples/reflection/trivial/classgetdeclaringclassexample/GetSuperclassExample.class b/tests/test_data/samples/reflection/trivial/classgetsuperclassexample/GetSuperclassExample.class similarity index 51% rename from tests/test_data/samples/reflection/trivial/classgetdeclaringclassexample/GetSuperclassExample.class rename to tests/test_data/samples/reflection/trivial/classgetsuperclassexample/GetSuperclassExample.class index 88ad61bf750a3afb9d2753ba28ea94d13e5ef8d7..5528927c52d6e86ed57a5585a056f4972a6f585c 100644 GIT binary patch delta 93 zcmaFMdy{uU9HZyNcxBe&(t^~YiQRRKQAj++$>EF>7`;(MOqt9XLs3L_F$pq;Ad764 IWWK@-04o(B-T(jq delta 122 zcmcb~`<8b?9HZ~#L?&g