Last active
August 29, 2015 14:19
-
-
Save gvsmirnov/c5f02f52c2227d53f2b7 to your computer and use it in GitHub Desktop.
Escaping this from constructor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.openjdk.jcstress.tests.finals; | |
import org.openjdk.jcstress.annotations.*; | |
import org.openjdk.jcstress.infra.results.IntResult2; | |
import org.openjdk.jcstress.infra.results.IntResult4; | |
@JCStressTest | |
@State | |
@Outcome(id = "[0, 0, 0, 0]", expect = Expect.ACCEPTABLE, desc = "Neither of the escaped writes is observed") | |
@Outcome(id = "[1, 42, 1, 42]", expect = Expect.ACCEPTABLE, desc = "Both of the escaped writes are observed, and the write to the final field is observed in both cases") | |
@Outcome(id = "[1, 0, 1, 0]", expect = Expect.ACCEPTABLE_INTERESTING, desc = "Both of the escaped writes are observed, but neither write to final is observed") | |
@Outcome(id = "[1, 0, 1, 42]", expect = Expect.ACCEPTABLE_INTERESTING, desc = "Both of the escaped writes are observed, but the write to final is only observed for the second") | |
@Outcome(id = "[1, 42, 1, 0]", expect = Expect.ACCEPTABLE_INTERESTING, desc = "Both of the escaped writes are observed, but the write to final is only observed for the first") | |
@Outcome(id = "[1, 0, 0, 0]", expect = Expect.ACCEPTABLE_INTERESTING, desc = "Only the first escaped write is observed, but the write to final is not observed") | |
@Outcome(id = "[0, 0, 1, 0]", expect = Expect.ACCEPTABLE_INTERESTING, desc = "Only the second escaped write is observed, but the write to final is not observed") | |
@Outcome(id = "[1, 42, 0, 0]", expect = Expect.ACCEPTABLE, desc = "Only the first escaped write is observed, and the write to teh final field is observed, too") | |
@Outcome(id = "[0, 0, 1, 42]", expect = Expect.ACCEPTABLE, desc = "Only the second escaped write is observed, and the write to teh final field is observed, too") | |
public class EscapingThisFromConstructorTest { | |
JailCell theCell1; | |
JailCell theCell2; | |
@State | |
private class JailCell { | |
private final int inmateId; | |
JailCell() { | |
theCell1 = this; | |
this.inmateId = 42; | |
theCell2 = this; | |
} | |
} | |
@Actor | |
public void actor1() { | |
new JailCell(); | |
} | |
@Actor | |
public void actor2(IntResult4 r) { | |
{ | |
JailCell localCell = theCell1; | |
int inmateId = localCell == null ? 0 : localCell.inmateId; | |
r.r1 = localCell == null ? 0 : 1; | |
r.r2 = inmateId; | |
} | |
{ | |
JailCell localCell = theCell2; | |
int inmateId = localCell == null ? 0 : localCell.inmateId; | |
r.r3 = localCell == null ? 0 : 1; | |
r.r4 = inmateId; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[0, 0, 0, 0] 120941861 ACCEPTABLE Neither of the escaped writes is observed | |
[1, 42, 1, 42] 11989566 ACCEPTABLE Both of the escaped writes are observed, and the write to the final field is observed in both cases | |
[1, 0, 1, 0] 0 ACCEPTABLE_INTERESTING Both of the escaped writes are observed, but neither write to final is observed | |
[1, 0, 1, 42] 2 ACCEPTABLE_INTERESTING Both of the escaped writes are observed, but the write to final is only observed for the second | |
[1, 42, 1, 0] 0 ACCEPTABLE_INTERESTING Both of the escaped writes are observed, but the write to final is only observed for the first | |
[1, 0, 0, 0] 14 ACCEPTABLE_INTERESTING Only the first escaped write is observed, but the write to final is not observed | |
[0, 0, 1, 0] 0 ACCEPTABLE_INTERESTING Only the second escaped write is observed, but the write to final is not observed | |
[1, 42, 0, 0] 7 ACCEPTABLE Only the first escaped write is observed, and the write to teh final field is observed, too | |
[0, 0, 1, 42] 102450 ACCEPTABLE Only the second escaped write is observed, and the write to teh final field is observed, too |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment