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

asynchronous assertions what are assertions
SMART_READER_LITE
LIVE PREVIEW

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);


slide-1
SLIDE 1

ASYNCHRONOUS ASSERTIONS

slide-2
SLIDE 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

slide-3
SLIDE 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?

slide-4
SLIDE 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…

slide-5
SLIDE 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

slide-6
SLIDE 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

slide-7
SLIDE 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

slide-8
SLIDE 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

slide-9
SLIDE 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

slide-10
SLIDE 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

slide-11
SLIDE 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

slide-12
SLIDE 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

slide-13
SLIDE 13

Discussion

„Handle into the future“ in violation of the JLS

slide-14
SLIDE 14

Evaluation

Microbenchmarks: Simple data structures,

synthetic benchmark: No significant improvement

JBB2000:

slide-15
SLIDE 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:

slide-16
SLIDE 16

Discussion

Fallback to synchronous assertions if checkers are Fallback to synchronous assertions if checkers are

  • verloaded?

Profile assertions and execute simple ones

synchronously?

slide-17
SLIDE 17

Evaluation

Sharing copies helps:

slide-18
SLIDE 18

Discussion

Are the benchmarks used really meaningful?

slide-19
SLIDE 19

Reception

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

slide-20
SLIDE 20

Discussion

Questions? Questions?

slide-21
SLIDE 21

Discussion