Skip to content

Commit

Permalink
Protect phaser interaction in ObjectTransitionSafepoint with finally
Browse files Browse the repository at this point in the history
This makes sure we always finish the safepoint even on exception.

Signed-off-by: Stefan Marr <git@stefan-marr.de>
  • Loading branch information
smarr committed Jun 13, 2020
1 parent ad315fe commit bbdd7b4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
48 changes: 28 additions & 20 deletions src/som/interpreter/objectstorage/ObjectTransitionSafepoint.java
Expand Up @@ -95,11 +95,13 @@ public void checkAndPerformSafepoint() {
public void transitionObject(final SObject obj) {
waitForSafepointStart();

// Safepoint phase, used to update the object
// object is required to handle updates from multiple threads correctly
obj.updateLayoutToMatchClass();

phaser.finishSafepointAndAwaitCompletion();
try {
// Safepoint phase, used to update the object
// object is required to handle updates from multiple threads correctly
obj.updateLayoutToMatchClass();
} finally {
phaser.finishSafepointAndAwaitCompletion();
}
}

/**
Expand All @@ -113,11 +115,13 @@ public void writeUninitializedSlot(final SObject obj, final SlotDefinition slot,
final Object value) {
waitForSafepointStart();

// Safepoint phase, used to update the object
// object is required to handle updates from multiple threads correctly
obj.writeUninitializedSlot(slot, value);

phaser.finishSafepointAndAwaitCompletion();
try {
// Safepoint phase, used to update the object
// object is required to handle updates from multiple threads correctly
obj.writeUninitializedSlot(slot, value);
} finally {
phaser.finishSafepointAndAwaitCompletion();
}
}

/**
Expand All @@ -131,22 +135,26 @@ public void writeAndGeneralizeSlot(final SObject obj, final SlotDefinition slot,
final Object value) {
waitForSafepointStart();

// Safepoint phase, used to update the object
// object is required to handle updates from multiple threads correctly
obj.writeAndGeneralizeSlot(slot, value);

phaser.finishSafepointAndAwaitCompletion();
try {
// Safepoint phase, used to update the object
// object is required to handle updates from multiple threads correctly
obj.writeAndGeneralizeSlot(slot, value);
} finally {
phaser.finishSafepointAndAwaitCompletion();
}
}

public void ensureSlotAllocatedToAvoidDeadlock(final SObject obj,
final SlotDefinition slot) {
waitForSafepointStart();

// Safepoint phase, used to update the object
// object is required to handle updates from multiple threads correctly
obj.ensureSlotAllocatedToAvoidDeadlock(slot);

phaser.finishSafepointAndAwaitCompletion();
try {
// Safepoint phase, used to update the object
// object is required to handle updates from multiple threads correctly
obj.ensureSlotAllocatedToAvoidDeadlock(slot);
} finally {
phaser.finishSafepointAndAwaitCompletion();
}
}

void renewAssumption() {
Expand Down
2 changes: 1 addition & 1 deletion src/som/interpreter/objectstorage/SafepointPhaser.java
Expand Up @@ -261,7 +261,7 @@ void arriveAtSafepointAndAwaitStart() {

void finishSafepointAndAwaitCompletion() {
int phase = arriveAndAwaitAdvance();
assert (phase & 1) == 0 : "Expect phase to be evem on completion of safepoint, but was "
assert (phase & 1) == 0 : "Expect phase to be even on completion of safepoint, but was "
+ phase;
}

Expand Down

0 comments on commit bbdd7b4

Please sign in to comment.