Fix 088 the way the test's author intended.
Not only was some of the verification code disabled in dalvik, part of the
test was too. This test was _intended_ to check that we fail gracefully
when our monitor-enter stack overflows. Re-enable the test, and throw a
verification error on overflow.
Change-Id: Iaa973633ecc59c3c4810b97ada80eae1e4db3db5
diff --git a/src/dex_verifier.cc b/src/dex_verifier.cc
index e002917..7c3b4db 100644
--- a/src/dex_verifier.cc
+++ b/src/dex_verifier.cc
@@ -771,6 +771,8 @@
const RegType& reg_type = GetRegisterType(reg_idx);
if (!reg_type.IsReferenceTypes()) {
verifier_->Fail(VERIFY_ERROR_GENERIC) << "monitor-enter on non-object (" << reg_type << ")";
+ } else if (monitors_.size() >= 32) {
+ verifier_->Fail(VERIFY_ERROR_GENERIC) << "monitor-enter stack overflow: " << monitors_.size();
} else {
SetRegToLockDepth(reg_idx, monitors_.size());
monitors_.push_back(insn_idx);
diff --git a/src/dex_verifier.h b/src/dex_verifier.h
index 0a8d051..5af09af 100644
--- a/src/dex_verifier.h
+++ b/src/dex_verifier.h
@@ -707,14 +707,14 @@
void CopyRegToLockDepth(size_t dst, size_t src) {
if (reg_to_lock_depths_.count(src) > 0) {
- uint64_t depths = reg_to_lock_depths_[src];
+ uint32_t depths = reg_to_lock_depths_[src];
reg_to_lock_depths_[dst] = depths;
}
}
bool IsSetLockDepth(size_t reg, size_t depth) {
if (reg_to_lock_depths_.count(reg) > 0) {
- uint64_t depths = reg_to_lock_depths_[reg];
+ uint32_t depths = reg_to_lock_depths_[reg];
return (depths & (1 << depth)) != 0;
} else {
return false;
@@ -722,9 +722,9 @@
}
void SetRegToLockDepth(size_t reg, size_t depth) {
- CHECK_LT(depth, 64u);
+ CHECK_LT(depth, 32u);
DCHECK(!IsSetLockDepth(reg, depth));
- uint64_t depths;
+ uint32_t depths;
if (reg_to_lock_depths_.count(reg) > 0) {
depths = reg_to_lock_depths_[reg];
depths = depths | (1 << depth);
@@ -735,9 +735,9 @@
}
void ClearRegToLockDepth(size_t reg, size_t depth) {
- CHECK_LT(depth, 64u);
+ CHECK_LT(depth, 32u);
DCHECK(IsSetLockDepth(reg, depth));
- uint64_t depths = reg_to_lock_depths_[reg];
+ uint32_t depths = reg_to_lock_depths_[reg];
depths = depths ^ (1 << depth);
if (depths != 0) {
reg_to_lock_depths_[reg] = depths;
@@ -766,7 +766,7 @@
// A map from register to a bit vector of indices into the monitors_ stack. As we pop the monitor
// stack we verify that monitor-enter/exit are correctly nested. That is, if there was a
// monitor-enter on v5 and then on v6, we expect the monitor-exit to be on v6 then on v5
- std::map<uint32_t, uint64_t> reg_to_lock_depths_;
+ std::map<uint32_t, uint32_t> reg_to_lock_depths_;
};
std::ostream& operator<<(std::ostream& os, const RegisterLine& rhs);
diff --git a/test/088-monitor-verification/src/Main.java b/test/088-monitor-verification/src/Main.java
index aa90b92..b60c71e 100644
--- a/test/088-monitor-verification/src/Main.java
+++ b/test/088-monitor-verification/src/Main.java
@@ -38,12 +38,10 @@
System.out.println("constantLock ok");
m.notExcessiveNesting();
- if (false) { // TODO: remove when verification is turned on
try {
TooDeep.excessiveNesting();
System.err.println("excessiveNesting did not throw");
} catch (VerifyError ve) {}
- }
System.out.println("excessiveNesting ok");
m.notNested();