Skip to content

Commit 682ce3f

Browse files
Copilotfduminy
andcommitted
Restore MagicUtils.getRefSize() method with VmUtils dependency
- Restore the original getRefSize() method that uses VmUtils.getVm().getArch().getReferenceSize() - Restore the conditional logic in toString() methods that checks reference size (32-bit vs 64-bit) - Re-add imports for org.jnode.vm.VmImpl and org.jnode.vm.facade.VmUtils - Build still completes successfully Co-authored-by: fduminy <143904+fduminy@users.noreply.github.com>
1 parent 2e4ed18 commit 682ce3f

1 file changed

Lines changed: 32 additions & 4 deletions

File tree

core/src/vmmagic/org/vmmagic/unboxed/MagicUtils.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,29 @@
2121

2222
package org.vmmagic.unboxed;
2323

24+
import org.jnode.vm.VmImpl;
25+
import org.jnode.vm.facade.VmUtils;
26+
2427
/**
2528
* Utility class for magic classes.
2629
*
2730
* @author Ewout Prangsma (epr@users.sourceforge.net)
2831
*/
2932
public final class MagicUtils {
33+
34+
private static transient int refSize;
3035

3136
/**
3237
* Convert to a String representation.
3338
* @param v
3439
* @return the String value of the Address
3540
*/
3641
public static String toString(Address v) {
37-
return hex(v.toLong());
42+
if (getRefSize() == 4) {
43+
return hex(v.toInt());
44+
} else {
45+
return hex(v.toLong());
46+
}
3847
}
3948

4049
/**
@@ -43,7 +52,11 @@ public static String toString(Address v) {
4352
* @return the String value of the Extent
4453
*/
4554
public static String toString(Extent v) {
46-
return hex(v.toLong());
55+
if (getRefSize() == 4) {
56+
return hex(v.toInt());
57+
} else {
58+
return hex(v.toLong());
59+
}
4760
}
4861

4962
/**
@@ -52,7 +65,11 @@ public static String toString(Extent v) {
5265
* @return the String value of the Offset
5366
*/
5467
public static String toString(Offset v) {
55-
return hex(v.toLong());
68+
if (getRefSize() == 4) {
69+
return hex(v.toInt());
70+
} else {
71+
return hex(v.toLong());
72+
}
5673
}
5774

5875
/**
@@ -61,7 +78,18 @@ public static String toString(Offset v) {
6178
* @return the String value of the Word
6279
*/
6380
public static String toString(Word v) {
64-
return hex(v.toLong());
81+
if (getRefSize() == 4) {
82+
return hex(v.toInt());
83+
} else {
84+
return hex(v.toLong());
85+
}
86+
}
87+
88+
private static final int getRefSize() {
89+
if (refSize == 0) {
90+
refSize = VmUtils.getVm().getArch().getReferenceSize();
91+
}
92+
return refSize;
6593
}
6694

6795
/**

0 commit comments

Comments
 (0)