asynchronous assertions what are assertions
play

ASYNCHRONOUS ASSERTIONS What are assertions? public class ATM { - PowerPoint PPT Presentation

ASYNCHRONOUS ASSERTIONS What are assertions? public class ATM { public void withdraw(Account a, int amount) { int oldBalance = a.getBalance(); a.setBalance(oldBalance - amount); assert a.getBalance() < oldBalance; dispense(amount);


  1. ASYNCHRONOUS ASSERTIONS

  2. What are assertions? public class ATM { … public void withdraw(Account a, int amount) { int oldBalance = a.getBalance(); a.setBalance(oldBalance - amount); assert a.getBalance() < oldBalance; dispense(amount); } } Assertions allow programmers to verify that their program is in a certain status

  3. What are assertions? public class ATM { … public void withdraw(Account a, int amount) { a.addTransaction(-amount, "ATM Withdrawal"); assert a.findTransaction(-amount, "ATM assert a.findTransaction(-amount, "ATM Withdrawal") != null; dispense(amount); } } What is the problem here?

  4. What are assertions? � Assertions are used to verify your assumptions about the program � Evaluating assertions is expensive – especially if they rely on expensive calculations themselves they rely on expensive calculations themselves � Because of this, you may opt to remove them from your production code � This leads to some implications…

  5. What are assertions NOT? public class ATM { … public void withdraw(Account a, int amount) { assert amount > 0; a.addTransaction(-amount, "ATM Withdrawal"); a.addTransaction(-amount, "ATM Withdrawal"); dispense(amount); } } Assertions cannot be used to verify user or method inputs

  6. What are assertions NOT? public class ATM { … public void withdraw(Account a, int amount) { assert a.addTransaction(-amount, "ATM Withdrawal") == true; dispense(amount); } } Assertions cannot have side effects

  7. Idea � If assertions are used only for debugging, we do not need the control flow to be halted while we evaluate the assertion � After all, we are sure that it is true anyway � After all, we are sure that it is true anyway � Why not do it asynchronously? � Problem: By then, object values have probably changed

  8. Snapshotting � If we copy the stack and the heap at the time of the assertion, we can make sure we still have the correct data � That‘s expensive… � That‘s expensive… � Thus, only copy objects that are really modified � Copy-on-write

  9. Snapshotting � Copy-on-write automatically guarantees isolation, preservance of identity, and consistent references � If many assertions are made, objects are copied � If many assertions are made, objects are copied more than necessary

  10. Snapshotting � Every assertion defines ist own epoch � Instead of having only a „modified“ flag, objects are checked whether they were changed in a later epoch epoch � Only then they have to be copied

  11. Snapshotting � Of course, if the epochs match, copies can be shared � Objects created after an assertion‘s epoch do not � Objects created after an assertion‘s epoch do not have to be copied

  12. In case of an error… � The user can decide how to handle assertion errors: � Either the program terminates, throwing an AssertionError, or � The user can handle the situation by using a handle to the asynchronous evaluation

  13. Discussion � „Handle into the future“ in violation of the JLS

  14. Evaluation � Microbenchmarks: Simple data structures, synthetic benchmark: No significant improvement � JBB2000:

  15. Evaluation � Asynchronous assertions reduce the overhead by approx. 90% � They scale good, at least as long as the checker threads are not overloaded: threads are not overloaded:

  16. Discussion � Fallback to synchronous assertions if checkers are � Fallback to synchronous assertions if checkers are overloaded? � Profile assertions and execute simple ones synchronously?

  17. Evaluation � Sharing copies helps:

  18. Discussion � Are the benchmarks used really meaningful?

  19. Reception � Only two theseses reference the paper � Not in the Jikes Research Archive � Not available in other VMs � Why? � Why?

  20. Discussion � Questions? � Questions?

  21. Discussion

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend