Eval4j: disable object collection during evaluation

This commit is contained in:
Natalia Ukhorskaya
2015-03-31 11:51:27 +03:00
parent 7abbf1ec12
commit 111f375fa6
@@ -218,7 +218,9 @@ public class JDIEval(
if (_class !is jdi.ClassType) throwBrokenCodeException(NoSuchMethodError("Static method is a non-class type: $method"))
val args = mapArguments(arguments, method.safeArgumentTypes())
args.disableCollection()
val result = mayThrow { _class.invokeMethod(thread, method, args, invokePolicy) }
args.enableCollection()
return result.asValue()
}
@@ -243,14 +245,18 @@ public class JDIEval(
val ctor = findMethod(methodDesc)
val _class = (instance as NewObjectValue).asmType.asReferenceType() as jdi.ClassType
val args = mapArguments(arguments, ctor.safeArgumentTypes())
args.disableCollection()
val result = mayThrow { _class.newInstance(thread, ctor, args, invokePolicy) }
args.enableCollection()
instance.value = result
return result.asValue()
}
fun doInvokeMethod(obj: ObjectReference, method: Method, policy: Int): Value {
val args = mapArguments(arguments, method.safeArgumentTypes())
args.disableCollection()
val result = mayThrow { obj.invokeMethod(thread, method, args, policy) }
args.enableCollection()
return result.asValue()
}
@@ -265,6 +271,15 @@ public class JDIEval(
}
}
private fun List<jdi.Value?>.disableCollection() {
forEach { (it as? ObjectReference)?.disableCollection() }
}
private fun List<jdi.Value?>.enableCollection() {
forEach { (it as? ObjectReference)?.enableCollection() }
}
private fun mapArguments(arguments: List<Value>, expecetedTypes: List<jdi.Type>): List<jdi.Value?> {
return arguments.zip(expecetedTypes).map {
val (arg, expectedType) = it