Skip to content

Commit

Permalink
Allow array types to be Ljava/lang/Object;
Browse files Browse the repository at this point in the history
Fixes #101 (kinda)
  • Loading branch information
CalebFenton committed Oct 14, 2018
1 parent 1de5290 commit 6238967
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion smalivm/src/main/java/org/cf/smalivm/opcode/APutOp.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.cf.smalivm.dex.CommonTypes;
import org.cf.smalivm.type.ClassManager;
import org.cf.smalivm.type.VirtualArray;
import org.cf.smalivm.type.VirtualClass;
import org.cf.smalivm.type.VirtualType;
import org.cf.util.ClassNameUtils;
import org.cf.util.Utils;
Expand Down Expand Up @@ -72,7 +73,13 @@ private static boolean isOverloadedPrimitiveType(String type) {
private static boolean throwsArrayStoreException(HeapItem arrayItem, HeapItem valueItem,
ClassManager classManager) {
VirtualType valueType = classManager.getVirtualType(valueItem.getType());
VirtualArray arrayType = (VirtualArray) classManager.getVirtualType(arrayItem.getType());
VirtualType arrayTypeType = classManager.getVirtualType(arrayItem.getType());
if (arrayTypeType instanceof VirtualClass && arrayTypeType.getName().equals(CommonTypes.OBJECT)) {
Exception e = new Exception("APutOp");
log.warn("Attempting to store item in array of type java.lang.Object. Not enough type information to know if this may throw an exception.", e);
return false;
}
VirtualArray arrayType = (VirtualArray) arrayTypeType;
VirtualType arrayComponentType = arrayType.getComponentType();

if (valueType.instanceOf(arrayComponentType)) {
Expand Down
8 changes: 8 additions & 0 deletions smalivm/src/test/java/org/cf/smalivm/opcode/APutOpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ public void canPutShortWithIntegerValue() {
VMTester.test(CLASS_NAME, "putShort()V", initial, expected);
}

@Test
public void canPutIntoUnknownValueOfObjectTypeWithoutThrowingException() {
initial.setRegisters(0, new UnknownValue(), CommonTypes.OBJECT, 1, 0, "I", 2, 0x5, "I");
expected.setRegisters(0, new UnknownValue(), CommonTypes.OBJECT);

VMTester.test(CLASS_NAME, "put()V", initial, expected);
}

@Test
public void canPutUnknownValue() {
// TODO: Ideally, setting an element unknown shouldn't set entire array unknown.
Expand Down

0 comments on commit 6238967

Please sign in to comment.