diff options
author | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2013-02-04 10:53:26 -0800 |
---|---|---|
committer | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2013-02-04 10:53:26 -0800 |
commit | 3d318be51f8e8cdec314565920327486212f5020 (patch) | |
tree | 93cd261e7435a9713e61b06aa55a5fdca8f0ae84 /test | |
parent | 8d25d05e9bf848d763e7b657d9c7e96ea5cb8daf (diff) | |
parent | 4fda83f8b02101a37871eadda9a13c70fd22bd2d (diff) | |
download | scala-3d318be51f8e8cdec314565920327486212f5020.tar.gz scala-3d318be51f8e8cdec314565920327486212f5020.tar.bz2 scala-3d318be51f8e8cdec314565920327486212f5020.zip |
Merge pull request #2001 from JamesIry/2.10.x_SI-5313
SI-5313 Do not eliminate stores that potentially wipe referenes
Diffstat (limited to 'test')
-rw-r--r-- | test/files/run/t5313.check | 12 | ||||
-rw-r--r-- | test/files/run/t5313.scala | 54 |
2 files changed, 66 insertions, 0 deletions
diff --git a/test/files/run/t5313.check b/test/files/run/t5313.check new file mode 100644 index 0000000000..7a48b2b711 --- /dev/null +++ b/test/files/run/t5313.check @@ -0,0 +1,12 @@ +STORE_LOCAL(variable kept1) +STORE_LOCAL(value result) +STORE_LOCAL(variable kept1) +STORE_LOCAL(variable kept2) +STORE_LOCAL(value kept3) +STORE_LOCAL(variable kept2) +STORE_LOCAL(variable kept4) +STORE_LOCAL(variable kept4) +STORE_LOCAL(variable kept5) +STORE_LOCAL(variable kept5) +STORE_LOCAL(variable kept6) +STORE_LOCAL(variable kept6) diff --git a/test/files/run/t5313.scala b/test/files/run/t5313.scala new file mode 100644 index 0000000000..7da8726a1f --- /dev/null +++ b/test/files/run/t5313.scala @@ -0,0 +1,54 @@ +import scala.tools.partest.IcodeTest + +object Test extends IcodeTest { + override def printIcodeAfterPhase = "dce" + + override def extraSettings: String = super.extraSettings + " -optimize" + + override def code = + """class Foo { + def randomBoolean = util.Random.nextInt % 2 == 0 + def bar = { + var kept1 = new Object + val result = new java.lang.ref.WeakReference(kept1) + kept1 = null // we can't eliminate this assigment because result can observe + // when the object has no more references. See SI-5313 + kept1 = new Object // but we can eliminate this one because kept1 has already been clobbered + var erased2 = null // we can eliminate this store because it's never used + val erased3 = erased2 // and this + var erased4 = erased2 // and this + val erased5 = erased4 // and this + var kept2: Object = new Object // ultimately can't be eliminated + while(randomBoolean) { + val kept3 = kept2 + kept2 = null // this can't, because it clobbers kept2, which is used + erased4 = null // safe to eliminate + println(kept3) + } + var kept4 = new Object // have to keep, it's used + try + println(kept4) + catch { + case _ : Throwable => kept4 = null // have to keep, it clobbers kept4 which is used + } + var kept5 = new Object + print(kept5) + kept5 = null // can't eliminate it's a clobber and it's used + print(kept5) + kept5 = null // can eliminate because we don't care about clobbers of nulls + while(randomBoolean) { + var kept6: AnyRef = null // not used, but have to keep because it clobbers the next used store + // on the back edge of the loop + kept6 = new Object // used + println(kept6) + } + result + } + }""".stripMargin + + override def show() { + val storeLocal = "STORE_LOCAL" + val lines1 = collectIcode("") filter (_ contains storeLocal) map (x => x.drop(x.indexOf(storeLocal))) + println(lines1 mkString "\n") + } +} |